2023-10-11 02:38:59 +08:00
|
|
|
import { tracked } from "@glimmer/tracking";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { action } from "@ember/object";
|
2023-07-19 03:53:23 +08:00
|
|
|
import { inject as service } from "@ember/service";
|
2023-09-14 18:27:09 +08:00
|
|
|
import { disableImplicitInjections } from "discourse/lib/implicit-injections";
|
2023-10-11 02:38:59 +08:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2023-09-14 18:27:09 +08:00
|
|
|
import ReseedModal from "admin/components/modal/reseed";
|
|
|
|
|
2016-04-14 03:16:37 +08:00
|
|
|
let lastSearch;
|
|
|
|
|
2023-09-14 18:27:09 +08:00
|
|
|
@disableImplicitInjections
|
2023-03-15 17:42:12 +08:00
|
|
|
export default class AdminSiteTextIndexController extends Controller {
|
2023-07-19 03:53:23 +08:00
|
|
|
@service router;
|
|
|
|
@service siteSettings;
|
2023-09-14 18:27:09 +08:00
|
|
|
@service modal;
|
|
|
|
@service store;
|
|
|
|
|
|
|
|
@tracked locale;
|
|
|
|
@tracked q;
|
|
|
|
@tracked overridden;
|
|
|
|
@tracked outdated;
|
|
|
|
|
|
|
|
@tracked model;
|
|
|
|
|
|
|
|
@tracked searching = false;
|
|
|
|
@tracked preferred = false;
|
2023-07-19 03:53:23 +08:00
|
|
|
|
2023-07-10 10:06:40 +08:00
|
|
|
queryParams = ["q", "overridden", "outdated", "locale"];
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2023-09-14 18:27:09 +08:00
|
|
|
get resolvedOverridden() {
|
|
|
|
return [true, "true"].includes(this.overridden) ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
get resolvedOutdated() {
|
|
|
|
return [true, "true"].includes(this.outdated) ?? false;
|
|
|
|
}
|
2021-01-19 01:53:45 +08:00
|
|
|
|
2023-09-14 18:27:09 +08:00
|
|
|
get resolvedLocale() {
|
|
|
|
return this.locale ?? this.siteSettings.default_locale;
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2021-01-19 01:53:45 +08:00
|
|
|
|
2023-09-14 18:27:09 +08:00
|
|
|
async _performSearch() {
|
|
|
|
try {
|
|
|
|
this.model = await this.store.find("site-text", {
|
|
|
|
q: this.q,
|
|
|
|
overridden: this.resolvedOverridden,
|
|
|
|
outdated: this.resolvedOutdated,
|
|
|
|
locale: this.resolvedLocale,
|
|
|
|
});
|
|
|
|
} finally {
|
|
|
|
this.searching = false;
|
|
|
|
}
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2023-09-14 18:27:09 +08:00
|
|
|
get availableLocales() {
|
2021-01-19 01:53:45 +08:00
|
|
|
return JSON.parse(this.siteSettings.available_locales);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2021-01-19 01:53:45 +08:00
|
|
|
|
2023-09-14 18:27:09 +08:00
|
|
|
get fallbackLocaleFullName() {
|
|
|
|
if (this.model.extras.fallback_locale) {
|
2021-01-19 01:53:45 +08:00
|
|
|
return this.availableLocales.find((l) => {
|
2023-09-14 18:27:09 +08:00
|
|
|
return l.value === this.model.extras.fallback_locale;
|
2021-01-19 01:53:45 +08:00
|
|
|
}).name;
|
|
|
|
}
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
edit(siteText) {
|
2023-07-19 03:53:23 +08:00
|
|
|
this.router.transitionTo("adminSiteText.edit", siteText.get("id"), {
|
2023-03-15 17:42:12 +08:00
|
|
|
queryParams: {
|
2023-09-14 18:27:09 +08:00
|
|
|
locale: this.resolvedLocale,
|
2023-03-15 17:42:12 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-01-19 01:53:45 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
toggleOverridden() {
|
2023-09-14 18:27:09 +08:00
|
|
|
if (this.resolvedOverridden) {
|
|
|
|
this.overridden = null;
|
|
|
|
} else {
|
|
|
|
this.overridden = true;
|
|
|
|
}
|
|
|
|
this.searching = true;
|
2023-03-15 17:42:12 +08:00
|
|
|
discourseDebounce(this, this._performSearch, 400);
|
|
|
|
}
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2023-07-10 10:06:40 +08:00
|
|
|
@action
|
|
|
|
toggleOutdated() {
|
2023-09-14 18:27:09 +08:00
|
|
|
if (this.resolvedOutdated) {
|
|
|
|
this.outdated = null;
|
|
|
|
} else {
|
|
|
|
this.outdated = true;
|
|
|
|
}
|
|
|
|
this.searching = true;
|
2023-07-10 10:06:40 +08:00
|
|
|
discourseDebounce(this, this._performSearch, 400);
|
|
|
|
}
|
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
search() {
|
|
|
|
const q = this.q;
|
|
|
|
if (q !== lastSearch) {
|
2023-09-14 18:27:09 +08:00
|
|
|
this.searching = true;
|
2020-12-18 21:18:52 +08:00
|
|
|
discourseDebounce(this, this._performSearch, 400);
|
2023-03-15 17:42:12 +08:00
|
|
|
lastSearch = q;
|
|
|
|
}
|
|
|
|
}
|
2021-01-19 01:53:45 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
updateLocale(value) {
|
2023-09-14 18:27:09 +08:00
|
|
|
this.searching = true;
|
|
|
|
this.locale = value;
|
2021-01-19 01:53:45 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
discourseDebounce(this, this._performSearch, 400);
|
|
|
|
}
|
2023-09-14 18:27:09 +08:00
|
|
|
|
|
|
|
@action
|
|
|
|
showReseedModal() {
|
|
|
|
this.modal.show(ReseedModal);
|
|
|
|
}
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|