discourse/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show.js
Osama Sayegh d4cbdf3ee0
FIX: Restore old admin themes/components page (#31887)
Follow-up to https://github.com/discourse/discourse/pull/30953

This PR is a partial revert of the linked PR — it changes the "Themes
and components" link in the admin sidebar back to the legacy
`/admin/customize/themes` page and adds the themes list/sidebar back to
the left hand side of the page. The new `/admin/config/customize/` route
is still available, but it's not linked from anywhere. When accessing
the new page and then navigating to a theme, the old components (e.g.
the themes list) of the page are hidden. This allows us to iterate on
the new page and improve until we're more ready to make it available
more widely.
2025-03-19 16:18:26 +03:00

91 lines
2.3 KiB
JavaScript
Vendored

import { action } from "@ember/object";
import Route from "@ember/routing/route";
import { service } from "@ember/service";
import { scrollTop } from "discourse/mixins/scroll-top";
import { i18n } from "discourse-i18n";
import { COMPONENTS, THEMES } from "admin/models/theme";
export default class AdminCustomizeThemesShowRoute extends Route {
@service dialog;
@service router;
serialize(model) {
return { theme_id: model.get("id") };
}
model(params) {
const all = this.modelFor("adminCustomizeThemes");
const model = all.findBy("id", parseInt(params.theme_id, 10));
if (model) {
return model;
} else {
this.router.replaceWith("adminCustomizeThemes.index");
}
}
setupController(controller, model, transition) {
super.setupController(...arguments);
const parentController = this.controllerFor("adminCustomizeThemes");
const fromNewConfigPage = [
"adminConfig.customize.themes",
"adminConfig.customize.components",
].includes(transition?.from?.name);
parentController.setProperties({
editingTheme: false,
currentTab: model.get("component") ? COMPONENTS : THEMES,
fromNewConfigPage,
});
controller.setProperties({
model,
parentController,
allThemes: parentController.get("model"),
colorSchemeId: model.get("color_scheme_id"),
colorSchemes: parentController.get("model.extras.color_schemes"),
editingName: false,
editingThemeSetting: false,
userLocale: parentController.get("model.extras.locale"),
fromNewConfigPage,
});
this.handleHighlight(model);
}
deactivate() {
this.handleHighlight();
}
handleHighlight(theme) {
this.get("controller.allThemes")
.filter((t) => t.get("selected"))
.forEach((t) => t.set("selected", false));
if (theme) {
theme.set("selected", true);
}
}
@action
didTransition() {
scrollTop();
}
@action
willTransition(transition) {
const model = this.controller.model;
if (model.warnUnassignedComponent) {
transition.abort();
this.dialog.yesNoConfirm({
message: i18n("admin.customize.theme.unsaved_parent_themes"),
didConfirm: () => {
model.set("recentlyInstalled", false);
transition.retry();
},
didCancel: () => model.set("recentlyInstalled", false),
});
}
}
}