mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 01:56:58 +08:00
DEV: introduces prettier for es6 files
This commit is contained in:
@ -1,66 +1,91 @@
|
||||
import { url } from 'discourse/lib/computed';
|
||||
import { default as computed, observes } from 'ember-addons/ember-computed-decorators';
|
||||
import { url } from "discourse/lib/computed";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
maximized: false,
|
||||
section: null,
|
||||
|
||||
editRouteName: 'adminCustomizeThemes.edit',
|
||||
editRouteName: "adminCustomizeThemes.edit",
|
||||
|
||||
targets: [
|
||||
{ id: 0, name: 'common' },
|
||||
{ id: 1, name: 'desktop' },
|
||||
{ id: 2, name: 'mobile' },
|
||||
{ id: 3, name: 'settings' }
|
||||
{ id: 0, name: "common" },
|
||||
{ id: 1, name: "desktop" },
|
||||
{ id: 2, name: "mobile" },
|
||||
{ id: 3, name: "settings" }
|
||||
],
|
||||
|
||||
fieldsForTarget: function (target) {
|
||||
const common = ["scss", "head_tag", "header", "after_header", "body_tag", "footer"];
|
||||
switch(target) {
|
||||
case "common": return [...common, "embedded_scss"];
|
||||
case "desktop": return common;
|
||||
case "mobile": return common;
|
||||
case "settings": return ["yaml"];
|
||||
fieldsForTarget: function(target) {
|
||||
const common = [
|
||||
"scss",
|
||||
"head_tag",
|
||||
"header",
|
||||
"after_header",
|
||||
"body_tag",
|
||||
"footer"
|
||||
];
|
||||
switch (target) {
|
||||
case "common":
|
||||
return [...common, "embedded_scss"];
|
||||
case "desktop":
|
||||
return common;
|
||||
case "mobile":
|
||||
return common;
|
||||
case "settings":
|
||||
return ["yaml"];
|
||||
}
|
||||
},
|
||||
|
||||
@computed('onlyOverridden')
|
||||
@computed("onlyOverridden")
|
||||
showCommon() {
|
||||
return this.shouldShow('common');
|
||||
return this.shouldShow("common");
|
||||
},
|
||||
|
||||
@computed('onlyOverridden')
|
||||
@computed("onlyOverridden")
|
||||
showDesktop() {
|
||||
return this.shouldShow('desktop');
|
||||
return this.shouldShow("desktop");
|
||||
},
|
||||
|
||||
@computed('onlyOverridden')
|
||||
@computed("onlyOverridden")
|
||||
showMobile() {
|
||||
return this.shouldShow('mobile');
|
||||
return this.shouldShow("mobile");
|
||||
},
|
||||
|
||||
@computed('onlyOverridden', 'model.remote_theme')
|
||||
@computed("onlyOverridden", "model.remote_theme")
|
||||
showSettings() {
|
||||
return false;
|
||||
},
|
||||
|
||||
@observes('onlyOverridden')
|
||||
@observes("onlyOverridden")
|
||||
onlyOverriddenChanged() {
|
||||
if (this.get('onlyOverridden')) {
|
||||
if (!this.get('model').hasEdited(this.get('currentTargetName'), this.get('fieldName'))) {
|
||||
let target = (this.get('showCommon') && 'common') ||
|
||||
(this.get('showDesktop') && 'desktop') ||
|
||||
(this.get('showMobile') && 'mobile');
|
||||
if (this.get("onlyOverridden")) {
|
||||
if (
|
||||
!this.get("model").hasEdited(
|
||||
this.get("currentTargetName"),
|
||||
this.get("fieldName")
|
||||
)
|
||||
) {
|
||||
let target =
|
||||
(this.get("showCommon") && "common") ||
|
||||
(this.get("showDesktop") && "desktop") ||
|
||||
(this.get("showMobile") && "mobile");
|
||||
|
||||
let fields = this.get('model.theme_fields');
|
||||
let field = fields && fields.find(f => (f.target === target));
|
||||
this.replaceRoute(this.get('editRouteName'), this.get('model.id'), target, field && field.name);
|
||||
let fields = this.get("model.theme_fields");
|
||||
let field = fields && fields.find(f => f.target === target);
|
||||
this.replaceRoute(
|
||||
this.get("editRouteName"),
|
||||
this.get("model.id"),
|
||||
target,
|
||||
field && field.name
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
shouldShow(target){
|
||||
if(!this.get("onlyOverridden")) {
|
||||
shouldShow(target) {
|
||||
if (!this.get("onlyOverridden")) {
|
||||
return true;
|
||||
}
|
||||
return this.get("model").hasEdited(target);
|
||||
@ -69,13 +94,13 @@ export default Ember.Controller.extend({
|
||||
currentTarget: 0,
|
||||
|
||||
setTargetName: function(name) {
|
||||
const target = this.get('targets').find(t => t.name === name);
|
||||
const target = this.get("targets").find(t => t.name === name);
|
||||
this.set("currentTarget", target && target.id);
|
||||
},
|
||||
|
||||
@computed("currentTarget")
|
||||
currentTargetName(id) {
|
||||
const target = this.get('targets').find(t => t.id === parseInt(id, 10));
|
||||
const target = this.get("targets").find(t => t.id === parseInt(id, 10));
|
||||
return target && target.name;
|
||||
},
|
||||
|
||||
@ -87,7 +112,7 @@ export default Ember.Controller.extend({
|
||||
|
||||
@computed("currentTargetName", "fieldName", "saving")
|
||||
error(target, fieldName) {
|
||||
return this.get('model').getError(target, fieldName);
|
||||
return this.get("model").getError(target, fieldName);
|
||||
},
|
||||
|
||||
@computed("fieldName", "currentTargetName")
|
||||
@ -116,9 +141,9 @@ export default Ember.Controller.extend({
|
||||
fields = fields.filter(name => model.hasEdited(targetName, name));
|
||||
}
|
||||
|
||||
return fields.map(name=>{
|
||||
return fields.map(name => {
|
||||
let hash = {
|
||||
key: (`admin.customize.theme.${name}.text`),
|
||||
key: `admin.customize.theme.${name}.text`,
|
||||
name: name
|
||||
};
|
||||
|
||||
@ -132,30 +157,36 @@ export default Ember.Controller.extend({
|
||||
});
|
||||
},
|
||||
|
||||
previewUrl: url('model.id', '/admin/themes/%@/preview'),
|
||||
previewUrl: url("model.id", "/admin/themes/%@/preview"),
|
||||
|
||||
maximizeIcon: function() {
|
||||
return this.get('maximized') ? 'compress' : 'expand';
|
||||
}.property('maximized'),
|
||||
return this.get("maximized") ? "compress" : "expand";
|
||||
}.property("maximized"),
|
||||
|
||||
saveButtonText: function() {
|
||||
return this.get('model.isSaving') ? I18n.t('saving') : I18n.t('admin.customize.save');
|
||||
}.property('model.isSaving'),
|
||||
return this.get("model.isSaving")
|
||||
? I18n.t("saving")
|
||||
: I18n.t("admin.customize.save");
|
||||
}.property("model.isSaving"),
|
||||
|
||||
saveDisabled: function() {
|
||||
return !this.get('model.changed') || this.get('model.isSaving');
|
||||
}.property('model.changed', 'model.isSaving'),
|
||||
return !this.get("model.changed") || this.get("model.isSaving");
|
||||
}.property("model.changed", "model.isSaving"),
|
||||
|
||||
actions: {
|
||||
save() {
|
||||
this.set('saving', true);
|
||||
this.get('model').saveChanges("theme_fields").finally(()=>{this.set('saving', false);});
|
||||
this.set("saving", true);
|
||||
this.get("model")
|
||||
.saveChanges("theme_fields")
|
||||
.finally(() => {
|
||||
this.set("saving", false);
|
||||
});
|
||||
},
|
||||
|
||||
toggleMaximize: function() {
|
||||
this.toggleProperty('maximized');
|
||||
Em.run.next(()=>{
|
||||
this.appEvents.trigger('ace:resize');
|
||||
this.toggleProperty("maximized");
|
||||
Em.run.next(() => {
|
||||
this.appEvents.trigger("ace:resize");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user