2023-08-28 08:48:59 +08:00
|
|
|
import { tracked } from "@glimmer/tracking";
|
2023-11-21 07:37:11 +08:00
|
|
|
import { capitalize } from "@ember/string";
|
2023-10-18 18:07:09 +08:00
|
|
|
import I18n from "discourse-i18n";
|
2023-08-28 08:48:59 +08:00
|
|
|
|
|
|
|
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;
|
2023-11-21 07:37:11 +08:00
|
|
|
this.isDiscourseOwned = args.is_discourse_owned;
|
2023-11-30 08:53:17 +08:00
|
|
|
this.label = args.label;
|
2023-08-28 08:48:59 +08:00
|
|
|
this.name = args.name;
|
|
|
|
this.url = args.url;
|
|
|
|
this.version = args.version;
|
2023-10-10 08:16:13 +08:00
|
|
|
this.metaUrl = args.meta_url;
|
2023-11-21 07:37:11 +08:00
|
|
|
this.authors = args.authors;
|
2023-08-28 08:48:59 +08:00
|
|
|
}
|
|
|
|
|
2023-11-23 06:40:55 +08:00
|
|
|
get snakeCaseName() {
|
|
|
|
return this.name.replaceAll("-", "_");
|
|
|
|
}
|
2023-08-28 08:48:59 +08:00
|
|
|
|
2023-11-23 06:40:55 +08:00
|
|
|
get translatedCategoryName() {
|
2023-08-28 08:48:59 +08: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 06:40:55 +08:00
|
|
|
return I18n.lookup(`admin.site_settings.categories.${this.snakeCaseName}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
get settingCategoryName() {
|
|
|
|
if (this.translatedCategoryName) {
|
|
|
|
return this.snakeCaseName;
|
2023-08-28 08:48:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return "plugins";
|
|
|
|
}
|
2023-11-21 07:37:11 +08:00
|
|
|
|
|
|
|
get nameTitleized() {
|
2023-11-23 06:40:55 +08:00
|
|
|
// 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 programattic version
|
|
|
|
// though if needed.
|
2023-11-30 08:53:17 +08:00
|
|
|
let name;
|
2023-11-23 06:40:55 +08:00
|
|
|
if (this.translatedCategoryName) {
|
2023-11-30 08:53:17 +08:00
|
|
|
name = this.translatedCategoryName;
|
|
|
|
} else {
|
|
|
|
name = this.name
|
|
|
|
.split("-")
|
|
|
|
.map((word) => {
|
|
|
|
return capitalize(word);
|
|
|
|
})
|
|
|
|
.join(" ");
|
2023-11-23 06:40:55 +08:00
|
|
|
}
|
|
|
|
|
2023-11-30 08:53:17 +08:00
|
|
|
// Cuts down on repetition.
|
|
|
|
const discoursePrefix = "Discourse ";
|
|
|
|
if (name.startsWith(discoursePrefix)) {
|
|
|
|
name = name.slice(discoursePrefix.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
2023-11-21 07:37:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2023-08-28 08:48:59 +08:00
|
|
|
}
|