@onecx/angular-accelerator 4.13.0 → 4.13.2

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Directive, Optional, Input, HostListener, EventEmitter, Component, Output, LOCALE_ID, Inject, ContentChild, Pipe, ViewChild, Injectable, Injector, ViewEncapsulation, NgModule, inject, importProvidersFrom, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
2
+ import { Directive, Optional, Input, HostListener, EventEmitter, Component, Output, LOCALE_ID, Inject, ContentChild, Pipe, ViewChild, Injectable, Injector, ViewEncapsulation, NgModule, inject, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
3
3
  import * as i2 from '@onecx/angular-integration-interface';
4
4
  import { UserService, AppStateService } from '@onecx/angular-integration-interface';
5
5
  import * as i1 from '@angular/common/http';
@@ -14,7 +14,7 @@ import { PrimeIcons } from 'primeng/api';
14
14
  import * as i3$1 from '@angular/forms';
15
15
  import { FormGroup, FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
16
16
  import * as i1$1 from '@ngx-translate/core';
17
- import { TranslateModule, TranslateLoader, MissingTranslationHandler } from '@ngx-translate/core';
17
+ import { TranslatePipe, TranslateModule, TranslateLoader, MissingTranslationHandler } from '@ngx-translate/core';
18
18
  import * as i6 from 'primeng/button';
19
19
  import { ButtonModule } from 'primeng/button';
20
20
  import * as i4 from 'primeng/dialog';
@@ -33,15 +33,12 @@ import * as i6$2 from 'primeng/table';
33
33
  import { TableModule } from 'primeng/table';
34
34
  import * as i7$1 from 'primeng/multiselect';
35
35
  import { MultiSelectModule } from 'primeng/multiselect';
36
- import { TimeagoPipe, TimeagoIntl, TimeagoModule, TimeagoFormatter, TimeagoCustomFormatter, TimeagoClock, TimeagoDefaultClock } from 'ngx-timeago';
37
36
  import * as d3 from 'd3-scale-chromatic';
38
37
  import * as i5$1 from 'primeng/chart';
39
38
  import { ChartModule } from 'primeng/chart';
40
39
  import * as i5$2 from 'primeng/breadcrumb';
41
40
  import { BreadcrumbModule } from 'primeng/breadcrumb';
42
41
  import { SyncableTopic } from '@onecx/accelerator';
43
- import { strings } from 'ngx-timeago/language-strings/en';
44
- import { strings as strings$1 } from 'ngx-timeago/language-strings/de';
45
42
  import { TranslateHttpLoader } from '@ngx-translate/http-loader';
46
43
 
47
44
  class IfPermissionDirective {
@@ -954,16 +951,107 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
954
951
  }] } });
955
952
 
956
953
  // eslint-disable-next-line @angular-eslint/use-pipe-transform-interface
957
- class OcxTimeAgoPipe extends TimeagoPipe {
954
+ class OcxTimeAgoPipe extends TranslatePipe {
955
+ constructor(changeDetectorRef, ngZone, translateService) {
956
+ super(translateService, changeDetectorRef);
957
+ this.changeDetectorRef = changeDetectorRef;
958
+ this.ngZone = ngZone;
959
+ this.translateService = translateService;
960
+ }
961
+ transform(value) {
962
+ this.removeTimer();
963
+ const d = new Date(value);
964
+ const now = new Date();
965
+ const seconds = Math.round(Math.abs((now.getTime() - d.getTime()) / 1000));
966
+ const timeToUpdate = Number.isNaN(seconds) ? 1000 : this.getSecondsUntilUpdate(seconds) * 1000;
967
+ this.timer = this.ngZone.runOutsideAngular(() => {
968
+ if (typeof window !== 'undefined') {
969
+ return window.setTimeout(() => {
970
+ this.ngZone.run(() => this.changeDetectorRef.markForCheck());
971
+ }, timeToUpdate);
972
+ }
973
+ return null;
974
+ });
975
+ const minutes = Math.round(Math.abs(seconds / 60));
976
+ const hours = Math.round(Math.abs(minutes / 60));
977
+ const days = Math.round(Math.abs(hours / 24));
978
+ const months = Math.round(Math.abs(days / 30.416));
979
+ const years = Math.round(Math.abs(days / 365));
980
+ let translationKey = 'UNKNOWN';
981
+ if (Number.isNaN(seconds)) {
982
+ translationKey = 'NAN';
983
+ }
984
+ else if (seconds <= 45) {
985
+ translationKey = 'A_FEW_SECONDS_AGO';
986
+ }
987
+ else if (seconds <= 90) {
988
+ translationKey = 'A_MINUTE_AGO';
989
+ }
990
+ else if (minutes <= 45) {
991
+ translationKey = 'MINUTES_AGO';
992
+ }
993
+ else if (minutes <= 90) {
994
+ translationKey = 'AN_HOUR_AGO';
995
+ }
996
+ else if (hours <= 22) {
997
+ translationKey = 'HOURS_AGO';
998
+ }
999
+ else if (hours <= 36) {
1000
+ translationKey = 'A_DAY_AGO';
1001
+ }
1002
+ else if (days <= 25) {
1003
+ translationKey = 'DAYS_AGO';
1004
+ }
1005
+ else if (days <= 45) {
1006
+ translationKey = 'A_MONTH_AGO';
1007
+ }
1008
+ else if (days <= 345) {
1009
+ translationKey = 'MONTHS_AGO';
1010
+ }
1011
+ else if (days <= 545) {
1012
+ translationKey = 'A_YEAR_AGO';
1013
+ }
1014
+ else {
1015
+ translationKey = 'YEARS_AGO';
1016
+ }
1017
+ return super.transform('OCX_TIMEAGO.' + translationKey, { minutes, hours, days, months, years });
1018
+ }
1019
+ ngOnDestroy() {
1020
+ this.removeTimer();
1021
+ super.ngOnDestroy();
1022
+ }
1023
+ removeTimer() {
1024
+ if (this.timer) {
1025
+ window.clearTimeout(this.timer);
1026
+ this.timer = null;
1027
+ }
1028
+ }
1029
+ getSecondsUntilUpdate(seconds) {
1030
+ const min = 60;
1031
+ const hr = min * 60;
1032
+ const day = hr * 24;
1033
+ if (seconds < min) {
1034
+ return 2;
1035
+ }
1036
+ else if (seconds < hr) {
1037
+ return 30;
1038
+ }
1039
+ else if (seconds < day) {
1040
+ return 300;
1041
+ }
1042
+ else {
1043
+ return 3600;
1044
+ }
1045
+ }
958
1046
  }
959
- OcxTimeAgoPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: OcxTimeAgoPipe, deps: null, target: i0.ɵɵFactoryTarget.Pipe });
1047
+ OcxTimeAgoPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: OcxTimeAgoPipe, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: i1$1.TranslateService }], target: i0.ɵɵFactoryTarget.Pipe });
960
1048
  OcxTimeAgoPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: OcxTimeAgoPipe, name: "timeago" });
961
1049
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: OcxTimeAgoPipe, decorators: [{
962
1050
  type: Pipe,
963
1051
  args: [{
964
1052
  name: 'timeago',
965
1053
  }]
966
- }] });
1054
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: i1$1.TranslateService }]; } });
967
1055
 
968
1056
  class DataTableComponent extends DataSortBase {
969
1057
  get rows() {
@@ -2805,36 +2893,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
2805
2893
  }]
2806
2894
  }] });
2807
2895
 
2808
- class OcxTimeagoIntl extends TimeagoIntl {
2809
- constructor(userService) {
2810
- super();
2811
- this.userService = userService;
2812
- this.LANG_TO_STRINGS = {
2813
- en: strings,
2814
- de: strings$1,
2815
- };
2816
- this.DEFAULT_LANG = 'en';
2817
- this.strings = strings;
2818
- userService.lang$
2819
- .pipe(map((lang) => {
2820
- return this.getBestMatchLanguage(lang);
2821
- }))
2822
- .subscribe((lang) => {
2823
- this.strings = this.LANG_TO_STRINGS[lang];
2824
- this.changes.next();
2825
- });
2826
- }
2827
- getBestMatchLanguage(lang) {
2828
- if (Object.keys(this.LANG_TO_STRINGS).includes(lang)) {
2829
- return lang;
2830
- }
2831
- else {
2832
- console.log(`${lang} is not supported. Using ${this.DEFAULT_LANG} as a fallback.`);
2833
- }
2834
- return this.DEFAULT_LANG;
2835
- }
2836
- }
2837
-
2838
2896
  class AsyncTranslateLoader {
2839
2897
  constructor(translateLoader$) {
2840
2898
  this.translateLoader$ = translateLoader$;
@@ -2964,25 +3022,6 @@ AngularAcceleratorModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0"
2964
3022
  },
2965
3023
  deps: [UserService],
2966
3024
  },
2967
- {
2968
- provide: TimeagoIntl,
2969
- useFactory: (userService) => {
2970
- return new OcxTimeagoIntl(userService);
2971
- },
2972
- deps: [UserService],
2973
- },
2974
- importProvidersFrom(TimeagoModule),
2975
- {
2976
- provide: TimeagoFormatter,
2977
- useFactory: (TimeagoIntl) => {
2978
- return new TimeagoCustomFormatter(TimeagoIntl);
2979
- },
2980
- deps: [TimeagoIntl],
2981
- },
2982
- {
2983
- provide: TimeagoClock,
2984
- useClass: TimeagoDefaultClock,
2985
- },
2986
3025
  ], imports: [CommonModule,
2987
3026
  AngularAcceleratorPrimeNgModule,
2988
3027
  TranslateModule.forRoot({
@@ -3050,25 +3089,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
3050
3089
  },
3051
3090
  deps: [UserService],
3052
3091
  },
3053
- {
3054
- provide: TimeagoIntl,
3055
- useFactory: (userService) => {
3056
- return new OcxTimeagoIntl(userService);
3057
- },
3058
- deps: [UserService],
3059
- },
3060
- importProvidersFrom(TimeagoModule),
3061
- {
3062
- provide: TimeagoFormatter,
3063
- useFactory: (TimeagoIntl) => {
3064
- return new TimeagoCustomFormatter(TimeagoIntl);
3065
- },
3066
- deps: [TimeagoIntl],
3067
- },
3068
- {
3069
- provide: TimeagoClock,
3070
- useClass: TimeagoDefaultClock,
3071
- },
3072
3092
  ],
3073
3093
  exports: [
3074
3094
  ColumnGroupSelectionComponent,