1
|
|
|
/** |
2
|
|
|
* 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 2020 Marcel Scherello |
9
|
|
|
*/ |
10
|
|
|
/** global: OCA */ |
11
|
|
|
/** global: OCP */ |
12
|
|
|
/** global: OC */ |
13
|
|
|
'use strict'; |
14
|
|
|
|
15
|
|
|
if (!OCA.Analytics) { |
16
|
|
|
/** |
17
|
|
|
* @namespace |
18
|
|
|
*/ |
19
|
|
|
OCA.Analytics = {}; |
20
|
|
|
} |
21
|
|
|
/** |
22
|
|
|
* @namespace OCA.Analytics.Wizzard |
23
|
|
|
*/ |
24
|
|
|
OCA.Analytics.Wizzard = { |
25
|
|
|
sildeArray: [ |
26
|
|
|
'', |
27
|
|
|
'wizzard-start', |
28
|
|
|
'wizzard-charts', |
29
|
|
|
'wizzard-filter', |
30
|
|
|
'wizzard-datasource', |
31
|
|
|
'wizzard-dataload', |
32
|
|
|
'wizzard-final' |
33
|
|
|
], |
34
|
|
|
currentSlide: 0, |
35
|
|
|
|
36
|
|
|
show: function () { |
37
|
|
|
OCA.Analytics.Wizzard.currentSlide = 0; |
38
|
|
|
let wizzard = document.importNode(document.getElementById('wizzardDialog').content, true); |
39
|
|
|
document.getElementById('content').appendChild(wizzard); |
40
|
|
|
document.getElementById('wizzardNext').addEventListener('click', OCA.Analytics.Wizzard.next); |
41
|
|
|
document.getElementById('wizzardPrevious').addEventListener('click', OCA.Analytics.Wizzard.previous); |
42
|
|
|
OCA.Analytics.Wizzard.next(); |
43
|
|
|
}, |
44
|
|
|
|
45
|
|
|
next: function () { |
46
|
|
|
if (OCA.Analytics.Wizzard.currentSlide < OCA.Analytics.Wizzard.sildeArray.length - 1) { |
47
|
|
|
OCA.Analytics.Wizzard.currentSlide++; |
48
|
|
|
OCA.Analytics.Wizzard.showPage(); |
49
|
|
|
} |
50
|
|
|
}, |
51
|
|
|
|
52
|
|
|
previous: function () { |
53
|
|
|
if (OCA.Analytics.Wizzard.currentSlide !== 1) { |
54
|
|
|
OCA.Analytics.Wizzard.currentSlide--; |
55
|
|
|
OCA.Analytics.Wizzard.showPage(); |
56
|
|
|
} |
57
|
|
|
}, |
58
|
|
|
|
59
|
|
|
close: function () { |
60
|
|
|
OCA.Analytics.Wizzard.dismiss(); |
61
|
|
|
document.getElementById('firstrunwizard').remove(); |
62
|
|
|
}, |
63
|
|
|
|
64
|
|
|
demo: function () { |
65
|
|
|
let notificationTest = '{"dataset":{"name":"Demo: Notification Test","type":2,"link":"{}","visualization":"table","chart":"","dimension1":"Object","dimension2":"Date","dimension3":"Value","subheader":"subhead","chartoptions":"","dataoptions":"","filteroptions":null,"value":"Value"},"dataload":[{"id":105,"user_id":"admin","dataset":103,"datasource":3,"name":"test github","option":"{\\"user\\":\\"a\\",\\"repository\\":\\"a\\",\\"limit\\":\\"1\\",\\"timestamp\\":\\"true\\",\\"delete\\":\\"false\\"}","schedule":""}],"threshold":[{"id":21,"dimension1":"a","dimension2":null,"value":"2.00","option":"=","severity":4},{"id":22,"dimension1":"a","dimension2":null,"value":"1.00","option":"!=","severity":1},{"id":32,"dimension1":"*","dimension2":null,"value":"6.00","option":"=","severity":2}],"data":[["a","a","3.00"],["a","b","2.00"],["a","c","2.00"],["b","b","6.00"],["red KPI","b","6.00"]]}'; |
66
|
|
|
OCA.Analytics.Navigation.importDataset(null, notificationTest); |
67
|
|
|
|
68
|
|
|
let population = '{"dataset":{"name":"Demo: Population Data","type":4,"link":"{\\"link\\":\\"https:\\/\\/raw.githubusercontent.com\\/Rello\\/analytics\\/master\\/sample_data\\/sample1.csv\\",\\"columns\\":\\"\\",\\"offset\\":\\"\\"}","visualization":"ct","chart":"line","dimension1":"","dimension2":"","dimension3":null,"subheader":"Realtime CSV Data from GitHub via the \\"Extrernal URL\\" datasource","chartoptions":"","dataoptions":"","filteroptions":null,"value":""},"dataload":[],"threshold":[],"favorite":"true"}'; |
69
|
|
|
OCA.Analytics.Navigation.importDataset(null, population); |
70
|
|
|
|
71
|
|
|
let github = '{"dataset":{"name":"Demo: Analytics Downloads","type":3,"link":"{\\"user\\":\\"rello\\",\\"repository\\":\\"analytics\\",\\"limit\\":\\"10\\",\\"timestamp\\":\\"false\\"}","visualization":"ct","chart":"column","dimension1":"Object","dimension2":"Date","dimension3":"Value","subheader":"Realtime download statistics form Github","chartoptions":"","dataoptions":"","filteroptions":null,"value":"Value"},"dataload":[{"id":59,"user_id":"admin","dataset":155,"datasource":6,"name":"New","option":"{}","schedule":null}],"threshold":[{"id":33,"dimension1":"*","dimension2":null,"value":"5000.00","option":">","severity":4}],"favorite":"true"}'; |
72
|
|
|
OCA.Analytics.Navigation.importDataset(null, github); |
73
|
|
|
|
74
|
|
|
}, |
75
|
|
|
|
76
|
|
|
showPage: function () { |
77
|
|
|
let nextSlide = OCA.Analytics.Wizzard.sildeArray[OCA.Analytics.Wizzard.currentSlide]; |
78
|
|
|
let newpage = document.importNode(document.getElementById(nextSlide).content, true); |
79
|
|
|
let prev = document.getElementById('wizzardPrevious'); |
80
|
|
|
let next = document.getElementById('wizzardNext'); |
81
|
|
|
|
82
|
|
|
document.getElementById('pageBody').innerHTML = ''; |
83
|
|
|
document.getElementById('pageBody').appendChild(newpage); |
84
|
|
|
|
85
|
|
|
if (OCA.Analytics.Wizzard.currentSlide === OCA.Analytics.Wizzard.sildeArray.length - 1) { |
86
|
|
|
document.getElementById('wizzardEnd').addEventListener('click', OCA.Analytics.Wizzard.close); |
87
|
|
|
document.getElementById('wizzardDemo').addEventListener('click', OCA.Analytics.Wizzard.demo); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
OCA.Analytics.Wizzard.currentSlide === 1 ? prev.hidden = true : prev.hidden = false; |
91
|
|
|
OCA.Analytics.Wizzard.currentSlide === OCA.Analytics.Wizzard.sildeArray.length - 1 ? next.hidden = true : next.hidden = false; |
92
|
|
|
}, |
93
|
|
|
|
94
|
|
|
dismiss: function () { |
95
|
|
|
$.ajax({ |
96
|
|
|
type: 'POST', |
97
|
|
|
url: OC.generateUrl('apps/analytics/wizzard'), |
98
|
|
|
}) |
99
|
|
|
}, |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @namespace OCA.Analytics.Wizzard |
104
|
|
|
*/ |
105
|
|
|
OCA.Analytics.WhatsNew = { |
106
|
|
|
|
107
|
|
|
whatsnew: function (options) { |
108
|
|
|
options = options || {} |
109
|
|
|
$.ajax({ |
110
|
|
|
type: 'GET', |
111
|
|
|
url: OC.generateUrl('apps/analytics/whatsnew'), |
112
|
|
|
data: {'format': 'json'}, |
113
|
|
|
success: options.success || function (data, statusText, xhr) { |
114
|
|
|
OCA.Analytics.WhatsNew.show(data, statusText, xhr); |
115
|
|
|
}, |
116
|
|
|
}); |
117
|
|
|
}, |
118
|
|
|
|
119
|
|
|
dismiss: function (version) { |
120
|
|
|
$.ajax({ |
121
|
|
|
type: 'POST', |
122
|
|
|
url: OC.generateUrl('apps/analytics/whatsnew'), |
123
|
|
|
data: {version: encodeURIComponent(version)} |
124
|
|
|
}) |
125
|
|
|
$('.whatsNewPopover').remove(); |
126
|
|
|
}, |
127
|
|
|
|
128
|
|
|
show: function (data, statusText, xhr) { |
129
|
|
|
if (xhr.status !== 200) { |
130
|
|
|
return |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
let item, menuItem, text, icon |
134
|
|
|
|
135
|
|
|
const div = document.createElement('div') |
136
|
|
|
div.classList.add('popovermenu', 'open', 'whatsNewPopover', 'menu-left') |
137
|
|
|
|
138
|
|
|
const list = document.createElement('ul') |
139
|
|
|
|
140
|
|
|
// header |
141
|
|
|
item = document.createElement('li') |
142
|
|
|
menuItem = document.createElement('span') |
143
|
|
|
menuItem.className = 'menuitem' |
144
|
|
|
|
145
|
|
|
text = document.createElement('span') |
146
|
|
|
text.innerText = t('core', 'New in') + ' ' + data['product'] |
147
|
|
|
text.className = 'caption' |
148
|
|
|
menuItem.appendChild(text) |
149
|
|
|
|
150
|
|
|
icon = document.createElement('span') |
151
|
|
|
icon.className = 'icon-close' |
152
|
|
|
icon.onclick = function () { |
153
|
|
|
OCA.Analytics.WhatsNew.dismiss(data['version']) |
154
|
|
|
} |
155
|
|
|
menuItem.appendChild(icon) |
156
|
|
|
|
157
|
|
|
item.appendChild(menuItem) |
158
|
|
|
list.appendChild(item) |
159
|
|
|
|
160
|
|
|
// Highlights |
161
|
|
|
for (const i in data['whatsNew']['regular']) { |
162
|
|
|
const whatsNewTextItem = data['whatsNew']['regular'][i] |
163
|
|
|
item = document.createElement('li') |
164
|
|
|
|
165
|
|
|
menuItem = document.createElement('span') |
166
|
|
|
menuItem.className = 'menuitem' |
167
|
|
|
|
168
|
|
|
icon = document.createElement('span') |
169
|
|
|
icon.className = 'icon-checkmark' |
170
|
|
|
menuItem.appendChild(icon) |
171
|
|
|
|
172
|
|
|
text = document.createElement('p') |
173
|
|
|
text.innerHTML = _.escape(whatsNewTextItem) |
|
|
|
|
174
|
|
|
menuItem.appendChild(text) |
175
|
|
|
|
176
|
|
|
item.appendChild(menuItem) |
177
|
|
|
list.appendChild(item) |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
// Changelog URL |
181
|
|
|
if (!_.isUndefined(data['changelogURL'])) { |
182
|
|
|
item = document.createElement('li') |
183
|
|
|
|
184
|
|
|
menuItem = document.createElement('a') |
185
|
|
|
menuItem.href = data['changelogURL'] |
186
|
|
|
menuItem.rel = 'noreferrer noopener' |
187
|
|
|
menuItem.target = '_blank' |
188
|
|
|
|
189
|
|
|
icon = document.createElement('span') |
190
|
|
|
icon.className = 'icon-link' |
191
|
|
|
menuItem.appendChild(icon) |
192
|
|
|
|
193
|
|
|
text = document.createElement('span') |
194
|
|
|
text.innerText = t('core', 'View changelog') |
195
|
|
|
menuItem.appendChild(text) |
196
|
|
|
|
197
|
|
|
item.appendChild(menuItem) |
198
|
|
|
list.appendChild(item) |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
div.appendChild(list) |
202
|
|
|
document.body.appendChild(div) |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
} |
206
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.