2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2020-08-19 01:02:13 +08:00
|
|
|
import I18n from "I18n";
|
2020-01-17 01:56:53 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-02-20 04:02:29 +08:00
|
|
|
import { fmt } from "discourse/lib/computed";
|
2021-01-22 23:03:43 +08:00
|
|
|
import { isDocumentRTL } from "discourse/lib/text-direction";
|
2019-10-30 21:48:24 +08:00
|
|
|
import { next } from "@ember/runloop";
|
2019-02-19 20:56:01 +08:00
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend({
|
2021-05-11 21:01:06 +08:00
|
|
|
warning: null,
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("theme.targets", "onlyOverridden", "showAdvanced")
|
2019-02-19 20:56:01 +08:00
|
|
|
visibleTargets(targets, onlyOverridden, showAdvanced) {
|
|
|
|
return targets.filter((target) => {
|
|
|
|
if (target.advanced && !showAdvanced) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!onlyOverridden) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return target.edited;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("currentTargetName", "onlyOverridden", "theme.fields")
|
2019-02-19 20:56:01 +08:00
|
|
|
visibleFields(targetName, onlyOverridden, fields) {
|
|
|
|
fields = fields[targetName];
|
|
|
|
if (onlyOverridden) {
|
|
|
|
fields = fields.filter((field) => field.edited);
|
|
|
|
}
|
|
|
|
return fields;
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("currentTargetName", "fieldName")
|
2019-02-19 20:56:01 +08:00
|
|
|
activeSectionMode(targetName, fieldName) {
|
2020-09-22 22:28:28 +08:00
|
|
|
if (["settings", "translations"].includes(targetName)) {
|
|
|
|
return "yaml";
|
|
|
|
}
|
|
|
|
if (["extra_scss"].includes(targetName)) {
|
|
|
|
return "scss";
|
|
|
|
}
|
|
|
|
if (["color_definitions"].includes(fieldName)) {
|
|
|
|
return "scss";
|
|
|
|
}
|
2022-07-18 02:48:36 +08:00
|
|
|
return fieldName && fieldName.includes("scss") ? "scss" : "html";
|
2019-02-19 20:56:01 +08:00
|
|
|
},
|
|
|
|
|
2020-08-19 01:02:13 +08:00
|
|
|
@discourseComputed("currentTargetName", "fieldName")
|
|
|
|
placeholder(targetName, fieldName) {
|
2021-01-22 23:03:43 +08:00
|
|
|
if (fieldName && fieldName === "color_definitions") {
|
|
|
|
const example =
|
|
|
|
":root {\n" +
|
|
|
|
" --mytheme-tertiary-or-quaternary: #{dark-light-choose($tertiary, $quaternary)};\n" +
|
|
|
|
"}";
|
|
|
|
|
|
|
|
return I18n.t("admin.customize.theme.color_definitions.placeholder", {
|
|
|
|
example: isDocumentRTL() ? `<div dir="ltr">${example}</div>` : example,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return "";
|
2020-08-19 01:02:13 +08:00
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("fieldName", "currentTargetName", "theme")
|
2019-02-19 20:56:01 +08:00
|
|
|
activeSection: {
|
|
|
|
get(fieldName, target, model) {
|
|
|
|
return model.getField(target, fieldName);
|
|
|
|
},
|
|
|
|
set(value, fieldName, target, model) {
|
|
|
|
model.setField(target, fieldName, value);
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2019-02-20 04:02:29 +08:00
|
|
|
editorId: fmt("fieldName", "currentTargetName", "%@|%@"),
|
2019-02-19 20:56:01 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("maximized")
|
2019-02-19 20:56:01 +08:00
|
|
|
maximizeIcon(maximized) {
|
|
|
|
return maximized ? "discourse-compress" : "discourse-expand";
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("currentTargetName", "theme.targets")
|
2019-02-19 20:56:01 +08:00
|
|
|
showAddField(currentTargetName, targets) {
|
|
|
|
return targets.find((t) => t.name === currentTargetName).customNames;
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed(
|
|
|
|
"currentTargetName",
|
|
|
|
"fieldName",
|
|
|
|
"theme.theme_fields.@each.error"
|
|
|
|
)
|
2019-02-19 20:56:01 +08:00
|
|
|
error(target, fieldName) {
|
2019-05-27 16:15:39 +08:00
|
|
|
return this.theme.getError(target, fieldName);
|
2019-02-19 20:56:01 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
toggleShowAdvanced() {
|
|
|
|
this.toggleProperty("showAdvanced");
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleAddField() {
|
|
|
|
this.toggleProperty("addingField");
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelAddField() {
|
|
|
|
this.set("addingField", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
addField(name) {
|
2020-09-22 22:28:28 +08:00
|
|
|
if (!name) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-12 18:36:08 +08:00
|
|
|
name = name.replace(/[^a-zA-Z0-9-_/]/g, "");
|
2019-05-27 16:15:39 +08:00
|
|
|
this.theme.setField(this.currentTargetName, name, "");
|
2019-02-20 04:02:29 +08:00
|
|
|
this.setProperties({ newFieldName: "", addingField: false });
|
2019-05-27 16:15:39 +08:00
|
|
|
this.fieldAdded(this.currentTargetName, name);
|
2019-02-19 20:56:01 +08:00
|
|
|
},
|
|
|
|
|
2021-11-13 21:01:55 +08:00
|
|
|
toggleMaximize() {
|
2019-02-19 20:56:01 +08:00
|
|
|
this.toggleProperty("maximized");
|
2019-10-30 21:48:24 +08:00
|
|
|
next(() => this.appEvents.trigger("ace:resize"));
|
2019-02-19 20:56:01 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
onlyOverriddenChanged(value) {
|
|
|
|
this.onlyOverriddenChanged(value);
|
|
|
|
},
|
2021-05-04 19:56:10 +08:00
|
|
|
|
|
|
|
save() {
|
|
|
|
this.attrs.save();
|
|
|
|
},
|
2021-05-11 21:01:06 +08:00
|
|
|
|
|
|
|
setWarning(message) {
|
|
|
|
this.set("warning", message);
|
|
|
|
},
|
2019-02-19 20:56:01 +08:00
|
|
|
},
|
|
|
|
});
|