@osovitny/anatoly 2.0.21 → 2.0.23

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 (26) hide show
  1. package/bundles/osovitny-anatoly.umd.js +382 -234
  2. package/bundles/osovitny-anatoly.umd.js.map +1 -1
  3. package/bundles/osovitny-anatoly.umd.min.js +2 -2
  4. package/bundles/osovitny-anatoly.umd.min.js.map +1 -1
  5. package/esm2015/lib/core/localization/localization.service.js +115 -0
  6. package/esm2015/lib/core/utils.js +58 -14
  7. package/esm2015/lib/ui/components/html-editor/forms-html-editor.component.js +2 -2
  8. package/esm2015/lib/ui/index.js +4 -4
  9. package/esm2015/lib/ui/ui.module.js +25 -25
  10. package/esm2015/lib/ui/validation/form-validation-summary.component.js +64 -0
  11. package/esm2015/lib/ui/validation/item-validation-summary.component.js +38 -0
  12. package/esm2015/lib/ui/validation/validation-summary.component.js +117 -0
  13. package/fesm2015/osovitny-anatoly.js +328 -183
  14. package/fesm2015/osovitny-anatoly.js.map +1 -1
  15. package/lib/core/localization/localization.service.d.ts +18 -0
  16. package/lib/core/utils.d.ts +9 -0
  17. package/lib/ui/index.d.ts +3 -3
  18. package/lib/ui/ui.module.d.ts +2 -2
  19. package/lib/ui/{components/validation → validation}/validation-summary.component.d.ts +1 -1
  20. package/osovitny-anatoly.metadata.json +1 -1
  21. package/package.json +1 -1
  22. package/esm2015/lib/ui/components/validation/form-validation-summary.component.js +0 -64
  23. package/esm2015/lib/ui/components/validation/item-validation-summary.component.js +0 -38
  24. package/esm2015/lib/ui/components/validation/validation-summary.component.js +0 -117
  25. /package/lib/ui/{components/validation → validation}/form-validation-summary.component.d.ts +0 -0
  26. /package/lib/ui/{components/validation → validation}/item-validation-summary.component.d.ts +0 -0
@@ -1,11 +1,14 @@
1
1
  import Swal from 'sweetalert2';
2
- import { v4 } from 'uuid';
3
- import { Injectable, ɵɵdefineInjectable, Injector, NgModule, Optional, SkipSelf, Component, Input, Directive, ElementRef } from '@angular/core';
4
- import { ActivatedRoute, Router } from '@angular/router';
2
+ import { ɵɵdefineInjectable, ɵɵinject, Injectable, NgModule, Injector, Optional, SkipSelf, Component, Input, Directive, ElementRef } from '@angular/core';
3
+ import { TranslateService } from '@ngx-translate/core';
4
+ import { isValid, format, formatDistanceToNow, formatDistance } from 'date-fns';
5
+ import enUS from 'date-fns/locale/en-US';
6
+ import { CommonModule } from '@angular/common';
5
7
  import { HttpClient, HttpResponse } from '@angular/common/http';
6
8
  import { map, tap } from 'rxjs/operators';
7
9
  import { BehaviorSubject } from 'rxjs';
8
- import { CommonModule } from '@angular/common';
10
+ import { v4 } from 'uuid';
11
+ import { ActivatedRoute, Router } from '@angular/router';
9
12
  import { NgControl, ReactiveFormsModule, FormsModule } from '@angular/forms';
10
13
  import { FroalaEditorModule, FroalaViewModule } from 'angular-froala-wysiwyg';
11
14
 
@@ -227,7 +230,7 @@ class Alerts {
227
230
  Anatoly Osovitny
228
231
 
229
232
  Created:
230
- 26 Jun 2020
233
+ 05 May 2020
231
234
 
232
235
  Version:
233
236
  1.0
@@ -235,131 +238,88 @@ class Alerts {
235
238
  Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
236
239
  </file>
237
240
  */
238
- class Utils {
239
- static getValueByNameInQS(name) {
240
- return Utils.getValueByName(location.search, name);
241
+ class LocalizationService {
242
+ constructor(translate) {
243
+ this.translate = translate;
244
+ this.setSupportedLanguages(['en']);
245
+ }
246
+ format(str, args) {
247
+ // tslint:disable-next-line:variable-name
248
+ return str.replace(/{(\d+)}/g, (match, number) => typeof args[number] !== 'undefined' ? args[number] : match);
249
+ }
250
+ ;
251
+ configureTranslationSettings(translate) {
252
+ const languageToSet = 'en';
253
+ translate.setDefaultLang(languageToSet);
254
+ return languageToSet;
255
+ }
256
+ getBrowserLanguage() {
257
+ return this.translate.getBrowserLang();
258
+ }
259
+ getDatefnsLocale() {
260
+ let dfnLocale;
261
+ switch (this.getBrowserLanguage()) {
262
+ case 'en':
263
+ dfnLocale = { locale: enUS };
264
+ break;
265
+ default:
266
+ dfnLocale = { locale: enUS };
267
+ }
268
+ return dfnLocale;
241
269
  }
242
- static getValueByName(url, name) {
243
- name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
244
- var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(url);
245
- return results === null
246
- ? ""
247
- : decodeURIComponent(results[1].replace(/\+/g, " "));
270
+ setDefaultLanguage(lang) {
271
+ this.translate.setDefaultLang(lang);
248
272
  }
249
- static copyToClipBoard(event, val) {
250
- event.preventDefault();
251
- let selBox = document.createElement("textarea");
252
- selBox.style.position = "fixed";
253
- selBox.style.left = "0";
254
- selBox.style.top = "0";
255
- selBox.style.opacity = "0";
256
- selBox.value = val;
257
- document.body.appendChild(selBox);
258
- selBox.focus();
259
- selBox.select();
260
- document.execCommand("copy");
261
- document.body.removeChild(selBox);
273
+ setSupportedLanguages(languages) {
274
+ this.translate.addLangs(languages);
262
275
  }
263
- static downloadFile(name, url) {
264
- var link = document.createElement("a");
265
- link.download = name;
266
- link.href = url;
267
- link.click();
268
- }
269
- }
270
-
271
- /*
272
- <file>
273
- Project:
274
- @osovitny/anatoly
275
-
276
- Authors:
277
- Vadim Osovitny
278
- Anatoly Osovitny
279
-
280
- Created:
281
- 26 Jun 2020
282
-
283
- Version:
284
- 1.0
285
-
286
- Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
287
- </file>
288
- */
289
- class Subs {
290
- constructor() {
291
- this.subs = [];
276
+ updateLanguage(language) {
277
+ this.translate.use(language);
292
278
  }
293
- add(...subscriptions) {
294
- this.subs = this.subs.concat(subscriptions);
295
- }
296
- set sink(subscription) {
297
- this.subs.push(subscription);
298
- }
299
- unsubscribe() {
300
- this.subs.forEach((sub) => sub && sub.unsubscribe());
301
- this.subs = [];
279
+ getLocalizedValue(key, params) {
280
+ const value = this.translate.instant(key);
281
+ if (!params || params.length === 0) {
282
+ return value;
283
+ }
284
+ return this.format(value, params);
302
285
  }
303
- }
304
-
305
- /*
306
- <file>
307
- Project:
308
- @osovitny/anatoly
309
-
310
- Authors:
311
- Vadim Osovitny
312
- Anatoly Osovitny
313
-
314
- Created:
315
- 26 Jun 2020
316
-
317
- Version:
318
- 1.0
319
-
320
- Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
321
- </file>
322
- */
323
- class Guid {
324
- static newGuid() {
325
- return v4();
286
+ getLocalizedDate(key) {
287
+ if (isValid(new Date(key))) {
288
+ return format(new Date(key), AppCoreSettings.DATE_FORMATS.angular, this.dateFnsLocale);
289
+ }
290
+ return 'Invalid Date';
291
+ }
292
+ getLocalizedDateTime(key) {
293
+ // To Do Manoj: Test in IE and make TimeZone specific changes accordingly
294
+ const dateValue = new Date(key);
295
+ if (isValid(dateValue)) {
296
+ const localDate = Utils.convertToLocalizedDateTime(dateValue);
297
+ return format(localDate, AppCoreSettings.DATE_FORMATS.angularWithTime, this.dateFnsLocale);
298
+ }
299
+ return 'Invalid Date';
326
300
  }
327
- }
328
-
329
- /*
330
- <file>
331
- Project:
332
- @osovitny/anatoly
333
-
334
- Authors:
335
- Vadim Osovitny
336
- Anatoly Osovitny
337
-
338
- Created:
339
- 17 Jun 2018
340
-
341
- Version:
342
- 1.0
343
-
344
- Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
345
- </file>
346
- */
347
- class BaseGoService {
348
- constructor(route, router) {
349
- this.route = route;
350
- this.router = router;
301
+ getLocalizedDistanceToNowInWords(date) {
302
+ // https://date-fns.org/v1.30.1/docs/distanceInWords
303
+ if (isValid(new Date(date))) {
304
+ return formatDistanceToNow(new Date(date), this.dateFnsLocale);
305
+ }
306
+ return 'Invalid Date';
351
307
  }
352
- locationReload() {
353
- //this.router.navigate([this.route.url]);
354
- window.location.reload();
308
+ getLocalizedDistanceInWords(endedDate, startedDate) {
309
+ if (isValid(new Date(endedDate)) && isValid(new Date(startedDate))) {
310
+ return formatDistance(new Date(endedDate), new Date(startedDate), this.dateFnsLocale);
311
+ }
312
+ return 'Invalid Date';
355
313
  }
356
314
  }
357
- BaseGoService.decorators = [
358
- { type: Injectable }
315
+ LocalizationService.ɵprov = ɵɵdefineInjectable({ factory: function LocalizationService_Factory() { return new LocalizationService(ɵɵinject(TranslateService)); }, token: LocalizationService, providedIn: "root" });
316
+ LocalizationService.decorators = [
317
+ { type: Injectable, args: [{
318
+ providedIn: 'root'
319
+ },] }
359
320
  ];
360
- BaseGoService.ctorParameters = () => [
361
- { type: ActivatedRoute },
362
- { type: Router }
321
+ LocalizationService.ctorParameters = () => [
322
+ { type: TranslateService }
363
323
  ];
364
324
 
365
325
  /*
@@ -397,42 +357,6 @@ LoggingService.decorators = [
397
357
  ];
398
358
  LoggingService.ctorParameters = () => [];
399
359
 
400
- /*
401
- <file>
402
- Project:
403
- @osovitny/anatoly
404
-
405
- Authors:
406
- Vadim Osovitny
407
- Anatoly Osovitny
408
-
409
- Created:
410
- 26 Jun 2020
411
-
412
- Version:
413
- 1.0
414
-
415
- Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
416
- </file>
417
- */
418
- class GlobalErrorHandler {
419
- constructor(injector) {
420
- this.injector = injector;
421
- }
422
- handleError(error) {
423
- const loggingService = this.injector.get(LoggingService);
424
- loggingService.logError(error);
425
- // IMPORTANT: Rethrow the error otherwise it gets swallowed
426
- throw error;
427
- }
428
- }
429
- GlobalErrorHandler.decorators = [
430
- { type: Injectable }
431
- ];
432
- GlobalErrorHandler.ctorParameters = () => [
433
- { type: Injector }
434
- ];
435
-
436
360
  /*
437
361
  <file>
438
362
  Project:
@@ -646,6 +570,251 @@ LoadingService.decorators = [
646
570
  ];
647
571
  LoadingService.ctorParameters = () => [];
648
572
 
573
+ const providers = [
574
+ LoggingService,
575
+ AppContextService,
576
+ LoadingService
577
+ ];
578
+ let InjectorInstance;
579
+ class AnatolyCoreModule {
580
+ constructor(injector, parentModule) {
581
+ this.injector = injector;
582
+ throwIfAlreadyLoaded(parentModule, 'AnatolyCoreModule');
583
+ InjectorInstance = this.injector;
584
+ }
585
+ }
586
+ AnatolyCoreModule.decorators = [
587
+ { type: NgModule, args: [{
588
+ imports: [CommonModule],
589
+ providers: [...providers],
590
+ },] }
591
+ ];
592
+ AnatolyCoreModule.ctorParameters = () => [
593
+ { type: Injector },
594
+ { type: AnatolyCoreModule, decorators: [{ type: Optional }, { type: SkipSelf }] }
595
+ ];
596
+
597
+ /*
598
+ <file>
599
+ Project:
600
+ @osovitny/anatoly
601
+
602
+ Authors:
603
+ Vadim Osovitny
604
+ Anatoly Osovitny
605
+
606
+ Created:
607
+ 19 March 2020
608
+
609
+ Version:
610
+ 1.0
611
+
612
+ Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
613
+ </file>
614
+ */
615
+ // @dynamic
616
+ class Utils {
617
+ static getValueByNameInQS(name) {
618
+ return Utils.getValueByName(location.search, name);
619
+ }
620
+ static getValueByName(url, name) {
621
+ name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
622
+ const regex = new RegExp('[\\?&]' + name + '=([^&#]*)'), results = regex.exec(url);
623
+ return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
624
+ }
625
+ static copyToClipBoard(event, val) {
626
+ event.preventDefault();
627
+ const selBox = document.createElement('textarea');
628
+ selBox.style.position = 'fixed';
629
+ selBox.style.left = '0';
630
+ selBox.style.top = '0';
631
+ selBox.style.opacity = '0';
632
+ selBox.value = val;
633
+ document.body.appendChild(selBox);
634
+ selBox.focus();
635
+ selBox.select();
636
+ document.execCommand('copy');
637
+ document.body.removeChild(selBox);
638
+ }
639
+ static downloadFile(name, url) {
640
+ const link = document.createElement('a');
641
+ link.download = name;
642
+ link.href = url;
643
+ link.click();
644
+ }
645
+ // Localization
646
+ // @dynamic
647
+ static get localizationService() {
648
+ const ns = InjectorInstance.get(LocalizationService);
649
+ return ns;
650
+ }
651
+ static getLocalizedValue(key, params, defaultKey) {
652
+ // VadimOS: DON'T CHANGE THIS CODE. NEED TO BE REVIEWED AND APPROVED BY VADIMOS
653
+ // defaultKey definition:
654
+ // if key is empty and defaultKey is defined => get localization for defaultKey
655
+ // Example: cancel()
656
+ if (!key && defaultKey) {
657
+ return this.localizationService.getLocalizedValue(defaultKey);
658
+ }
659
+ // VadimOS:
660
+ // if key is not empty value MUST be in localization table, othewise we will return key
661
+ if (key) {
662
+ const value = this.localizationService.getLocalizedValue(key, params);
663
+ return value;
664
+ }
665
+ return key;
666
+ }
667
+ /**
668
+ * Convert date time lo local time zone value.
669
+ * @param value
670
+ */
671
+ static convertToLocalizedDateTime(value) {
672
+ if (value) {
673
+ return new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate(), value.getHours(), value.getMinutes(), value.getSeconds(), value.getMilliseconds()));
674
+ }
675
+ return null;
676
+ }
677
+ static downloadBlobFile(value, fileName) {
678
+ if (window.navigator.msSaveOrOpenBlob) {
679
+ window.navigator.msSaveOrOpenBlob(value, fileName);
680
+ }
681
+ else {
682
+ const downloadURL = window.URL.createObjectURL(value);
683
+ Utils.downloadFile(fileName, downloadURL);
684
+ }
685
+ }
686
+ }
687
+
688
+ /*
689
+ <file>
690
+ Project:
691
+ @osovitny/anatoly
692
+
693
+ Authors:
694
+ Vadim Osovitny
695
+ Anatoly Osovitny
696
+
697
+ Created:
698
+ 26 Jun 2020
699
+
700
+ Version:
701
+ 1.0
702
+
703
+ Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
704
+ </file>
705
+ */
706
+ class Subs {
707
+ constructor() {
708
+ this.subs = [];
709
+ }
710
+ add(...subscriptions) {
711
+ this.subs = this.subs.concat(subscriptions);
712
+ }
713
+ set sink(subscription) {
714
+ this.subs.push(subscription);
715
+ }
716
+ unsubscribe() {
717
+ this.subs.forEach((sub) => sub && sub.unsubscribe());
718
+ this.subs = [];
719
+ }
720
+ }
721
+
722
+ /*
723
+ <file>
724
+ Project:
725
+ @osovitny/anatoly
726
+
727
+ Authors:
728
+ Vadim Osovitny
729
+ Anatoly Osovitny
730
+
731
+ Created:
732
+ 26 Jun 2020
733
+
734
+ Version:
735
+ 1.0
736
+
737
+ Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
738
+ </file>
739
+ */
740
+ class Guid {
741
+ static newGuid() {
742
+ return v4();
743
+ }
744
+ }
745
+
746
+ /*
747
+ <file>
748
+ Project:
749
+ @osovitny/anatoly
750
+
751
+ Authors:
752
+ Vadim Osovitny
753
+ Anatoly Osovitny
754
+
755
+ Created:
756
+ 17 Jun 2018
757
+
758
+ Version:
759
+ 1.0
760
+
761
+ Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
762
+ </file>
763
+ */
764
+ class BaseGoService {
765
+ constructor(route, router) {
766
+ this.route = route;
767
+ this.router = router;
768
+ }
769
+ locationReload() {
770
+ //this.router.navigate([this.route.url]);
771
+ window.location.reload();
772
+ }
773
+ }
774
+ BaseGoService.decorators = [
775
+ { type: Injectable }
776
+ ];
777
+ BaseGoService.ctorParameters = () => [
778
+ { type: ActivatedRoute },
779
+ { type: Router }
780
+ ];
781
+
782
+ /*
783
+ <file>
784
+ Project:
785
+ @osovitny/anatoly
786
+
787
+ Authors:
788
+ Vadim Osovitny
789
+ Anatoly Osovitny
790
+
791
+ Created:
792
+ 26 Jun 2020
793
+
794
+ Version:
795
+ 1.0
796
+
797
+ Copyright (c) 2016-2020 Osovitny Inc. All rights reserved.
798
+ </file>
799
+ */
800
+ class GlobalErrorHandler {
801
+ constructor(injector) {
802
+ this.injector = injector;
803
+ }
804
+ handleError(error) {
805
+ const loggingService = this.injector.get(LoggingService);
806
+ loggingService.logError(error);
807
+ // IMPORTANT: Rethrow the error otherwise it gets swallowed
808
+ throw error;
809
+ }
810
+ }
811
+ GlobalErrorHandler.decorators = [
812
+ { type: Injectable }
813
+ ];
814
+ GlobalErrorHandler.ctorParameters = () => [
815
+ { type: Injector }
816
+ ];
817
+
649
818
  /*
650
819
  <file>
651
820
  Project:
@@ -745,30 +914,6 @@ AnatolyHttpInterceptor.ctorParameters = () => [
745
914
  { type: LoggingService }
746
915
  ];
747
916
 
748
- const providers = [
749
- LoggingService,
750
- AppContextService,
751
- LoadingService
752
- ];
753
- let InjectorInstance;
754
- class AnatolyCoreModule {
755
- constructor(injector, parentModule) {
756
- this.injector = injector;
757
- throwIfAlreadyLoaded(parentModule, 'AnatolyCoreModule');
758
- InjectorInstance = this.injector;
759
- }
760
- }
761
- AnatolyCoreModule.decorators = [
762
- { type: NgModule, args: [{
763
- imports: [CommonModule],
764
- providers: [...providers],
765
- },] }
766
- ];
767
- AnatolyCoreModule.ctorParameters = () => [
768
- { type: Injector },
769
- { type: AnatolyCoreModule, decorators: [{ type: Optional }, { type: SkipSelf }] }
770
- ];
771
-
772
917
  /*
773
918
  <file>
774
919
  Project:
@@ -1694,7 +1839,7 @@ class FormsHtmlEditorComponent extends BaseHtmlEditorComponent {
1694
1839
  FormsHtmlEditorComponent.decorators = [
1695
1840
  { type: Component, args: [{
1696
1841
  selector: "anatoly-forms-html-editor",
1697
- template: "<div [formGroup]=\"formGroup\">\r\n <div class=\"form-group\" [ngClass]=\"{'has-error': isItemInvalid(editorFormKey) }\">\r\n <label class=\"control-label\">{{ editorLabelText }}</label>\r\n <textarea [formControlName]=\"editorFormKey\"\r\n [froalaEditor]=\"options\" (froalaInit)=\"initializeControl($event)\">\r\n </textarea>\r\n <anatoly-item-validation-summary [formGroup]=\"formGroup\"\r\n [formSubmitted]=\"formSubmitted\"\r\n [controlName]=\"editorFormKey\"\r\n [controlTitle]=\"editorLabelText\">\r\n </anatoly-item-validation-summary>\r\n </div>\r\n</div>\r\n"
1842
+ template: "<div [formGroup]=\"formGroup\">\r\n <div class=\"form-group\" [ngClass]=\"{'has-error': isControlInvalid(editorFormKey) }\">\r\n <label class=\"control-label\">{{ editorLabelText }}</label>\r\n <textarea [formControlName]=\"editorFormKey\"\r\n [froalaEditor]=\"options\" (froalaInit)=\"initializeControl($event)\">\r\n </textarea>\r\n <anatoly-item-validation-summary [formGroup]=\"formGroup\"\r\n [formSubmitted]=\"formSubmitted\"\r\n [controlName]=\"editorFormKey\"\r\n [controlTitle]=\"editorLabelText\">\r\n </anatoly-item-validation-summary>\r\n </div>\r\n</div>\r\n"
1698
1843
  },] }
1699
1844
  ];
1700
1845
  FormsHtmlEditorComponent.ctorParameters = () => [];
@@ -1994,7 +2139,7 @@ AnatolyUIModule.decorators = [
1994
2139
  HtmlEditorComponent,
1995
2140
  FormsHtmlEditorComponent,
1996
2141
  ContentHeaderComponent,
1997
- //Directives
2142
+ // Directives
1998
2143
  NativeElementDirective
1999
2144
  ],
2000
2145
  declarations: [
@@ -2009,7 +2154,7 @@ AnatolyUIModule.decorators = [
2009
2154
  HtmlEditorComponent,
2010
2155
  FormsHtmlEditorComponent,
2011
2156
  ContentHeaderComponent,
2012
- //Directives
2157
+ // Directives
2013
2158
  NativeElementDirective
2014
2159
  ]
2015
2160
  },] }