2019-10-31 04:28:29 +08:00
|
|
|
import { gt, equal } from "@ember/object/computed";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2018-08-31 03:23:15 +08:00
|
|
|
import { THEMES, COMPONENTS } from "admin/models/theme";
|
|
|
|
import { default as computed } from "ember-addons/ember-computed-decorators";
|
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend({
|
2018-08-31 03:23:15 +08:00
|
|
|
THEMES: THEMES,
|
|
|
|
COMPONENTS: COMPONENTS,
|
|
|
|
|
2018-08-24 09:30:00 +08:00
|
|
|
classNames: ["themes-list"],
|
2018-08-31 03:23:15 +08:00
|
|
|
|
2019-10-31 04:28:29 +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
|
|
|
|
2019-10-31 04:28:29 +08:00
|
|
|
themesTabActive: equal("currentTab", THEMES),
|
|
|
|
componentsTabActive: equal("currentTab", COMPONENTS),
|
2018-08-31 03:23:15 +08:00
|
|
|
|
|
|
|
@computed("themes", "components", "currentTab")
|
|
|
|
themesList(themes, components) {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.themesTabActive) {
|
2018-08-31 03:23:15 +08:00
|
|
|
return themes;
|
|
|
|
} else {
|
|
|
|
return components;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed(
|
|
|
|
"themesList",
|
|
|
|
"currentTab",
|
|
|
|
"themesList.@each.user_selectable",
|
|
|
|
"themesList.@each.default"
|
|
|
|
)
|
|
|
|
inactiveThemes(themes) {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.componentsTabActive) {
|
2019-01-25 22:19:01 +08:00
|
|
|
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")
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
@computed(
|
|
|
|
"themesList",
|
|
|
|
"currentTab",
|
|
|
|
"themesList.@each.user_selectable",
|
|
|
|
"themesList.@each.default"
|
|
|
|
)
|
2019-01-23 17:20:13 +08:00
|
|
|
activeThemes(themes) {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.componentsTabActive) {
|
2019-01-25 22:19:01 +08:00
|
|
|
return themes.filter(theme => theme.get("parent_themes.length") > 0);
|
2019-01-23 17:20:13 +08:00
|
|
|
} 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) {
|
2019-05-27 16:15:39 +08:00
|
|
|
if (newTab !== this.currentTab) {
|
2018-08-31 03:23:15 +08:00
|
|
|
this.set("currentTab", newTab);
|
|
|
|
}
|
2018-09-07 02:56:00 +08:00
|
|
|
},
|
|
|
|
navigateToTheme(theme) {
|
2019-01-12 00:54:23 +08:00
|
|
|
Ember.getOwner(this)
|
2018-09-07 02:56:00 +08:00
|
|
|
.lookup("router:main")
|
|
|
|
.transitionTo("adminCustomizeThemes.show", theme);
|
2018-08-31 03:23:15 +08:00
|
|
|
}
|
|
|
|
}
|
2018-08-24 09:30:00 +08:00
|
|
|
});
|