sf-i-events 1.0.909 → 1.0.911
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/dev/index.html +40 -1
- package/package.json +3 -2
- package/sf-i-events.d.ts +8 -1
- package/sf-i-events.js +411 -119
- package/src/sf-i-events.ts +433 -131
- package/src/util.ts +372 -326
- package/util.d.ts +2 -0
- package/util.js +39 -1
package/src/util.ts
CHANGED
|
@@ -1,271 +1,272 @@
|
|
|
1
|
+
import * as XLSX from 'xlsx';
|
|
1
2
|
|
|
2
3
|
const validateName = (name: string) => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
return false;
|
|
4
|
+
if ((name + "").length > 2) {
|
|
5
|
+
return true;
|
|
7
6
|
}
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
10
|
+
function createDiagonalPattern1(color: string) {
|
|
11
|
+
// create a 10x10 px canvas for the pattern's base shape
|
|
12
|
+
let shape = document.createElement('canvas')
|
|
13
|
+
shape.width = 10
|
|
14
|
+
shape.height = 10
|
|
15
|
+
// get the context for drawing
|
|
16
|
+
let c = shape.getContext('2d')
|
|
17
|
+
// draw 1st line of the shape
|
|
18
|
+
c!.strokeStyle = color
|
|
19
|
+
c!.lineWidth = 3
|
|
20
|
+
c!.beginPath()
|
|
21
|
+
c!.moveTo(2, 0)
|
|
22
|
+
c!.lineTo(10, 8)
|
|
23
|
+
c!.stroke()
|
|
24
|
+
// draw 2nd line of the shape
|
|
25
|
+
c!.beginPath()
|
|
26
|
+
c!.moveTo(2, 10)
|
|
27
|
+
c!.lineTo(0, 8)
|
|
28
|
+
c!.stroke()
|
|
29
|
+
// create the pattern from the shape
|
|
30
|
+
return c!.createPattern(shape, 'repeat')
|
|
31
|
+
}
|
|
31
32
|
|
|
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
|
-
|
|
33
|
+
// function createDiagonalPattern2(color: string) {
|
|
34
|
+
// let shape = document.createElement('canvas')
|
|
35
|
+
// shape.width = 10
|
|
36
|
+
// shape.height = 10
|
|
37
|
+
// // get the context for drawing
|
|
38
|
+
// let c = shape.getContext('2d')
|
|
39
|
+
// // draw 1st line of the shape
|
|
40
|
+
// c!.beginPath();
|
|
41
|
+
// c!.rect(2, 2, 8, 8)
|
|
42
|
+
// c!.fillStyle = color;
|
|
43
|
+
// c!.fill();
|
|
44
|
+
// // create the pattern from the shape
|
|
45
|
+
// return c!.createPattern(shape, 'repeat')
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
function createDiagonalPattern2(color: string) {
|
|
49
|
+
// create a 10x10 px canvas for the pattern's base shape
|
|
50
|
+
let shape = document.createElement('canvas')
|
|
51
|
+
shape.width = 10
|
|
52
|
+
shape.height = 10
|
|
53
|
+
// get the context for drawing
|
|
54
|
+
let c = shape.getContext('2d')
|
|
55
|
+
// draw 1st line of the shape
|
|
56
|
+
c!.beginPath();
|
|
57
|
+
c!.rect(1, 1, 9, 9)
|
|
58
|
+
c!.fillStyle = color;
|
|
59
|
+
c!.fill();
|
|
60
|
+
c!.lineWidth = 1;
|
|
61
|
+
c!.strokeStyle = color;
|
|
62
|
+
c!.stroke();
|
|
63
|
+
// create the pattern from the shape
|
|
64
|
+
|
|
65
|
+
// create tick
|
|
66
|
+
|
|
67
|
+
//draw tick
|
|
68
|
+
c!.beginPath();
|
|
69
|
+
c!.moveTo(2, 2);
|
|
70
|
+
c!.lineTo(8, 8);
|
|
71
|
+
c!.moveTo(2, 8);
|
|
72
|
+
c!.lineTo(8, 2);
|
|
73
|
+
c!.lineWidth = 2;
|
|
74
|
+
c!.strokeStyle = '#fff';
|
|
75
|
+
c!.stroke();
|
|
76
|
+
|
|
77
|
+
return c!.createPattern(shape, 'repeat')
|
|
78
|
+
}
|
|
78
79
|
|
|
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
|
-
|
|
80
|
+
function createDiagonalPattern3(color: string) {
|
|
81
|
+
// create a 10x10 px canvas for the pattern's base shape
|
|
82
|
+
let shape = document.createElement('canvas')
|
|
83
|
+
shape.width = 10
|
|
84
|
+
shape.height = 10
|
|
85
|
+
// get the context for drawing
|
|
86
|
+
let c = shape.getContext('2d')
|
|
87
|
+
// draw 1st line of the shape
|
|
88
|
+
c!.beginPath();
|
|
89
|
+
c!.rect(1, 1, 9, 9)
|
|
90
|
+
c!.fillStyle = color;
|
|
91
|
+
c!.fill();
|
|
92
|
+
c!.lineWidth = 1;
|
|
93
|
+
c!.strokeStyle = color;
|
|
94
|
+
c!.stroke();
|
|
95
|
+
// create the pattern from the shape
|
|
96
|
+
|
|
97
|
+
// create tick
|
|
98
|
+
|
|
99
|
+
//draw tick
|
|
100
|
+
c!.beginPath();
|
|
101
|
+
c!.moveTo(2, 5);
|
|
102
|
+
c!.lineTo(4, 7);
|
|
103
|
+
c!.lineTo(8, 2);
|
|
104
|
+
c!.lineWidth = 2;
|
|
105
|
+
c!.strokeStyle = '#fff';
|
|
106
|
+
c!.stroke();
|
|
107
|
+
|
|
108
|
+
return c!.createPattern(shape, 'repeat')
|
|
109
|
+
}
|
|
109
110
|
|
|
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
|
-
|
|
111
|
+
// function createDiagonalPattern3(color: string) {
|
|
112
|
+
// // create a 10x10 px canvas for the pattern's base shape
|
|
113
|
+
// let shape = document.createElement('canvas')
|
|
114
|
+
// shape.width = 14
|
|
115
|
+
// shape.height = 14
|
|
116
|
+
// // get the context for drawing
|
|
117
|
+
// let c = shape.getContext('2d')
|
|
118
|
+
// // draw 1st line of the shape
|
|
119
|
+
// c!.beginPath();
|
|
120
|
+
// c!.arc(7, 7, 6, 0, 2 * Math.PI, false);
|
|
121
|
+
// c!.fillStyle = color;
|
|
122
|
+
// c!.fill();
|
|
123
|
+
// c!.lineWidth = 1;
|
|
124
|
+
// c!.strokeStyle = color;
|
|
125
|
+
// c!.stroke();
|
|
126
|
+
// // create the pattern from the shape
|
|
127
|
+
|
|
128
|
+
// // create tick
|
|
129
|
+
|
|
130
|
+
// //draw tick
|
|
131
|
+
// c!.beginPath();
|
|
132
|
+
// c!.moveTo(4,6);
|
|
133
|
+
// c!.lineTo(6,9);
|
|
134
|
+
// c!.lineTo(10,4);
|
|
135
|
+
// c!.lineWidth = 2;
|
|
136
|
+
// c!.strokeStyle = '#fff';
|
|
137
|
+
// c!.stroke();
|
|
138
|
+
|
|
139
|
+
// return c!.createPattern(shape, 'repeat')
|
|
140
|
+
// }
|
|
141
|
+
|
|
142
|
+
// function createDiagonalPattern3(color: string) {
|
|
143
|
+
// // create a 10x10 px canvas for the pattern's base shape
|
|
144
|
+
// let shape = document.createElement('canvas')
|
|
145
|
+
// shape.width = 10
|
|
146
|
+
// shape.height = 10
|
|
147
|
+
// // get the context for drawing
|
|
148
|
+
// let c = shape.getContext('2d')
|
|
149
|
+
// // draw 1st line of the shape
|
|
150
|
+
// c!.beginPath();
|
|
151
|
+
// c!.arc(5, 5, 4, 0, 2 * Math.PI, false);
|
|
152
|
+
// c!.fillStyle = color;
|
|
153
|
+
// c!.fill();
|
|
154
|
+
// c!.lineWidth = 1;
|
|
155
|
+
// c!.strokeStyle = color;
|
|
156
|
+
// c!.stroke();
|
|
157
|
+
// // create the pattern from the shape
|
|
158
|
+
// return c!.createPattern(shape, 'repeat')
|
|
159
|
+
// }
|
|
160
|
+
|
|
161
|
+
const timeSince = (date: number) => {
|
|
162
|
+
|
|
163
|
+
var seconds = Math.floor((new Date().getTime() - date) / 1000);
|
|
164
|
+
|
|
165
|
+
if (seconds > 0) {
|
|
166
|
+
|
|
167
|
+
var interval = seconds / 31536000;
|
|
168
|
+
|
|
169
|
+
if (interval > 1) {
|
|
170
|
+
return Math.floor(interval) + " years ago";
|
|
171
|
+
}
|
|
172
|
+
interval = seconds / 2592000;
|
|
173
|
+
if (interval > 1) {
|
|
174
|
+
return Math.floor(interval) + " months ago";
|
|
175
|
+
}
|
|
176
|
+
interval = seconds / 86400;
|
|
177
|
+
if (interval > 1) {
|
|
178
|
+
return Math.floor(interval) + " days ago";
|
|
179
|
+
}
|
|
180
|
+
interval = seconds / 3600;
|
|
181
|
+
if (interval > 1) {
|
|
182
|
+
return Math.floor(interval) + " hours ago";
|
|
183
|
+
}
|
|
184
|
+
interval = seconds / 60;
|
|
185
|
+
if (interval > 1) {
|
|
186
|
+
return Math.floor(interval) + " minutes ago";
|
|
187
|
+
}
|
|
188
|
+
return Math.floor(seconds) + " seconds ago";
|
|
188
189
|
|
|
189
|
-
|
|
190
|
+
} else {
|
|
190
191
|
|
|
191
|
-
|
|
192
|
+
var interval = Math.abs(seconds) / 31536000;
|
|
192
193
|
|
|
193
194
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
console.log('interval year', interval);
|
|
198
|
-
if (interval > 1) {
|
|
199
|
-
return Math.floor(interval) + " years later";
|
|
200
|
-
}
|
|
201
|
-
interval = Math.abs(seconds) / 2592000;
|
|
202
|
-
console.log('interval months', interval);
|
|
203
|
-
if (interval > 1) {
|
|
204
|
-
return Math.floor(interval) + " months later";
|
|
205
|
-
}
|
|
195
|
+
console.log('timesince', seconds);
|
|
206
196
|
|
|
207
|
-
interval = Math.abs(seconds) / 86400;
|
|
208
|
-
console.log('interval days', interval);
|
|
209
|
-
if (interval > 1) {
|
|
210
|
-
return Math.floor(interval) + " days later";
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
interval = Math.abs(seconds) / 3600;
|
|
214
|
-
console.log('interval hours', interval);
|
|
215
|
-
if (interval > 1) {
|
|
216
|
-
return Math.floor(interval) + " hours later";
|
|
217
|
-
}
|
|
218
|
-
interval = Math.abs(seconds) / 60;
|
|
219
|
-
if (interval > 1) {
|
|
220
|
-
return Math.floor(interval) + " minutes later";
|
|
221
|
-
}
|
|
222
|
-
return Math.floor(Math.abs(seconds)) + " seconds";
|
|
223
197
|
|
|
198
|
+
console.log('interval year', interval);
|
|
199
|
+
if (interval > 1) {
|
|
200
|
+
return Math.floor(interval) + " years later";
|
|
224
201
|
}
|
|
202
|
+
interval = Math.abs(seconds) / 2592000;
|
|
203
|
+
console.log('interval months', interval);
|
|
204
|
+
if (interval > 1) {
|
|
205
|
+
return Math.floor(interval) + " months later";
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
interval = Math.abs(seconds) / 86400;
|
|
209
|
+
console.log('interval days', interval);
|
|
210
|
+
if (interval > 1) {
|
|
211
|
+
return Math.floor(interval) + " days later";
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
interval = Math.abs(seconds) / 3600;
|
|
215
|
+
console.log('interval hours', interval);
|
|
216
|
+
if (interval > 1) {
|
|
217
|
+
return Math.floor(interval) + " hours later";
|
|
218
|
+
}
|
|
219
|
+
interval = Math.abs(seconds) / 60;
|
|
220
|
+
if (interval > 1) {
|
|
221
|
+
return Math.floor(interval) + " minutes later";
|
|
222
|
+
}
|
|
223
|
+
return Math.floor(Math.abs(seconds)) + " seconds";
|
|
224
|
+
|
|
225
225
|
}
|
|
226
|
+
}
|
|
226
227
|
|
|
227
228
|
|
|
228
229
|
function readCookie(key: string) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
230
|
+
let name = key + "=";
|
|
231
|
+
let decodedCookie = decodeURIComponent(document.cookie);
|
|
232
|
+
let ca = decodedCookie.split(';');
|
|
233
|
+
for (let i = 0; i < ca.length; i++) {
|
|
234
|
+
let c = ca[i];
|
|
235
|
+
while (c.charAt(0) == ' ') {
|
|
236
|
+
c = c.substring(1);
|
|
237
|
+
}
|
|
238
|
+
if (c.indexOf(name) == 0) {
|
|
239
|
+
return c.substring(name.length, c.length);
|
|
240
240
|
}
|
|
241
|
-
|
|
241
|
+
}
|
|
242
|
+
return "";
|
|
242
243
|
}
|
|
243
244
|
|
|
244
245
|
async function callApi(url: string, data: string, authorization: any) {
|
|
245
246
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
xhr.open("POST", url);
|
|
258
|
-
xhr.timeout = 1800000;
|
|
259
|
-
xhr.setRequestHeader("Content-Type", "application/json");
|
|
260
|
-
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
|
261
|
-
if(authorization != null) {
|
|
262
|
-
xhr.setRequestHeader('Authorization', 'Basic ' + authorization);
|
|
247
|
+
return new Promise((resolve: any) => {
|
|
248
|
+
|
|
249
|
+
const jsonData = JSON.stringify(data);
|
|
250
|
+
var xhr = new XMLHttpRequest();
|
|
251
|
+
xhr.addEventListener("readystatechange", () => {
|
|
252
|
+
if (xhr != null) {
|
|
253
|
+
if (xhr.readyState === 4) {
|
|
254
|
+
resolve(xhr);
|
|
263
255
|
}
|
|
264
|
-
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
xhr.open("POST", url);
|
|
259
|
+
xhr.timeout = 1800000;
|
|
260
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
261
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
|
262
|
+
if (authorization != null) {
|
|
263
|
+
xhr.setRequestHeader('Authorization', 'Basic ' + authorization);
|
|
264
|
+
}
|
|
265
|
+
xhr.send(jsonData);
|
|
265
266
|
|
|
266
|
-
|
|
267
|
+
return xhr;
|
|
267
268
|
|
|
268
|
-
|
|
269
|
+
})
|
|
269
270
|
|
|
270
271
|
}
|
|
271
272
|
|
|
@@ -274,21 +275,21 @@ async function callApiPresignedDelete(url: string) {
|
|
|
274
275
|
|
|
275
276
|
return new Promise((resolve: any) => {
|
|
276
277
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
278
|
+
var xhr = new XMLHttpRequest();
|
|
279
|
+
xhr.addEventListener("readystatechange", () => {
|
|
280
|
+
if (xhr != null) {
|
|
281
|
+
if (xhr.readyState === 4) {
|
|
282
|
+
resolve(xhr);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
xhr.open("DELETE", url);
|
|
287
|
+
xhr.timeout = 1800000;
|
|
288
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
289
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
|
290
|
+
xhr.send(null);
|
|
291
|
+
|
|
292
|
+
return xhr;
|
|
292
293
|
|
|
293
294
|
})
|
|
294
295
|
|
|
@@ -298,21 +299,21 @@ async function callApiPresignedGet(url: string) {
|
|
|
298
299
|
|
|
299
300
|
return new Promise((resolve: any) => {
|
|
300
301
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
302
|
+
var xhr = new XMLHttpRequest();
|
|
303
|
+
xhr.addEventListener("readystatechange", () => {
|
|
304
|
+
if (xhr != null) {
|
|
305
|
+
if (xhr.readyState === 4) {
|
|
306
|
+
resolve(xhr);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
xhr.open("GET", url);
|
|
311
|
+
xhr.timeout = 1800000;
|
|
312
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
313
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
|
314
|
+
xhr.send(null);
|
|
315
|
+
|
|
316
|
+
return xhr;
|
|
316
317
|
|
|
317
318
|
})
|
|
318
319
|
|
|
@@ -322,22 +323,22 @@ async function callApiPresigned(url: string, data: string) {
|
|
|
322
323
|
|
|
323
324
|
return new Promise((resolve: any) => {
|
|
324
325
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
326
|
+
const jsonData = JSON.stringify(data);
|
|
327
|
+
var xhr = new XMLHttpRequest();
|
|
328
|
+
xhr.addEventListener("readystatechange", () => {
|
|
329
|
+
if (xhr != null) {
|
|
330
|
+
if (xhr.readyState === 4) {
|
|
331
|
+
resolve(xhr);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
xhr.open("PUT", url);
|
|
336
|
+
xhr.timeout = 1800000;
|
|
337
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
338
|
+
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
|
339
|
+
xhr.send(jsonData);
|
|
340
|
+
|
|
341
|
+
return xhr;
|
|
341
342
|
|
|
342
343
|
})
|
|
343
344
|
|
|
@@ -366,32 +367,32 @@ function jsonObjectToHtml(json: any) {
|
|
|
366
367
|
|
|
367
368
|
var html = '';
|
|
368
369
|
|
|
369
|
-
|
|
370
|
-
for(var i = 0; i < Object.keys(json).length; i++) {
|
|
370
|
+
|
|
371
|
+
for (var i = 0; i < Object.keys(json).length; i++) {
|
|
371
372
|
var key = Object.keys(json)[i];
|
|
372
373
|
html += '<div>';
|
|
373
374
|
html += ('<span style="margin-left: 0px; padding-left: 0px">' + key + ':</span> ');
|
|
374
|
-
html += ('<span class="td-body" part="td-head"><sf-i-elastic-text text="' + json[key].replace(/"/g,'') + '" lineSize="6" minLength="10"></sf-i-elastic-text></span>');
|
|
375
|
+
html += ('<span class="td-body" part="td-head"><sf-i-elastic-text text="' + json[key].replace(/"/g, '') + '" lineSize="6" minLength="10"></sf-i-elastic-text></span>');
|
|
375
376
|
html += '</div>';
|
|
376
377
|
}
|
|
377
|
-
|
|
378
|
+
|
|
378
379
|
|
|
379
380
|
return html;
|
|
380
381
|
|
|
381
382
|
}
|
|
382
383
|
|
|
383
|
-
function convertToCSV(arr:any[]) {
|
|
384
|
+
function convertToCSV(arr: any[]) {
|
|
384
385
|
const array = [Object.keys(arr[0])].concat(arr)
|
|
385
386
|
let fieldsArr = Object.keys(arr[0]);
|
|
386
387
|
return array.map((it, index) => {
|
|
387
388
|
let strIt = ""
|
|
388
|
-
for(let [i,objkey] of Object.keys(it).entries()){
|
|
389
|
-
if(index == 0){
|
|
390
|
-
strIt += "\"" + it[objkey as any].replace(/"/g,"\"\"") + "\""
|
|
391
|
-
}else{
|
|
392
|
-
strIt += "\"" + JSON.stringify(it[fieldsArr[i] as any] ?? "").replace(/"/g,"\"\"") + "\""
|
|
389
|
+
for (let [i, objkey] of Object.keys(it).entries()) {
|
|
390
|
+
if (index == 0) {
|
|
391
|
+
strIt += "\"" + it[objkey as any].replace(/"/g, "\"\"") + "\""
|
|
392
|
+
} else {
|
|
393
|
+
strIt += "\"" + JSON.stringify(it[fieldsArr[i] as any] ?? "").replace(/"/g, "\"\"") + "\""
|
|
393
394
|
}
|
|
394
|
-
if(i < (Object.keys(it).length - 1)){
|
|
395
|
+
if (i < (Object.keys(it).length - 1)) {
|
|
395
396
|
strIt += ","
|
|
396
397
|
}
|
|
397
398
|
}
|
|
@@ -399,10 +400,10 @@ function convertToCSV(arr:any[]) {
|
|
|
399
400
|
}).join('\n')
|
|
400
401
|
}
|
|
401
402
|
|
|
402
|
-
function parseCsv(csv:string){
|
|
403
|
+
function parseCsv(csv: string) {
|
|
403
404
|
const re = /(,|\r?\n|\r|^)(?:"([^"]*(?:""[^"]*)*)"|([^,\r\n]*))/gi
|
|
404
|
-
const result:any = [[]]
|
|
405
|
-
let matches:any;
|
|
405
|
+
const result: any = [[]]
|
|
406
|
+
let matches: any;
|
|
406
407
|
while ((matches = re.exec(csv))) {
|
|
407
408
|
if (matches[1].length && matches[1] !== ',') result.push([])
|
|
408
409
|
result[result.length - 1].push(
|
|
@@ -413,55 +414,55 @@ function parseCsv(csv:string){
|
|
|
413
414
|
let csvResult = arrayToObject(result)
|
|
414
415
|
return csvResult
|
|
415
416
|
}
|
|
416
|
-
function arrayToObject
|
|
417
|
+
function arrayToObject(csvArray: any) {
|
|
417
418
|
|
|
418
419
|
//Take the first line (headers) from the array and remove it from the array.
|
|
419
|
-
const headers = csvArray.shift()
|
|
420
|
+
const headers = csvArray.shift()
|
|
420
421
|
|
|
421
422
|
// Iterate through the rows and reduce each column to an object
|
|
422
|
-
|
|
423
|
-
return csvArray.filter((row:any)=>{
|
|
423
|
+
|
|
424
|
+
return csvArray.filter((row: any) => {
|
|
424
425
|
console.log('csv object keys lngth', Object.keys(row).length)
|
|
425
426
|
return Object.keys(row).length > 1
|
|
426
|
-
}).map((row: { [x: string]: any; }
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
427
|
+
}).map((row: { [x: string]: any; }) => {
|
|
428
|
+
|
|
429
|
+
return headers.reduce((acc: any, currentHeader: any, i: string | number) => {
|
|
430
|
+
// console.log('parsing row', row[i], index);
|
|
431
|
+
return ((currentHeader.indexOf('cols_') >= 0 || currentHeader == '') ? acc : ((row[i] != '' && row[i] != null) ? { ...acc, ...{ [currentHeader]: JSON.parse(row[i] == "TRUE" ? "true" : row[i]) } } : acc))
|
|
432
|
+
}, {})
|
|
432
433
|
})
|
|
433
434
|
}
|
|
434
435
|
|
|
435
436
|
function titleCase(str: string) {
|
|
436
437
|
var splitStr = str.toLowerCase().split(' ');
|
|
437
438
|
for (var i = 0; i < splitStr.length; i++) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
439
|
+
// You do not need to check if i is larger than splitStr length, as your for does that for you
|
|
440
|
+
// Assign it back to the array
|
|
441
|
+
splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
|
|
441
442
|
}
|
|
442
443
|
// Directly return the joined string
|
|
443
|
-
return splitStr.join(' ');
|
|
444
|
+
return splitStr.join(' ');
|
|
444
445
|
}
|
|
445
446
|
|
|
446
|
-
function alphabeticalSort(arr:string[]){
|
|
447
|
-
let arrSorted = arr.sort((a,b) => {
|
|
447
|
+
function alphabeticalSort(arr: string[]) {
|
|
448
|
+
let arrSorted = arr.sort((a, b) => {
|
|
448
449
|
return a.trim().toLowerCase().localeCompare(b.trim().toLowerCase())
|
|
449
450
|
})
|
|
450
451
|
return arrSorted
|
|
451
452
|
}
|
|
452
453
|
|
|
453
|
-
function percentageString(val: number, valTotal: number){
|
|
454
|
-
if(valTotal == 0){
|
|
454
|
+
function percentageString(val: number, valTotal: number) {
|
|
455
|
+
if (valTotal == 0) {
|
|
455
456
|
return ""
|
|
456
457
|
}
|
|
457
458
|
let num = (100 * val) / valTotal
|
|
458
459
|
return " (" + (Math.round((num + Number.EPSILON) * 100) / 100) + "%)"
|
|
459
460
|
}
|
|
460
461
|
|
|
461
|
-
function getCurrentFiscal(){
|
|
462
|
+
function getCurrentFiscal() {
|
|
462
463
|
let date = new Date()
|
|
463
|
-
if(date.getMonth() < 4){
|
|
464
|
-
|
|
464
|
+
if (date.getMonth() < 4) {
|
|
465
|
+
return (date.getFullYear() - 1)
|
|
465
466
|
}
|
|
466
467
|
return date.getFullYear();
|
|
467
468
|
}
|
|
@@ -510,16 +511,61 @@ function getProjectUsermap() {
|
|
|
510
511
|
return projectUsermap;
|
|
511
512
|
}
|
|
512
513
|
|
|
513
|
-
function setFeatures(features:any){
|
|
514
|
+
function setFeatures(features: any) {
|
|
514
515
|
localStorage.setItem('features', JSON.stringify(features))
|
|
515
516
|
}
|
|
516
|
-
function getFeatures(){
|
|
517
|
+
function getFeatures() {
|
|
517
518
|
let features = JSON.parse(localStorage.getItem('features') ?? '["compliances"]')
|
|
518
519
|
return features
|
|
519
520
|
}
|
|
520
521
|
|
|
522
|
+
export const downloadExcelFromCSV = (csvString: string, fileName: string = 'report.xlsx', title: string, projectname: string): void => {
|
|
523
|
+
const coverSheetData = [
|
|
524
|
+
[title],
|
|
525
|
+
[],
|
|
526
|
+
['Project:', projectname],
|
|
527
|
+
['Date:', getDateTimeStrings(new Date().getTime())],
|
|
528
|
+
['Classification:', 'Confidential'],
|
|
529
|
+
['Confidentiality Notice:', 'This document is intended only for the recipient(s) and may contain confidential information. Unauthorized use or disclosure is prohibited. If you are not the intended recipient, please notify the sender and delete this document.']
|
|
530
|
+
];
|
|
531
|
+
|
|
532
|
+
// Create cover sheet
|
|
533
|
+
const coverSheet = XLSX.utils.aoa_to_sheet(coverSheetData);
|
|
534
|
+
|
|
535
|
+
// Create CSV data sheet
|
|
536
|
+
const csvSheet = XLSX.read(csvString, { type: 'string' }).Sheets.Sheet1;
|
|
537
|
+
|
|
538
|
+
// Create a workbook and append both sheets
|
|
539
|
+
const workbook: XLSX.WorkBook = XLSX.utils.book_new();
|
|
540
|
+
XLSX.utils.book_append_sheet(workbook, coverSheet, 'Doc');
|
|
541
|
+
XLSX.utils.book_append_sheet(workbook, csvSheet, title);
|
|
542
|
+
|
|
543
|
+
// Write workbook to binary
|
|
544
|
+
const wbout: string = XLSX.write(workbook, { bookType: 'xlsx', type: 'binary' });
|
|
545
|
+
|
|
546
|
+
const s2ab = (s: string): ArrayBuffer => {
|
|
547
|
+
const buf = new ArrayBuffer(s.length);
|
|
548
|
+
const view = new Uint8Array(buf);
|
|
549
|
+
for (let i = 0; i < s.length; i++) {
|
|
550
|
+
view[i] = s.charCodeAt(i) & 0xff;
|
|
551
|
+
}
|
|
552
|
+
return buf;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
const blob = new Blob([s2ab(wbout)], {
|
|
556
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
const link = document.createElement('a');
|
|
560
|
+
link.href = URL.createObjectURL(blob);
|
|
561
|
+
link.download = fileName;
|
|
562
|
+
document.body.appendChild(link);
|
|
563
|
+
link.click();
|
|
564
|
+
document.body.removeChild(link);
|
|
565
|
+
};
|
|
566
|
+
|
|
521
567
|
const exportFunctions = {
|
|
522
|
-
callApiPresignedDelete, callApiPresignedGet, callApiPresigned, jsonObjectToHtml, clearListeners, isInteger, callApi, validateName, readCookie, timeSince, createDiagonalPattern1, createDiagonalPattern2, createDiagonalPattern3, getRandomColor, convertToCSV, parseCsv, titleCase, alphabeticalSort, percentageString, getCurrentFiscal, getDateTimeStrings, getUsermap, setFeatures, getFeatures, getProjectUsermap
|
|
568
|
+
callApiPresignedDelete, callApiPresignedGet, callApiPresigned, jsonObjectToHtml, clearListeners, isInteger, callApi, validateName, readCookie, timeSince, createDiagonalPattern1, createDiagonalPattern2, createDiagonalPattern3, getRandomColor, convertToCSV, parseCsv, titleCase, alphabeticalSort, percentageString, getCurrentFiscal, getDateTimeStrings, getUsermap, setFeatures, getFeatures, getProjectUsermap, downloadExcelFromCSV
|
|
523
569
|
};
|
|
524
570
|
|
|
525
571
|
export default exportFunctions;
|