2023-10-11 02:38:59 +08:00
|
|
|
import Controller from "@ember/controller";
|
2023-03-15 17:42:12 +08:00
|
|
|
import { action } from "@ember/object";
|
|
|
|
import { or } from "@ember/object/computed";
|
2024-03-07 01:05:11 +08:00
|
|
|
import { service } from "@ember/service";
|
2023-03-15 17:42:12 +08:00
|
|
|
import { observes } from "@ember-decorators/object";
|
2022-02-09 14:11:41 +08:00
|
|
|
import { clipboardCopy } from "discourse/lib/utilities";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2023-10-18 18:07:09 +08:00
|
|
|
import I18n from "discourse-i18n";
|
2023-10-11 02:38:59 +08:00
|
|
|
import Permalink from "admin/models/permalink";
|
2015-08-11 05:11:27 +08:00
|
|
|
|
2024-11-14 07:03:58 +08:00
|
|
|
export default class AdminPermalinksIndexController extends Controller {
|
2023-03-15 17:42:12 +08:00
|
|
|
@service dialog;
|
2024-11-14 07:03:58 +08:00
|
|
|
@service toasts;
|
2023-03-15 17:42:12 +08:00
|
|
|
|
|
|
|
loading = false;
|
|
|
|
filter = null;
|
|
|
|
|
|
|
|
@or("model.length", "filter") showSearch;
|
2015-07-15 20:54:28 +08:00
|
|
|
|
2020-12-18 21:18:52 +08:00
|
|
|
_debouncedShow() {
|
2019-05-27 16:15:39 +08:00
|
|
|
Permalink.findAll(this.filter).then((result) => {
|
2016-10-21 01:26:41 +08:00
|
|
|
this.set("model", result);
|
|
|
|
this.set("loading", false);
|
2015-07-15 20:54:28 +08:00
|
|
|
});
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2020-12-18 21:18:52 +08:00
|
|
|
|
|
|
|
@observes("filter")
|
|
|
|
show() {
|
|
|
|
discourseDebounce(this, this._debouncedShow, INPUT_DELAY);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
copyUrl(pl) {
|
|
|
|
let linkElement = document.querySelector(`#admin-permalink-${pl.id}`);
|
|
|
|
clipboardCopy(linkElement.textContent);
|
2024-11-14 07:03:58 +08:00
|
|
|
this.toasts.success({
|
|
|
|
duration: 3000,
|
|
|
|
data: {
|
|
|
|
message: I18n.t("admin.permalink.copy_success"),
|
|
|
|
},
|
|
|
|
});
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2024-11-14 07:03:58 +08:00
|
|
|
destroyRecord(permalink) {
|
|
|
|
this.dialog.yesNoConfirm({
|
2023-03-15 17:42:12 +08:00
|
|
|
message: I18n.t("admin.permalink.delete_confirm"),
|
2024-11-14 07:03:58 +08:00
|
|
|
didConfirm: async () => {
|
|
|
|
try {
|
|
|
|
await this.store.destroyRecord("permalink", permalink);
|
|
|
|
this.model.removeObject(permalink);
|
|
|
|
} catch {
|
|
|
|
this.dialog.alert(I18n.t("generic_error"));
|
|
|
|
}
|
2023-03-15 17:42:12 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|