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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-08-30 15:23:15 -04:00
import { COMPONENTS, THEMES } from "admin/models/theme";
import { equal, gt } from "@ember/object/computed";
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
import { inject as service } from "@ember/service";
2018-08-30 15:23:15 -04:00
export default Component.extend({
router: service(),
THEMES,
COMPONENTS,
2018-08-30 15:23:15 -04:00
classNames: ["themes-list"],
2018-08-30 15:23:15 -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
themesTabActive: equal("currentTab", THEMES),
componentsTabActive: equal("currentTab", COMPONENTS),
2018-08-30 15:23:15 -04:00
@discourseComputed("themes", "components", "currentTab")
2018-08-30 15:23:15 -04:00
themesList(themes, components) {
if (this.themesTabActive) {
2018-08-30 15:23:15 -04:00
return themes;
} else {
return components;
}
},
@discourseComputed(
2018-08-30 15:23:15 -04: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-30 15:23:15 -04:00
}
return themes.filter(
(theme) => !theme.get("user_selectable") && !theme.get("default")
);
},
@discourseComputed(
2018-08-30 15:23:15 -04: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 {
2020-09-01 13:24:41 -04:00
return themes
.filter((theme) => theme.get("user_selectable") || theme.get("default"))
.sort((a, b) => {
if (a.get("default") && !b.get("default")) {
return -1;
} else if (b.get("default")) {
return 1;
}
return a
.get("name")
.toLowerCase()
.localeCompare(b.get("name").toLowerCase());
});
2018-08-30 15:23:15 -04:00
}
},
actions: {
changeView(newTab) {
if (newTab !== this.currentTab) {
2018-08-30 15:23:15 -04:00
this.set("currentTab", newTab);
}
},
navigateToTheme(theme) {
this.router.transitionTo("adminCustomizeThemes.show", theme);
2018-08-30 15:23:15 -04:00
},
},
});