-
Notifications
You must be signed in to change notification settings - Fork 19
/
WorkPackage.vue
311 lines (295 loc) · 8.2 KB
/
WorkPackage.vue
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
<template>
<div class="workpackage" @mouseover="resetColorsOnHover" @mouseleave="resetColorsOnHover">
<div class="row">
<div class="row__status"
:style="{'background-color': getWPStatusColor(), border: wpStatusBorder}">
<div class="row__status__title"
:style="{'color': wpStatusFontColor }">
{{ workpackage.statusTitle }}
</div>
</div>
<div class="row__workpackage">
#{{ workpackage.id }} - {{ workpackage.project }}
</div>
</div>
<div class="row">
<div class="row__subject">
<span :ref="workpackage.typeTitle"
class="row__subject__type"
:style="{'color': workpackage.typeCol, '-webkit-text-stroke': wpTypeTextStroke}">
{{ workpackage.typeTitle }}
</span>
{{ workpackage.subject }}
</div>
</div>
<div class="row">
<div v-if="workpackage.assignee" class="row__assignee">
<div class="row__assignee__avatar">
<NcAvatar class="item-avatar"
:size="23"
:url="workpackage.picture"
:user="workpackage.assignee"
:display-name="workpackage.assignee" />
</div>
<div class="row__assignee__assignee">
{{ workpackage.assignee }}
</div>
</div>
</div>
</div>
</template>
<script>
import { NcAvatar } from '@nextcloud/vue'
export default {
name: 'WorkPackage',
components: {
NcAvatar,
},
props: {
workpackage: {
type: Object,
required: true,
},
isSmartPicker: {
type: Boolean,
default: false,
},
isLinkPreviews: {
type: Boolean,
default: false,
},
},
data: () => ({
wpTypeTextStroke: 'unset',
wpStatusFontColor: '#FFFFFF',
wpStatusBorder: '0',
}),
created() {
this.setWPTypeTextStroke()
this.setWPStatusFontColor()
this.setWPStatusBorder()
},
methods: {
resetColorsOnHover() {
this.setWPTypeTextStroke()
this.setWPStatusBorder()
},
getWPStatusColor() {
if (this.workpackage.statusCol === undefined || this.workpackage.statusCol === '') {
return '#F99601'
}
return this.workpackage.statusCol
},
setWPStatusFontColor() {
this.wpStatusFontColor = '#FFFFFF'
try {
const contrast = this.contrastRatio(
this.wpStatusFontColor,
this.getWPStatusColor(),
)
if (contrast <= 2) {
this.wpStatusFontColor = '#000000'
}
} catch (e) {
// something went wrong, leave the values as they are
}
},
setWPStatusBorder() {
try {
let contrast = this.getContrastBetweenStatusColorAndBackground()
if (contrast <= 2) {
contrast = this.contrastRatio(this.getWPStatusColor(), '#000000')
if (contrast <= 2) {
this.wpStatusBorder = 'solid 1px #FFFFFF'
return
}
this.wpStatusBorder = 'solid 1px #000000'
return
}
this.wpStatusBorder = '0'
} catch (e) {
// something went wrong, leave the values as they are
}
},
getContrastBetweenStatusColorAndBackground() {
const backgroundColor = this.getBackgroundColor(this.getWPBackgroundElement())
return this.contrastRatio(this.getWPStatusColor(), backgroundColor)
},
setWPTypeTextStroke() {
this.wpTypeTextStroke = 'unset'
try {
const contrast = this.getContrastBetweenTypeColorAndBackground()
if (contrast <= 2) {
this.wpTypeTextStroke = '0.5px grey'
}
} catch {
// something went wrong, leave the values as they are
}
},
getContrastBetweenTypeColorAndBackground() {
const backgroundColor = this.getBackgroundColor(this.getWPBackgroundElement())
return this.contrastRatio(this.workpackage.typeCol, backgroundColor)
},
getWPBackgroundElement() {
let el = document.getElementById('workpackage-' + this.workpackage.id)
if (this.isSmartPicker) {
el = document.getElementById('work-package-smart-picker')
} else if (this.isLinkPreviews) {
el = document.getElementById('workpackage-link-previews')
}
if (el === null) {
el = document.getElementById('tab-open-project')
}
return el
},
hexToRgbA(hex) {
let c
if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
c = hex.substring(1).split('')
if (c.length === 3) {
c = [c[0], c[0], c[1], c[1], c[2], c[2]]
}
c = '0x' + c.join('')
return 'rgba(' + [(c >> 16) & 255, (c >> 8) & 255, c & 255].join(',') + ',1)'
}
throw new Error('Bad Hex')
},
// Parse rgb(r, g, b) and rgba(r, g, b, a) strings into an array.
// originated from https://github.com/jasonday/color-contrast/blob/e533684ce5d0c8d28479b3301b184bf88f5b7dd6/color-contrast.js
// Adapted from https://github.com/gka/chroma.js
parseRgb(colorString) {
let i, rgb, _i, _j
try {
colorString = this.hexToRgbA(colorString)
} catch (e) {
// it was not a hex string, so most likely a rgb(a) string
}
const rgbMatch = colorString.match(/rgb\(\s*(-?\d+),\s*(-?\d+)\s*,\s*(-?\d+)\s*\)/)
const rgbaMatch = colorString.match(/rgba\(\s*(-?\d+),\s*(-?\d+)\s*,\s*(-?\d+)\s*,\s*([01]|[01]?\.\d+)\)/)
if (rgbMatch !== null) {
rgb = rgbMatch.slice(1, 4)
for (i = _i = 0; _i <= 2; i = ++_i) {
rgb[i] = +rgb[i]
}
rgb[3] = 1
// eslint-disable-next-line no-cond-assign
} else if (rgbaMatch !== null) {
rgb = rgbaMatch.slice(1, 5)
for (i = _j = 0; _j <= 3; i = ++_j) {
rgb[i] = +rgb[i]
}
} else {
throw new Error('could not parse color')
}
return rgb
},
// originated from https://github.com/jasonday/color-contrast/blob/e533684ce5d0c8d28479b3301b184bf88f5b7dd6/color-contrast.js
// Based on http://www.w3.org/TR/WCAG20/#relativeluminancedef
relativeLuminance(c) {
const lum = []
for (let i = 0; i < 3; i++) {
const v = c[i] / 255
lum.push(v < 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4))
}
return (0.2126 * lum[0]) + (0.7152 * lum[1]) + (0.0722 * lum[2])
},
// originated from https://github.com/jasonday/color-contrast/blob/e533684ce5d0c8d28479b3301b184bf88f5b7dd6/color-contrast.js
// Based on http://www.w3.org/TR/WCAG20/#contrast-ratiodef
contrastRatio(x, y) {
const l1 = this.relativeLuminance(this.parseRgb(x))
const l2 = this.relativeLuminance(this.parseRgb(y))
return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05)
},
// originated from https://github.com/jasonday/color-contrast/blob/e533684ce5d0c8d28479b3301b184bf88f5b7dd6/color-contrast.js
getBackgroundColor(el) {
const styles = getComputedStyle(el)
const bgColor = styles.backgroundColor
const bgImage = styles.backgroundImage
const rgb = this.parseRgb(bgColor) + ''
const alpha = rgb.split(',')
// if background has alpha transparency, flag manual check
if (alpha[3] < 1 && alpha[3] > 0) {
throw new Error('could not determine background color')
}
// if element has no background image, or transparent background (alpha == 0) return bgColor
if (bgColor !== 'rgba(0, 0, 0, 0)' && bgColor !== 'transparent' && bgImage === 'none' && alpha[3] !== '0') {
return bgColor
} else if (bgImage !== 'none') {
throw new Error('could not determine background color')
}
// retest if not returned above
if (el.tagName === 'HTML') {
return 'rgb(255, 255, 255)'
} else {
return this.getBackgroundColor(el.parentNode)
}
},
},
}
</script>
<style scoped lang="scss">
.workpackage {
width: 100%;
padding: 15px 6px 0 10px;
.row {
display: flex;
padding: 3px;
flex-wrap: wrap;
&__status {
padding: 5px 10px;
width: fit-content;
height: 20px;
justify-content: center;
display: flex;
align-items: center;
text-align: center;
font-size: 0.75rem;
border-radius: 2px;
margin-right: 4px;
&__title {
font-size: 0.75rem;
line-height: 14px;
text-align: center;
}
}
&__workpackage {
color: #878787;
font-size: 0.8rem;
height: 20px;
line-height: 20px;
display: flex;
align-self: center;
}
&__subject {
font-size: 0.875rem;
text-align: justify;
white-space: normal;
text-justify: inter-word;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
&__type {
font-size: 0.75rem;
font-weight: bold;
text-transform: uppercase;
margin-right: 4px;
}
}
&__assignee {
display: flex;
flex-direction: row;
&__assignee {
font-size: 0.81rem;
color: #878787;
text-align: center;
padding-left: 5px;
}
}
}
}
.workpackage div {
cursor: pointer;
}
</style>