author | ymh <ymh.work@gmail.com> |
Mon, 17 Sep 2018 15:32:33 +0200 | |
changeset 6 | 819a7ab4e3fb |
parent 4 | df751568fda6 |
permissions | -rw-r--r-- |
0
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
export const categoryColors = { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
topic: 'black', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
approval: '#00FF7F', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
disapproval: '#ff6666', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
question: '#3399ff', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
reference: '#FFFF66', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
important: '#abd9e9', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
keyword: '#c2a5cf', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
comment: '#abdda4', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
trouble: '#fdae61', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
call: '#007533', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
highlight: '#ffff3c', |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
}; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
export const categoryStyles = (cat) => { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
const color = categoryColors[cat]; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
if (color) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
return { backgroundColor: color, fontWeight: 'normal' }; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
return {}; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
}; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
export function getAnnotationStyle(annotation, metacategories) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
let style = 'highlight'; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
annotation.tags.some((tag) => { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
const tagStr = tag.startsWith('cat:') ? tag.substring(4) : tag; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
const tagStrLc = tagStr.toLowerCase(); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
let metacategory = false; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
if (tag.startsWith('cat:')) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
metacategory = metacategories.find(mc => mc.tag === tagStrLc); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
if (metacategory) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
style = metacategory.id; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
return true; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
return false; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
38 |
}); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
39 |
return categoryStyles(style); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
40 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
41 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
export function isDefinitionInTags(tags) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
43 |
return ( |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
tags.includes('définition') |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
|| tags.includes('definition') |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
46 |
|| tags.includes('act:définition') |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
47 |
|| tags.includes('act:definition') |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
48 |
|| tags.includes('act:def') |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
49 |
); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
50 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
51 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
52 |
// taken from https://github.com/disqus/disqus-react/blob/master/src/utils.js |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
53 |
export function insertScript(src, id, parentElement, attrs = {}) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
54 |
const script = window.document.createElement('script'); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
55 |
script.async = true; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
56 |
script.src = src; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
57 |
script.id = id; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
58 |
Object.keys(attrs).forEach((k) => { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
59 |
script.setAttribute(k, attrs[k]); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
60 |
}); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
61 |
parentElement.appendChild(script); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
62 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
63 |
return script; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
64 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
65 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
66 |
// take from https://github.com/disqus/disqus-react/blob/master/src/utils.js |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
67 |
export function removeScript(id, parentElement) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
68 |
const script = window.document.getElementById(id); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
69 |
if (script) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
70 |
parentElement.removeChild(script); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
71 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
72 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
73 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
74 |
export function getTerms(annotations) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
75 |
return annotations.reduce((res, annotation) => { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
76 |
const tags = annotation.tags.map(t => t.toLowerCase()); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
77 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
78 |
if (!tags.includes('cat:mot-clef')) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
79 |
return res; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
80 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
81 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
82 |
let term; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
83 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
84 |
(annotation.target[0].selector || []).some((selector) => { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
85 |
if (selector.type === 'TextQuoteSelector' && selector.exact) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
86 |
term = selector.exact.trim().toLowerCase(); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
87 |
return true; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
88 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
89 |
return false; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
90 |
}); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
91 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
92 |
if (term) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
93 |
res[term] = (res[term] || []); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
94 |
res[term].push(annotation); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
95 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
96 |
return res; |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
97 |
}, {}); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
98 |
} |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
99 |
|
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
100 |
export function toBase64(msg) { |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
101 |
return Buffer.from(msg).toString('base64'); |
5f4fcbc80b37
Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
102 |
} |
4
df751568fda6
Add dashboardId for calculating discussionId
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
103 |
|
df751568fda6
Add dashboardId for calculating discussionId
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
104 |
export function getTermId(term, dashboardId) { |
df751568fda6
Add dashboardId for calculating discussionId
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
105 |
return toBase64(dashboardId ? `${dashboardId}::${term}` : term); |
df751568fda6
Add dashboardId for calculating discussionId
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
106 |
} |