discourse/app/assets/javascripts/admin/components/themes-list.js.es6

77 lines
2.0 KiB
Plaintext
Raw Normal View History

2018-08-30 15:23:15 -04:00
import { THEMES, COMPONENTS } from "admin/models/theme";
import { default as computed } from "ember-addons/ember-computed-decorators";
export default Ember.Component.extend({
2018-08-30 15:23:15 -04:00
THEMES: THEMES,
COMPONENTS: COMPONENTS,
classNames: ["themes-list"],
2018-08-30 15:23:15 -04:00
2019-01-11 11:54:23 -05:00
hasThemes: Ember.computed.gt("themesList.length", 0),
hasActiveThemes: Ember.computed.gt("activeThemes.length", 0),
2019-01-11 11:54:23 -05:00
hasInactiveThemes: Ember.computed.gt("inactiveThemes.length", 0),
2018-08-30 15:23:15 -04:00
2019-01-11 11:54:23 -05:00
themesTabActive: Ember.computed.equal("currentTab", THEMES),
componentsTabActive: Ember.computed.equal("currentTab", COMPONENTS),
2018-08-30 15:23:15 -04:00
@computed("themes", "components", "currentTab")
themesList(themes, components) {
if (this.get("themesTabActive")) {
return themes;
} else {
return components;
}
},
@computed(
"themesList",
"currentTab",
"themesList.@each.user_selectable",
"themesList.@each.default"
)
inactiveThemes(themes) {
if (this.get("componentsTabActive")) {
return themes.filter(theme => theme.get("parent_themes.length") <= 0);
2018-08-30 15:23:15 -04:00
}
return themes.filter(
theme => !theme.get("user_selectable") && !theme.get("default")
);
},
@computed(
"themesList",
"currentTab",
"themesList.@each.user_selectable",
"themesList.@each.default"
)
activeThemes(themes) {
2018-08-30 15:23:15 -04:00
if (this.get("componentsTabActive")) {
return themes.filter(theme => theme.get("parent_themes.length") > 0);
} else {
themes = themes.filter(
theme => theme.get("user_selectable") || theme.get("default")
);
return _.sortBy(themes, t => {
return [
!t.get("default"),
!t.get("user_selectable"),
t.get("name").toLowerCase()
];
});
2018-08-30 15:23:15 -04:00
}
},
actions: {
changeView(newTab) {
if (newTab !== this.get("currentTab")) {
this.set("currentTab", newTab);
}
},
navigateToTheme(theme) {
2019-01-11 11:54:23 -05:00
Ember.getOwner(this)
.lookup("router:main")
.transitionTo("adminCustomizeThemes.show", theme);
2018-08-30 15:23:15 -04:00
}
}
});