/
category-wrapper.js
99 lines (83 loc) · 2.29 KB
/
category-wrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import Component from "@ember/component";
import { action } from "@ember/object";
import { service } from "@ember/service";
import discourseComputed from "discourse-common/utils/decorators";
import I18n from "I18n";
export default Component.extend({
router: service(),
tagName: "",
listOrder: ["title", "activity"],
init() {
this._super(...arguments);
},
@action
selectCategory() {
this.get("router").transitionTo("docs.index", {
queryParams: {
category: this.category.id,
order: this.order,
ascending: this.ascending,
},
});
},
@discourseComputed("category")
categoryInfo(category) {
return this.site.categories.findBy("id", category.id);
},
@discourseComputed("categoryIcons", "categoryInfo.id")
categoryIcon(icons, id) {
return icons[id];
},
@discourseComputed("categoryOrders", "categoryInfo.id")
order(orders, id) {
if (orders[id] && orders[id].split("-").length > 0) {
if (
this.listOrder.includes(orders[id].split("-")[0].trim().toLowerCase())
) {
return orders[id].split("-")[0].trim().toLowerCase();
}
}
return null;
},
@discourseComputed("categoryOrders", "categoryInfo.id")
ascending(orders, id) {
if (orders[id] && orders[id].split("-").length > 1) {
if (orders[id].split("-")[1].trim().toLowerCase().startsWith("a")) {
return true;
}
}
return false;
},
@discourseComputed("categoryInfo.name")
categoryName(categoryName) {
return categoryName;
},
@discourseComputed("categoryInfo.slug")
categorySlug(categorySlug) {
return categorySlug;
},
@discourseComputed("categoryInfo.description")
hasDescription(description) {
return description && settings.category_description;
},
@discourseComputed("categoryInfo.description")
categoryDescription(description) {
return description;
},
@discourseComputed("categoryInfo.color")
categoryColor(color) {
return `#${color}`;
},
@discourseComputed("categoryInfo.topic_count")
hasTopics(count) {
return count >= 1;
},
@discourseComputed("categoryInfo.topic_count")
topicCount(count) {
if (count > 1) {
return `${count} ${I18n.t(themePrefix("topics"))}`;
} else {
return `${count} ${I18n.t(themePrefix("topic"))}`;
}
},
});