-
Notifications
You must be signed in to change notification settings - Fork 25
/
kanban-manager.js
162 lines (137 loc) · 4.46 KB
/
kanban-manager.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { tracked } from "@glimmer/tracking";
import { action, get } from "@ember/object";
import Service, { inject as service } from "@ember/service";
import Category from "discourse/models/category";
import buildAssignedLists from "../lib/kanban-list-builders/assigned";
import buildCategoryLists from "../lib/kanban-list-builders/categories";
import buildTagLists from "../lib/kanban-list-builders/tags";
export default class KanbanManager extends Service {
@service router;
@tracked fullscreen;
getBoardUrl({ category, tag, descriptor = "default" }) {
const categorySlug = category ? Category.slugFor(category) : null;
let url;
if (category && tag) {
url = `/tags/c/${categorySlug}/${tag.id}?board=${descriptor}`;
} else if (tag) {
url = `/tags/${tag.id}?board=${descriptor}`;
} else if (category) {
url = `/c/${categorySlug}/l/latest?board=${descriptor}`;
} else {
url = `/latest?board=${descriptor}`;
}
return url;
}
discoveryRouteAttribute(path) {
const { name, attributes } = this.router.currentRoute;
if (
(name.startsWith("discovery.latest") ||
name.startsWith("tags.show") ||
name === "tag.show") &&
attributes
) {
return get(attributes, path);
}
}
get discoveryParams() {
return (
this.discoveryRouteAttribute("params") ||
this.discoveryRouteAttribute("modelParams") ||
this.discoveryRouteAttribute("list.listParams") // tag.show
);
}
get discoveryTopTags() {
return this.discoveryRouteAttribute("list.topic_list.top_tags");
}
get discoveryCategory() {
return this.discoveryRouteAttribute("category");
}
get discoveryTag() {
return this.discoveryRouteAttribute("tag");
}
get active() {
return !!this.currentDescriptor;
}
get currentDescriptor() {
return this.discoveryParams && get(this.discoveryParams, "board");
}
get listDefinitions() {
return this.findDefinition()?.lists;
}
get definitionBuilders() {
return {
tags: (param) => buildTagLists({ kanbanManager: this, param }),
categories: (param) => buildCategoryLists({ kanbanManager: this, param }),
assigned: (param) => buildAssignedLists({ kanbanManager: this, param }),
};
}
get resolvedDescriptorParts() {
let descriptor = this.currentDescriptor;
if (typeof descriptor !== "string") {
return;
}
const setDefaults = settings.default_modes
.split("|")
.map((m) => m.split(":"));
const lookup = this.get("discoveryCategory.slug") || "@";
const defaultMode = setDefaults.find((m) => m[0] === lookup);
if (defaultMode && descriptor === "default") {
defaultMode.shift();
descriptor = defaultMode.join(":");
}
if (descriptor === "default") {
if (!this.discoveryCategory) {
descriptor = "categories";
} else if (
this.discoveryCategory.subcategories &&
this.discoveryCategory.subcategories.length > 0
) {
descriptor = "categories";
} else {
descriptor = "tags";
}
}
return descriptor.split(":");
}
get mode() {
return this.resolvedDescriptorParts[0];
}
@action
calcListsHeights() {
const mainOutlet = document.querySelector("#main-outlet");
const mainOutletHeight = mainOutlet.getBoundingClientRect().height;
const mainOutletPadding = 40;
// Get all previous siblings of the list container and add their heights
let currentElement =
mainOutlet.querySelector(".list-container").previousElementSibling;
let previousSiblingsHeight = 0;
while (currentElement !== null) {
previousSiblingsHeight += currentElement.getBoundingClientRect().height;
currentElement = currentElement.previousElementSibling;
}
const listTitleHeight = mainOutlet
.querySelector(".list-title")
.getBoundingClientRect().height;
let height;
if (this.fullscreen) {
// the 10px is for the padding on the top of the list
height = mainOutletHeight + 10;
} else {
height =
mainOutletHeight -
previousSiblingsHeight -
listTitleHeight -
mainOutletPadding;
}
const lists = document.querySelectorAll(".discourse-kanban-list .topics");
lists.forEach((element) => {
element.style.height = `${height}px`;
});
}
findDefinition() {
const [type, param] = this.resolvedDescriptorParts;
if (this.definitionBuilders[type]) {
return this.definitionBuilders[type](param);
}
}
}