sf-i-events 1.0.1

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/LICENSE +28 -0
  3. package/README copy.md +588 -0
  4. package/README.md +3 -0
  5. package/coverage/lcov-report/base.css +224 -0
  6. package/coverage/lcov-report/block-navigation.js +87 -0
  7. package/coverage/lcov-report/favicon.png +0 -0
  8. package/coverage/lcov-report/index.html +146 -0
  9. package/coverage/lcov-report/prettify.css +1 -0
  10. package/coverage/lcov-report/prettify.js +2 -0
  11. package/coverage/lcov-report/sf-i-select.ts.html +4384 -0
  12. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  13. package/coverage/lcov-report/sorter.js +196 -0
  14. package/coverage/lcov.info +1719 -0
  15. package/dev/index.html +476 -0
  16. package/index.html +11 -0
  17. package/package.json +84 -0
  18. package/rollup.config.js +38 -0
  19. package/sf-i-events.d.ts +69 -0
  20. package/sf-i-events.d.ts.map +1 -0
  21. package/sf-i-events.js +617 -0
  22. package/sf-i-events.js.map +1 -0
  23. package/src/sf-i-events.ts +726 -0
  24. package/src/test/sf-i-form_test.ts +23 -0
  25. package/src/util.ts +56 -0
  26. package/test/sf-i-form_test.d.ts +7 -0
  27. package/test/sf-i-form_test.d.ts.map +1 -0
  28. package/test/sf-i-form_test.js +18 -0
  29. package/test/sf-i-form_test.js.map +1 -0
  30. package/test/sf-i-select_test.d.ts +7 -0
  31. package/test/sf-i-select_test.d.ts.map +1 -0
  32. package/test/sf-i-select_test.js +18 -0
  33. package/test/sf-i-select_test.js.map +1 -0
  34. package/test/sf-nav_profile_test.d.ts +7 -0
  35. package/test/sf-nav_profile_test.d.ts.map +1 -0
  36. package/test/sf-nav_profile_test.js +139 -0
  37. package/test/sf-nav_profile_test.js.map +1 -0
  38. package/test/sf-nav_test.d.ts +7 -0
  39. package/test/sf-nav_test.d.ts.map +1 -0
  40. package/test/sf-nav_test.js +358 -0
  41. package/test/sf-nav_test.js.map +1 -0
  42. package/tsconfig.json +33 -0
  43. package/util.d.ts +9 -0
  44. package/util.d.ts.map +1 -0
  45. package/util.js +47 -0
  46. package/util.js.map +1 -0
  47. package/web-dev-server.config.js +25 -0
  48. package/web-test-runner.config.js +124 -0
@@ -0,0 +1,726 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022 Superflow.dev
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ import {LitElement, html, css, PropertyValueMap} from 'lit';
8
+ // import {customElement, query, queryAssignedElements, property} from 'lit/decorators.js';
9
+ import {customElement, query, property} from 'lit/decorators.js';
10
+ import Util from './util';
11
+ // import {LitElement, html, css} from 'lit';
12
+ // import {customElement} from 'lit/decorators.js';
13
+
14
+
15
+ /*
16
+
17
+ Modes: View, Add, Edit, Delete, Admin
18
+ DB: partitionKey, rangeKey, values
19
+
20
+ */
21
+
22
+ /**
23
+ * SfIEvents element.
24
+ * @fires renderComplete - When the list is populated
25
+ * @fires valueChanged - When the value is changed
26
+ * @property apiId - backend api id
27
+ * @property label - input label
28
+ * @property name - name of the input
29
+ * @property mode - mode of operation
30
+ * @property selectedId - id to preselect
31
+ * @property selectedValue - callback function
32
+ */
33
+ @customElement('sf-i-events')
34
+ export class SfIEvents extends LitElement {
35
+
36
+ @property()
37
+ apiIdList!: string;
38
+
39
+ @property()
40
+ apiIdDetail!: string;
41
+
42
+ @property()
43
+ apiMethodList!: string;
44
+
45
+ @property()
46
+ apiMethodDetail!: string;
47
+
48
+ @property()
49
+ apiBodyList!: string;
50
+
51
+ @property()
52
+ apiBodyDetail!: string;
53
+
54
+ @property()
55
+ apiResponseFieldList!: string;
56
+
57
+ @property()
58
+ calendarStartDD!: string;
59
+
60
+ @property()
61
+ calendarStartMM!: string;
62
+
63
+ @property()
64
+ calendarStartYYYY!: string;
65
+
66
+ @property()
67
+ calendar: Date [] = [];
68
+
69
+ @property()
70
+ monthNames: string [] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
71
+
72
+ @property()
73
+ events: any = null;
74
+
75
+ getApiBodyList = () => {
76
+ return JSON.parse(this.apiBodyList);
77
+ }
78
+
79
+ getApiBodyDetail = () => {
80
+ return JSON.parse(this.apiBodyDetail);
81
+ }
82
+
83
+ @property()
84
+ mode!: string;
85
+
86
+ @property()
87
+ flow: string = "";
88
+
89
+ static override styles = css`
90
+
91
+
92
+ .SfIEventsC {
93
+ display: flex;
94
+ flex-direction: column;
95
+ align-items: stretch;
96
+ justify-content: space-between;
97
+ }
98
+
99
+ .flex-grow {
100
+ flex-grow: 1;
101
+ }
102
+
103
+ .flex-wrap {
104
+ flex-wrap: wrap;
105
+ }
106
+
107
+ .left-sticky {
108
+ left: 0px;
109
+ position: sticky;
110
+ }
111
+
112
+ .link {
113
+ text-decoration: underline;
114
+ cursor: pointer;
115
+ }
116
+
117
+ .gone {
118
+ display: none
119
+ }
120
+
121
+ .loader-element {
122
+ position: fixed;
123
+ right: 10px;
124
+ top: 10px;
125
+ margin-left: 5px;
126
+ }
127
+
128
+ #calendar-container {
129
+ width: 90%;
130
+ }
131
+
132
+ .day-item {
133
+ width: 14%;
134
+ margin-bottom: 5px;
135
+ text-align: center;
136
+ }
137
+
138
+ .date-item {
139
+ font-size: 80%;
140
+ color: #333;
141
+ }
142
+
143
+ .date-item-before {
144
+ font-size: 80%;
145
+ color: #999;
146
+ }
147
+
148
+ .date-item-selected {
149
+ color: white;
150
+ background-color: #cd0078;
151
+ border-radius: 8px;
152
+ }
153
+
154
+ .title-item {
155
+ margin-bottom: 10px;
156
+ }
157
+
158
+ .calendar-item {
159
+ width: 90%;
160
+ margin-bottom: 20px;
161
+ }
162
+
163
+ .td-head {
164
+ text-transform: capitalize;
165
+ }
166
+
167
+ .td-body {
168
+ padding: 5px;
169
+ }
170
+
171
+ .td-dark {
172
+ background-color: #e9e9e9;
173
+ }
174
+
175
+ .td-highlight {
176
+ background-color: black;
177
+ color: white;
178
+ }
179
+
180
+ .td-light {
181
+ background-color: #f6f6f6;
182
+ }
183
+
184
+ td {
185
+ white-space: nowrap;
186
+ }
187
+
188
+ .align-start {
189
+ align-items: flex-start;
190
+ }
191
+
192
+ .align-end {
193
+ align-items: flex-end;
194
+ }
195
+
196
+ .align-center {
197
+ align-items: center;
198
+ }
199
+
200
+ .lds-dual-ring {
201
+ display: inline-block;
202
+ width: 50px;
203
+ height: 50px;
204
+ }
205
+ .lds-dual-ring:after {
206
+ content: " ";
207
+ display: block;
208
+ width: 50px;
209
+ height: 50px;
210
+ margin: 0px;
211
+ border-radius: 50%;
212
+ border: 2px solid #fff;
213
+ border-color: #888 #ddd #888 #ddd;
214
+ background-color: white;
215
+ animation: lds-dual-ring 0.8s linear infinite;
216
+ }
217
+
218
+ .lds-dual-ring-lg {
219
+ display: inline-block;
220
+ width: 30px;
221
+ height: 30px;
222
+ }
223
+ .lds-dual-ring-lg:after {
224
+ content: " ";
225
+ display: block;
226
+ width: 30px;
227
+ height: 30px;
228
+ margin: 0px;
229
+ border-radius: 50%;
230
+ border: 3px solid #fff;
231
+ border-color: #888 #ddd #888 #ddd;
232
+ animation: lds-dual-ring 0.8s linear infinite;
233
+ }
234
+
235
+ .div-row-error {
236
+ display: flex;
237
+ justify-content: center;
238
+ position: fixed;
239
+ position: fixed;
240
+ top: 0px;
241
+ right: 0px;
242
+ margin-top: 20px;
243
+ margin-right: 20px;
244
+ display: none;
245
+ align-items:center;
246
+ background-color: white;
247
+ border: dashed 1px red;
248
+ padding: 20px;
249
+ }
250
+
251
+ .div-row-error-message {
252
+ color: red;
253
+ padding: 5px;
254
+ background-color: white;
255
+ text-align: center;
256
+ }
257
+
258
+ .div-row-success {
259
+ display: flex;
260
+ justify-content: center;
261
+ position: fixed;
262
+ top: 0px;
263
+ right: 0px;
264
+ margin-top: 20px;
265
+ margin-right: 20px;
266
+ display: none;
267
+ align-items:center;
268
+ background-color: white;
269
+ border: dashed 1px green;
270
+ padding: 20px;
271
+ }
272
+
273
+ .div-row-success-message {
274
+ color: green;
275
+ padding: 5px;
276
+ background-color: white;
277
+ text-align: center;
278
+ }
279
+
280
+ .d-flex {
281
+ display: flex;
282
+ }
283
+
284
+ .flex-col {
285
+ flex-direction: column;
286
+ }
287
+
288
+ .justify-center {
289
+ justify-content: center;
290
+ }
291
+
292
+ .justify-between {
293
+ justify-content: space-between;
294
+ }
295
+
296
+ .justify-end {
297
+ justify-content: flex-end;
298
+ }
299
+
300
+ @keyframes lds-dual-ring {
301
+ 0% {
302
+ transform: rotate(0deg);
303
+ }
304
+ 100% {
305
+ transform: rotate(360deg);
306
+ }
307
+ }
308
+
309
+ .hide {
310
+ display: none;
311
+ }
312
+
313
+ .lb {
314
+ width: 5%
315
+ }
316
+ .rb {
317
+ width: 5%
318
+ }
319
+
320
+ @media (orientation: landscape) {
321
+
322
+ .lb {
323
+ width: 30%
324
+ }
325
+ .rb {
326
+ width: 30%
327
+ }
328
+
329
+ #calendar-container {
330
+ width: 40%;
331
+ }
332
+
333
+ .calendar-item {
334
+ width: 25%;
335
+ }
336
+
337
+ }
338
+
339
+ `;
340
+
341
+ @query('.div-row-error')
342
+ _SfRowError: any;
343
+
344
+ @query('.div-row-error-message')
345
+ _SfRowErrorMessage: any;
346
+
347
+ @query('.div-row-success')
348
+ _SfRowSuccess: any;
349
+
350
+ @query('.div-row-success-message')
351
+ _SfRowSuccessMessage: any;
352
+
353
+ @query('.loader-element')
354
+ _SfLoader: any;
355
+
356
+ @query('#calendar-container')
357
+ _SfCalendarContainer: any;
358
+
359
+ prepareXhr = async (data: any, url: string, loaderElement: any, authorization: any) => {
360
+
361
+
362
+ if(loaderElement != null) {
363
+ loaderElement.innerHTML = '<div class="lds-dual-ring"></div>';
364
+ }
365
+ return await Util.callApi(url, data, authorization);
366
+
367
+ }
368
+
369
+ clearMessages = () => {
370
+ this._SfRowError.style.display = 'none';
371
+ this._SfRowErrorMessage.innerHTML = '';
372
+ this._SfRowSuccess.style.display = 'none';
373
+ this._SfRowSuccessMessage.innerHTML = '';
374
+ }
375
+
376
+ setError = (msg: string) => {
377
+ this._SfRowError.style.display = 'flex';
378
+ this._SfRowErrorMessage.innerHTML = msg;
379
+ this._SfRowSuccess.style.display = 'none';
380
+ this._SfRowSuccessMessage.innerHTML = '';
381
+ }
382
+
383
+ setSuccess = (msg: string) => {
384
+ this._SfRowError.style.display = 'none';
385
+ this._SfRowErrorMessage.innerHTML = '';
386
+ this._SfRowSuccess.style.display = 'flex';
387
+ this._SfRowSuccessMessage.innerHTML = msg;
388
+ }
389
+
390
+ getLastDayOfLastMonth = (month: number, year: number) => {
391
+ const date = new Date(year, month, 0);
392
+ console.log('last date of last month', month, date.getDate());
393
+ return date.getDate()
394
+ }
395
+
396
+ getLastDayOfMonth = (month: number, year: number) => {
397
+ const date = new Date(year, month + 1, 0);
398
+ return date.getDate()
399
+ }
400
+
401
+ getBlanks = (month: number, year: number) => {
402
+
403
+ const date = new Date(("0" + (month+1)).slice(-2) + '/01/' + year);
404
+ const day = date.getDay();
405
+ return day;
406
+
407
+ }
408
+
409
+ insertDates = (month: number, year: number) => {
410
+
411
+ var html = "";
412
+
413
+ html += '<div class="d-flex align-center flex-grow flex-wrap">';
414
+
415
+ const dateNumber = this.getLastDayOfLastMonth(month, year);
416
+
417
+ for(var i = 0; i < this.getBlanks(month, year); i++) {
418
+
419
+ html += '<div class="day-item date-item-before">';
420
+ html += dateNumber-(this.getBlanks(month, year) - i - 1);
421
+ html += '</div>';
422
+
423
+ }
424
+
425
+ for(i = 0; i < this.getLastDayOfMonth(month, year); i++) {
426
+
427
+ const mmdd = ("0" + month).slice(-2) + "/" + ("0" + (i+1)).slice(-2);
428
+
429
+ if(this.events[mmdd] != null) {
430
+
431
+ console.log('found not null event');
432
+
433
+ html += '<div class="day-item date-item-selected">';
434
+ html += (i + 1);
435
+ html += '</div>';
436
+
437
+ } else {
438
+
439
+ html += '<div class="day-item date-item">';
440
+ html += (i + 1);
441
+ html += '</div>';
442
+
443
+ }
444
+
445
+ }
446
+
447
+ for(i = 0; i < 42 - (this.getBlanks(month, year) + this.getLastDayOfMonth(month, year)); i++) {
448
+ html += '<div class="day-item date-item-before">';
449
+ html += (i+1);
450
+ html += '</div>';
451
+ }
452
+
453
+ html += '</div>';
454
+
455
+ return html;
456
+
457
+ }
458
+
459
+ insertDayNames = () => {
460
+
461
+ var html = "";
462
+
463
+ html += '<div class="d-flex align-center flex-grow">';
464
+
465
+ html += '<div class="day-item">';
466
+ html += 'S';
467
+ html += '</div>';
468
+
469
+ html += '<div class="day-item">';
470
+ html += 'M';
471
+ html += '</div>';
472
+
473
+ html += '<div class="day-item">';
474
+ html += 'T';
475
+ html += '</div>';
476
+
477
+ html += '<div class="day-item">';
478
+ html += 'W';
479
+ html += '</div>';
480
+
481
+ html += '<div class="day-item">';
482
+ html += 'T';
483
+ html += '</div>';
484
+
485
+ html += '<div class="day-item">';
486
+ html += 'F';
487
+ html += '</div>';
488
+
489
+ html += '<div class="day-item">';
490
+ html += 'S';
491
+ html += '</div>';
492
+
493
+ html += '</div>';
494
+
495
+ return html;
496
+
497
+ }
498
+
499
+ renderCalendar = () => {
500
+
501
+ console.log('redering calendar', this.events);
502
+
503
+ var startDate = new Date(this.calendarStartMM + '/' + this.calendarStartDD + '/' + this.calendarStartYYYY);
504
+
505
+ var html = '';
506
+
507
+ for(var i = 0; i < 12; i++) {
508
+
509
+ html += '<div class="calendar-item d-flex flex-col flex-grow">';
510
+ html += '<div class="d-flex">';
511
+ html += '<div class="title-item">' + this.monthNames[startDate.getMonth()] + '&nbsp;&nbsp;' + startDate.getFullYear() + '</div>';
512
+ html += '</div>';
513
+ html += this.insertDayNames();
514
+ html += this.insertDates(startDate.getMonth(), startDate.getFullYear());
515
+ html += '</div>';
516
+
517
+ startDate.setMonth(startDate.getMonth() + 1);
518
+
519
+ }
520
+
521
+ (this._SfCalendarContainer as HTMLDivElement).innerHTML = html;
522
+
523
+ }
524
+
525
+ processEvent = (value: any) => {
526
+
527
+ console.log('processing due date', value.duedate.replace(/['"]+/g, ''));
528
+ const duedateArr = value.duedate.replace(/['"]+/g, '').split(",") as Array<string>;
529
+
530
+ const startMonth = parseInt(this.calendarStartMM) - 1;
531
+
532
+ for(var i = 0; i < duedateArr.length; i++) {
533
+
534
+ const dateArr = duedateArr[i].split("/");
535
+ console.log('datearr', dateArr);
536
+
537
+ if(dateArr[2] == "*") {
538
+ if(dateArr[1] == "*") {
539
+
540
+ var j = startMonth;
541
+
542
+ while(true) {
543
+
544
+ if(j === (startMonth - 1)) {
545
+ break;
546
+ }
547
+
548
+ const mmdd = ("0" +j).slice(-2) + "/" + ("0" + dateArr[0]).slice(-2);
549
+
550
+ if(this.events == null) {
551
+ this.events = {};
552
+ }
553
+ this.events[mmdd] = value;
554
+
555
+ j++;
556
+
557
+ if(j === 12) {
558
+ j = 0;
559
+ }
560
+
561
+ }
562
+
563
+ } else {
564
+
565
+ const mmdd = ("0" +dateArr[1]).slice(-2) + "/" + ("0" + dateArr[0]).slice(-2);
566
+
567
+ if(this.events == null) {
568
+ this.events = {};
569
+ }
570
+ this.events[mmdd] = value;
571
+
572
+ }
573
+ }
574
+
575
+ }
576
+
577
+ console.log('calendar processed', this.calendar);
578
+ console.log('event processed', this.events);
579
+
580
+ }
581
+
582
+ fetchDetail = async (value: any) => {
583
+
584
+ const body: any = this.getApiBodyList();
585
+ body.id = value;
586
+ console.log('detail', value, body);
587
+ let url = "https://"+this.apiIdDetail+".execute-api.us-east-1.amazonaws.com/test/" + this.apiMethodDetail;
588
+
589
+ const authorization = btoa(Util.readCookie('email') + ":" + Util.readCookie('accessToken'));
590
+ const xhr : any = (await this.prepareXhr(body, url, this._SfLoader, authorization)) as any;
591
+ this._SfLoader.innerHTML = '';
592
+ if(xhr.status == 200) {
593
+
594
+ const jsonRespose = JSON.parse(xhr.responseText);
595
+ console.log('jsonResponse', jsonRespose);
596
+ this.processEvent(jsonRespose.data.value)
597
+
598
+ } else {
599
+ const jsonRespose = JSON.parse(xhr.responseText);
600
+ this.setError(jsonRespose.error);
601
+ }
602
+
603
+ }
604
+
605
+ fetchList = async () => {
606
+
607
+ const body: any = this.getApiBodyList();
608
+ let url = "https://"+this.apiIdList+".execute-api.us-east-1.amazonaws.com/test/" + this.apiMethodList;
609
+
610
+ const authorization = btoa(Util.readCookie('email') + ":" + Util.readCookie('accessToken'));
611
+ const xhr : any = (await this.prepareXhr(body, url, this._SfLoader, authorization)) as any;
612
+ this._SfLoader.innerHTML = '';
613
+ if(xhr.status == 200) {
614
+
615
+ const jsonRespose = JSON.parse(xhr.responseText);
616
+ const fieldArr = JSON.parse(jsonRespose.data.value[this.apiResponseFieldList]) as Array<string>;
617
+
618
+ for(var i = 0; i < fieldArr.length; i++) {
619
+
620
+ console.log(fieldArr[i]);
621
+ await this.fetchDetail(fieldArr[i])
622
+
623
+ }
624
+
625
+ } else {
626
+ const jsonRespose = JSON.parse(xhr.responseText);
627
+ this.setError(jsonRespose.error);
628
+ }
629
+
630
+ }
631
+
632
+ initCalendar = async () => {
633
+
634
+ var newDate = null;
635
+ var newMonth = null;
636
+ var newYear = null;
637
+ var startDate = new Date(this.calendarStartMM + '/' + this.calendarStartDD + '/' + this.calendarStartYYYY);
638
+
639
+ console.log('startDate', startDate);
640
+
641
+ do {
642
+
643
+ this.calendar.push(startDate);
644
+ startDate.setDate(startDate.getDate() + 1);
645
+
646
+ newDate = ("0" + startDate.getDate()).slice(-2);
647
+ newMonth = ("0" + startDate.getMonth()).slice(-2);
648
+ newYear = (startDate.getFullYear());
649
+
650
+ } while(!(newDate == this.calendarStartDD && newMonth == (("0" + ((parseInt(this.calendarStartMM) - 1) + "")).slice(-2)) && newYear === (parseInt(this.calendarStartYYYY) + 1)));
651
+
652
+ console.log(this.calendar);
653
+
654
+ }
655
+
656
+ initInputs = () => {
657
+
658
+ this.calendarStartDD = ("0" + this.calendarStartDD).slice(-2);
659
+ this.calendarStartMM = ("0" + this.calendarStartMM).slice(-2);
660
+
661
+ }
662
+
663
+ loadMode = async () => {
664
+
665
+ this.initInputs();
666
+ this.initCalendar();
667
+ await this.fetchList();
668
+ this.renderCalendar();
669
+
670
+ }
671
+
672
+ constructor() {
673
+ super();
674
+ }
675
+
676
+ protected override firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
677
+
678
+ this.loadMode();
679
+
680
+ }
681
+
682
+ override connectedCallback() {
683
+ super.connectedCallback()
684
+ }
685
+
686
+ override render() {
687
+
688
+ return html`
689
+
690
+ <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
691
+ <div class="SfIEventsC">
692
+
693
+ <div class="d-flex justify-center">
694
+ <div class="loader-element"></div>
695
+ </div>
696
+ <div class="d-flex justify-center">
697
+ <div class="lb"></div>
698
+ <div class="d-flex flex-grow flex-wrap justify-center align-start" id="calendar-container">
699
+
700
+ </div>
701
+ <div class="rb"></div>
702
+ </div>
703
+ <div class="d-flex justify-between">
704
+ <div class="lb"></div>
705
+ <div>
706
+ <div class="div-row-error div-row-submit gone">
707
+ <div part="errormsg" class="div-row-error-message"></div>
708
+ </div>
709
+ <div class="div-row-success div-row-submit gone">
710
+ <div part="successmsg" class="div-row-success-message"></div>
711
+ </div>
712
+ </div>
713
+ <div class="rb"></div>
714
+ </div>
715
+ </div>
716
+
717
+ `;
718
+ }
719
+
720
+ }
721
+
722
+ declare global {
723
+ interface HTMLElementTagNameMap {
724
+ 'sf-i-events': SfIEvents;
725
+ }
726
+ }