2023-03-15 21:17:51 +08:00
|
|
|
import { action } from "@ember/object";
|
2019-10-24 00:39:32 +08:00
|
|
|
import Route from "@ember/routing/route";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { next } from "@ember/runloop";
|
|
|
|
import { inject as service } from "@ember/service";
|
2023-10-18 18:07:09 +08:00
|
|
|
import I18n from "discourse-i18n";
|
2023-08-03 23:52:04 +08:00
|
|
|
import InstallThemeModal from "../components/modal/install-theme";
|
2017-04-12 22:52:52 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
export default class AdminCustomizeThemesRoute extends Route {
|
|
|
|
@service dialog;
|
2023-07-19 03:52:55 +08:00
|
|
|
@service router;
|
2023-08-03 23:52:04 +08:00
|
|
|
@service modal;
|
2022-10-07 23:38:27 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
queryParams = {
|
2021-02-19 01:51:44 +08:00
|
|
|
repoUrl: null,
|
|
|
|
repoName: null,
|
2023-03-15 21:17:51 +08:00
|
|
|
};
|
2021-02-19 01:51:44 +08:00
|
|
|
|
2017-04-12 22:52:52 +08:00
|
|
|
model() {
|
|
|
|
return this.store.findAll("theme");
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2017-04-12 22:52:52 +08:00
|
|
|
|
|
|
|
setupController(controller, model) {
|
2023-03-15 21:17:51 +08:00
|
|
|
super.setupController(controller, model);
|
2017-04-12 22:52:52 +08:00
|
|
|
controller.set("editingTheme", false);
|
2021-02-19 01:51:44 +08:00
|
|
|
if (controller.repoUrl) {
|
|
|
|
next(() => {
|
2023-08-03 23:52:04 +08:00
|
|
|
this.modal.show(InstallThemeModal, {
|
|
|
|
model: {
|
|
|
|
uploadUrl: controller.repoUrl,
|
|
|
|
uploadName: controller.repoName,
|
|
|
|
selection: "directRepoInstall",
|
|
|
|
clearParams: this.clearParams,
|
|
|
|
...this.installThemeOptions(model),
|
|
|
|
},
|
2021-02-19 01:51:44 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2017-04-12 22:52:52 +08:00
|
|
|
|
2023-08-03 23:52:04 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
@action
|
|
|
|
installModal() {
|
2023-08-03 23:52:04 +08:00
|
|
|
const currentTheme = this.modelFor("adminCustomizeThemes");
|
|
|
|
if (this.currentModel?.warnUnassignedComponent) {
|
2023-03-15 21:17:51 +08:00
|
|
|
this.dialog.yesNoConfirm({
|
|
|
|
message: I18n.t("admin.customize.theme.unsaved_parent_themes"),
|
|
|
|
didConfirm: () => {
|
|
|
|
currentTheme.set("recentlyInstalled", false);
|
2023-08-03 23:52:04 +08:00
|
|
|
this.modal.show(InstallThemeModal, {
|
|
|
|
model: { ...this.installThemeOptions(currentTheme) },
|
|
|
|
});
|
2021-02-19 01:51:44 +08:00
|
|
|
},
|
|
|
|
});
|
2023-03-15 21:17:51 +08:00
|
|
|
} else {
|
2023-08-03 23:52:04 +08:00
|
|
|
this.modal.show(InstallThemeModal, {
|
|
|
|
model: { ...this.installThemeOptions(currentTheme) },
|
|
|
|
});
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-03 23:52:04 +08:00
|
|
|
@action
|
|
|
|
updateSelectedType(type) {
|
|
|
|
this.controller.set("currentTab", type);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
clearParams() {
|
|
|
|
this.controller.setProperties({
|
|
|
|
repoUrl: null,
|
|
|
|
repoName: null,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
@action
|
|
|
|
addTheme(theme) {
|
|
|
|
this.refresh();
|
|
|
|
theme.setProperties({ recentlyInstalled: true });
|
2023-07-19 03:52:55 +08:00
|
|
|
this.router.transitionTo("adminCustomizeThemes.show", theme.get("id"), {
|
2023-03-15 21:17:51 +08:00
|
|
|
queryParams: {
|
|
|
|
repoName: null,
|
|
|
|
repoUrl: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|