@osimatic/helpers-js 1.0.91 → 1.0.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/google_charts.js +16 -15
- package/http_client.js +47 -2
- package/package.json +1 -1
package/google_charts.js
CHANGED
|
@@ -13,7 +13,7 @@ class GoogleCharts {
|
|
|
13
13
|
// on supprime du tableau la liste des graphiques dont l'id div n'a pas été trouvé (le graphique ne pourra pas être généré)
|
|
14
14
|
chartsList = chartsList.filter(chartData => typeof chartData.div_id != 'undefined' && $('#'+chartData.div_id).length);
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
let nbChartsCompleted = 0;
|
|
17
17
|
chartsList.forEach(chartData => {
|
|
18
18
|
//console.log(chartData);
|
|
19
19
|
GoogleCharts.draw(
|
|
@@ -41,17 +41,18 @@ class GoogleCharts {
|
|
|
41
41
|
|
|
42
42
|
static draw(div, typeGraph, titre, libelleAbs, tabDataAbsParam, listeLibelleOrd, listeTabDataOrd, tabColor, formatData, height, width, onComplete) {
|
|
43
43
|
if (typeof div == 'undefined' || !div.length) {
|
|
44
|
+
console.error('div not found');
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
height = height || null;
|
|
48
49
|
width = width || null;
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
let htmlDomDiv = div[0];
|
|
51
52
|
|
|
52
|
-
|
|
53
|
+
let afficherLibelleOrd = false;
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
let isStacked = false;
|
|
55
56
|
if (typeGraph === 'stacked_bar_chart') {
|
|
56
57
|
typeGraph = 'bar_chart';
|
|
57
58
|
isStacked = true;
|
|
@@ -65,7 +66,7 @@ class GoogleCharts {
|
|
|
65
66
|
isStacked = true;
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
let isDualChart = false;
|
|
69
70
|
if (typeGraph === 'dual_column_chart') {
|
|
70
71
|
typeGraph = 'column_chart';
|
|
71
72
|
isDualChart = true;
|
|
@@ -75,7 +76,7 @@ class GoogleCharts {
|
|
|
75
76
|
isDualChart = true;
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
let data = null;
|
|
79
80
|
if (typeGraph === 'pie_chart') {
|
|
80
81
|
//data = google.visualization.arrayToDataTable(tabDataAbsParam);
|
|
81
82
|
|
|
@@ -83,7 +84,7 @@ class GoogleCharts {
|
|
|
83
84
|
data.addColumn('string', libelleAbs);
|
|
84
85
|
data.addColumn('number', '');
|
|
85
86
|
|
|
86
|
-
|
|
87
|
+
let numRow = 0;
|
|
87
88
|
$.each(tabDataAbsParam, function(idx, value) {
|
|
88
89
|
data.addRows(1);
|
|
89
90
|
data.setCell(numRow, 0, idx);
|
|
@@ -100,8 +101,8 @@ class GoogleCharts {
|
|
|
100
101
|
});
|
|
101
102
|
|
|
102
103
|
// Remplissage des données
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
let nbCells = 0;
|
|
105
|
+
let numRow = 0;
|
|
105
106
|
$.each(tabDataAbsParam, function(idx, dataAbs) {
|
|
106
107
|
// dataOrd = tabDataOrd[idx];
|
|
107
108
|
// data.addRow([dataAbs, dataOrd]);
|
|
@@ -109,7 +110,7 @@ class GoogleCharts {
|
|
|
109
110
|
|
|
110
111
|
data.setCell(numRow, 0, dataAbs);
|
|
111
112
|
|
|
112
|
-
|
|
113
|
+
let numCell = 1;
|
|
113
114
|
$.each(listeTabDataOrd, function(idx2, tabDataOrd) {
|
|
114
115
|
data.setCell(numRow, numCell, tabDataOrd[idx]);
|
|
115
116
|
//data.setCell(numRow, numCell, Math.round(tabDataOrd[idx], 2));
|
|
@@ -126,7 +127,7 @@ class GoogleCharts {
|
|
|
126
127
|
// console.log('drawGraph : '+div+' ; type : '+typeGraph);
|
|
127
128
|
|
|
128
129
|
// Options générales
|
|
129
|
-
|
|
130
|
+
let options = {
|
|
130
131
|
colors: tabColor,
|
|
131
132
|
fontName: 'Trebuchet MS',
|
|
132
133
|
fontSize: 12,
|
|
@@ -221,7 +222,7 @@ class GoogleCharts {
|
|
|
221
222
|
// console.log(idx);
|
|
222
223
|
if (idx <= 1) {
|
|
223
224
|
// key = 'series_'+idx;
|
|
224
|
-
|
|
225
|
+
let key = idx;
|
|
225
226
|
// options.series[idx] = {axis: key, targetAxisIndex: key};
|
|
226
227
|
options.series[idx] = {axis: key, targetAxisIndex: idx};
|
|
227
228
|
if (typeGraph === 'column_chart') {
|
|
@@ -278,7 +279,7 @@ class GoogleCharts {
|
|
|
278
279
|
// console.log(options);
|
|
279
280
|
|
|
280
281
|
// Création du graphique
|
|
281
|
-
|
|
282
|
+
let chart = null;
|
|
282
283
|
if (typeGraph === 'column_chart') {
|
|
283
284
|
// chart = new google.visualization.ColumnChart(htmlDomDiv);
|
|
284
285
|
chart = new google.charts.Bar(htmlDomDiv);
|
|
@@ -301,7 +302,7 @@ class GoogleCharts {
|
|
|
301
302
|
div.removeClass('loading');
|
|
302
303
|
|
|
303
304
|
if (chart === null) {
|
|
304
|
-
console.
|
|
305
|
+
console.error('error during creating chart');
|
|
305
306
|
div.addClass('graphique_error');
|
|
306
307
|
htmlDomDiv.innerHTML = 'Une erreur s\'est produite lors du chargement du graphique.';
|
|
307
308
|
return;
|
|
@@ -317,7 +318,7 @@ class GoogleCharts {
|
|
|
317
318
|
tabPaneDiv = div.closest('.tab-pane');
|
|
318
319
|
}
|
|
319
320
|
|
|
320
|
-
|
|
321
|
+
let hasClassActive = tabPaneDiv.hasClass('active');
|
|
321
322
|
if (!hasClassActive) {
|
|
322
323
|
tabPaneDiv.addClass('active');
|
|
323
324
|
}
|
package/http_client.js
CHANGED
|
@@ -3,11 +3,17 @@ class HTTPClient {
|
|
|
3
3
|
static setRefreshTokenUrl(url) {
|
|
4
4
|
HTTPClient.refreshTokenUrl = url;
|
|
5
5
|
}
|
|
6
|
-
|
|
7
6
|
static setRefreshTokenCallback(callback) {
|
|
8
7
|
HTTPClient.refreshTokenCallback = callback;
|
|
9
8
|
}
|
|
10
9
|
|
|
10
|
+
static setOnInvalidTokenRedirectUrl(url) {
|
|
11
|
+
HTTPClient.onInvalidTokenRedirectUrl = url;
|
|
12
|
+
}
|
|
13
|
+
static setOnInvalidTokenCallback(callback) {
|
|
14
|
+
HTTPClient.onInvalidTokenCallback = callback;
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
static getHeaders(asObject) {
|
|
12
18
|
HTTPClient.setAuthorizationToken(JwtSession.getToken());
|
|
13
19
|
|
|
@@ -48,6 +54,10 @@ class HTTPClient {
|
|
|
48
54
|
HTTPClient.headers = {};
|
|
49
55
|
}
|
|
50
56
|
|
|
57
|
+
if (typeof authorizationToken == 'undefined' || null == authorizationToken) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
51
61
|
HTTPClient.headers['Authorization'] = 'Bearer ' + authorizationToken;
|
|
52
62
|
}
|
|
53
63
|
|
|
@@ -126,12 +136,37 @@ class HTTPClient {
|
|
|
126
136
|
response.statusText === 'Expired JWT Token'
|
|
127
137
|
|| (typeof json['message'] != 'undefined' && json['message'] === 'Expired JWT Token')
|
|
128
138
|
|| (typeof json['error'] != 'undefined' && json['error'] === 'expired_token')
|
|
129
|
-
|| (typeof json['error'] != 'undefined' && json['error'] === 'authentification_failure')
|
|
130
139
|
|| (json === 'expired_token')
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static isInvalidToken(response, json) {
|
|
144
|
+
if (response.status !== 401) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
response.statusText === 'Invalid JWT Token'
|
|
150
|
+
|| (typeof json['message'] != 'undefined' && json['message'] === 'Invalid JWT Token')
|
|
151
|
+
|| (typeof json['error'] != 'undefined' && json['error'] === 'invalid_token')
|
|
152
|
+
|| (typeof json['error'] != 'undefined' && json['error'] === 'authentification_failure')
|
|
153
|
+
|| (json === 'invalid_token')
|
|
131
154
|
|| (json === 'authentification_failure')
|
|
132
155
|
);
|
|
133
156
|
}
|
|
134
157
|
|
|
158
|
+
static onInvalidToken() {
|
|
159
|
+
if (typeof HTTPClient.onInvalidTokenCallback == 'function') {
|
|
160
|
+
HTTPClient.onInvalidTokenCallback();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
JwtSession.logout();
|
|
165
|
+
if (typeof HTTPClient.onInvalidTokenRedirectUrl != 'undefined') {
|
|
166
|
+
window.location.href = HTTPClient.onInvalidTokenRedirectUrl;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
135
170
|
static async request(method, url, data, successCallback, errorCallback, formErrorCallback) {
|
|
136
171
|
method = method.toUpperCase();
|
|
137
172
|
|
|
@@ -169,6 +204,11 @@ class HTTPClient {
|
|
|
169
204
|
return;
|
|
170
205
|
}
|
|
171
206
|
|
|
207
|
+
if (HTTPClient.isInvalidToken(response, jsonData)) {
|
|
208
|
+
HTTPClient.onInvalidToken();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
172
212
|
if (response.ok) {
|
|
173
213
|
if (typeof successCallback != 'undefined' && successCallback != null) {
|
|
174
214
|
successCallback(jsonData, response);
|
|
@@ -225,6 +265,11 @@ class HTTPClient {
|
|
|
225
265
|
return;
|
|
226
266
|
}
|
|
227
267
|
|
|
268
|
+
if (response.status === 401 && response.statusText === 'Invalid JWT Token') {
|
|
269
|
+
HTTPClient.onInvalidToken();
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
228
273
|
if (response.ok) {
|
|
229
274
|
const blobData = await response.blob();
|
|
230
275
|
File.download(blobData, response.headers.get('content-type'), response.headers.get('content-disposition'));
|