DEV: Update admin routes to native class syntax (#20686)

This commit is contained in:
David Taylor 2023-03-15 13:17:51 +00:00 committed by GitHub
parent 7288bc277b
commit e700f0af93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
71 changed files with 583 additions and 559 deletions

View File

@ -1,7 +1,7 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default class AdminApiIndexRoute extends Route {
beforeModel() { beforeModel() {
this.transitionTo("adminApiKeys"); this.transitionTo("adminApiKeys");
}, }
}); }

View File

@ -1,7 +1,7 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default class AdminApiKeysIndexRoute extends Route {
model() { model() {
return this.store.findAll("api-key"); return this.store.findAll("api-key");
}, }
}); }

View File

@ -1,7 +1,7 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default class AdminApiKeysNewRoute extends Route {
model() { model() {
return this.store.createRecord("api-key"); return this.store.createRecord("api-key");
}, }
}); }

View File

@ -1,7 +1,7 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default class AdminApiKeysShowRoute extends Route {
model(params) { model(params) {
return this.store.find("api-key", params.api_key_id); return this.store.find("api-key", params.api_key_id);
}, }
}); }

View File

@ -1,13 +1,14 @@
import { action } from "@ember/object";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default class AdminApiKeysRoute extends Route {
actions: { @action
show(apiKey) { show(apiKey) {
this.transitionTo("adminApiKeys.show", apiKey.id); this.transitionTo("adminApiKeys.show", apiKey.id);
}, }
new() { @action
this.transitionTo("adminApiKeys.new"); new() {
}, this.transitionTo("adminApiKeys.new");
}, }
}); }

View File

@ -2,20 +2,20 @@ import Backup from "admin/models/backup";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import { bind } from "discourse-common/utils/decorators"; import { bind } from "discourse-common/utils/decorators";
export default Route.extend({ export default class AdminBackupsIndexRoute extends Route {
activate() { activate() {
this.messageBus.subscribe("/admin/backups", this.onMessage); this.messageBus.subscribe("/admin/backups", this.onMessage);
}, }
deactivate() { deactivate() {
this.messageBus.unsubscribe("/admin/backups", this.onMessage); this.messageBus.unsubscribe("/admin/backups", this.onMessage);
}, }
model() { model() {
return Backup.find().then((backups) => return Backup.find().then((backups) =>
backups.map((backup) => Backup.create(backup)) backups.map((backup) => Backup.create(backup))
); );
}, }
@bind @bind
onMessage(backups) { onMessage(backups) {
@ -23,5 +23,5 @@ export default Route.extend({
"model", "model",
backups.map((backup) => Backup.create(backup)) backups.map((backup) => Backup.create(backup))
); );
}, }
}); }

View File

@ -2,7 +2,7 @@ import EmberObject from "@ember/object";
import PreloadStore from "discourse/lib/preload-store"; import PreloadStore from "discourse/lib/preload-store";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default class AdminBackupsLogsRoute extends Route {
// since the logs are pushed via the message bus // since the logs are pushed via the message bus
// we only want to preload them (hence the beforeModel hook) // we only want to preload them (hence the beforeModel hook)
beforeModel() { beforeModel() {
@ -20,9 +20,9 @@ export default Route.extend({
logs.pushObjects(newLogs); logs.pushObjects(newLogs);
} }
}); });
}, }
setupController() { setupController() {
/* prevent default behavior */ /* prevent default behavior */
}, }
}); }

View File

@ -1,7 +1,8 @@
import { inject as service } from "@ember/service";
import Backup from "admin/models/backup"; import Backup from "admin/models/backup";
import BackupStatus from "admin/models/backup-status"; import BackupStatus from "admin/models/backup-status";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import EmberObject from "@ember/object"; import EmberObject, { action } from "@ember/object";
import I18n from "I18n"; import I18n from "I18n";
import PreloadStore from "discourse/lib/preload-store"; import PreloadStore from "discourse/lib/preload-store";
import User from "discourse/models/user"; import User from "discourse/models/user";
@ -9,21 +10,20 @@ import { ajax } from "discourse/lib/ajax";
import { extractError } from "discourse/lib/ajax-error"; import { extractError } from "discourse/lib/ajax-error";
import getURL from "discourse-common/lib/get-url"; import getURL from "discourse-common/lib/get-url";
import showModal from "discourse/lib/show-modal"; import showModal from "discourse/lib/show-modal";
import { inject as service } from "@ember/service";
import { bind } from "discourse-common/utils/decorators"; import { bind } from "discourse-common/utils/decorators";
const LOG_CHANNEL = "/admin/backups/logs"; const LOG_CHANNEL = "/admin/backups/logs";
export default DiscourseRoute.extend({ export default class AdminBackupsRoute extends DiscourseRoute {
dialog: service(), @service dialog;
activate() { activate() {
this.messageBus.subscribe(LOG_CHANNEL, this.onMessage); this.messageBus.subscribe(LOG_CHANNEL, this.onMessage);
}, }
deactivate() { deactivate() {
this.messageBus.unsubscribe(LOG_CHANNEL, this.onMessage); this.messageBus.unsubscribe(LOG_CHANNEL, this.onMessage);
}, }
model() { model() {
return PreloadStore.getAndRemove("operations_status", () => return PreloadStore.getAndRemove("operations_status", () =>
@ -35,7 +35,7 @@ export default DiscourseRoute.extend({
allowRestore: status.allow_restore, allowRestore: status.allow_restore,
}) })
); );
}, }
@bind @bind
onMessage(log) { onMessage(log) {
@ -62,104 +62,111 @@ export default DiscourseRoute.extend({
.get("logs") .get("logs")
.pushObject(EmberObject.create(log)); .pushObject(EmberObject.create(log));
} }
}, }
actions: { @action
showStartBackupModal() { showStartBackupModal() {
showModal("admin-start-backup", { admin: true }); showModal("admin-start-backup", { admin: true });
}, }
startBackup(withUploads) { @action
this.transitionTo("admin.backups.logs"); startBackup(withUploads) {
Backup.start(withUploads).then((result) => { this.transitionTo("admin.backups.logs");
if (!result.success) { Backup.start(withUploads).then((result) => {
this.dialog.alert(result.message); if (!result.success) {
} this.dialog.alert(result.message);
}); }
}, });
}
destroyBackup(backup) { @action
return this.dialog.yesNoConfirm({ destroyBackup(backup) {
message: I18n.t("admin.backups.operations.destroy.confirm"), return this.dialog.yesNoConfirm({
didConfirm: () => { message: I18n.t("admin.backups.operations.destroy.confirm"),
backup didConfirm: () => {
.destroy() backup
.then(() => .destroy()
this.controllerFor("adminBackupsIndex") .then(() =>
.get("model") this.controllerFor("adminBackupsIndex")
.removeObject(backup) .get("model")
); .removeObject(backup)
},
});
},
startRestore(backup) {
this.dialog.yesNoConfirm({
message: I18n.t("admin.backups.operations.restore.confirm"),
didConfirm: () => {
this.transitionTo("admin.backups.logs");
backup.restore();
},
});
},
cancelOperation() {
this.dialog.yesNoConfirm({
message: I18n.t("admin.backups.operations.cancel.confirm"),
didConfirm: () => {
Backup.cancel().then(() => {
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
false
);
});
},
});
},
rollback() {
return this.dialog.yesNoConfirm({
message: I18n.t("admin.backups.operations.rollback.confirm"),
didConfirm: () => {
Backup.rollback().then((result) => {
if (!result.success) {
this.dialog.alert(result.message);
} else {
// redirect to homepage (session might be lost)
window.location = getURL("/");
}
});
},
});
},
uploadSuccess(filename) {
this.dialog.alert(I18n.t("admin.backups.upload.success", { filename }));
},
uploadError(filename, message) {
this.dialog.alert(
I18n.t("admin.backups.upload.error", { filename, message })
);
},
remoteUploadSuccess() {
Backup.find()
.then((backups) => backups.map((backup) => Backup.create(backup)))
.then((backups) => {
this.controllerFor("adminBackupsIndex").set(
"model",
backups.map((backup) => Backup.create(backup))
); );
}) },
.catch((error) => { });
this.dialog.alert( }
I18n.t("admin.backups.backup_storage_error", {
error_message: extractError(error), @action
}) startRestore(backup) {
this.dialog.yesNoConfirm({
message: I18n.t("admin.backups.operations.restore.confirm"),
didConfirm: () => {
this.transitionTo("admin.backups.logs");
backup.restore();
},
});
}
@action
cancelOperation() {
this.dialog.yesNoConfirm({
message: I18n.t("admin.backups.operations.cancel.confirm"),
didConfirm: () => {
Backup.cancel().then(() => {
this.controllerFor("adminBackups").set(
"model.isOperationRunning",
false
); );
return [];
}); });
}, },
}, });
}); }
@action
rollback() {
return this.dialog.yesNoConfirm({
message: I18n.t("admin.backups.operations.rollback.confirm"),
didConfirm: () => {
Backup.rollback().then((result) => {
if (!result.success) {
this.dialog.alert(result.message);
} else {
// redirect to homepage (session might be lost)
window.location = getURL("/");
}
});
},
});
}
@action
uploadSuccess(filename) {
this.dialog.alert(I18n.t("admin.backups.upload.success", { filename }));
}
@action
uploadError(filename, message) {
this.dialog.alert(
I18n.t("admin.backups.upload.error", { filename, message })
);
}
@action
remoteUploadSuccess() {
Backup.find()
.then((backups) => backups.map((backup) => Backup.create(backup)))
.then((backups) => {
this.controllerFor("adminBackupsIndex").set(
"model",
backups.map((backup) => Backup.create(backup))
);
})
.catch((error) => {
this.dialog.alert(
I18n.t("admin.backups.backup_storage_error", {
error_message: extractError(error),
})
);
return [];
});
}
}

View File

@ -1,17 +1,18 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({
export default class AdminCustomizeColorsShowRoute extends Route {
model(params) { model(params) {
const all = this.modelFor("adminCustomize.colors"); const all = this.modelFor("adminCustomize.colors");
const model = all.findBy("id", parseInt(params.scheme_id, 10)); const model = all.findBy("id", parseInt(params.scheme_id, 10));
return model ? model : this.replaceWith("adminCustomize.colors.index"); return model ? model : this.replaceWith("adminCustomize.colors.index");
}, }
serialize(model) { serialize(model) {
return { scheme_id: model.get("id") }; return { scheme_id: model.get("id") };
}, }
setupController(controller, model) { setupController(controller, model) {
controller.set("model", model); controller.set("model", model);
controller.set("allColors", this.modelFor("adminCustomize.colors")); controller.set("allColors", this.modelFor("adminCustomize.colors"));
}, }
}); }

View File

@ -1,12 +1,12 @@
import ColorScheme from "admin/models/color-scheme"; import ColorScheme from "admin/models/color-scheme";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default class AdminCustomizeColorsRoute extends Route {
model() { model() {
return ColorScheme.findAll(); return ColorScheme.findAll();
}, }
setupController(controller, model) { setupController(controller, model) {
controller.set("model", model); controller.set("model", model);
}, }
}); }

View File

@ -1,15 +1,17 @@
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import I18n from "I18n"; import I18n from "I18n";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import { inject as service } from "@ember/service";
export default Route.extend({ export default class AdminCustomizeEmailStyleEditRoute extends Route {
dialog: service(), @service dialog;
model(params) { model(params) {
return { return {
model: this.modelFor("adminCustomizeEmailStyle"), model: this.modelFor("adminCustomizeEmailStyle"),
fieldName: params.field_name, fieldName: params.field_name,
}; };
}, }
setupController(controller, model) { setupController(controller, model) {
controller.setProperties({ controller.setProperties({
@ -17,26 +19,25 @@ export default Route.extend({
model: model.model, model: model.model,
}); });
this._shouldAlertUnsavedChanges = true; this._shouldAlertUnsavedChanges = true;
}, }
actions: { @action
willTransition(transition) { willTransition(transition) {
if ( if (
this.get("controller.model.changed") && this.get("controller.model.changed") &&
this._shouldAlertUnsavedChanges && this._shouldAlertUnsavedChanges &&
transition.intent.name !== this.routeName transition.intent.name !== this.routeName
) { ) {
transition.abort(); transition.abort();
this.dialog.confirm({ this.dialog.confirm({
message: I18n.t("admin.customize.theme.unsaved_changes_alert"), message: I18n.t("admin.customize.theme.unsaved_changes_alert"),
confirmButtonLabel: "admin.customize.theme.discard", confirmButtonLabel: "admin.customize.theme.discard",
cancelButtonLabel: "admin.customize.theme.stay", cancelButtonLabel: "admin.customize.theme.stay",
didConfirm: () => { didConfirm: () => {
this._shouldAlertUnsavedChanges = false; this._shouldAlertUnsavedChanges = false;
transition.retry(); transition.retry();
}, },
}); });
} }
}, }
}, }
});

View File

@ -1,7 +1,7 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default class AdminCustomizeEmailStyleIndexRoute extends Route {
beforeModel() { beforeModel() {
this.replaceWith("adminCustomizeEmailStyle.edit", "html"); this.replaceWith("adminCustomizeEmailStyle.edit", "html");
}, }
}); }

View File

@ -1,7 +1,7 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default class AdminCustomizeEmailStyleRoute extends Route {
model() { model() {
return this.store.find("email-style"); return this.store.find("email-style");
}, }
}); }

View File

@ -1,18 +1,18 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import { scrollTop } from "discourse/mixins/scroll-top"; import { scrollTop } from "discourse/mixins/scroll-top";
export default Route.extend({ export default class AdminCustomizeEmailTemplatesEditRoute extends Route {
model(params) { model(params) {
const all = this.modelFor("adminCustomizeEmailTemplates"); const all = this.modelFor("adminCustomizeEmailTemplates");
return all.findBy("id", params.id); return all.findBy("id", params.id);
}, }
setupController(controller, emailTemplate) { setupController(controller, emailTemplate) {
controller.setProperties({ emailTemplate, saved: false }); controller.setProperties({ emailTemplate, saved: false });
scrollTop(); scrollTop();
}, }
deactivate() { deactivate() {
this.controller.set("emailTemplate", null); this.controller.set("emailTemplate", null);
}, }
}); }

View File

@ -1,14 +1,14 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import { action } from "@ember/object"; import { action } from "@ember/object";
export default Route.extend({ export default class AdminCustomizeEmailTemplatesRoute extends Route {
model() { model() {
return this.store.findAll("email-template"); return this.store.findAll("email-template");
}, }
setupController(controller, model) { setupController(controller, model) {
controller.set("emailTemplates", model); controller.set("emailTemplates", model);
}, }
@action @action
didTransition() { didTransition() {
@ -22,5 +22,5 @@ export default Route.extend({
this.controller.get("sortedTemplates.firstObject") this.controller.get("sortedTemplates.firstObject")
); );
} }
}, }
}); }

View File

@ -1,6 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { action } from "@ember/object"; import { action } from "@ember/object";
import FormTemplate from "admin/models/form-template"; import FormTemplate from "admin/models/form-template";
export default class AdminCustomizeFormTemplatesIndex extends DiscourseRoute { export default class AdminCustomizeFormTemplatesIndex extends DiscourseRoute {
model() { model() {
return FormTemplate.findAll(); return FormTemplate.findAll();

View File

@ -1,10 +1,11 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({
export default class AdminCustomizeIndexRoute extends Route {
beforeModel() { beforeModel() {
if (this.currentUser.admin) { if (this.currentUser.admin) {
this.transitionTo("adminCustomizeThemes"); this.transitionTo("adminCustomizeThemes");
} else { } else {
this.transitionTo("adminWatchedWords"); this.transitionTo("adminWatchedWords");
} }
}, }
}); }

View File

@ -1,8 +1,8 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
export default Route.extend({ export default class AdminCustomizeRobotsTxtRoute extends Route {
model() { model() {
return ajax("/admin/customize/robots"); return ajax("/admin/customize/robots");
}, }
}); }

View File

@ -1,9 +1,10 @@
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import I18n from "I18n"; import I18n from "I18n";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import { inject as service } from "@ember/service";
export default Route.extend({ export default class AdminCustomizeThemesEditRoute extends Route {
dialog: service(), @service dialog;
model(params) { model(params) {
const all = this.modelFor("adminCustomizeThemes"); const all = this.modelFor("adminCustomizeThemes");
@ -15,7 +16,7 @@ export default Route.extend({
field_name: params.field_name, field_name: params.field_name,
} }
: this.replaceWith("adminCustomizeThemes.index"); : this.replaceWith("adminCustomizeThemes.index");
}, }
serialize(wrapper) { serialize(wrapper) {
return { return {
@ -24,7 +25,7 @@ export default Route.extend({
field_name: wrapper.field_name || "scss", field_name: wrapper.field_name || "scss",
theme_id: wrapper.model.get("id"), theme_id: wrapper.model.get("id"),
}; };
}, }
setupController(controller, wrapper) { setupController(controller, wrapper) {
const fields = wrapper.model const fields = wrapper.model
@ -48,27 +49,26 @@ export default Route.extend({
controller.set("fieldName", wrapper.field_name || "scss"); controller.set("fieldName", wrapper.field_name || "scss");
this.controllerFor("adminCustomizeThemes").set("editingTheme", true); this.controllerFor("adminCustomizeThemes").set("editingTheme", true);
this.set("shouldAlertUnsavedChanges", true); this.set("shouldAlertUnsavedChanges", true);
}, }
actions: { @action
willTransition(transition) { willTransition(transition) {
if ( if (
this.get("controller.model.changed") && this.get("controller.model.changed") &&
this.shouldAlertUnsavedChanges && this.shouldAlertUnsavedChanges &&
transition.intent.name !== this.routeName transition.intent.name !== this.routeName
) { ) {
transition.abort(); transition.abort();
this.dialog.confirm({ this.dialog.confirm({
message: I18n.t("admin.customize.theme.unsaved_changes_alert"), message: I18n.t("admin.customize.theme.unsaved_changes_alert"),
confirmButtonLabel: "admin.customize.theme.discard", confirmButtonLabel: "admin.customize.theme.discard",
cancelButtonLabel: "admin.customize.theme.stay", cancelButtonLabel: "admin.customize.theme.stay",
didConfirm: () => { didConfirm: () => {
this.set("shouldAlertUnsavedChanges", false); this.set("shouldAlertUnsavedChanges", false);
transition.retry(); transition.retry();
}, },
}); });
} }
}, }
}, }
});

View File

@ -19,13 +19,13 @@ const externalResources = [
}, },
]; ];
export default Route.extend({ export default class AdminCustomizeThemesIndexRoute extends Route {
setupController(controller) { setupController(controller) {
this._super(...arguments); super.setupController(...arguments);
this.controllerFor("adminCustomizeThemes").set("editingTheme", false); this.controllerFor("adminCustomizeThemes").set("editingTheme", false);
controller.setProperties({ controller.setProperties({
externalResources, externalResources,
womanArtistEmojiURL: emojiUrlFor("woman_artist:t5"), womanArtistEmojiURL: emojiUrlFor("woman_artist:t5"),
}); });
}, }
}); }

View File

@ -1,24 +1,25 @@
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { COMPONENTS, THEMES } from "admin/models/theme"; import { COMPONENTS, THEMES } from "admin/models/theme";
import I18n from "I18n"; import I18n from "I18n";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import { scrollTop } from "discourse/mixins/scroll-top"; import { scrollTop } from "discourse/mixins/scroll-top";
import { inject as service } from "@ember/service";
export default Route.extend({ export default class AdminCustomizeThemesShowRoute extends Route {
dialog: service(), @service dialog;
serialize(model) { serialize(model) {
return { theme_id: model.get("id") }; return { theme_id: model.get("id") };
}, }
model(params) { model(params) {
const all = this.modelFor("adminCustomizeThemes"); const all = this.modelFor("adminCustomizeThemes");
const model = all.findBy("id", parseInt(params.theme_id, 10)); const model = all.findBy("id", parseInt(params.theme_id, 10));
return model ? model : this.replaceWith("adminCustomizeThemes.index"); return model ? model : this.replaceWith("adminCustomizeThemes.index");
}, }
setupController(controller, model) { setupController(controller, model) {
this._super(...arguments); super.setupController(...arguments);
const parentController = this.controllerFor("adminCustomizeThemes"); const parentController = this.controllerFor("adminCustomizeThemes");
@ -37,11 +38,11 @@ export default Route.extend({
}); });
this.handleHighlight(model); this.handleHighlight(model);
}, }
deactivate() { deactivate() {
this.handleHighlight(); this.handleHighlight();
}, }
handleHighlight(theme) { handleHighlight(theme) {
this.get("controller.allThemes") this.get("controller.allThemes")
@ -50,26 +51,27 @@ export default Route.extend({
if (theme) { if (theme) {
theme.set("selected", true); theme.set("selected", true);
} }
}, }
actions: { @action
didTransition() { didTransition() {
scrollTop(); scrollTop();
}, }
willTransition(transition) {
const model = this.controller.model;
if (model.warnUnassignedComponent) {
transition.abort();
this.dialog.yesNoConfirm({ @action
message: I18n.t("admin.customize.theme.unsaved_parent_themes"), willTransition(transition) {
didConfirm: () => { const model = this.controller.model;
model.set("recentlyInstalled", false); if (model.warnUnassignedComponent) {
transition.retry(); transition.abort();
},
didCancel: () => model.set("recentlyInstalled", false), this.dialog.yesNoConfirm({
}); message: I18n.t("admin.customize.theme.unsaved_parent_themes"),
} didConfirm: () => {
}, model.set("recentlyInstalled", false);
}, transition.retry();
}); },
didCancel: () => model.set("recentlyInstalled", false),
});
}
}
}

View File

@ -1,23 +1,24 @@
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import showModal from "discourse/lib/show-modal"; import showModal from "discourse/lib/show-modal";
import I18n from "I18n"; import I18n from "I18n";
import { next } from "@ember/runloop"; import { next } from "@ember/runloop";
import { inject as service } from "@ember/service";
export default Route.extend({ export default class AdminCustomizeThemesRoute extends Route {
dialog: service(), @service dialog;
queryParams: { queryParams = {
repoUrl: null, repoUrl: null,
repoName: null, repoName: null,
}, };
model() { model() {
return this.store.findAll("theme"); return this.store.findAll("theme");
}, }
setupController(controller, model) { setupController(controller, model) {
this._super(controller, model); super.setupController(controller, model);
controller.set("editingTheme", false); controller.set("editingTheme", false);
if (controller.repoUrl) { if (controller.repoUrl) {
@ -31,35 +32,33 @@ export default Route.extend({
}); });
}); });
} }
}, }
actions: { @action
installModal() { installModal() {
const currentTheme = this.controllerFor( const currentTheme = this.controllerFor("adminCustomizeThemes.show").model;
"adminCustomizeThemes.show" if (currentTheme?.warnUnassignedComponent) {
).model; this.dialog.yesNoConfirm({
if (currentTheme?.warnUnassignedComponent) { message: I18n.t("admin.customize.theme.unsaved_parent_themes"),
this.dialog.yesNoConfirm({ didConfirm: () => {
message: I18n.t("admin.customize.theme.unsaved_parent_themes"), currentTheme.set("recentlyInstalled", false);
didConfirm: () => { showModal("admin-install-theme", { admin: true });
currentTheme.set("recentlyInstalled", false);
showModal("admin-install-theme", { admin: true });
},
});
} else {
showModal("admin-install-theme", { admin: true });
}
},
addTheme(theme) {
this.refresh();
theme.setProperties({ recentlyInstalled: true });
this.transitionTo("adminCustomizeThemes.show", theme.get("id"), {
queryParams: {
repoName: null,
repoUrl: null,
}, },
}); });
}, } else {
}, showModal("admin-install-theme", { admin: true });
}); }
}
@action
addTheme(theme) {
this.refresh();
theme.setProperties({ recentlyInstalled: true });
this.transitionTo("adminCustomizeThemes.show", theme.get("id"), {
queryParams: {
repoName: null,
repoUrl: null,
},
});
}
}

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminDashboardGeneralRoute extends DiscourseRoute {
activate() { activate() {
this.controllerFor("admin-dashboard-general").fetchDashboard(); this.controllerFor("admin-dashboard-general").fetchDashboard();
}, }
}); }

View File

@ -1,12 +1,12 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
export default DiscourseRoute.extend({ export default class AdminDashboardReportsRoute extends DiscourseRoute {
model() { model() {
return ajax("/admin/reports"); return ajax("/admin/reports");
}, }
setupController(controller, model) { setupController(controller, model) {
controller.setProperties({ model: model.reports, filter: null }); controller.setProperties({ model: model.reports, filter: null });
}, }
}); }

View File

@ -1,10 +1,10 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { scrollTop } from "discourse/mixins/scroll-top"; import { scrollTop } from "discourse/mixins/scroll-top";
export default DiscourseRoute.extend({ export default class AdminDashboardRoute extends DiscourseRoute {
activate() { activate() {
this.controllerFor("admin-dashboard").fetchProblems(); this.controllerFor("admin-dashboard").fetchProblems();
this.controllerFor("admin-dashboard").fetchDashboard(); this.controllerFor("admin-dashboard").fetchDashboard();
scrollTop(); scrollTop();
}, }
}); }

View File

@ -1,13 +1,13 @@
import { action } from "@ember/object";
import AdminEmailLogs from "admin/routes/admin-email-logs"; import AdminEmailLogs from "admin/routes/admin-email-logs";
import showModal from "discourse/lib/show-modal"; import showModal from "discourse/lib/show-modal";
export default AdminEmailLogs.extend({ export default class AdminEmailBouncedRoute extends AdminEmailLogs {
status: "bounced", status = "bounced";
actions: { @action
showIncomingEmail(id) { showIncomingEmail(id) {
showModal("admin-incoming-email", { admin: true }); showModal("admin-incoming-email", { admin: true });
this.controllerFor("modals/admin-incoming-email").loadFromBounced(id); this.controllerFor("modals/admin-incoming-email").loadFromBounced(id);
}, }
}, }
});

View File

@ -1,13 +1,13 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import IncomingEmail from "admin/models/incoming-email"; import IncomingEmail from "admin/models/incoming-email";
export default DiscourseRoute.extend({ export default class AdminEmailIncomingsRoute extends DiscourseRoute {
model() { model() {
return IncomingEmail.findAll({ status: this.status }); return IncomingEmail.findAll({ status: this.status });
}, }
setupController(controller, model) { setupController(controller, model) {
controller.set("model", model); controller.set("model", model);
controller.set("filter.status", this.status); controller.set("filter.status", this.status);
}, }
}); }

View File

@ -1,8 +1,8 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import EmailSettings from "admin/models/email-settings"; import EmailSettings from "admin/models/email-settings";
export default DiscourseRoute.extend({ export default class AdminEmailIndexRoute extends DiscourseRoute {
model() { model() {
return EmailSettings.find(); return EmailSettings.find();
}, }
}); }

View File

@ -1,10 +1,10 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminEmailLogsRoute extends DiscourseRoute {
setupController(controller) { setupController(controller) {
controller.setProperties({ controller.setProperties({
loading: true, loading: true,
filter: { status: this.status }, filter: { status: this.status },
}); });
}, }
}); }

View File

@ -1,10 +1,10 @@
import EmailPreview, { oneWeekAgo } from "admin/models/email-preview"; import EmailPreview, { oneWeekAgo } from "admin/models/email-preview";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminEmailPreviewDigestRoute extends DiscourseRoute {
model() { model() {
return EmailPreview.findDigest(this.currentUser.get("username")); return EmailPreview.findDigest(this.currentUser.get("username"));
}, }
afterModel(model) { afterModel(model) {
const controller = this.controllerFor("adminEmailPreviewDigest"); const controller = this.controllerFor("adminEmailPreviewDigest");
@ -14,5 +14,5 @@ export default DiscourseRoute.extend({
lastSeen: oneWeekAgo(), lastSeen: oneWeekAgo(),
showHtml: true, showHtml: true,
}); });
}, }
}); }

View File

@ -1,2 +1,5 @@
import AdminEmailIncomings from "admin/routes/admin-email-incomings"; import AdminEmailIncomings from "admin/routes/admin-email-incomings";
export default AdminEmailIncomings.extend({ status: "received" });
export default class AdminEmailReceivedRoute extends AdminEmailIncomings {
status = "received";
}

View File

@ -1,13 +1,13 @@
import { action } from "@ember/object";
import AdminEmailIncomings from "admin/routes/admin-email-incomings"; import AdminEmailIncomings from "admin/routes/admin-email-incomings";
import showModal from "discourse/lib/show-modal"; import showModal from "discourse/lib/show-modal";
export default AdminEmailIncomings.extend({ export default class AdminEmailRejectedRoute extends AdminEmailIncomings {
status: "rejected", status = "rejected";
actions: { @action
showIncomingEmail(id) { showIncomingEmail(id) {
showModal("admin-incoming-email", { admin: true }); showModal("admin-incoming-email", { admin: true });
this.controllerFor("modals/admin-incoming-email").load(id); this.controllerFor("modals/admin-incoming-email").load(id);
}, }
}, }
});

View File

@ -1,2 +1,5 @@
import AdminEmailLogs from "admin/routes/admin-email-logs"; import AdminEmailLogs from "admin/routes/admin-email-logs";
export default AdminEmailLogs.extend({ status: "sent" });
export default class AdminEmailSentRoute extends AdminEmailLogs {
status = "sent";
}

View File

@ -1,2 +1,5 @@
import AdminEmailLogs from "admin/routes/admin-email-logs"; import AdminEmailLogs from "admin/routes/admin-email-logs";
export default AdminEmailLogs.extend({ status: "skipped" });
export default class AdminEmailSkippedRoute extends AdminEmailLogs {
status = "skipped";
}

View File

@ -1,10 +1,11 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({
export default class AdminEmbeddingRoute extends Route {
model() { model() {
return this.store.find("embedding"); return this.store.find("embedding");
}, }
setupController(controller, model) { setupController(controller, model) {
controller.set("embedding", model); controller.set("embedding", model);
}, }
}); }

View File

@ -2,12 +2,12 @@ import DiscourseRoute from "discourse/routes/discourse";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
export default DiscourseRoute.extend({ export default class AdminEmojisRoute extends DiscourseRoute {
model() { model() {
return ajax("/admin/customize/emojis.json").then(function (emojis) { return ajax("/admin/customize/emojis.json").then(function (emojis) {
return emojis.map(function (emoji) { return emojis.map(function (emoji) {
return EmberObject.create(emoji); return EmberObject.create(emoji);
}); });
}); });
}, }
}); }

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminFlagsPostsActiveRoute extends DiscourseRoute {
model() { model() {
return this.store.findAll("flagged-post", { filter: "active" }); return this.store.findAll("flagged-post", { filter: "active" });
}, }
}); }

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminFlagsPostsOldRoute extends DiscourseRoute {
model() { model() {
return this.store.findAll("flagged-post", { filter: "old" }); return this.store.findAll("flagged-post", { filter: "old" });
}, }
}); }

View File

@ -1,11 +1,11 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminFlagsTopicsIndexRoute extends DiscourseRoute {
model() { model() {
return this.store.findAll("flagged-topic"); return this.store.findAll("flagged-topic");
}, }
setupController(controller, model) { setupController(controller, model) {
controller.set("flaggedTopics", model); controller.set("flaggedTopics", model);
}, }
}); }

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminLogsIndexRoute extends DiscourseRoute {
redirect() { redirect() {
this.transitionTo("adminLogs.staffActionLogs"); this.transitionTo("adminLogs.staffActionLogs");
}, }
}); }

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminLogsScreenedEmailsRoute extends DiscourseRoute {
setupController() { setupController() {
return this.controllerFor("adminLogsScreenedEmails").show(); return this.controllerFor("adminLogsScreenedEmails").show();
}, }
}); }

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminLogsScreenedIpAddressesRoute extends DiscourseRoute {
setupController() { setupController() {
return this.controllerFor("adminLogsScreenedIpAddresses").show(); return this.controllerFor("adminLogsScreenedIpAddresses").show();
}, }
}); }

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminLogsScreenedUrlsRoute extends DiscourseRoute {
setupController() { setupController() {
return this.controllerFor("adminLogsScreenedUrls").show(); return this.controllerFor("adminLogsScreenedUrls").show();
}, }
}); }

View File

@ -1,10 +1,10 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import EmberObject from "@ember/object"; import EmberObject, { action } from "@ember/object";
export default DiscourseRoute.extend({ export default class AdminLogsStaffActionLogsRoute extends DiscourseRoute {
queryParams: { queryParams = {
filters: { refreshModel: true }, filters: { refreshModel: true },
}, };
beforeModel(transition) { beforeModel(transition) {
const params = transition.to.queryParams; const params = transition.to.queryParams;
@ -12,15 +12,15 @@ export default DiscourseRoute.extend({
if (controller.filters === null || params.force_refresh) { if (controller.filters === null || params.force_refresh) {
controller.resetFilters(); controller.resetFilters();
} }
}, }
deserializeQueryParam(value, urlKey, defaultValueType) { deserializeQueryParam(value, urlKey, defaultValueType) {
if (urlKey === "filters") { if (urlKey === "filters") {
return EmberObject.create(JSON.parse(decodeURIComponent(value))); return EmberObject.create(JSON.parse(decodeURIComponent(value)));
} }
return this._super(value, urlKey, defaultValueType); return super.deserializeQueryParam(value, urlKey, defaultValueType);
}, }
serializeQueryParam(value, urlKey, defaultValueType) { serializeQueryParam(value, urlKey, defaultValueType) {
if (urlKey === "filters") { if (urlKey === "filters") {
@ -31,18 +31,17 @@ export default DiscourseRoute.extend({
} }
} }
return this._super(value, urlKey, defaultValueType); return super.serializeQueryParam(value, urlKey, defaultValueType);
}, }
actions: { @action
onFiltersChange(filters) { onFiltersChange(filters) {
if (filters && Object.keys(filters) === 0) { if (filters && Object.keys(filters) === 0) {
this.transitionTo("adminLogs.staffActionLogs"); this.transitionTo("adminLogs.staffActionLogs");
} else { } else {
this.transitionTo("adminLogs.staffActionLogs", { this.transitionTo("adminLogs.staffActionLogs", {
queryParams: { filters }, queryParams: { filters },
}); });
} }
}, }
}, }
});

View File

@ -1,12 +1,12 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import Permalink from "admin/models/permalink"; import Permalink from "admin/models/permalink";
export default DiscourseRoute.extend({ export default class AdminPermalinksRoute extends DiscourseRoute {
model() { model() {
return Permalink.findAll(); return Permalink.findAll();
}, }
setupController(controller, model) { setupController(controller, model) {
controller.set("model", model); controller.set("model", model);
}, }
}); }

View File

@ -1,22 +1,23 @@
import { action } from "@ember/object";
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({
export default class AdminPluginsRoute extends Route {
model() { model() {
return this.store.findAll("plugin"); return this.store.findAll("plugin");
}, }
actions: { @action
showSettings(plugin) { showSettings(plugin) {
const controller = this.controllerFor("adminSiteSettings"); const controller = this.controllerFor("adminSiteSettings");
this.transitionTo("adminSiteSettingsCategory", "plugins").then(() => { this.transitionTo("adminSiteSettingsCategory", "plugins").then(() => {
if (plugin) { if (plugin) {
// filterContent() is normally on a debounce from typing. // filterContent() is normally on a debounce from typing.
// Because we don't want the default of "All Results", we tell it // Because we don't want the default of "All Results", we tell it
// to skip the next debounce. // to skip the next debounce.
controller.set("filter", `plugin:${plugin.id}`); controller.set("filter", `plugin:${plugin.id}`);
controller.set("_skipBounce", true); controller.set("_skipBounce", true);
controller.filterContentNow("plugins"); controller.filterContentNow("plugins");
} }
}); });
}, }
}, }
});

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminReportsIndexRoute extends DiscourseRoute {
beforeModel() { beforeModel() {
this.transitionTo("admin.dashboardReports"); this.transitionTo("admin.dashboardReports");
}, }
}); }

View File

@ -1,13 +1,14 @@
import { action } from "@ember/object";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminReportsShowRoute extends DiscourseRoute {
queryParams: { queryParams = {
start_date: { refreshModel: true }, start_date: { refreshModel: true },
end_date: { refreshModel: true }, end_date: { refreshModel: true },
filters: { refreshModel: true }, filters: { refreshModel: true },
chart_grouping: { refreshModel: true }, chart_grouping: { refreshModel: true },
mode: { refreshModel: true }, mode: { refreshModel: true },
}, };
model(params) { model(params) {
params.customFilters = params.filters; params.customFilters = params.filters;
@ -30,15 +31,15 @@ export default DiscourseRoute.extend({
delete params.chart_grouping; delete params.chart_grouping;
return params; return params;
}, }
deserializeQueryParam(value, urlKey, defaultValueType) { deserializeQueryParam(value, urlKey, defaultValueType) {
if (urlKey === "filters") { if (urlKey === "filters") {
return JSON.parse(decodeURIComponent(value)); return JSON.parse(decodeURIComponent(value));
} }
return this._super(value, urlKey, defaultValueType); return super.deserializeQueryParam(value, urlKey, defaultValueType);
}, }
serializeQueryParam(value, urlKey, defaultValueType) { serializeQueryParam(value, urlKey, defaultValueType) {
if (urlKey === "filters") { if (urlKey === "filters") {
@ -49,25 +50,24 @@ export default DiscourseRoute.extend({
} }
} }
return this._super(value, urlKey, defaultValueType); return super.serializeQueryParam(value, urlKey, defaultValueType);
}, }
actions: { @action
onParamsChange(params) { onParamsChange(params) {
const queryParams = { const queryParams = {
type: params.type, type: params.type,
mode: params.mode, mode: params.mode,
start_date: params.startDate start_date: params.startDate
? params.startDate.toISOString(true).split("T")[0] ? params.startDate.toISOString(true).split("T")[0]
: null, : null,
chart_grouping: params.chartGrouping, chart_grouping: params.chartGrouping,
filters: params.filters, filters: params.filters,
end_date: params.endDate end_date: params.endDate
? params.endDate.toISOString(true).split("T")[0] ? params.endDate.toISOString(true).split("T")[0]
: null, : null,
}; };
this.transitionTo("adminReports.show", { queryParams }); this.transitionTo("adminReports.show", { queryParams });
}, }
}, }
});

View File

@ -2,11 +2,11 @@ import DiscourseRoute from "discourse/routes/discourse";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
export default DiscourseRoute.extend({ export default class AdminSearchLogsIndexRoute extends DiscourseRoute {
queryParams: { queryParams = {
period: { refreshModel: true }, period: { refreshModel: true },
searchType: { refreshModel: true }, searchType: { refreshModel: true },
}, };
model(params) { model(params) {
this._params = params; this._params = params;
@ -15,7 +15,7 @@ export default DiscourseRoute.extend({
}).then((search_logs) => { }).then((search_logs) => {
return search_logs.map((sl) => EmberObject.create(sl)); return search_logs.map((sl) => EmberObject.create(sl));
}); });
}, }
setupController(controller, model) { setupController(controller, model) {
const params = this._params; const params = this._params;
@ -24,5 +24,5 @@ export default DiscourseRoute.extend({
period: params.period, period: params.period,
searchType: params.searchType, searchType: params.searchType,
}); });
}, }
}); }

View File

@ -4,12 +4,12 @@ import { ajax } from "discourse/lib/ajax";
import { fillMissingDates } from "discourse/lib/utilities"; import { fillMissingDates } from "discourse/lib/utilities";
import { translateResults } from "discourse/lib/search"; import { translateResults } from "discourse/lib/search";
export default DiscourseRoute.extend({ export default class AdminSearchLogsTermRoute extends DiscourseRoute {
queryParams: { queryParams = {
term: { refreshModel: true }, term: { refreshModel: true },
period: { refreshModel: true }, period: { refreshModel: true },
searchType: { refreshModel: true }, searchType: { refreshModel: true },
}, };
model(params) { model(params) {
this._params = params; this._params = params;
@ -40,7 +40,7 @@ export default DiscourseRoute.extend({
model.setProperties(json.term); model.setProperties(json.term);
return model; return model;
}); });
}, }
setupController(controller, model) { setupController(controller, model) {
const params = this._params; const params = this._params;
@ -50,5 +50,5 @@ export default DiscourseRoute.extend({
period: params.period, period: params.period,
searchType: params.searchType, searchType: params.searchType,
}); });
}, }
}); }

View File

@ -2,7 +2,7 @@ import DiscourseRoute from "discourse/routes/discourse";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import I18n from "I18n"; import I18n from "I18n";
export default DiscourseRoute.extend({ export default class AdminSiteSettingsCategoryRoute extends DiscourseRoute {
model(params) { model(params) {
// The model depends on user input, so let the controller do the work: // The model depends on user input, so let the controller do the work:
this.controllerFor("adminSiteSettingsCategory").set( this.controllerFor("adminSiteSettingsCategory").set(
@ -20,5 +20,5 @@ export default DiscourseRoute.extend({
"filteredContent" "filteredContent"
), ),
}); });
}, }
}); }

View File

@ -4,12 +4,12 @@
**/ **/
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminSiteSettingsIndexRoute extends DiscourseRoute {
beforeModel() { beforeModel() {
this.replaceWith( this.replaceWith(
"adminSiteSettingsCategory", "adminSiteSettingsCategory",
this.controllerFor("adminSiteSettings").get("visibleSiteSettings")[0] this.controllerFor("adminSiteSettings").get("visibleSiteSettings")[0]
.nameKey .nameKey
); );
}, }
}); }

View File

@ -1,14 +1,15 @@
import { action } from "@ember/object";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import SiteSetting from "admin/models/site-setting"; import SiteSetting from "admin/models/site-setting";
export default DiscourseRoute.extend({ export default class AdminSiteSettingsRoute extends DiscourseRoute {
queryParams: { queryParams = {
filter: { replace: true }, filter: { replace: true },
}, };
model() { model() {
return SiteSetting.findAll(); return SiteSetting.findAll();
}, }
afterModel(siteSettings) { afterModel(siteSettings) {
const controller = this.controllerFor("adminSiteSettings"); const controller = this.controllerFor("adminSiteSettings");
@ -16,13 +17,12 @@ export default DiscourseRoute.extend({
if (!controller.get("visibleSiteSettings")) { if (!controller.get("visibleSiteSettings")) {
controller.set("visibleSiteSettings", siteSettings); controller.set("visibleSiteSettings", siteSettings);
} }
}, }
actions: { @action
refreshAll() { refreshAll() {
SiteSetting.findAll().then((settings) => { SiteSetting.findAll().then((settings) => {
this.controllerFor("adminSiteSettings").set("model", settings); this.controllerFor("adminSiteSettings").set("model", settings);
}); });
}, }
}, }
});

View File

@ -1,10 +1,10 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
export default Route.extend({ export default class AdminSiteTextEditRoute extends Route {
queryParams: { queryParams = {
locale: { replace: true }, locale: { replace: true },
}, };
model(params) { model(params) {
return ajax( return ajax(
@ -12,7 +12,7 @@ export default Route.extend({
).then((result) => { ).then((result) => {
return this.store.createRecord("site-text", result.site_text); return this.store.createRecord("site-text", result.site_text);
}); });
}, }
setupController(controller, siteText) { setupController(controller, siteText) {
const locales = JSON.parse(this.siteSettings.available_locales); const locales = JSON.parse(this.siteSettings.available_locales);
@ -26,5 +26,5 @@ export default Route.extend({
saved: false, saved: false,
localeFullName, localeFullName,
}); });
}, }
}); }

View File

@ -1,28 +1,27 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import { getProperties } from "@ember/object"; import { action, getProperties } from "@ember/object";
import showModal from "discourse/lib/show-modal"; import showModal from "discourse/lib/show-modal";
export default Route.extend({ export default class AdminSiteTextIndexRoute extends Route {
queryParams: { queryParams = {
q: { replace: true }, q: { replace: true },
overridden: { replace: true }, overridden: { replace: true },
locale: { replace: true }, locale: { replace: true },
}, };
model(params) { model(params) {
return this.store.find( return this.store.find(
"site-text", "site-text",
getProperties(params, "q", "overridden", "locale") getProperties(params, "q", "overridden", "locale")
); );
}, }
setupController(controller, model) { setupController(controller, model) {
controller.set("siteTexts", model); controller.set("siteTexts", model);
}, }
actions: { @action
showReseedModal() { showReseedModal() {
showModal("admin-reseed", { admin: true }); showModal("admin-reseed", { admin: true });
}, }
}, }
});

View File

@ -2,11 +2,11 @@ import Badge from "discourse/models/badge";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import UserBadge from "discourse/models/user-badge"; import UserBadge from "discourse/models/user-badge";
export default DiscourseRoute.extend({ export default class AdminUserBadgesRoute extends DiscourseRoute {
model() { model() {
const username = this.modelFor("adminUser").get("username"); const username = this.modelFor("adminUser").get("username");
return UserBadge.findByUsername(username); return UserBadge.findByUsername(username);
}, }
setupController(controller, model) { setupController(controller, model) {
// Find all badges. // Find all badges.
@ -23,5 +23,5 @@ export default DiscourseRoute.extend({
}); });
// Set the model. // Set the model.
controller.set("model", model); controller.set("model", model);
}, }
}); }

View File

@ -1,12 +1,12 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import UserField from "admin/models/user-field"; import UserField from "admin/models/user-field";
export default DiscourseRoute.extend({ export default class AdminUserFieldsRoute extends DiscourseRoute {
model() { model() {
return this.store.findAll("user-field"); return this.store.findAll("user-field");
}, }
setupController(controller, model) { setupController(controller, model) {
controller.setProperties({ model, fieldTypes: UserField.fieldTypes() }); controller.setProperties({ model, fieldTypes: UserField.fieldTypes() });
}, }
}); }

View File

@ -1,10 +1,10 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import Group from "discourse/models/group"; import Group from "discourse/models/group";
export default DiscourseRoute.extend({ export default class AdminUserIndexRoute extends DiscourseRoute {
model() { model() {
return this.modelFor("adminUser"); return this.modelFor("adminUser");
}, }
afterModel(model) { afterModel(model) {
if (this.currentUser.admin) { if (this.currentUser.admin) {
@ -13,7 +13,7 @@ export default DiscourseRoute.extend({
return model; return model;
}); });
} }
}, }
setupController(controller, model) { setupController(controller, model) {
controller.setProperties({ controller.setProperties({
@ -24,5 +24,5 @@ export default DiscourseRoute.extend({
ssoLastPayload: null, ssoLastPayload: null,
model, model,
}); });
}, }
}); }

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminUserTl3RequirementsRoute extends DiscourseRoute {
model() { model() {
return this.modelFor("adminUser"); return this.modelFor("adminUser");
}, }
}); }

View File

@ -2,22 +2,22 @@ import AdminUser from "admin/models/admin-user";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { get } from "@ember/object"; import { get } from "@ember/object";
export default DiscourseRoute.extend({ export default class AdminUserRoute extends DiscourseRoute {
serialize(model) { serialize(model) {
return { return {
user_id: model.get("id"), user_id: model.get("id"),
username: model.get("username").toLowerCase(), username: model.get("username").toLowerCase(),
}; };
}, }
model(params) { model(params) {
return AdminUser.find(get(params, "user_id")); return AdminUser.find(get(params, "user_id"));
}, }
afterModel(adminUser) { afterModel(adminUser) {
return adminUser.loadDetails().then(function () { return adminUser.loadDetails().then(function () {
adminUser.setOriginalTrustLevel(); adminUser.setOriginalTrustLevel();
return adminUser; return adminUser;
}); });
}, }
}); }

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminUsersIndexRoute extends DiscourseRoute {
redirect() { redirect() {
this.transitionTo("adminUsersList"); this.transitionTo("adminUsersList");
}, }
}); }

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminUsersListIndexRoute extends DiscourseRoute {
beforeModel() { beforeModel() {
this.transitionTo("adminUsersList.show", "active"); this.transitionTo("adminUsersList.show", "active");
}, }
}); }

View File

@ -1,10 +1,10 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminUsersListShowRoute extends DiscourseRoute {
queryParams: { queryParams = {
order: { refreshModel: true }, order: { refreshModel: true },
asc: { refreshModel: true }, asc: { refreshModel: true },
}, };
// TODO: this has been introduced to fix a bug in admin-users-list-show // TODO: this has been introduced to fix a bug in admin-users-list-show
// loading AdminUser model multiple times without refactoring the controller // loading AdminUser model multiple times without refactoring the controller
@ -27,5 +27,5 @@ export default DiscourseRoute.extend({
controller.resetFilters(); controller.resetFilters();
} }
} }
}, }
}); }

View File

@ -1,22 +1,24 @@
import { action } from "@ember/object";
import AdminUser from "admin/models/admin-user"; import AdminUser from "admin/models/admin-user";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { exportEntity } from "discourse/lib/export-csv"; import { exportEntity } from "discourse/lib/export-csv";
import { outputExportResult } from "discourse/lib/export-result"; import { outputExportResult } from "discourse/lib/export-result";
export default DiscourseRoute.extend({ export default class AdminUsersListRoute extends DiscourseRoute {
actions: { @action
exportUsers() { exportUsers() {
exportEntity("user_list", { exportEntity("user_list", {
trust_level: this.controllerFor("admin-users-list-show").get("query"), trust_level: this.controllerFor("admin-users-list-show").get("query"),
}).then(outputExportResult); }).then(outputExportResult);
}, }
sendInvites() { @action
this.transitionTo("userInvited", this.currentUser); sendInvites() {
}, this.transitionTo("userInvited", this.currentUser);
}
deleteUser(user) { @action
AdminUser.create(user).destroy({ deletePosts: true }); deleteUser(user) {
}, AdminUser.create(user).destroy({ deletePosts: true });
}, }
}); }

View File

@ -2,7 +2,7 @@ import DiscourseRoute from "discourse/routes/discourse";
import EmberObject from "@ember/object"; import EmberObject from "@ember/object";
import I18n from "I18n"; import I18n from "I18n";
export default DiscourseRoute.extend({ export default class AdminWatchedWordsActionRoute extends DiscourseRoute {
model(params) { model(params) {
const controller = this.controllerFor("adminWatchedWordsAction"); const controller = this.controllerFor("adminWatchedWordsAction");
controller.set("actionNameKey", params.action_id); controller.set("actionNameKey", params.action_id);
@ -11,5 +11,5 @@ export default DiscourseRoute.extend({
name: I18n.t("admin.watched_words.actions." + params.action_id), name: I18n.t("admin.watched_words.actions." + params.action_id),
words: controller.filteredContent, words: controller.filteredContent,
}); });
}, }
}); }

View File

@ -1,10 +1,10 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminWatchedWordsIndexRoute extends DiscourseRoute {
beforeModel() { beforeModel() {
this.replaceWith( this.replaceWith(
"adminWatchedWords.action", "adminWatchedWords.action",
this.modelFor("adminWatchedWords")[0].nameKey this.modelFor("adminWatchedWords")[0].nameKey
); );
}, }
}); }

View File

@ -1,17 +1,17 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import WatchedWord from "admin/models/watched-word"; import WatchedWord from "admin/models/watched-word";
export default DiscourseRoute.extend({ export default class AdminWatchedWordsRoute extends DiscourseRoute {
queryParams: { queryParams = {
filter: { replace: true }, filter: { replace: true },
}, };
model() { model() {
return WatchedWord.findAll(); return WatchedWord.findAll();
}, }
afterModel(model) { afterModel(model) {
const controller = this.controllerFor("adminWatchedWords"); const controller = this.controllerFor("adminWatchedWords");
controller.set("allWatchedWords", model); controller.set("allWatchedWords", model);
}, }
}); }

View File

@ -1,9 +1,9 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminWebHooksEditRoute extends DiscourseRoute {
serialize(model) { serialize(model) {
return { web_hook_id: model.id || "new" }; return { web_hook_id: model.id || "new" };
}, }
model(params) { model(params) {
if (params.web_hook_id === "new") { if (params.web_hook_id === "new") {
@ -11,10 +11,10 @@ export default DiscourseRoute.extend({
} }
return this.store.find("web-hook", params.web_hook_id); return this.store.find("web-hook", params.web_hook_id);
}, }
setupController(controller, model) { setupController(controller, model) {
this._super(...arguments); super.setupController(...arguments);
if (model.get("isNew")) { if (model.get("isNew")) {
model.set( model.set(
@ -24,5 +24,5 @@ export default DiscourseRoute.extend({
} }
controller.set("saved", false); controller.set("saved", false);
}, }
}); }

View File

@ -1,7 +1,7 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend({ export default class AdminWebHooksShowRoute extends DiscourseRoute {
model(params) { model(params) {
return this.store.find("web-hook", params.web_hook_id); return this.store.find("web-hook", params.web_hook_id);
}, }
}); }

View File

@ -1,9 +1,9 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
export default Route.extend({ export default class AdminWebHooksRoute extends Route {
model() { model() {
return this.store.findAll("web-hook"); return this.store.findAll("web-hook");
}, }
setupController(controller, model) { setupController(controller, model) {
controller.setProperties({ controller.setProperties({
@ -13,5 +13,5 @@ export default Route.extend({
contentTypes: model.extras.content_types, contentTypes: model.extras.content_types,
deliveryStatuses: model.extras.delivery_statuses, deliveryStatuses: model.extras.delivery_statuses,
}); });
}, }
}); }

View File

@ -1,19 +1,19 @@
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import I18n from "I18n"; import I18n from "I18n";
export default DiscourseRoute.extend({ export default class AdminRoute extends DiscourseRoute {
titleToken() { titleToken() {
return I18n.t("admin_title"); return I18n.t("admin_title");
}, }
activate() { activate() {
this.controllerFor("application").setProperties({ this.controllerFor("application").setProperties({
showTop: false, showTop: false,
showFooter: false, showFooter: false,
}); });
}, }
deactivate() { deactivate() {
this.controllerFor("application").set("showTop", true); this.controllerFor("application").set("showTop", true);
}, }
}); }