1
|
|
|
/** |
2
|
|
|
* Data Analytics |
3
|
|
|
* |
4
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
5
|
|
|
* later. See the LICENSE.md file. |
6
|
|
|
* |
7
|
|
|
* @author Marcel Scherello <[email protected]> |
8
|
|
|
* @copyright 2019 Marcel Scherello |
9
|
|
|
*/ |
10
|
|
|
/** global: OCA */ |
11
|
|
|
/** global: OCP */ |
12
|
|
|
/** global: OC */ |
13
|
|
|
'use strict'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @namespace OCA.Analytics.Advanced |
17
|
|
|
*/ |
18
|
|
|
OCA.Analytics.Advanced = {}; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @namespace OCA.Analytics.Advanced.Dataload |
22
|
|
|
*/ |
23
|
|
|
OCA.Analytics.Advanced.Dataload = { |
24
|
|
|
datasourceTemplates: [], |
25
|
|
|
dataloadArray: [], |
26
|
|
|
|
27
|
|
|
tabContainerDataload: function () { |
28
|
|
|
const datasetId = document.getElementById('app-sidebar').dataset.id; |
29
|
|
|
|
30
|
|
|
OCA.Analytics.Sidebar.resetView(); |
31
|
|
|
document.getElementById('tabHeaderDataload').classList.add('selected'); |
32
|
|
|
document.getElementById('tabContainerDataload').classList.remove('hidden'); |
33
|
|
|
document.getElementById('tabContainerDataload').innerHTML = '<div style="text-align:center; word-wrap:break-word;" class="get-metadata"><p><img src="' + OC.imagePath('core', 'loading.gif') + '"><br><br></p><p>' + t('analytics', 'Reading data') + '</p></div>'; |
34
|
|
|
|
35
|
|
|
$.ajax({ |
36
|
|
|
type: 'GET', |
37
|
|
|
url: OC.generateUrl('apps/analytics/dataload/') + datasetId, |
38
|
|
|
success: function (data) { |
39
|
|
|
let table; |
40
|
|
|
table = document.getElementById('templateDataload').cloneNode(true); |
41
|
|
|
table.id = 'tableDataload'; |
42
|
|
|
document.getElementById('tabContainerDataload').innerHTML = ''; |
43
|
|
|
document.getElementById('tabContainerDataload').appendChild(table); |
44
|
|
|
document.getElementById('createDataloadButton').addEventListener('click', OCA.Analytics.Advanced.Dataload.handleDataloadCreateButton); |
45
|
|
|
document.getElementById('dataloadList').innerHTML = ''; |
46
|
|
|
for (let dataload of data['dataloads']) { |
47
|
|
|
const li = OCA.Analytics.Advanced.Dataload.buildDataloadRow(dataload); |
48
|
|
|
document.getElementById('dataloadList').appendChild(li); |
49
|
|
|
} |
50
|
|
|
OCA.Analytics.Advanced.Dataload.datasourceTemplates = data['templates']; |
51
|
|
|
OCA.Analytics.Advanced.Dataload.dataloadArray = data['dataloads']; |
52
|
|
|
} |
53
|
|
|
}); |
54
|
|
|
}, |
55
|
|
|
|
56
|
|
|
handleDataloadCreateButton: function () { |
57
|
|
|
OCA.Analytics.Advanced.Dataload.createDataload(); |
58
|
|
|
}, |
59
|
|
|
|
60
|
|
|
handleDataloadUpdateButton: function () { |
61
|
|
|
OCA.Analytics.Advanced.Dataload.updateDataload(); |
62
|
|
|
}, |
63
|
|
|
|
64
|
|
|
handleDataloadDeleteButton: function () { |
65
|
|
|
OC.dialogs.confirm( |
66
|
|
|
t('analytics', 'Are you sure?'), |
67
|
|
|
t('analytics', 'Delete Dataload'), |
68
|
|
|
function (e) { |
69
|
|
|
if (e === true) { |
70
|
|
|
OCA.Analytics.Advanced.Dataload.deleteDataload(); |
71
|
|
|
} |
72
|
|
|
}, |
73
|
|
|
true |
74
|
|
|
); |
75
|
|
|
}, |
76
|
|
|
|
77
|
|
|
handleDataloadEditClick: function (evt) { |
78
|
|
|
OCA.Analytics.Advanced.Dataload.bildDataloadDetails(evt); |
79
|
|
|
}, |
80
|
|
|
|
81
|
|
|
handleDataloadExecuteButton: function (evt) { |
|
|
|
|
82
|
|
|
OCA.Analytics.Advanced.Dataload.executeDataload(); |
83
|
|
|
}, |
84
|
|
|
|
85
|
|
|
buildDataloadRow: function (dataload) { |
86
|
|
|
|
87
|
|
|
let item = document.createElement('div'); |
88
|
|
|
item.classList.add('dataloadItem'); |
89
|
|
|
|
90
|
|
|
let typeINT = parseInt(dataload.datasource); |
91
|
|
|
let typeIcon; |
92
|
|
|
if (typeINT === OCA.Analytics.TYPE_INTERNAL_FILE) { |
93
|
|
|
typeIcon = 'icon-file'; |
94
|
|
|
} else if (typeINT === OCA.Analytics.TYPE_INTERNAL_DB) { |
95
|
|
|
typeIcon = 'icon-projects'; |
96
|
|
|
} else if (typeINT === OCA.Analytics.TYPE_GIT || typeINT === OCA.Analytics.TYPE_EXTERNAL_FILE) { |
97
|
|
|
typeIcon = 'icon-external'; |
98
|
|
|
} else { |
99
|
|
|
typeIcon = 'icon-external'; |
100
|
|
|
} |
101
|
|
|
let a = document.createElement('a'); |
102
|
|
|
//a.setAttribute('href', '#'); |
103
|
|
|
a.classList.add(typeIcon); |
104
|
|
|
a.innerText = dataload.name; |
105
|
|
|
a.dataset.id = dataload.id; |
106
|
|
|
a.dataset.datasourceId = dataload.datasource; |
107
|
|
|
a.addEventListener('click', OCA.Analytics.Advanced.Dataload.handleDataloadEditClick); |
108
|
|
|
item.appendChild(a); |
109
|
|
|
return item; |
110
|
|
|
}, |
111
|
|
|
|
112
|
|
|
bildDataloadDetails: function (evt) { |
113
|
|
|
let dataload = OCA.Analytics.Advanced.Dataload.dataloadArray.find(x => x.id === parseInt(evt.target.dataset.id)); |
114
|
|
|
let template = OCA.Analytics.Advanced.Dataload.datasourceTemplates[evt.target.dataset.datasourceId]; |
115
|
|
|
|
116
|
|
|
document.getElementById('dataloadDetail').dataset.id = dataload.id; |
117
|
|
|
document.getElementById('dataloadName').value = dataload.name; |
118
|
|
|
document.getElementById('dataloadDetailHeader').hidden = false; |
119
|
|
|
document.getElementById('dataloadDetailButtons').hidden = false; |
120
|
|
|
document.getElementById('dataloadUpdateButton').addEventListener('click', OCA.Analytics.Advanced.Dataload.handleDataloadUpdateButton); |
121
|
|
|
document.getElementById('dataloadDeleteButton').addEventListener('click', OCA.Analytics.Advanced.Dataload.handleDataloadDeleteButton); |
122
|
|
|
document.getElementById('dataloadSchedule').value = dataload.schedule; |
123
|
|
|
document.getElementById('dataloadSchedule').addEventListener('change', OCA.Analytics.Advanced.Dataload.updateDataload); |
124
|
|
|
|
125
|
|
|
let item = document.getElementById('dataloadDetailItems'); |
126
|
|
|
item.innerHTML = ''; |
127
|
|
|
|
128
|
|
|
for (let option of template) { |
129
|
|
|
let tablerow = document.createElement('div'); |
130
|
|
|
//tablerow.style.display = 'table-row'; |
131
|
|
|
let label = document.createElement('div'); |
132
|
|
|
label.style.display = 'inline-flex'; |
133
|
|
|
label.classList.add('input150'); |
134
|
|
|
label.innerText = option.name; |
135
|
|
|
let input = document.createElement('input'); |
136
|
|
|
input.style.display = 'inline-flex'; |
137
|
|
|
input.classList.add('input150'); |
138
|
|
|
input.placeholder = option.placeholder; |
139
|
|
|
input.id = option.id; |
140
|
|
|
let fieldValues = JSON.parse(dataload.option); |
141
|
|
|
if (option.id in fieldValues) { |
142
|
|
|
input.value = fieldValues[option.id]; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
item.appendChild(tablerow); |
146
|
|
|
tablerow.appendChild(label); |
147
|
|
|
tablerow.appendChild(input); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
document.getElementById('dataloadRun').hidden = false; |
151
|
|
|
document.getElementById('dataloadExecuteButton').addEventListener('click', OCA.Analytics.Advanced.Dataload.handleDataloadExecuteButton); |
152
|
|
|
//scheduleButton.addEventListener('click', OCA.Analytics.Advanced.Dataload.handleDataloadExecuteButton); |
153
|
|
|
//useButton.addEventListener('click', OCA.Analytics.Advanced.Dataload.handleDataloadExecuteButton); |
154
|
|
|
|
155
|
|
|
}, |
156
|
|
|
|
157
|
|
|
createDataload: function () { |
158
|
|
|
const datasetId = parseInt(document.getElementById('app-sidebar').dataset.id); |
159
|
|
|
|
160
|
|
|
$.ajax({ |
161
|
|
|
type: 'POST', |
162
|
|
|
url: OC.generateUrl('apps/analytics/dataload'), |
163
|
|
|
data: { |
164
|
|
|
'datasetId': datasetId, |
165
|
|
|
'datasourceId': document.getElementById('dataloadType').value, |
166
|
|
|
}, |
167
|
|
|
success: function () { |
168
|
|
|
document.querySelector('.tabHeader.selected').click(); |
169
|
|
|
} |
170
|
|
|
}); |
171
|
|
|
}, |
172
|
|
|
|
173
|
|
|
updateDataload: function () { |
174
|
|
|
const dataloadId = document.getElementById('dataloadDetail').dataset.id; |
175
|
|
|
let option = {}; |
176
|
|
|
|
177
|
|
|
let inputFields = document.querySelectorAll('#dataloadDetailItems input'); |
178
|
|
|
for (let inputField of inputFields) { |
179
|
|
|
option[inputField.id] = inputField.value; |
180
|
|
|
} |
181
|
|
|
option = JSON.stringify(option); |
182
|
|
|
|
183
|
|
|
$.ajax({ |
184
|
|
|
type: 'PUT', |
185
|
|
|
url: OC.generateUrl('apps/analytics/dataload/') + dataloadId, |
186
|
|
|
data: { |
187
|
|
|
'name': document.getElementById('dataloadName').value, |
188
|
|
|
'schedule': document.getElementById('dataloadSchedule').value, |
189
|
|
|
'option': option, |
190
|
|
|
}, |
191
|
|
|
success: function () { |
192
|
|
|
OCA.Analytics.UI.notification('success', t('analytics', 'Dataload saved')); |
193
|
|
|
OCA.Analytics.Advanced.Dataload.dataloadArray.find(x => x.id === parseInt(dataloadId)).schedule = document.getElementById('dataloadSchedule').value; |
194
|
|
|
OCA.Analytics.Advanced.Dataload.dataloadArray.find(x => x.id === parseInt(dataloadId)).name = document.getElementById('dataloadName').value; |
195
|
|
|
} |
196
|
|
|
}); |
197
|
|
|
}, |
198
|
|
|
|
199
|
|
|
deleteDataload: function () { |
200
|
|
|
const dataloadId = document.getElementById('dataloadDetail').dataset.id; |
201
|
|
|
$.ajax({ |
202
|
|
|
type: 'DELETE', |
203
|
|
|
url: OC.generateUrl('apps/analytics/dataload/') + dataloadId, |
204
|
|
|
success: function (data) { |
|
|
|
|
205
|
|
|
document.querySelector('.tabHeader.selected').click(); |
206
|
|
|
} |
207
|
|
|
}); |
208
|
|
|
}, |
209
|
|
|
|
210
|
|
|
executeDataload: function () { |
211
|
|
|
const dataloadId = document.getElementById('dataloadDetail').dataset.id; |
212
|
|
|
let mode; |
213
|
|
|
if (document.getElementById('testrunCheckbox').checked) { |
214
|
|
|
mode = 'simulate'; |
215
|
|
|
} else { |
216
|
|
|
mode = 'execute'; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
$.ajax({ |
220
|
|
|
type: 'POST', |
221
|
|
|
url: OC.generateUrl('apps/analytics/dataload/') + mode, |
222
|
|
|
data: { |
223
|
|
|
'dataloadId': dataloadId, |
224
|
|
|
}, |
225
|
|
|
success: function (data) { |
226
|
|
|
if (mode === 'simulate') { |
227
|
|
|
OC.dialogs.message( |
228
|
|
|
JSON.stringify(data.data), |
229
|
|
|
t('analytics', 'Datasource simulation'), |
230
|
|
|
'info', |
231
|
|
|
OC.dialogs.OK_BUTTON, |
232
|
|
|
function (e) { |
|
|
|
|
233
|
|
|
}, |
234
|
|
|
true, |
235
|
|
|
true |
236
|
|
|
); |
237
|
|
|
} else { |
238
|
|
|
if (data.error === 0) { |
239
|
|
|
OCA.Analytics.UI.notification('success', data.insert + t('analytics', ' records inserted, ') + data.update + t('analytics', ' records updated')); |
240
|
|
|
//document.querySelector('#navigationDatasets [data-id="' + datasetId + '"]').click(); |
241
|
|
|
} else { |
242
|
|
|
OCA.Analytics.UI.notification('error', data.error); |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
}); |
247
|
|
|
}, |
248
|
|
|
|
249
|
|
|
}; |
250
|
|
|
|
251
|
|
|
OCA.Analytics.Advanced.Threshold = { |
252
|
|
|
|
253
|
|
|
tabContainerThreshold: function () { |
254
|
|
|
const datasetId = document.getElementById('app-sidebar').dataset.id; |
255
|
|
|
|
256
|
|
|
OCA.Analytics.Sidebar.resetView(); |
257
|
|
|
document.getElementById('tabHeaderThreshold').classList.add('selected'); |
258
|
|
|
document.getElementById('tabContainerThreshold').classList.remove('hidden'); |
259
|
|
|
document.getElementById('tabContainerThreshold').innerHTML = '<div style="text-align:center; word-wrap:break-word;" class="get-metadata"><p><img src="' + OC.imagePath('core', 'loading.gif') + '"><br><br></p><p>' + t('analytics', 'Reading data') + '</p></div>'; |
260
|
|
|
|
261
|
|
|
$.ajax({ |
262
|
|
|
type: 'GET', |
263
|
|
|
url: OC.generateUrl('apps/analytics/dataset/') + datasetId, |
264
|
|
|
success: function (data) { |
265
|
|
|
let table; |
266
|
|
|
table = document.getElementById('templateThreshold').cloneNode(true); |
267
|
|
|
table.id = 'tableThreshold'; |
268
|
|
|
document.getElementById('tabContainerThreshold').innerHTML = ''; |
269
|
|
|
document.getElementById('tabContainerThreshold').appendChild(table); |
270
|
|
|
document.getElementById('sidebarThresholdTextDimension1').innerText = data.dimension1 || t('analytics', 'Column 1'); |
271
|
|
|
document.getElementById('sidebarThresholdTextDimension3').innerText = data.dimension3 || t('analytics', 'Column 3'); |
272
|
|
|
document.getElementById('createThresholdButton').addEventListener('click', OCA.Analytics.Advanced.Threshold.handleThresholdCreateButton); |
273
|
|
|
if (parseInt(data.type) !== OCA.Analytics.TYPE_INTERNAL_DB) { |
274
|
|
|
document.getElementById('sidebarThresholdSeverity').remove(0); |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
}); |
278
|
|
|
|
279
|
|
|
$.ajax({ |
280
|
|
|
type: 'GET', |
281
|
|
|
url: OC.generateUrl('apps/analytics/threshold/') + datasetId, |
282
|
|
|
success: function (data) { |
283
|
|
|
if (data !== false) { |
284
|
|
|
document.getElementById('sidebarThresholdList').innerHTML = ''; |
285
|
|
|
for (let threshold of data) { |
286
|
|
|
const li = OCA.Analytics.Advanced.Threshold.buildThresholdRow(threshold); |
287
|
|
|
document.getElementById('sidebarThresholdList').appendChild(li); |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
}); |
292
|
|
|
}, |
293
|
|
|
|
294
|
|
|
handleThresholdCreateButton: function () { |
295
|
|
|
OCA.Analytics.Advanced.Threshold.createThreashold(); |
296
|
|
|
}, |
297
|
|
|
|
298
|
|
|
handleThresholdDeleteButton: function (evt) { |
299
|
|
|
const thresholdId = evt.target.dataset.id; |
300
|
|
|
OCA.Analytics.Advanced.Threshold.deleteThreshold(thresholdId); |
301
|
|
|
}, |
302
|
|
|
|
303
|
|
|
buildThresholdRow: function (data) { |
304
|
|
|
|
305
|
|
|
let bulletColor, bullet; |
306
|
|
|
data.severity = parseInt(data.severity); |
307
|
|
|
if (data.severity === 2) { |
308
|
|
|
bulletColor = 'red'; |
309
|
|
|
} else if (data.severity === 3) { |
310
|
|
|
bulletColor = 'orange'; |
311
|
|
|
} else { |
312
|
|
|
bulletColor = 'green'; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
if (data.severity === 1) { |
316
|
|
|
bullet = document.createElement('img'); |
317
|
|
|
bullet.src = OC.imagePath('notifications', 'notifications-dark.svg'); |
318
|
|
|
bullet.classList.add('thresholdBullet'); |
319
|
|
|
} else { |
320
|
|
|
bullet = document.createElement('div'); |
321
|
|
|
bullet.style.backgroundColor = bulletColor; |
322
|
|
|
bullet.classList.add('thresholdBullet'); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
let item = document.createElement('div'); |
326
|
|
|
item.classList.add('thresholdItem'); |
327
|
|
|
|
328
|
|
|
let text = document.createElement('div'); |
329
|
|
|
text.classList.add('thresholdText'); |
330
|
|
|
text.innerText = data.dimension1 + ' ' + data.option + ' ' + data.dimension3; |
331
|
|
|
|
332
|
|
|
let tDelete = document.createElement('div'); |
333
|
|
|
tDelete.classList.add('icon-close'); |
334
|
|
|
tDelete.dataset.id = data.id; |
335
|
|
|
tDelete.addEventListener('click', OCA.Analytics.Advanced.Threshold.handleThresholdDeleteButton); |
336
|
|
|
|
337
|
|
|
item.appendChild(bullet); |
338
|
|
|
item.appendChild(text); |
339
|
|
|
item.appendChild(tDelete); |
340
|
|
|
return item; |
341
|
|
|
}, |
342
|
|
|
|
343
|
|
|
createThreashold: function () { |
344
|
|
|
const datasetId = parseInt(document.getElementById('app-sidebar').dataset.id); |
345
|
|
|
const url = OC.generateUrl('apps/analytics/threshold'); |
346
|
|
|
|
347
|
|
|
$.ajax({ |
348
|
|
|
type: 'POST', |
349
|
|
|
url: url, |
350
|
|
|
data: { |
351
|
|
|
'datasetId': datasetId, |
352
|
|
|
'dimension1': document.getElementById('sidebarThresholdDimension1').value, |
353
|
|
|
'option': document.getElementById('sidebarThresholdOption').value, |
354
|
|
|
'dimension3': document.getElementById('sidebarThresholdDimension3').value, |
355
|
|
|
'severity': document.getElementById('sidebarThresholdSeverity').value, |
356
|
|
|
}, |
357
|
|
|
success: function () { |
358
|
|
|
document.querySelector('.tabHeader.selected').click(); |
359
|
|
|
} |
360
|
|
|
}); |
361
|
|
|
}, |
362
|
|
|
|
363
|
|
|
deleteThreshold: function (thresholdId) { |
364
|
|
|
|
365
|
|
|
$.ajax({ |
366
|
|
|
type: 'DELETE', |
367
|
|
|
url: OC.generateUrl('apps/analytics/threshold/') + thresholdId, |
368
|
|
|
success: function (data) { |
|
|
|
|
369
|
|
|
document.querySelector('.tabHeader.selected').click(); |
370
|
|
|
} |
371
|
|
|
}); |
372
|
|
|
}, |
373
|
|
|
|
374
|
|
|
}; |
375
|
|
|
|
376
|
|
|
document.addEventListener('DOMContentLoaded', function () { |
377
|
|
|
OCA.Analytics.Sidebar.registerSidebarTab({ |
378
|
|
|
id: 'tabHeaderDataload', |
379
|
|
|
class: 'tabContainerDataload', |
380
|
|
|
tabindex: '2', |
381
|
|
|
name: t('analytics', 'Dataload'), |
382
|
|
|
action: OCA.Analytics.Advanced.Dataload.tabContainerDataload, |
383
|
|
|
}); |
384
|
|
|
|
385
|
|
|
OCA.Analytics.Sidebar.registerSidebarTab({ |
386
|
|
|
id: 'tabHeaderThreshold', |
387
|
|
|
class: 'tabContainerThreshold', |
388
|
|
|
tabindex: '3', |
389
|
|
|
name: t('analytics', 'Thresholds'), |
390
|
|
|
action: OCA.Analytics.Advanced.Threshold.tabContainerThreshold, |
391
|
|
|
}); |
392
|
|
|
|
393
|
|
|
}); |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.