2024-03-14 12:28:08 +11:00
|
|
|
import { cached, tracked } from "@glimmer/tracking";
|
2025-02-04 14:57:28 +08:00
|
|
|
import { dasherize } from "@ember/string";
|
2025-01-13 13:02:49 +00:00
|
|
|
import { snakeCaseToCamelCase } from "discourse/lib/case-converter";
|
2024-11-19 20:45:18 +00:00
|
|
|
import I18n, { i18n } from "discourse-i18n";
|
2023-08-28 10:48:59 +10:00
|
|
|
|
|
|
|
export default class AdminPlugin {
|
|
|
|
static create(args = {}) {
|
|
|
|
return new AdminPlugin(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
@tracked enabled;
|
|
|
|
|
|
|
|
constructor(args = {}) {
|
2024-07-05 13:22:48 +10:00
|
|
|
Object.keys(args).forEach((key) => {
|
|
|
|
this[snakeCaseToCamelCase(key)] = args[key];
|
|
|
|
});
|
2023-08-28 10:48:59 +10:00
|
|
|
}
|
|
|
|
|
2024-05-22 11:34:12 +10:00
|
|
|
get useNewShowRoute() {
|
|
|
|
return this.adminRoute?.use_new_show_route;
|
|
|
|
}
|
|
|
|
|
2023-11-23 08:40:55 +10:00
|
|
|
get snakeCaseName() {
|
|
|
|
return this.name.replaceAll("-", "_");
|
|
|
|
}
|
2023-08-28 10:48:59 +10:00
|
|
|
|
2024-10-08 08:28:32 +10:00
|
|
|
get dasherizedName() {
|
|
|
|
return dasherize(this.name);
|
2024-09-30 14:35:23 +10:00
|
|
|
}
|
|
|
|
|
2023-11-23 08:40:55 +10:00
|
|
|
get translatedCategoryName() {
|
2023-08-28 10:48:59 +10:00
|
|
|
// 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.
|
2023-11-23 08:40:55 +10:00
|
|
|
return I18n.lookup(`admin.site_settings.categories.${this.snakeCaseName}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
get settingCategoryName() {
|
|
|
|
if (this.translatedCategoryName) {
|
|
|
|
return this.snakeCaseName;
|
2023-08-28 10:48:59 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
return "plugins";
|
|
|
|
}
|
2023-11-21 09:37:11 +10:00
|
|
|
|
2024-03-14 12:28:08 +11:00
|
|
|
@cached
|
2023-11-21 09:37:11 +10:00
|
|
|
get nameTitleized() {
|
2025-02-04 14:57:28 +08:00
|
|
|
return this.translatedCategoryName || this.humanizedName;
|
2023-11-21 09:37:11 +10:00
|
|
|
}
|
|
|
|
|
2024-03-14 12:28:08 +11:00
|
|
|
@cached
|
|
|
|
get nameTitleizedLower() {
|
|
|
|
return this.nameTitleized.toLowerCase();
|
|
|
|
}
|
|
|
|
|
2023-11-21 09:37:11 +10:00
|
|
|
get author() {
|
|
|
|
if (this.isOfficial || this.isDiscourseOwned) {
|
2024-11-19 20:45:18 +00:00
|
|
|
return i18n("admin.plugins.author", { author: "Discourse" });
|
2023-11-21 09:37:11 +10:00
|
|
|
}
|
|
|
|
|
2024-11-19 20:45:18 +00:00
|
|
|
return i18n("admin.plugins.author", { author: this.authors });
|
2023-11-21 09:37:11 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
get linkUrl() {
|
|
|
|
return this.metaUrl || this.url;
|
|
|
|
}
|
2023-08-28 10:48:59 +10:00
|
|
|
}
|