2019-10-23 12:30:52 -04:00
|
|
|
import Component from "@ember/component";
|
2020-08-18 13:02:13 -04:00
|
|
|
import I18n from "I18n";
|
2020-01-16 12:56:53 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-02-19 15:02:29 -05:00
|
|
|
import { fmt } from "discourse/lib/computed";
|
2021-01-22 10:03:43 -05:00
|
|
|
import { isDocumentRTL } from "discourse/lib/text-direction";
|
2019-10-30 09:48:24 -04:00
|
|
|
import { next } from "@ember/runloop";
|
2019-02-19 07:56:01 -05:00
|
|
|
|
2019-10-23 12:30:52 -04:00
|
|
|
export default Component.extend({
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("theme.targets", "onlyOverridden", "showAdvanced")
|
2019-02-19 07:56:01 -05:00
|
|
|
visibleTargets(targets, onlyOverridden, showAdvanced) {
|
|
|
|
return targets.filter((target) => {
|
|
|
|
if (target.advanced && !showAdvanced) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!onlyOverridden) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return target.edited;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("currentTargetName", "onlyOverridden", "theme.fields")
|
2019-02-19 07:56:01 -05:00
|
|
|
visibleFields(targetName, onlyOverridden, fields) {
|
|
|
|
fields = fields[targetName];
|
|
|
|
if (onlyOverridden) {
|
|
|
|
fields = fields.filter((field) => field.edited);
|
|
|
|
}
|
|
|
|
return fields;
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("currentTargetName", "fieldName")
|
2019-02-19 07:56:01 -05:00
|
|
|
activeSectionMode(targetName, fieldName) {
|
2020-09-22 10:28:28 -04:00
|
|
|
if (["settings", "translations"].includes(targetName)) {
|
|
|
|
return "yaml";
|
|
|
|
}
|
|
|
|
if (["extra_scss"].includes(targetName)) {
|
|
|
|
return "scss";
|
|
|
|
}
|
|
|
|
if (["color_definitions"].includes(fieldName)) {
|
|
|
|
return "scss";
|
|
|
|
}
|
2019-02-19 07:56:01 -05:00
|
|
|
return fieldName && fieldName.indexOf("scss") > -1 ? "scss" : "html";
|
|
|
|
},
|
|
|
|
|
2020-08-18 13:02:13 -04:00
|
|
|
@discourseComputed("currentTargetName", "fieldName")
|
|
|
|
placeholder(targetName, fieldName) {
|
2021-01-22 10:03:43 -05: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-18 13:02:13 -04:00
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("fieldName", "currentTargetName", "theme")
|
2019-02-19 07:56:01 -05: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-19 15:02:29 -05:00
|
|
|
editorId: fmt("fieldName", "currentTargetName", "%@|%@"),
|
2019-02-19 07:56:01 -05:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("maximized")
|
2019-02-19 07:56:01 -05:00
|
|
|
maximizeIcon(maximized) {
|
|
|
|
return maximized ? "discourse-compress" : "discourse-expand";
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("currentTargetName", "theme.targets")
|
2019-02-19 07:56:01 -05:00
|
|
|
showAddField(currentTargetName, targets) {
|
|
|
|
return targets.find((t) => t.name === currentTargetName).customNames;
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed(
|
|
|
|
"currentTargetName",
|
|
|
|
"fieldName",
|
|
|
|
"theme.theme_fields.@each.error"
|
|
|
|
)
|
2019-02-19 07:56:01 -05:00
|
|
|
error(target, fieldName) {
|
2019-05-27 04:15:39 -04:00
|
|
|
return this.theme.getError(target, fieldName);
|
2019-02-19 07:56:01 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
toggleShowAdvanced() {
|
|
|
|
this.toggleProperty("showAdvanced");
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleAddField() {
|
|
|
|
this.toggleProperty("addingField");
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelAddField() {
|
|
|
|
this.set("addingField", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
addField(name) {
|
2020-09-22 10:28:28 -04:00
|
|
|
if (!name) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-12 06:36:08 -04:00
|
|
|
name = name.replace(/[^a-zA-Z0-9-_/]/g, "");
|
2019-05-27 04:15:39 -04:00
|
|
|
this.theme.setField(this.currentTargetName, name, "");
|
2019-02-19 15:02:29 -05:00
|
|
|
this.setProperties({ newFieldName: "", addingField: false });
|
2019-05-27 04:15:39 -04:00
|
|
|
this.fieldAdded(this.currentTargetName, name);
|
2019-02-19 07:56:01 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleMaximize: function () {
|
|
|
|
this.toggleProperty("maximized");
|
2019-10-30 09:48:24 -04:00
|
|
|
next(() => this.appEvents.trigger("ace:resize"));
|
2019-02-19 07:56:01 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
onlyOverriddenChanged(value) {
|
|
|
|
this.onlyOverriddenChanged(value);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|