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