discourse/app/assets/javascripts/admin/addon/models/admin-plugin.js
Martin Brennan b58f660cd2
DEV: Add meta_topic_id plugin metadata (#23838)
For the admin plugin list we want to be able to link to
a meta topic for plugins, but we have no standard way to
do this at the moment. This adds support for meta_topic_id
alongside other plugin metadata like authors, URL etc,
that gets built into a Meta topic URL in the serializer.
2023-10-10 10:16:13 +10:00

48 lines
1.4 KiB
JavaScript

import { tracked } from "@glimmer/tracking";
import I18n from "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.name = args.name;
this.url = args.url;
this.version = args.version;
this.metaUrl = args.meta_url;
}
get settingCategoryName() {
const snakeCaseName = this.name.replaceAll("-", "_");
// 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.
const translationAttempt = I18n.lookup(
`admin.site_settings.categories.${snakeCaseName}`
);
if (translationAttempt) {
return snakeCaseName;
}
return "plugins";
}
}