2020-08-18 13:02:13 -04:00
|
|
|
import I18n from "I18n";
|
2019-10-30 09:48:24 -04:00
|
|
|
import { next } from "@ember/runloop";
|
2019-10-23 12:30:52 -04:00
|
|
|
import Component from "@ember/component";
|
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";
|
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) {
|
|
|
|
if (["settings", "translations"].includes(targetName)) return "yaml";
|
2019-04-12 06:36:08 -04:00
|
|
|
if (["extra_scss"].includes(targetName)) return "scss";
|
2020-08-18 13:02:13 -04:00
|
|
|
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) {
|
|
|
|
return fieldName && fieldName === "color_definitions"
|
|
|
|
? I18n.t("admin.customize.theme.color_definitions.placeholder")
|
|
|
|
: "";
|
|
|
|
},
|
|
|
|
|
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) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|