/
tag-wrapper.js
73 lines (62 loc) · 1.6 KB
/
tag-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
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: "",
init() {
this._super(...arguments);
},
@action
selectTag() {
this.get("router").transitionTo("docs.index", {
queryParams: {
tags: this.tag.id,
order: this.order,
ascending: this.ascending,
},
});
},
@discourseComputed("tagOrders", "tag.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("tagOrders", "tag.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("tagIcons", "tag.id")
tagIcon(tagIcons, id) {
return tagIcons[id];
},
@discourseComputed("tag.id")
tagTitle(tagTitle) {
return tagTitle.replaceAll("-", " ");
},
@discourseComputed("tag")
hasTopics(tag) {
return tag.count >= 1;
},
@discourseComputed("tag.count")
topicCount(count) {
if (count > 1) {
return `${count} ${I18n.t(themePrefix("topics"))}`;
} else {
return `${count} ${I18n.t(themePrefix("topic"))}`;
}
},
});