discourse/app/assets/javascripts/admin/addon/routes/admin-customize-themes.js
Godfrey Chan c34f8b65cb
DEV: Rename I18n imports to discourse-i18n (#23915)
As of #23867 this is now a real package, so updating the imports to
use the real package name, rather than relying on the alias. The
name change in the package name is because `I18n` is not a valid
name as NPM packages must be all lowercase.

This commit also introduces an eslint rule to prevent importing from
the old I18n path.

For themes/plugins, the old 'i18n' name remains functional.
2023-10-18 11:07:09 +01:00

101 lines
2.4 KiB
JavaScript

import { action } from "@ember/object";
import Route from "@ember/routing/route";
import { next } from "@ember/runloop";
import { inject as service } from "@ember/service";
import I18n from "discourse-i18n";
import InstallThemeModal from "../components/modal/install-theme";
export default class AdminCustomizeThemesRoute extends Route {
@service dialog;
@service router;
@service modal;
queryParams = {
repoUrl: null,
repoName: null,
};
model() {
return this.store.findAll("theme");
}
setupController(controller, model) {
super.setupController(controller, model);
controller.set("editingTheme", false);
if (controller.repoUrl) {
next(() => {
this.modal.show(InstallThemeModal, {
model: {
uploadUrl: controller.repoUrl,
uploadName: controller.repoName,
selection: "directRepoInstall",
clearParams: this.clearParams,
...this.installThemeOptions(model),
},
});
});
}
}
installThemeOptions(model) {
return {
selectedType: this.controller.currentTab,
userId: model.userId,
content: model.content,
installedThemes: this.controller.installedThemes,
addTheme: this.addTheme,
updateSelectedType: this.updateSelectedType,
};
}
@action
routeRefreshModel() {
this.refresh();
}
@action
installModal() {
const currentTheme = this.modelFor("adminCustomizeThemes");
if (this.currentModel?.warnUnassignedComponent) {
this.dialog.yesNoConfirm({
message: I18n.t("admin.customize.theme.unsaved_parent_themes"),
didConfirm: () => {
currentTheme.set("recentlyInstalled", false);
this.modal.show(InstallThemeModal, {
model: { ...this.installThemeOptions(currentTheme) },
});
},
});
} else {
this.modal.show(InstallThemeModal, {
model: { ...this.installThemeOptions(currentTheme) },
});
}
}
@action
updateSelectedType(type) {
this.controller.set("currentTab", type);
}
@action
clearParams() {
this.controller.setProperties({
repoUrl: null,
repoName: null,
});
}
@action
addTheme(theme) {
this.refresh();
theme.setProperties({ recentlyInstalled: true });
this.router.transitionTo("adminCustomizeThemes.show", theme.get("id"), {
queryParams: {
repoName: null,
repoUrl: null,
},
});
}
}