2019-10-30 16:28:29 -04:00
|
|
|
import { gt, equal } from "@ember/object/computed";
|
2019-10-23 12:30:52 -04:00
|
|
|
import Component from "@ember/component";
|
2018-08-30 15:23:15 -04:00
|
|
|
import { THEMES, COMPONENTS } from "admin/models/theme";
|
2019-11-07 16:38:28 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-11-07 12:20:35 -05:00
|
|
|
import { getOwner } from "@ember/application";
|
2018-08-30 15:23:15 -04:00
|
|
|
|
2019-10-23 12:30:52 -04:00
|
|
|
export default Component.extend({
|
2018-08-30 15:23:15 -04:00
|
|
|
THEMES: THEMES,
|
|
|
|
COMPONENTS: COMPONENTS,
|
|
|
|
|
2018-08-23 21:30:00 -04:00
|
|
|
classNames: ["themes-list"],
|
2018-08-30 15:23:15 -04:00
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
hasThemes: gt("themesList.length", 0),
|
|
|
|
hasActiveThemes: gt("activeThemes.length", 0),
|
|
|
|
hasInactiveThemes: gt("inactiveThemes.length", 0),
|
2018-08-30 15:23:15 -04:00
|
|
|
|
2019-10-30 16:28:29 -04:00
|
|
|
themesTabActive: equal("currentTab", THEMES),
|
|
|
|
componentsTabActive: equal("currentTab", COMPONENTS),
|
2018-08-30 15:23:15 -04:00
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("themes", "components", "currentTab")
|
2018-08-30 15:23:15 -04:00
|
|
|
themesList(themes, components) {
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.themesTabActive) {
|
2018-08-30 15:23:15 -04:00
|
|
|
return themes;
|
|
|
|
} else {
|
|
|
|
return components;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed(
|
2018-08-30 15:23:15 -04:00
|
|
|
"themesList",
|
|
|
|
"currentTab",
|
|
|
|
"themesList.@each.user_selectable",
|
|
|
|
"themesList.@each.default"
|
|
|
|
)
|
|
|
|
inactiveThemes(themes) {
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.componentsTabActive) {
|
2019-01-25 09:19:01 -05:00
|
|
|
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")
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed(
|
2018-08-30 15:23:15 -04:00
|
|
|
"themesList",
|
|
|
|
"currentTab",
|
|
|
|
"themesList.@each.user_selectable",
|
|
|
|
"themesList.@each.default"
|
|
|
|
)
|
2019-01-23 04:20:13 -05:00
|
|
|
activeThemes(themes) {
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.componentsTabActive) {
|
2019-01-25 09:19:01 -05:00
|
|
|
return themes.filter(theme => theme.get("parent_themes.length") > 0);
|
2019-01-23 04:20:13 -05: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-30 15:23:15 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
changeView(newTab) {
|
2019-05-27 04:15:39 -04:00
|
|
|
if (newTab !== this.currentTab) {
|
2018-08-30 15:23:15 -04:00
|
|
|
this.set("currentTab", newTab);
|
|
|
|
}
|
2018-09-06 14:56:00 -04:00
|
|
|
},
|
|
|
|
navigateToTheme(theme) {
|
2019-11-07 12:20:35 -05:00
|
|
|
getOwner(this)
|
2018-09-06 14:56:00 -04:00
|
|
|
.lookup("router:main")
|
|
|
|
.transitionTo("adminCustomizeThemes.show", theme);
|
2018-08-30 15:23:15 -04:00
|
|
|
}
|
|
|
|
}
|
2018-08-23 21:30:00 -04:00
|
|
|
});
|