mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 13:35:47 +08:00
feat: add Admin.generalIndexItems
extender (#4068)
* feat: add `Admin.generalIndexItems` extender * docs
This commit is contained in:
parent
77f3685033
commit
f83020cd1f
|
@ -27,5 +27,26 @@ export default [
|
||||||
help: app.translator.trans('flarum-extension-manager.admin.settings.task_retention_days_help'),
|
help: app.translator.trans('flarum-extension-manager.admin.settings.task_retention_days_help'),
|
||||||
type: 'number',
|
type: 'number',
|
||||||
}))
|
}))
|
||||||
.page(SettingsPage),
|
.page(SettingsPage)
|
||||||
|
.generalIndexItems('settings', () => [
|
||||||
|
{
|
||||||
|
id: 'minimum-stability',
|
||||||
|
label: app.translator.trans('flarum-extension-manager.admin.composer.minimum_stability.label', {}, true),
|
||||||
|
help: app.translator.trans('flarum-extension-manager.admin.composer.minimum_stability.help', {}, true),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'repositories',
|
||||||
|
label: app.translator.trans('flarum-extension-manager.admin.composer.repositories.label', {}, true),
|
||||||
|
help: app.translator.trans('flarum-extension-manager.admin.composer.repositories.help', {}, true),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'composer-auth',
|
||||||
|
label: app.translator.trans('flarum-extension-manager.admin.auth_config.title', {}, true),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'updates',
|
||||||
|
label: app.translator.trans('flarum-extension-manager.admin.updater.updater_title', {}, true),
|
||||||
|
help: app.translator.trans('flarum-extension-manager.admin.updater.updater_help', {}, true),
|
||||||
|
},
|
||||||
|
]),
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,9 +1,28 @@
|
||||||
export type GeneralIndexItem = {
|
export type GeneralIndexItem = {
|
||||||
|
/**
|
||||||
|
* The unique identifier for this index item.
|
||||||
|
*/
|
||||||
id: string;
|
id: string;
|
||||||
|
/**
|
||||||
|
* Optional: The tree path to this item, used for grouping in the search results.
|
||||||
|
*/
|
||||||
tree?: string[];
|
tree?: string[];
|
||||||
|
/**
|
||||||
|
* The label to display in the search results.
|
||||||
|
*/
|
||||||
label: string;
|
label: string;
|
||||||
|
/**
|
||||||
|
* Optional: The description to display in the search results.
|
||||||
|
*/
|
||||||
help?: string;
|
help?: string;
|
||||||
|
/**
|
||||||
|
* Optional: The URL to navigate to when this item is selected.
|
||||||
|
* The default is to navigate to the extension page.
|
||||||
|
*/
|
||||||
link?: string;
|
link?: string;
|
||||||
|
/**
|
||||||
|
* Optional: A callback that returns a boolean indicating whether this item should be visible in the search results.
|
||||||
|
*/
|
||||||
visible?: () => boolean;
|
visible?: () => boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,14 @@ import IExtender, { IExtensionModule } from './IExtender';
|
||||||
import type AdminApplication from '../../admin/AdminApplication';
|
import type AdminApplication from '../../admin/AdminApplication';
|
||||||
import type { CustomExtensionPage, SettingConfigInternal } from '../../admin/utils/AdminRegistry';
|
import type { CustomExtensionPage, SettingConfigInternal } from '../../admin/utils/AdminRegistry';
|
||||||
import type { PermissionConfig, PermissionType } from '../../admin/components/PermissionGrid';
|
import type { PermissionConfig, PermissionType } from '../../admin/components/PermissionGrid';
|
||||||
import Mithril from 'mithril';
|
import type Mithril from 'mithril';
|
||||||
|
import type { GeneralIndexItem } from '../../admin/states/GeneralSearchIndex';
|
||||||
|
|
||||||
export default class Admin implements IExtender<AdminApplication> {
|
export default class Admin implements IExtender<AdminApplication> {
|
||||||
protected settings: { setting?: () => SettingConfigInternal; customSetting?: () => Mithril.Children; priority: number }[] = [];
|
protected settings: { setting?: () => SettingConfigInternal; customSetting?: () => Mithril.Children; priority: number }[] = [];
|
||||||
protected permissions: { permission: () => PermissionConfig; type: PermissionType; priority: number }[] = [];
|
protected permissions: { permission: () => PermissionConfig; type: PermissionType; priority: number }[] = [];
|
||||||
protected customPage: CustomExtensionPage | null = null;
|
protected customPage: CustomExtensionPage | null = null;
|
||||||
|
protected generalIndexes: { settings?: () => GeneralIndexItem[]; permissions?: () => GeneralIndexItem[] } = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a setting to be shown on the extension's settings page.
|
* Register a setting to be shown on the extension's settings page.
|
||||||
|
@ -45,6 +47,15 @@ export default class Admin implements IExtender<AdminApplication> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a custom general search index entry.
|
||||||
|
*/
|
||||||
|
generalIndexItems(type: 'settings' | 'permissions', items: () => GeneralIndexItem[]) {
|
||||||
|
this.generalIndexes[type] = items;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
extend(app: AdminApplication, extension: IExtensionModule) {
|
extend(app: AdminApplication, extension: IExtensionModule) {
|
||||||
app.registry.for(extension.name);
|
app.registry.for(extension.name);
|
||||||
|
|
||||||
|
@ -59,5 +70,17 @@ export default class Admin implements IExtender<AdminApplication> {
|
||||||
if (this.customPage) {
|
if (this.customPage) {
|
||||||
app.registry.registerPage(this.customPage);
|
app.registry.registerPage(this.customPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.generalIndex.for(extension.name);
|
||||||
|
|
||||||
|
Object.keys(this.generalIndexes).forEach((key) => {
|
||||||
|
if (key !== 'settings' && key !== 'permissions') return;
|
||||||
|
|
||||||
|
const callback = this.generalIndexes[key];
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
app.generalIndex.add(key, callback());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user