2023-03-15 17:42:12 +08:00
|
|
|
import { action } from "@ember/object";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2021-01-19 01:53:45 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2020-12-18 21:18:52 +08:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2016-04-14 03:16:37 +08:00
|
|
|
let lastSearch;
|
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
export default class AdminSiteTextIndexController extends Controller {
|
|
|
|
searching = false;
|
|
|
|
siteTexts = null;
|
|
|
|
preferred = false;
|
2023-07-10 10:06:40 +08:00
|
|
|
queryParams = ["q", "overridden", "outdated", "locale"];
|
2023-03-15 17:42:12 +08:00
|
|
|
locale = null;
|
|
|
|
q = null;
|
|
|
|
overridden = false;
|
2023-07-10 10:06:40 +08:00
|
|
|
outdated = false;
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2021-01-19 01:53:45 +08:00
|
|
|
init() {
|
2023-03-15 17:42:12 +08:00
|
|
|
super.init(...arguments);
|
2021-01-19 01:53:45 +08:00
|
|
|
|
|
|
|
this.set("locale", this.siteSettings.default_locale);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2021-01-19 01:53:45 +08:00
|
|
|
|
2015-11-24 05:45:05 +08:00
|
|
|
_performSearch() {
|
2015-12-01 04:22:58 +08:00
|
|
|
this.store
|
2023-07-10 10:06:40 +08:00
|
|
|
.find(
|
|
|
|
"site-text",
|
|
|
|
this.getProperties("q", "overridden", "outdated", "locale")
|
|
|
|
)
|
2015-12-01 04:22:58 +08:00
|
|
|
.then((results) => {
|
2015-11-24 05:45:05 +08:00
|
|
|
this.set("siteTexts", results);
|
|
|
|
})
|
|
|
|
.finally(() => this.set("searching", false));
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2021-01-19 01:53:45 +08:00
|
|
|
@discourseComputed()
|
|
|
|
availableLocales() {
|
|
|
|
return JSON.parse(this.siteSettings.available_locales);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2021-01-19 01:53:45 +08:00
|
|
|
|
|
|
|
@discourseComputed("locale")
|
|
|
|
fallbackLocaleFullName() {
|
|
|
|
if (this.siteTexts.extras.fallback_locale) {
|
|
|
|
return this.availableLocales.find((l) => {
|
|
|
|
return l.value === this.siteTexts.extras.fallback_locale;
|
|
|
|
}).name;
|
|
|
|
}
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
edit(siteText) {
|
|
|
|
this.transitionToRoute("adminSiteText.edit", siteText.get("id"), {
|
|
|
|
queryParams: {
|
|
|
|
locale: this.locale,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2021-01-19 01:53:45 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
toggleOverridden() {
|
|
|
|
this.toggleProperty("overridden");
|
|
|
|
this.set("searching", true);
|
|
|
|
discourseDebounce(this, this._performSearch, 400);
|
|
|
|
}
|
2015-11-24 05:45:05 +08:00
|
|
|
|
2023-07-10 10:06:40 +08:00
|
|
|
@action
|
|
|
|
toggleOutdated() {
|
|
|
|
this.toggleProperty("outdated");
|
|
|
|
this.set("searching", true);
|
|
|
|
discourseDebounce(this, this._performSearch, 400);
|
|
|
|
}
|
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@action
|
|
|
|
search() {
|
|
|
|
const q = this.q;
|
|
|
|
if (q !== lastSearch) {
|
2019-02-21 22:54:54 +08:00
|
|
|
this.set("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) {
|
|
|
|
this.setProperties({
|
|
|
|
searching: true,
|
|
|
|
locale: value,
|
|
|
|
});
|
2021-01-19 01:53:45 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
discourseDebounce(this, this._performSearch, 400);
|
|
|
|
}
|
|
|
|
}
|