mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 09:34:17 +08:00
70f7c0ee6f
This commit changes the API for registering the plugin config page nav configuration from a server-side to a JS one; there is no need for it to be server-side. It also makes some changes to allow for 2 different ways of displaying navigation for plugin pages, depending on complexity: * TOP - This is the best mode for simple plugins without a lot of different custom configuration pages, and it reuses the grey horizontal nav bar already used for admins. * SIDEBAR - This is better for more complex plugins; likely this won't be used in the near future, but it's readily available if needed There is a new AdminPluginConfigNavManager service too to manage which plugin the admin is actively viewing, otherwise we would have trouble hiding the main plugin nav for admins when viewing a single plugin.
99 lines
2.7 KiB
JavaScript
99 lines
2.7 KiB
JavaScript
import { cached, tracked } from "@glimmer/tracking";
|
|
import { capitalize } from "@ember/string";
|
|
import I18n from "discourse-i18n";
|
|
|
|
export default class AdminPlugin {
|
|
static create(args = {}) {
|
|
return new AdminPlugin(args);
|
|
}
|
|
|
|
@tracked enabled;
|
|
|
|
constructor(args = {}) {
|
|
this.about = args.about;
|
|
this.adminRoute = args.admin_route;
|
|
this.commitHash = args.commit_hash;
|
|
this.commitUrl = args.commit_url;
|
|
this.enabled = args.enabled;
|
|
this.enabledSetting = args.enabled_setting;
|
|
this.hasSettings = args.has_settings;
|
|
this.id = args.id;
|
|
this.isOfficial = args.is_official;
|
|
this.isDiscourseOwned = args.is_discourse_owned;
|
|
this.label = args.label;
|
|
this.name = args.name;
|
|
this.url = args.url;
|
|
this.version = args.version;
|
|
this.metaUrl = args.meta_url;
|
|
this.authors = args.authors;
|
|
}
|
|
|
|
get snakeCaseName() {
|
|
return this.name.replaceAll("-", "_");
|
|
}
|
|
|
|
get translatedCategoryName() {
|
|
// We do this because the site setting list is grouped by category,
|
|
// with plugins that have their root site setting key defined as `plugins:`
|
|
// being grouped under the generic "plugins" category.
|
|
//
|
|
// If a site setting has defined a proper root key and translated category name,
|
|
// we can use that instead to go directly to the setting category.
|
|
//
|
|
// Over time, no plugins should be missing this data.
|
|
return I18n.lookup(`admin.site_settings.categories.${this.snakeCaseName}`);
|
|
}
|
|
|
|
get settingCategoryName() {
|
|
if (this.translatedCategoryName) {
|
|
return this.snakeCaseName;
|
|
}
|
|
|
|
return "plugins";
|
|
}
|
|
|
|
@cached
|
|
get nameTitleized() {
|
|
// The category name is better in a lot of cases, as it's a human-inputted
|
|
// translation, and we can handle things like SAML instead of showing them
|
|
// as Saml from discourse-saml. We can fall back to the programmatic version
|
|
// though if needed.
|
|
let name;
|
|
if (this.translatedCategoryName) {
|
|
name = this.translatedCategoryName;
|
|
} else {
|
|
name = this.name
|
|
.split("-")
|
|
.map((word) => {
|
|
return capitalize(word);
|
|
})
|
|
.join(" ");
|
|
}
|
|
|
|
// Cuts down on repetition.
|
|
const discoursePrefix = "Discourse ";
|
|
if (name.startsWith(discoursePrefix)) {
|
|
name = name.slice(discoursePrefix.length);
|
|
}
|
|
|
|
return name;
|
|
}
|
|
|
|
@cached
|
|
get nameTitleizedLower() {
|
|
return this.nameTitleized.toLowerCase();
|
|
}
|
|
|
|
get author() {
|
|
if (this.isOfficial || this.isDiscourseOwned) {
|
|
return I18n.t("admin.plugins.author", { author: "Discourse" });
|
|
}
|
|
|
|
return I18n.t("admin.plugins.author", { author: this.authors });
|
|
}
|
|
|
|
get linkUrl() {
|
|
return this.metaUrl || this.url;
|
|
}
|
|
}
|