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

80 lines
2.0 KiB
Plaintext
Raw Normal View History

import { gt, equal } from "@ember/object/computed";
import Component from "@ember/component";
2018-08-31 03:23:15 +08:00
import { THEMES, COMPONENTS } from "admin/models/theme";
import discourseComputed from "discourse-common/utils/decorators";
import { getOwner } from "@ember/application";
2018-08-31 03:23:15 +08:00
export default Component.extend({
2018-08-31 03:23:15 +08:00
THEMES: THEMES,
COMPONENTS: COMPONENTS,
classNames: ["themes-list"],
2018-08-31 03:23:15 +08:00
hasThemes: gt("themesList.length", 0),
hasActiveThemes: gt("activeThemes.length", 0),
hasInactiveThemes: gt("inactiveThemes.length", 0),
2018-08-31 03:23:15 +08:00
themesTabActive: equal("currentTab", THEMES),
componentsTabActive: equal("currentTab", COMPONENTS),
2018-08-31 03:23:15 +08:00
@discourseComputed("themes", "components", "currentTab")
2018-08-31 03:23:15 +08:00
themesList(themes, components) {
if (this.themesTabActive) {
2018-08-31 03:23:15 +08:00
return themes;
} else {
return components;
}
},
@discourseComputed(
2018-08-31 03:23:15 +08:00
"themesList",
"currentTab",
"themesList.@each.user_selectable",
"themesList.@each.default"
)
inactiveThemes(themes) {
if (this.componentsTabActive) {
return themes.filter(theme => theme.get("parent_themes.length") <= 0);
2018-08-31 03:23:15 +08:00
}
return themes.filter(
theme => !theme.get("user_selectable") && !theme.get("default")
);
},
@discourseComputed(
2018-08-31 03:23:15 +08:00
"themesList",
"currentTab",
"themesList.@each.user_selectable",
"themesList.@each.default"
)
activeThemes(themes) {
if (this.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-31 03:23:15 +08:00
}
},
actions: {
changeView(newTab) {
if (newTab !== this.currentTab) {
2018-08-31 03:23:15 +08:00
this.set("currentTab", newTab);
}
},
navigateToTheme(theme) {
getOwner(this)
.lookup("router:main")
.transitionTo("adminCustomizeThemes.show", theme);
2018-08-31 03:23:15 +08:00
}
}
});