2019-10-30 16:28:29 -04:00
|
|
|
import { and, gt } from "@ember/object/computed";
|
2021-10-27 13:09:34 -04:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2019-07-03 04:18:11 -04:00
|
|
|
import Component from "@ember/component";
|
|
|
|
import { escape } from "pretty-text/sanitizer";
|
|
|
|
import { iconHTML } from "discourse-common/lib/icon-library";
|
2018-08-30 15:23:15 -04:00
|
|
|
|
|
|
|
const MAX_COMPONENTS = 4;
|
|
|
|
|
2019-10-23 12:30:52 -04:00
|
|
|
export default Component.extend({
|
2018-09-06 14:56:00 -04:00
|
|
|
childrenExpanded: false,
|
2018-08-30 15:23:15 -04:00
|
|
|
classNames: ["themes-list-item"],
|
2018-09-06 14:56:00 -04:00
|
|
|
classNameBindings: ["theme.selected:selected"],
|
2019-10-30 16:28:29 -04:00
|
|
|
hasComponents: gt("children.length", 0),
|
|
|
|
displayComponents: and("hasComponents", "theme.isActive"),
|
|
|
|
displayHasMore: gt("theme.childThemes.length", MAX_COMPONENTS),
|
2018-09-06 14:56:00 -04:00
|
|
|
|
|
|
|
click(e) {
|
2022-06-02 17:01:24 -04:00
|
|
|
if (!e.target.classList.contains("others-count")) {
|
2018-09-06 14:56:00 -04:00
|
|
|
this.navigateToTheme();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed(
|
2018-08-30 15:23:15 -04:00
|
|
|
"theme.component",
|
|
|
|
"theme.childThemes.@each.name",
|
2018-09-06 14:56:00 -04:00
|
|
|
"theme.childThemes.length",
|
|
|
|
"childrenExpanded"
|
2018-08-30 15:23:15 -04:00
|
|
|
)
|
|
|
|
children() {
|
2019-05-27 04:15:39 -04:00
|
|
|
const theme = this.theme;
|
2018-09-06 14:56:00 -04:00
|
|
|
let children = theme.get("childThemes");
|
2018-08-30 15:23:15 -04:00
|
|
|
if (theme.get("component") || !children) {
|
|
|
|
return [];
|
|
|
|
}
|
2019-05-27 04:15:39 -04:00
|
|
|
children = this.childrenExpanded
|
2018-09-06 14:56:00 -04:00
|
|
|
? children
|
|
|
|
: children.slice(0, MAX_COMPONENTS);
|
2019-07-03 04:18:11 -04:00
|
|
|
return children.map((t) => {
|
|
|
|
const name = escape(t.name);
|
|
|
|
return t.enabled ? name : `${iconHTML("ban")} ${name}`;
|
|
|
|
});
|
2018-08-30 15:23:15 -04:00
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed("children")
|
2018-11-13 08:57:50 -05:00
|
|
|
childrenString(children) {
|
|
|
|
return children.join(", ");
|
|
|
|
},
|
|
|
|
|
2019-11-07 16:38:28 -05:00
|
|
|
@discourseComputed(
|
2018-09-06 14:56:00 -04:00
|
|
|
"theme.childThemes.length",
|
|
|
|
"theme.component",
|
|
|
|
"childrenExpanded",
|
|
|
|
"children.length"
|
|
|
|
)
|
|
|
|
moreCount(childrenCount, component, expanded) {
|
|
|
|
if (component || !childrenCount || expanded) {
|
2018-08-30 15:23:15 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return childrenCount - MAX_COMPONENTS;
|
2018-09-06 14:56:00 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
toggleChildrenExpanded() {
|
|
|
|
this.toggleProperty("childrenExpanded");
|
|
|
|
},
|
2018-08-30 15:23:15 -04:00
|
|
|
},
|
|
|
|
});
|