DEV: Update admin modal controllers to native class syntax (#20685)

This commit was generated using the ember-native-class-codemod along with a handful of manual updates
This commit is contained in:
David Taylor 2023-03-15 17:39:33 +00:00 committed by GitHub
parent 62bbdd25ab
commit c190994046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 483 additions and 423 deletions

View File

@ -1,6 +1,8 @@
import Controller, { inject as controller } from "@ember/controller"; import { action } from "@ember/object";
import { and, not } from "@ember/object/computed"; import { and, not } from "@ember/object/computed";
import discourseComputed, { observes } from "discourse-common/utils/decorators"; import Controller, { inject as controller } from "@ember/controller";
import discourseComputed from "discourse-common/utils/decorators";
import { observes } from "@ember-decorators/object";
import I18n from "I18n"; import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
@ -53,18 +55,20 @@ const SCSS_VARIABLE_NAMES = [
"love-low", "love-low",
]; ];
export default Controller.extend(ModalFunctionality, { export default class AdminAddUploadController extends Controller.extend(
adminCustomizeThemesShow: controller(), ModalFunctionality
) {
@controller adminCustomizeThemesShow;
uploadUrl: "/admin/themes/upload_asset", uploadUrl = "/admin/themes/upload_asset";
@and("nameValid", "fileSelected") enabled;
@not("enabled") disabled;
onShow() { onShow() {
this.set("name", null); this.set("name", null);
this.set("fileSelected", false); this.set("fileSelected", false);
}, }
enabled: and("nameValid", "fileSelected"),
disabled: not("enabled"),
@discourseComputed("name", "adminCustomizeThemesShow.model.theme_fields") @discourseComputed("name", "adminCustomizeThemesShow.model.theme_fields")
errorMessage(name, themeFields) { errorMessage(name, themeFields) {
@ -89,20 +93,20 @@ export default Controller.extend(ModalFunctionality, {
} }
return null; return null;
}, }
@discourseComputed("errorMessage") @discourseComputed("errorMessage")
nameValid(errorMessage) { nameValid(errorMessage) {
return null === errorMessage; return null === errorMessage;
}, }
@observes("name") @observes("name")
uploadChanged() { uploadChanged() {
const file = $("#file-input")[0]; const file = $("#file-input")[0];
this.set("fileSelected", file && file.files[0]); this.set("fileSelected", file && file.files[0]);
}, }
actions: { @action
updateName() { updateName() {
let name = this.name; let name = this.name;
if (isEmpty(name)) { if (isEmpty(name)) {
@ -110,8 +114,9 @@ export default Controller.extend(ModalFunctionality, {
this.set("name", name.split(".")[0]); this.set("name", name.split(".")[0]);
} }
this.uploadChanged(); this.uploadChanged();
}, }
@action
upload() { upload() {
const file = $("#file-input")[0].files[0]; const file = $("#file-input")[0].files[0];
@ -137,6 +142,5 @@ export default Controller.extend(ModalFunctionality, {
.catch((e) => { .catch((e) => {
popupAjaxError(e); popupAjaxError(e);
}); });
}, }
}, }
});

View File

@ -4,39 +4,12 @@ import I18n from "I18n";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { escapeExpression } from "discourse/lib/utilities"; import { escapeExpression } from "discourse/lib/utilities";
export default Controller.extend({ export default class AdminBadgePreviewController extends Controller {
sample: alias("model.sample"), @alias("model.sample") sample;
errors: alias("model.errors"), @alias("model.errors") errors;
count: alias("model.grant_count"), @alias("model.grant_count") count;
@discourseComputed("count", "sample.length") @map("model.sample", (grant) => {
countWarning(count, sampleLength) {
if (count <= 10) {
return sampleLength !== count;
} else {
return sampleLength !== 10;
}
},
@discourseComputed("model.query_plan")
hasQueryPlan(queryPlan) {
return !!queryPlan;
},
@discourseComputed("model.query_plan")
queryPlanHtml(queryPlan) {
let output = `<pre class="badge-query-plan">`;
queryPlan.forEach((linehash) => {
output += escapeExpression(linehash["QUERY PLAN"]);
output += "<br>";
});
output += "</pre>";
return output;
},
processedSample: map("model.sample", (grant) => {
let i18nKey = "admin.badges.preview.grant.with"; let i18nKey = "admin.badges.preview.grant.with";
const i18nParams = { username: escapeExpression(grant.username) }; const i18nParams = { username: escapeExpression(grant.username) };
@ -55,5 +28,33 @@ export default Controller.extend({
} }
return I18n.t(i18nKey, i18nParams); return I18n.t(i18nKey, i18nParams);
}), })
}); processedSample;
@discourseComputed("count", "sample.length")
countWarning(count, sampleLength) {
if (count <= 10) {
return sampleLength !== count;
} else {
return sampleLength !== 10;
}
}
@discourseComputed("model.query_plan")
hasQueryPlan(queryPlan) {
return !!queryPlan;
}
@discourseComputed("model.query_plan")
queryPlanHtml(queryPlan) {
let output = `<pre class="badge-query-plan">`;
queryPlan.forEach((linehash) => {
output += escapeExpression(linehash["QUERY PLAN"]);
output += "<br>";
});
output += "</pre>";
return output;
}
}

View File

@ -1,27 +1,29 @@
import { action } from "@ember/object";
import Controller, { inject as controller } from "@ember/controller"; import Controller, { inject as controller } from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality, { export default class AdminColorSchemeSelectBaseController extends Controller.extend(
adminCustomizeColors: controller(), ModalFunctionality
) {
@controller adminCustomizeColors;
selectedBaseThemeId: null, selectedBaseThemeId = null;
init() { init() {
this._super(...arguments); super.init(...arguments);
const defaultScheme = this.get( const defaultScheme = this.get(
"adminCustomizeColors.baseColorSchemes.0.base_scheme_id" "adminCustomizeColors.baseColorSchemes.0.base_scheme_id"
); );
this.set("selectedBaseThemeId", defaultScheme); this.set("selectedBaseThemeId", defaultScheme);
}, }
actions: { @action
selectBase() { selectBase() {
this.adminCustomizeColors.send( this.adminCustomizeColors.send(
"newColorSchemeWithBase", "newColorSchemeWithBase",
this.selectedBaseThemeId this.selectedBaseThemeId
); );
this.send("closeModal"); this.send("closeModal");
}, }
}, }
});

View File

@ -1,18 +1,21 @@
import { alias } from "@ember/object/computed";
import Controller, { inject as controller } from "@ember/controller"; import Controller, { inject as controller } from "@ember/controller";
import I18n from "I18n"; import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { alias } from "@ember/object/computed";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default Controller.extend(ModalFunctionality, { export default class AdminDeletePostsConfirmationController extends Controller.extend(
adminUserIndex: controller(), ModalFunctionality
username: alias("model.username"), ) {
postCount: alias("model.post_count"), @controller adminUserIndex;
@alias("model.username") username;
@alias("model.post_count") postCount;
onShow() { onShow() {
this.set("value", null); this.set("value", null);
}, }
@discourseComputed("username", "postCount") @discourseComputed("username", "postCount")
text(username, postCount) { text(username, postCount) {
@ -20,27 +23,27 @@ export default Controller.extend(ModalFunctionality, {
username, username,
postCount, postCount,
}); });
}, }
@discourseComputed("username") @discourseComputed("username")
deleteButtonText(username) { deleteButtonText(username) {
return I18n.t(`admin.user.delete_posts.confirmation.delete`, { return I18n.t(`admin.user.delete_posts.confirmation.delete`, {
username, username,
}); });
}, }
@discourseComputed("value", "text") @discourseComputed("value", "text")
deleteDisabled(value, text) { deleteDisabled(value, text) {
return !value || text !== value; return !value || text !== value;
}, }
@action @action
confirm() { confirm() {
this.adminUserIndex.send("deleteAllPosts"); this.adminUserIndex.send("deleteAllPosts");
}, }
@action @action
close() { close() {
this.send("closeModal"); this.send("closeModal");
}, }
}); }

View File

@ -1,6 +1,8 @@
import Controller from "@ember/controller"; import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality, { export default class AdminDeleteUserPostsProgressController extends Controller.extend(
deletedPercentage: 0, ModalFunctionality
}); ) {
deletedPercentage = 0;
}

View File

@ -1,13 +1,16 @@
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { A } from "@ember/array"; import { A } from "@ember/array";
import Controller from "@ember/controller"; import Controller from "@ember/controller";
import I18n from "I18n"; import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { observes } from "discourse-common/utils/decorators"; import { observes } from "discourse-common/utils/decorators";
import { inject as service } from "@ember/service";
export default Controller.extend(ModalFunctionality, { export default class AdminEditBadgeGroupingsController extends Controller.extend(
dialog: service(), ModalFunctionality
) {
@service dialog;
@observes("model") @observes("model")
modelChanged() { modelChanged() {
@ -22,7 +25,7 @@ export default Controller.extend(ModalFunctionality, {
} }
this.set("workingCopy", copy); this.set("workingCopy", copy);
}, }
moveItem(item, delta) { moveItem(item, delta) {
const copy = this.workingCopy; const copy = this.workingCopy;
@ -33,35 +36,49 @@ export default Controller.extend(ModalFunctionality, {
copy.removeAt(index); copy.removeAt(index);
copy.insertAt(index + delta, item); copy.insertAt(index + delta, item);
}, }
actions: { @action
up(item) { up(item) {
this.moveItem(item, -1); this.moveItem(item, -1);
}, }
@action
down(item) { down(item) {
this.moveItem(item, 1); this.moveItem(item, 1);
}, }
@action
delete(item) { delete(item) {
this.workingCopy.removeObject(item); this.workingCopy.removeObject(item);
}, }
@action
cancel() { cancel() {
this.setProperties({ model: null, workingCopy: null }); this.setProperties({ model: null, workingCopy: null });
this.send("closeModal"); this.send("closeModal");
}, }
@action
edit(item) { edit(item) {
item.set("editing", true); item.set("editing", true);
}, }
@action
save(item) { save(item) {
item.set("editing", false); item.set("editing", false);
}, }
@action
add() { add() {
const obj = this.store.createRecord("badge-grouping", { const obj = this.store.createRecord("badge-grouping", {
editing: true, editing: true,
name: I18n.t("admin.badges.badge_grouping"), name: I18n.t("admin.badges.badge_grouping"),
}); });
this.workingCopy.pushObject(obj); this.workingCopy.pushObject(obj);
}, }
@action
saveAll() { saveAll() {
let items = this.workingCopy; let items = this.workingCopy;
const groupIds = items.map((i) => i.get("id") || -1); const groupIds = items.map((i) => i.get("id") || -1);
@ -82,6 +99,5 @@ export default Controller.extend(ModalFunctionality, {
}, },
() => this.dialog.alert(I18n.t("generic_error")) () => this.dialog.alert(I18n.t("generic_error"))
); );
}, }
}, }
});

View File

@ -5,15 +5,17 @@ import discourseComputed from "discourse-common/utils/decorators";
import { longDate } from "discourse/lib/formatter"; import { longDate } from "discourse/lib/formatter";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
export default Controller.extend(ModalFunctionality, { export default class AdminIncomingEmailController extends Controller.extend(
ModalFunctionality
) {
@discourseComputed("model.date") @discourseComputed("model.date")
date(d) { date(d) {
return longDate(d); return longDate(d);
}, }
load(id) { load(id) {
return IncomingEmail.find(id).then((result) => this.set("model", result)); return IncomingEmail.find(id).then((result) => this.set("model", result));
}, }
loadFromBounced(id) { loadFromBounced(id) {
return IncomingEmail.findByBounced(id) return IncomingEmail.findByBounced(id)
@ -22,5 +24,5 @@ export default Controller.extend(ModalFunctionality, {
this.send("closeModal"); this.send("closeModal");
popupAjaxError(error); popupAjaxError(error);
}); });
}, }
}); }

View File

@ -1,46 +1,46 @@
import { alias, equal, match } from "@ember/object/computed";
import { COMPONENTS, THEMES } from "admin/models/theme"; import { COMPONENTS, THEMES } from "admin/models/theme";
import Controller, { inject as controller } from "@ember/controller"; import Controller, { inject as controller } from "@ember/controller";
import { alias, equal, match } from "@ember/object/computed"; import discourseComputed from "discourse-common/utils/decorators";
import discourseComputed, { observes } from "discourse-common/utils/decorators"; import { observes } from "@ember-decorators/object";
import I18n from "I18n"; import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { POPULAR_THEMES } from "discourse-common/helpers/popular-themes"; import { POPULAR_THEMES } from "discourse-common/helpers/popular-themes";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error"; import { popupAjaxError } from "discourse/lib/ajax-error";
import { set } from "@ember/object"; import { action, set } from "@ember/object";
const MIN_NAME_LENGTH = 4; const MIN_NAME_LENGTH = 4;
export default Controller.extend(ModalFunctionality, { export default class AdminInstallThemeController extends Controller.extend(
adminCustomizeThemes: controller(), ModalFunctionality
themesController: controller("adminCustomizeThemes"), ) {
popular: equal("selection", "popular"), @controller adminCustomizeThemes;
local: equal("selection", "local"), @controller("adminCustomizeThemes") themesController;
remote: equal("selection", "remote"),
create: equal("selection", "create"),
directRepoInstall: equal("selection", "directRepoInstall"),
selection: "popular",
loading: false,
keyGenUrl: "/admin/themes/generate_key_pair",
importUrl: "/admin/themes/import",
recordType: "theme",
checkPrivate: match("uploadUrl", /^ssh:\/\/.+@.+$|.+@.+:.+$/),
localFile: null,
uploadUrl: null,
uploadName: null,
advancedVisible: false,
selectedType: alias("themesController.currentTab"),
component: equal("selectedType", COMPONENTS),
urlPlaceholder: "https://github.com/discourse/sample_theme",
init() { @equal("selection", "popular") popular;
this._super(...arguments); @equal("selection", "local") local;
@equal("selection", "remote") remote;
@equal("selection", "create") create;
@equal("selection", "directRepoInstall") directRepoInstall;
selection = "popular";
loading = false;
keyGenUrl = "/admin/themes/generate_key_pair";
importUrl = "/admin/themes/import";
recordType = "theme";
@match("uploadUrl", /^ssh:\/\/.+@.+$|.+@.+:.+$/) checkPrivate;
localFile = null;
uploadUrl = null;
uploadName = null;
advancedVisible = false;
@alias("themesController.currentTab") selectedType;
@equal("selectedType", COMPONENTS) component;
urlPlaceholder = "https://github.com/discourse/sample_theme";
this.createTypes = [ createTypes = [
{ name: I18n.t("admin.customize.theme.theme"), value: THEMES }, { name: I18n.t("admin.customize.theme.theme"), value: THEMES },
{ name: I18n.t("admin.customize.theme.component"), value: COMPONENTS }, { name: I18n.t("admin.customize.theme.component"), value: COMPONENTS },
]; ];
},
@discourseComputed("themesController.installedThemes") @discourseComputed("themesController.installedThemes")
themes(installedThemes) { themes(installedThemes) {
@ -52,7 +52,7 @@ export default Controller.extend(ModalFunctionality, {
} }
return t; return t;
}); });
}, }
@discourseComputed( @discourseComputed(
"loading", "loading",
@ -78,12 +78,12 @@ export default Controller.extend(ModalFunctionality, {
(isLocal && !localFile) || (isLocal && !localFile) ||
(isCreate && nameTooShort) (isCreate && nameTooShort)
); );
}, }
@discourseComputed("name") @discourseComputed("name")
nameTooShort(name) { nameTooShort(name) {
return !name || name.length < MIN_NAME_LENGTH; return !name || name.length < MIN_NAME_LENGTH;
}, }
@discourseComputed("component") @discourseComputed("component")
placeholder(component) { placeholder(component) {
@ -92,7 +92,7 @@ export default Controller.extend(ModalFunctionality, {
} else { } else {
return I18n.t("admin.customize.theme.theme_name"); return I18n.t("admin.customize.theme.theme_name");
} }
}, }
@observes("checkPrivate") @observes("checkPrivate")
privateWasChecked() { privateWasChecked() {
@ -108,7 +108,7 @@ export default Controller.extend(ModalFunctionality, {
this._keyLoading = false; this._keyLoading = false;
}); });
} }
}, }
@discourseComputed("selection", "themeCannotBeInstalled") @discourseComputed("selection", "themeCannotBeInstalled")
submitLabel(selection, themeCannotBeInstalled) { submitLabel(selection, themeCannotBeInstalled) {
@ -119,12 +119,12 @@ export default Controller.extend(ModalFunctionality, {
return `admin.customize.theme.${ return `admin.customize.theme.${
selection === "create" ? "create" : "install" selection === "create" ? "create" : "install"
}`; }`;
}, }
@discourseComputed("checkPrivate", "publicKey") @discourseComputed("checkPrivate", "publicKey")
showPublicKey(checkPrivate, publicKey) { showPublicKey(checkPrivate, publicKey) {
return checkPrivate && publicKey; return checkPrivate && publicKey;
}, }
onClose() { onClose() {
this.setProperties({ this.setProperties({
@ -140,7 +140,7 @@ export default Controller.extend(ModalFunctionality, {
repoName: null, repoName: null,
repoUrl: null, repoUrl: null,
}); });
}, }
themeHasSameUrl(theme, url) { themeHasSameUrl(theme, url) {
const themeUrl = theme.remote_theme && theme.remote_theme.remote_url; const themeUrl = theme.remote_theme && theme.remote_theme.remote_url;
@ -149,22 +149,25 @@ export default Controller.extend(ModalFunctionality, {
url && url &&
url.replace(/\.git$/, "") === themeUrl.replace(/\.git$/, "") url.replace(/\.git$/, "") === themeUrl.replace(/\.git$/, "")
); );
}, }
actions: { @action
uploadLocaleFile() { uploadLocaleFile() {
this.set("localFile", $("#file-input")[0].files[0]); this.set("localFile", $("#file-input")[0].files[0]);
}, }
@action
toggleAdvanced() { toggleAdvanced() {
this.toggleProperty("advancedVisible"); this.toggleProperty("advancedVisible");
}, }
@action
installThemeFromList(url) { installThemeFromList(url) {
this.set("uploadUrl", url); this.set("uploadUrl", url);
this.send("installTheme"); this.send("installTheme");
}, }
@action
installTheme() { installTheme() {
if (this.create) { if (this.create) {
this.set("loading", true); this.set("loading", true);
@ -197,10 +200,9 @@ export default Controller.extend(ModalFunctionality, {
this.themeHasSameUrl(theme, this.uploadUrl) this.themeHasSameUrl(theme, this.uploadUrl)
); );
if (duplicate && !this.duplicateRemoteThemeWarning) { if (duplicate && !this.duplicateRemoteThemeWarning) {
const warning = I18n.t( const warning = I18n.t("admin.customize.theme.duplicate_remote_theme", {
"admin.customize.theme.duplicate_remote_theme", name: duplicate.name,
{ name: duplicate.name } });
);
this.set("duplicateRemoteThemeWarning", warning); this.set("duplicateRemoteThemeWarning", warning);
return; return;
} }
@ -243,6 +245,5 @@ export default Controller.extend(ModalFunctionality, {
); );
}) })
.finally(() => this.set("loading", false)); .finally(() => this.set("loading", false));
}, }
}, }
});

View File

@ -1,18 +1,21 @@
import { alias } from "@ember/object/computed";
import Controller, { inject as controller } from "@ember/controller"; import Controller, { inject as controller } from "@ember/controller";
import I18n from "I18n"; import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { alias } from "@ember/object/computed";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default Controller.extend(ModalFunctionality, { export default class AdminMergeUsersConfirmationController extends Controller.extend(
adminUserIndex: controller(), ModalFunctionality
username: alias("model.username"), ) {
targetUsername: alias("model.targetUsername"), @controller adminUserIndex;
@alias("model.username") username;
@alias("model.targetUsername") targetUsername;
onShow() { onShow() {
this.set("value", null); this.set("value", null);
}, }
@discourseComputed("username", "targetUsername") @discourseComputed("username", "targetUsername")
text(username, targetUsername) { text(username, targetUsername) {
@ -20,28 +23,28 @@ export default Controller.extend(ModalFunctionality, {
username, username,
targetUsername, targetUsername,
}); });
}, }
@discourseComputed("username") @discourseComputed("username")
mergeButtonText(username) { mergeButtonText(username) {
return I18n.t(`admin.user.merge.confirmation.transfer_and_delete`, { return I18n.t(`admin.user.merge.confirmation.transfer_and_delete`, {
username, username,
}); });
}, }
@discourseComputed("value", "text") @discourseComputed("value", "text")
mergeDisabled(value, text) { mergeDisabled(value, text) {
return !value || text !== value; return !value || text !== value;
}, }
@action @action
confirm() { confirm() {
this.adminUserIndex.send("merge", this.targetUsername); this.adminUserIndex.send("merge", this.targetUsername);
this.send("closeModal"); this.send("closeModal");
}, }
@action @action
close() { close() {
this.send("closeModal"); this.send("closeModal");
}, }
}); }

View File

@ -4,16 +4,18 @@ import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { bind } from "discourse-common/utils/decorators"; import { bind } from "discourse-common/utils/decorators";
export default Controller.extend(ModalFunctionality, { export default class AdminMergeUsersProgressController extends Controller.extend(
message: I18n.t("admin.user.merging_user"), ModalFunctionality
) {
message = I18n.t("admin.user.merging_user");
onShow() { onShow() {
this.messageBus.subscribe("/merge_user", this.onMessage); this.messageBus.subscribe("/merge_user", this.onMessage);
}, }
onClose() { onClose() {
this.messageBus.unsubscribe("/merge_user", this.onMessage); this.messageBus.unsubscribe("/merge_user", this.onMessage);
}, }
@bind @bind
onMessage(data) { onMessage(data) {
@ -30,5 +32,5 @@ export default Controller.extend(ModalFunctionality, {
} else if (data.failed) { } else if (data.failed) {
this.set("message", I18n.t("admin.user.merge_failed")); this.set("message", I18n.t("admin.user.merge_failed"));
} }
}, }
}); }

View File

@ -1,43 +1,46 @@
import { alias } from "@ember/object/computed";
import Controller, { inject as controller } from "@ember/controller"; import Controller, { inject as controller } from "@ember/controller";
import I18n from "I18n"; import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { action, get } from "@ember/object"; import { action, get } from "@ember/object";
import { alias } from "@ember/object/computed";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
export default Controller.extend(ModalFunctionality, { export default class AdminMergeUsersPromptController extends Controller.extend(
adminUserIndex: controller(), ModalFunctionality
username: alias("model.username"), ) {
@controller adminUserIndex;
@alias("model.username") username;
onShow() { onShow() {
this.set("targetUsername", null); this.set("targetUsername", null);
}, }
@discourseComputed("username", "targetUsername") @discourseComputed("username", "targetUsername")
mergeDisabled(username, targetUsername) { mergeDisabled(username, targetUsername) {
return !targetUsername || username === targetUsername; return !targetUsername || username === targetUsername;
}, }
@discourseComputed("username") @discourseComputed("username")
mergeButtonText(username) { mergeButtonText(username) {
return I18n.t(`admin.user.merge.confirmation.transfer_and_delete`, { return I18n.t(`admin.user.merge.confirmation.transfer_and_delete`, {
username, username,
}); });
}, }
@action @action
showConfirmation() { showConfirmation() {
this.send("closeModal"); this.send("closeModal");
this.adminUserIndex.send("showMergeConfirmation", this.targetUsername); this.adminUserIndex.send("showMergeConfirmation", this.targetUsername);
}, }
@action @action
close() { close() {
this.send("closeModal"); this.send("closeModal");
}, }
@action @action
updateUsername(selected) { updateUsername(selected) {
this.set("targetUsername", get(selected, "firstObject")); this.set("targetUsername", get(selected, "firstObject"));
}, }
}); }

View File

@ -1,29 +1,31 @@
import { inject as service } from "@ember/service";
import Controller from "@ember/controller"; import Controller from "@ember/controller";
import { action } from "@ember/object"; import { action } from "@ember/object";
import { next } from "@ember/runloop"; import { next } from "@ember/runloop";
import { inject as service } from "@ember/service";
import { isEmpty } from "@ember/utils"; import { isEmpty } from "@ember/utils";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { extractError } from "discourse/lib/ajax-error"; import { extractError } from "discourse/lib/ajax-error";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import I18n from "I18n"; import I18n from "I18n";
export default Controller.extend(ModalFunctionality, { export default class AdminPenalizeUserController extends Controller.extend(
dialog: service(), ModalFunctionality
) {
@service dialog;
loadingUser: false, loadingUser = false;
errorMessage: null, errorMessage = null;
penaltyType: null, penaltyType = null;
penalizeUntil: null, penalizeUntil = null;
reason: null, reason = null;
message: null, message = null;
postId: null, postId = null;
postAction: null, postAction = null;
postEdit: null, postEdit = null;
user: null, user = null;
otherUserIds: null, otherUserIds = null;
loading: false, loading = false;
confirmClose: false, confirmClose = false;
onShow() { onShow() {
this.setProperties({ this.setProperties({
@ -44,11 +46,11 @@ export default Controller.extend(ModalFunctionality, {
message: null, message: null,
confirmClose: false, confirmClose: false,
}); });
}, }
finishedSetup() { finishedSetup() {
this.set("penalizeUntil", this.user?.next_penalty); this.set("penalizeUntil", this.user?.next_penalty);
}, }
beforeClose() { beforeClose() {
if (this.confirmClose) { if (this.confirmClose) {
@ -73,7 +75,7 @@ export default Controller.extend(ModalFunctionality, {
return false; return false;
} }
}, }
@discourseComputed("penaltyType") @discourseComputed("penaltyType")
modalTitle(penaltyType) { modalTitle(penaltyType) {
@ -82,7 +84,7 @@ export default Controller.extend(ModalFunctionality, {
} else if (penaltyType === "silence") { } else if (penaltyType === "silence") {
return "admin.user.silence_modal_title"; return "admin.user.silence_modal_title";
} }
}, }
@discourseComputed("penaltyType") @discourseComputed("penaltyType")
buttonLabel(penaltyType) { buttonLabel(penaltyType) {
@ -91,7 +93,7 @@ export default Controller.extend(ModalFunctionality, {
} else if (penaltyType === "silence") { } else if (penaltyType === "silence") {
return "admin.user.silence"; return "admin.user.silence";
} }
}, }
@discourseComputed( @discourseComputed(
"user.penalty_counts.suspended", "user.penalty_counts.suspended",
@ -102,7 +104,7 @@ export default Controller.extend(ModalFunctionality, {
SUSPENDED: suspendedCount, SUSPENDED: suspendedCount,
SILENCED: silencedCount, SILENCED: silencedCount,
}); });
}, }
@discourseComputed("penaltyType", "user.canSuspend", "user.canSilence") @discourseComputed("penaltyType", "user.canSuspend", "user.canSilence")
canPenalize(penaltyType, canSuspend, canSilence) { canPenalize(penaltyType, canSuspend, canSilence) {
@ -113,12 +115,12 @@ export default Controller.extend(ModalFunctionality, {
} }
return false; return false;
}, }
@discourseComputed("penalizing", "penalizeUntil", "reason") @discourseComputed("penalizing", "penalizeUntil", "reason")
submitDisabled(penalizing, penalizeUntil, reason) { submitDisabled(penalizing, penalizeUntil, reason) {
return penalizing || isEmpty(penalizeUntil) || !reason || reason.length < 1; return penalizing || isEmpty(penalizeUntil) || !reason || reason.length < 1;
}, }
@action @action
async penalizeUser() { async penalizeUser() {
@ -164,5 +166,5 @@ export default Controller.extend(ModalFunctionality, {
} finally { } finally {
this.set("penalizing", false); this.set("penalizing", false);
} }
}, }
}); }

View File

@ -1,15 +1,19 @@
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import Controller from "@ember/controller"; import Controller from "@ember/controller";
import I18n from "I18n"; import I18n from "I18n";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { inject as service } from "@ember/service";
export default Controller.extend(ModalFunctionality, { export default class AdminReseedController extends Controller.extend(
dialog: service(), ModalFunctionality
loading: true, ) {
reseeding: false, @service dialog;
categories: null,
topics: null, loading = true;
reseeding = false;
categories = null;
topics = null;
onShow() { onShow() {
ajax("/admin/customize/reseed") ajax("/admin/customize/reseed")
@ -20,13 +24,13 @@ export default Controller.extend(ModalFunctionality, {
}); });
}) })
.finally(() => this.set("loading", false)); .finally(() => this.set("loading", false));
}, }
_extractSelectedIds(items) { _extractSelectedIds(items) {
return items.filter((item) => item.selected).map((item) => item.id); return items.filter((item) => item.selected).map((item) => item.id);
}, }
actions: { @action
reseed() { reseed() {
this.set("reseeding", true); this.set("reseeding", true);
ajax("/admin/customize/reseed", { ajax("/admin/customize/reseed", {
@ -41,6 +45,5 @@ export default Controller.extend(ModalFunctionality, {
this.set("reseeding", false); this.set("reseeding", false);
this.send("closeModal"); this.send("closeModal");
}); });
}, }
}, }
});

View File

@ -1,4 +1,6 @@
import Controller from "@ember/controller"; import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality); export default class AdminStaffActionLogDetailsController extends Controller.extend(
ModalFunctionality
) {}

View File

@ -1,35 +1,39 @@
import { action } from "@ember/object";
import Controller, { inject as controller } from "@ember/controller"; import Controller, { inject as controller } from "@ember/controller";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality, { export default class AdminStartBackupController extends Controller.extend(
adminBackupsLogs: controller(), ModalFunctionality
) {
@controller adminBackupsLogs;
@discourseComputed @discourseComputed
warningMessage() { warningMessage() {
// this is never shown here, but we may want to show different // this is never shown here, but we may want to show different
// messages in plugins // messages in plugins
return ""; return "";
}, }
@discourseComputed @discourseComputed
yesLabel() { yesLabel() {
return "yes_value"; return "yes_value";
}, }
actions: { @action
startBackupWithUploads() { startBackupWithUploads() {
this.send("closeModal"); this.send("closeModal");
this.send("startBackup", true); this.send("startBackup", true);
}, }
@action
startBackupWithoutUploads() { startBackupWithoutUploads() {
this.send("closeModal"); this.send("closeModal");
this.send("startBackup", false); this.send("startBackup", false);
}, }
@action
cancel() { cancel() {
this.send("closeModal"); this.send("closeModal");
}, }
}, }
});

View File

@ -2,7 +2,9 @@ import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
export default Controller.extend(ModalFunctionality, { export default class AdminThemeChangeController extends Controller.extend(
ModalFunctionality
) {
loadDiff() { loadDiff() {
this.set("loading", true); this.set("loading", true);
ajax( ajax(
@ -11,5 +13,5 @@ export default Controller.extend(ModalFunctionality, {
this.set("loading", false); this.set("loading", false);
this.set("diff", diff.side_by_side); this.set("diff", diff.side_by_side);
}); });
}, }
}); }

View File

@ -1,30 +1,32 @@
import { observes, on } from "discourse-common/utils/decorators"; import { observes, on } from "@ember-decorators/object";
import Controller from "@ember/controller"; import Controller from "@ember/controller";
import { action } from "@ember/object"; import { action } from "@ember/object";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
export default Controller.extend(ModalFunctionality, { export default class AdminUploadedImageListController extends Controller.extend(
ModalFunctionality
) {
@on("init") @on("init")
@observes("model.value") @observes("model.value")
_setup() { _setup() {
const value = this.get("model.value"); const value = this.get("model.value");
this.set("images", value && value.length ? value.split("|") : []); this.set("images", value && value.length ? value.split("|") : []);
}, }
@action @action
remove(url, event) { remove(url, event) {
event?.preventDefault(); event?.preventDefault();
this.images.removeObject(url); this.images.removeObject(url);
}, }
actions: { @action
uploadDone({ url }) { uploadDone({ url }) {
this.images.addObject(url); this.images.addObject(url);
}, }
@action
close() { close() {
this.save(this.images.join("|")); this.save(this.images.join("|"));
this.send("closeModal"); this.send("closeModal");
}, }
}, }
});

View File

@ -1,16 +1,19 @@
import { equal } from "@ember/object/computed";
import Controller from "@ember/controller"; import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import discourseComputed from "discourse-common/utils/decorators"; import discourseComputed from "discourse-common/utils/decorators";
import { equal } from "@ember/object/computed";
import { import {
createWatchedWordRegExp, createWatchedWordRegExp,
toWatchedWord, toWatchedWord,
} from "discourse-common/utils/watched-words"; } from "discourse-common/utils/watched-words";
export default Controller.extend(ModalFunctionality, { export default class AdminWatchedWordTestController extends Controller.extend(
isReplace: equal("model.nameKey", "replace"), ModalFunctionality
isTag: equal("model.nameKey", "tag"), ) {
isLink: equal("model.nameKey", "link"), @equal("model.nameKey", "replace") isReplace;
@equal("model.nameKey", "tag") isTag;
@equal("model.nameKey", "link") isLink;
@discourseComputed( @discourseComputed(
"value", "value",
@ -71,5 +74,5 @@ export default Controller.extend(ModalFunctionality, {
return matches; return matches;
} }
}, }
}); }

View File

@ -2,4 +2,7 @@ import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality"; import ModalFunctionality from "discourse/mixins/modal-functionality";
import ModalUpdateExistingUsers from "discourse/mixins/modal-update-existing-users"; import ModalUpdateExistingUsers from "discourse/mixins/modal-update-existing-users";
export default Controller.extend(ModalFunctionality, ModalUpdateExistingUsers); export default class SiteSettingDefaultCategoriesController extends Controller.extend(
ModalFunctionality,
ModalUpdateExistingUsers
) {}