discourse/app/assets/javascripts/admin/addon/routes/admin-customize-themes-show.js
Alan Guo Xiang Tan 94b09f3331
DEV: Open theme settings objects editor from admin customize theme page (#26006)
Why this change?

The `/admin/customize/themes/:id/schema/name` route is a work in
progress but we want to be able to start navigating to it from the
`/admin/customize/themes/:id` route.

What does this change do?

1. Move `adminCustomizeThemes.schema` to a child route of
   `adminCustomizeThemes.show`. This is because we need the model
   from the parent route and if it isn't a child route we end up
   having to load the theme model again from the server.

1. Add the `objects_schema` attribute to `ThemeSettingsSerializer`

1. Refactor `SiteSettingComponent` to be able to render a button
   so that we don't have to hardcode the button rendering into the
   `SiteSettings::String` component
2024-03-06 08:24:29 +08:00

84 lines
2.1 KiB
JavaScript

import { action } from "@ember/object";
import Route from "@ember/routing/route";
import { inject as 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) {
super.setupController(...arguments);
const parentController = this.controllerFor("adminCustomizeThemes");
parentController.setProperties({
editingTheme: false,
currentTab: model.get("component") ? COMPONENTS : THEMES,
});
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,
});
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.t("admin.customize.theme.unsaved_parent_themes"),
didConfirm: () => {
model.set("recentlyInstalled", false);
transition.retry();
},
didCancel: () => model.set("recentlyInstalled", false),
});
}
}
}