-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsummation_rows.js
264 lines (245 loc) · 12.6 KB
/
summation_rows.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
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
const summationRowContents = (function() {
const fragment = document.createDocumentFragment()
for(let i = columns.baseID; i < columns.endID; i ++) fragment.appendChild(createCell(''))
return fragment
})()
const rows = (function() {
function getRowCells(query) {
const row = document.querySelector(query)
row.style.width = columns.applicationWidth + columns.sidebarWidth + 'px'
row.appendChild(summationRowContents.cloneNode(true))
return Array.from(row.querySelectorAll('.slotCell'))
}
const emptyCells = getRowCells('.emptyRow')
const workloadCells = getRowCells('.workloadRow')
const employeeCells = getRowCells('.employeesRow')
const summationCells = getRowCells('.summationRow')
const emptyCellsI = getRowCells('.emptyRowI')
const workloadCellsI = getRowCells('.workloadRowI')
const employeeCellsI = getRowCells('.employeesRowI')
const summationCellsI = getRowCells('.summationRowI')
const summationCellsT = getRowCells('.summationRowT')
return {
get empty() {
let empty = []
projects.list.filter(project => !project.interiors).forEach(project => project.visibleSlots.filter(slot => !slot.employee).map(slot => slot.workload).forEach(workload => {
empty.push(workload)
}))
return empty
},
get emptyI() {
let empty = []
projects.list.filter(project => project.interiors).forEach(project => project.visibleSlots.filter(slot => !slot.employee).map(slot => slot.workload).forEach(workload => {
empty.push(workload)
}))
return empty
},
get workload() {
let totalWorkload = []
projects.list.filter(project => !project.interiors).forEach(project => project.visibleSlots.map(slot => slot.workload).forEach(workload => {
totalWorkload.push(workload)
}))
return totalWorkload
},
get workloadI() {
let totalWorkload = []
projects.list.filter(project => project.interiors).forEach(project => project.visibleSlots.map(slot => slot.workload).forEach(workload => {
totalWorkload.push(workload)
}))
return totalWorkload
},
get workloadT() {
let totalWorkload = []
projects.list.forEach(project => project.visibleSlots.map(slot => slot.workload).forEach(workload => {
totalWorkload.push(workload)
}))
return totalWorkload
},
get employees() {
let employeeCapability = {}
employees.visibleList.filter(employee => !employee.interiors).forEach(employee => {
for(let i = columns.baseID; i < columns.endID; i++) {
if(employee.joining && i <= employee.joining || employee.leaving && i >= employee.leaving) continue
employeeCapability[i] = employeeCapability[i] + Number(employee.fullTime) || Number(employee.fullTime)
employee.slots.forEach(slot => {
if(slot.host.interiors && slot.workload[i]) {
employeeCapability[i] = employeeCapability[i] - Number(slot.workload[i])
}
})
}
})
employees.visibleList.filter(employee => employee.interiors).forEach(employee => {
for(let i = columns.baseID; i < columns.endID; i++) {
if(employee.joining && i <= employee.joining || employee.leaving && i >= employee.leaving) continue
employee.slots.forEach(slot => {
if(!slot.host.interiors && slot.workload[i]) {
employeeCapability[i] = employeeCapability[i] + Number(slot.workload[i])
}
})
}
})
// go through the other category and look for jobs of the type, and count the workload those employees are doing
return [employeeCapability]
},
get employeesI() {
let employeeCapability = {}
employees.visibleList.filter(employee => employee.interiors).forEach(employee => {
for(let i = columns.baseID; i < columns.endID; i++) {
if(employee.joining && i <= employee.joining || employee.leaving && i >= employee.leaving) continue
employeeCapability[i] = employeeCapability[i] + Number(employee.fullTime) || Number(employee.fullTime)
employee.slots.forEach(slot => {
if(!slot.host.interiors && slot.workload[i]) {
employeeCapability[i] = employeeCapability[i] - Number(slot.workload[i])
}
})
}
})
employees.visibleList.filter(employee => !employee.interiors).forEach(employee => {
for(let i = columns.baseID; i < columns.endID; i++) {
if(employee.joining && i <= employee.joining || employee.leaving && i >= employee.leaving) continue
employee.slots.forEach(slot => {
if(slot.host.interiors && slot.workload[i]) {
console.log(employeeCapability[i], slot.workload[i])
employeeCapability[i] = employeeCapability[i] + Number(slot.workload[i]) || Number(slot.workload[i])
}
})
}
})
return [employeeCapability]
},
get employeesT() {
let employeeCapability = {}
employees.visibleList.forEach(employee => {
for(let i = columns.baseID; i < columns.endID; i++) {
if(employee.joining && i <= employee.joining || employee.leaving && i >= employee.leaving) continue
employeeCapability[i] = employeeCapability[i] + Number(employee.fullTime) || Number(employee.fullTime)
}
})
return [employeeCapability]
},
get summation() {
let summation = {}
const workload = this.totalWorkload(this.workload)
const employees = this.employees[0]
for(const key in workload) {
summation[key] = (employees[key] || 0) - (workload[key] || 0)
}
return summation
},
get summationI() {
let summation = {}
const workload = this.totalWorkload(this.workloadI)
const employees = this.employeesI[0]
for(const key in workload) {
summation[key] = (employees[key] || 0) - (workload[key] || 0)
}
return summation
},
get summationT() {
const totalSummation = this.summation
const summationI = this.summationI
for(const key in summationI) {
if(totalSummation[key]) totalSummation[key] += summationI[key]
else totalSummation[key] = summationI[key]
}
return totalSummation
},
totalWorkload(list) {
let totalWorkload = {}
list.forEach(workload => {
for(const key in workload) totalWorkload[key] = totalWorkload[key] + Number(workload[key]) || Number(workload[key])
})
for(let i = columns.baseID; i < columns.endID; i++) {
if(totalWorkload[i]) continue
totalWorkload[i] = 0
}
return totalWorkload
},
refreshCellsSlots() {
this.refreshCells(emptyCells, this.totalWorkload(this.empty))
this.refreshCells(emptyCellsI, this.totalWorkload(this.emptyI))
this.refreshCells(workloadCells, this.totalWorkload(this.workload))
this.refreshCells(workloadCellsI, this.totalWorkload(this.workloadI))
// this.refreshCells(summationCells, this.summation, true)
this.refreshSummation()
},
refreshCellsEmployees() {
this.refreshCells(employeeCells, this.totalWorkload(this.employees))
this.refreshCells(employeeCellsI, this.totalWorkload(this.employeesI))
// this.refreshCells(summationCells, this.summation, true)
this.refreshSummation()
},
refreshCellsAll() {
this.refreshCells(emptyCells, this.totalWorkload(this.empty))
this.refreshCells(emptyCellsI, this.totalWorkload(this.emptyI))
this.refreshCells(workloadCells, this.totalWorkload(this.workload))
this.refreshCells(workloadCellsI, this.totalWorkload(this.workloadI))
this.refreshCells(employeeCells, this.totalWorkload(this.employees))
this.refreshCells(employeeCellsI, this.totalWorkload(this.employeesI))
// this.refreshCells(summationCells, this.summation, true)
this.refreshSummation()
},
refreshCells(cells, list, color = false) {
for(const key in list) {
if(cells[key - columns.baseID]) cells[key - columns.baseID].textContent = rowSanitise(list[key])
}
},
refreshSummation() {
const employees = this.totalWorkload(this.employees)
const workload = this.totalWorkload(this.workload)
const summation = this.summation
for(const key in summation) {
if(summationCells[key - columns.baseID]) {
summationCells[key - columns.baseID].textContent = rowSanitise(summation[key])
// const value = Math.round(workload[key] / employees[key] * 100)
// summationCells[key - columns.baseID].textContent = value == Infinity ? 0 : value
if(workload[key] / employees[key] < sheets.active.minimum) {
summationCells[key - columns.baseID].style.backgroundColor = 'orange'
} else if(workload[key] / employees[key] > sheets.active.maximum) {
summationCells[key - columns.baseID].style.backgroundColor = 'red'
} else {
summationCells[key - columns.baseID].style.backgroundColor = 'green'
}
}
}
const employeesI = this.totalWorkload(this.employeesI)
const workloadI = this.totalWorkload(this.workloadI)
const summationI = this.summationI
for(const key in summationI) {
if(summationCellsI[key - columns.baseID]) {
summationCellsI[key - columns.baseID].textContent = rowSanitise(summationI[key])
// const value = Math.round(workload[key] / employees[key] * 100)
// summationCellsI[key - columns.baseID].textContent = value == Infinity ? 0 : value
if(workloadI[key] / employeesI[key] < sheets.active.minimum) {
summationCellsI[key - columns.baseID].style.backgroundColor = 'orange'
} else if(workloadI[key] / employeesI[key] > sheets.active.maximum) {
summationCellsI[key - columns.baseID].style.backgroundColor = 'red'
} else {
summationCellsI[key - columns.baseID].style.backgroundColor = 'green'
}
}
}
const employeesT = this.totalWorkload(this.employeesT)
const workloadT = this.totalWorkload(this.workloadT)
const summationT = this.summationT
for(const key in summationT) {
if(summationCellsT[key - columns.baseID]) {
summationCellsT[key - columns.baseID].textContent = rowSanitise(summationT[key])
// const value = Math.round(workload[key] / employees[key] * 100)
// summationCellsT[key - columns.baseID].textContent = value == Infinity ? 0 : value
if(workloadT[key] / employeesT[key] < sheets.active.minimum) {
summationCellsT[key - columns.baseID].style.backgroundColor = 'orange'
} else if(workloadT[key] / employeesT[key] > sheets.active.maximum) {
summationCellsT[key - columns.baseID].style.backgroundColor = 'red'
} else {
summationCellsT[key - columns.baseID].style.backgroundColor = 'green'
}
}
}
}
}
})()
function rowSanitise(value) {
return (Number(value) / 5).toFixed(1)
}
var called = 0