-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.js
44 lines (37 loc) · 1.15 KB
/
util.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
const MILLISECONDS_IN_DAY = 1000 * 60 * 60 * 24
export function futureDays (date) {
return Math.floor((date * 1000 - Date.now()) / MILLISECONDS_IN_DAY)
}
export function createElement (tag, text = null, props = {}) {
const elem = document.createElement(tag)
if (text) {
elem.textContent = text
}
for (const [key, value] of Object.entries(props)) {
elem[key] = value
}
return elem
}
export function createGoalLabel ({ baremin, losedate }) {
const text = ` (${baremin}/${futureDays(losedate)}d)`
return createElement('span', text, {
className: 'small-description'
})
}
export function goalCmp ({ dataset: x }, { dataset: y }) {
if (+x.collapsed === +y.collapsed) {
return x.urgencykey === y.urgencykey ? 0 : x.urgencykey > y.urgencykey ? 1 : -1
} else {
if (+x.collapsed) return 1
else return -1
}
}
export function getGoalElements () {
return Array.from(document.querySelectorAll('.dashboard > .panel > .goals > .goal'))
}
export function getGoalParentElement () {
return document.querySelector('.dashboard > .panel > .goals')
}
export function isGoalCollapsed (elem) {
return Boolean(+elem.dataset.collapsed)
}