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";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2020-08-14 03:42:03 +08:00
|
|
|
import { inject as service } from "@ember/service";
|
2018-08-31 03:23:15 +08:00
|
|
|
|
2019-10-24 00:30:52 +08:00
|
|
|
export default Component.extend({
|
2020-08-14 03:42:03 +08:00
|
|
|
router: service(),
|
|
|
|
THEMES,
|
|
|
|
COMPONENTS,
|
2018-08-31 03:23:15 +08:00
|
|
|
|
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
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("themes", "components", "currentTab")
|
2018-08-31 03:23:15 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed(
|
2018-08-31 03:23:15 +08:00
|
|
|
"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")
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed(
|
2018-08-31 03:23:15 +08:00
|
|
|
"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 {
|
2020-09-02 01:24:41 +08: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-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) {
|
2020-08-14 03:42:03 +08:00
|
|
|
this.router.transitionTo("adminCustomizeThemes.show", theme);
|
2018-08-31 03:23:15 +08:00
|
|
|
},
|
|
|
|
},
|
2018-08-24 09:30:00 +08:00
|
|
|
});
|