2019-10-30 21:48:24 +08:00
|
|
|
import { next } from "@ember/runloop";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2019-11-08 05:38:28 +08:00
|
|
|
import { default as discourseComputed } from "discourse-common/utils/decorators";
|
2019-02-20 04:02:29 +08:00
|
|
|
import { fmt } from "discourse/lib/computed";
|
2019-02-19 20:56:01 +08:00
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend({
|
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) {
|
|
|
|
if (["settings", "translations"].includes(targetName)) return "yaml";
|
2019-04-12 18:36:08 +08:00
|
|
|
if (["extra_scss"].includes(targetName)) return "scss";
|
2019-02-19 20:56:01 +08:00
|
|
|
return fieldName && fieldName.indexOf("scss") > -1 ? "scss" : "html";
|
|
|
|
},
|
|
|
|
|
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) {
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
toggleMaximize: function() {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|