@onecx/angular-accelerator 7.0.3 → 8.0.0-rc.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.
@@ -2,11 +2,11 @@ import * as i0 from '@angular/core';
2
2
  import { inject, ElementRef, Input, Directive, Renderer2, ViewContainerRef, TemplateRef, HostListener, EventEmitter, Output, Injectable, Injector, LOCALE_ID, Pipe, ContentChild, ViewEncapsulation, Component, ViewChild, ContentChildren, NgZone, ChangeDetectorRef, ViewChildren, QueryList, Type, NgModule, APP_INITIALIZER } from '@angular/core';
3
3
  import { UserService, AppStateService, ConfigurationService, CONFIG_KEY, ShellCapabilityService, Capability, AppConfigService } from '@onecx/angular-integration-interface';
4
4
  import { HAS_PERMISSION_CHECKER, SKIP_STYLE_SCOPING, getScopeIdentifier, dataStyleIdKey, dataNoPortalLayoutStylesKey, MultiLanguageMissingTranslationHandler, providePermissionChecker, provideTranslationPathFromMeta, provideTranslationConnectionService } from '@onecx/angular-utils';
5
- import { BehaviorSubject, switchMap, of, from, map, filter, concat, combineLatest, startWith, debounceTime, firstValueFrom, mergeMap, first, shareReplay, withLatestFrom, ReplaySubject, timestamp, distinctUntilChanged, isObservable, skip } from 'rxjs';
5
+ import { BehaviorSubject, switchMap, of, from, take, map, filter, concat, combineLatest, startWith, debounceTime, firstValueFrom, mergeMap, first, shareReplay, withLatestFrom, ReplaySubject, timestamp, distinctUntilChanged, isObservable, skip } from 'rxjs';
6
+ import { createLoggerFactory, Topic, getLocation, isValidDate, getUTCDateWithoutTimezoneIssues } from '@onecx/accelerator';
6
7
  import { HttpClient } from '@angular/common/http';
7
8
  import * as i3 from '@angular/forms';
8
9
  import { FormGroupDirective, FormControlName, FormsModule, ReactiveFormsModule } from '@angular/forms';
9
- import { Topic, getLocation, isValidDate, getUTCDateWithoutTimezoneIssues } from '@onecx/accelerator';
10
10
  import * as i1 from '@angular/common';
11
11
  import { DatePipe, DecimalPipe, CurrencyPipe, formatDate, CommonModule } from '@angular/common';
12
12
  import * as i2$1 from 'primeng/button';
@@ -209,6 +209,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
209
209
  type: Input
210
210
  }] } });
211
211
 
212
+ // This file is not planned to be in the index.ts so it is private to this lib
213
+ const createLogger = createLoggerFactory('@onecx/angular-accelerator');
214
+
212
215
  class IfPermissionDirective {
213
216
  set permission(value) {
214
217
  this.permissionSubject$.next(value);
@@ -227,6 +230,7 @@ class IfPermissionDirective {
227
230
  this.ocxIfPermissionElseTemplate = value;
228
231
  }
229
232
  constructor() {
233
+ this.logger = createLogger('IfPermissionDirective');
230
234
  this.renderer = inject(Renderer2);
231
235
  this.el = inject(ElementRef);
232
236
  this.viewContainer = inject(ViewContainerRef);
@@ -265,7 +269,7 @@ class IfPermissionDirective {
265
269
  if (this.ocxIfPermissionPermissions) {
266
270
  const result = permission.every((p) => this.ocxIfPermissionPermissions?.includes(p));
267
271
  if (!result) {
268
- console.log('👮‍♀️ No permission in overwrites for: `', permission);
272
+ this.logger.debug('No permission in overwrites for:', permission);
269
273
  }
270
274
  return of(result);
271
275
  }
@@ -273,7 +277,7 @@ class IfPermissionDirective {
273
277
  return this.permissionChecker.getPermissions().pipe(switchMap((permissions) => {
274
278
  const result = permission.every((p) => permissions.includes(p));
275
279
  if (!result) {
276
- console.log('👮‍♀️ No permission from permission checker for: `', permission);
280
+ this.logger.debug('No permission from permission checker for:', permission);
277
281
  }
278
282
  return of(result);
279
283
  }));
@@ -390,28 +394,37 @@ class SrcDirective {
390
394
  return this._src;
391
395
  }
392
396
  set ocxSrc(value) {
393
- if (value && this._src !== value && window.location.hostname) {
397
+ if (value && this._src !== value && globalThis.location.hostname) {
394
398
  try {
395
- if (new URL(value, window.location.origin).hostname === window.location.hostname) {
396
- this.httpClient.get(value, { observe: 'response', responseType: 'blob' }).subscribe((response) => {
397
- // ok with content
398
- if (response?.status === 200) {
399
- const url = URL.createObjectURL(response.body);
400
- this.el.nativeElement.addEventListener('load', () => {
401
- URL.revokeObjectURL(url);
402
- });
403
- this.el.nativeElement.src = url;
404
- }
405
- // no content
406
- if (response?.status === 204) {
399
+ if (new URL(value, globalThis.location.origin).hostname === globalThis.location.hostname) {
400
+ this.httpClient
401
+ .get(value, { observe: 'response', responseType: 'blob' })
402
+ .pipe(take(1))
403
+ .subscribe({
404
+ next: (response) => {
405
+ // ok with content
406
+ if (response?.status === 200) {
407
+ const url = URL.createObjectURL(response.body);
408
+ const onLoad = () => {
409
+ URL.revokeObjectURL(url);
410
+ this.el.nativeElement.removeEventListener('load', onLoad);
411
+ };
412
+ this.el.nativeElement.addEventListener('load', onLoad);
413
+ this.el.nativeElement.src = url;
414
+ }
415
+ // no content
416
+ if (response?.status === 204) {
417
+ this.error.emit();
418
+ }
419
+ },
420
+ error: () => {
421
+ // on error
407
422
  this.error.emit();
408
- }
409
- }, () => {
410
- // on error
411
- this.error.emit();
412
- }, () => {
413
- // on complete
414
- this.el.nativeElement.style.visibility = 'initial';
423
+ },
424
+ complete: () => {
425
+ // on complete
426
+ this.el.nativeElement.style.visibility = 'initial';
427
+ },
415
428
  });
416
429
  }
417
430
  else {
@@ -420,7 +433,7 @@ class SrcDirective {
420
433
  }
421
434
  }
422
435
  catch (error) {
423
- console.error('Cannot parse URL ', value, error);
436
+ this.logger.error('Cannot parse URL', value, error);
424
437
  this.el.nativeElement.src = value;
425
438
  this.el.nativeElement.style.visibility = 'initial';
426
439
  }
@@ -428,6 +441,7 @@ class SrcDirective {
428
441
  }
429
442
  }
430
443
  constructor() {
444
+ this.logger = createLogger('SrcDirective');
431
445
  this.el = inject(ElementRef);
432
446
  this.httpClient = inject(HttpClient);
433
447
  // eslint-disable-next-line @angular-eslint/no-output-native
@@ -1000,7 +1014,7 @@ class AdvancedDirective {
1000
1014
  this.searchHeader = inject(SearchHeaderComponent, { optional: true });
1001
1015
  const searchHeader = this.searchHeader;
1002
1016
  if (!searchHeader) {
1003
- throw 'Advanced directive can only be used inside search header component';
1017
+ throw new Error('Advanced directive can only be used inside search header component');
1004
1018
  }
1005
1019
  searchHeader.hasAdvanced = true;
1006
1020
  }
@@ -1102,7 +1116,7 @@ class BasicDirective {
1102
1116
  this.searchHeader = inject(SearchHeaderComponent, { optional: true });
1103
1117
  const searchHeader = this.searchHeader;
1104
1118
  if (!searchHeader) {
1105
- throw 'Basic directive can only be used inside search header component';
1119
+ throw new Error('Basic directive can only be used inside search header component');
1106
1120
  }
1107
1121
  }
1108
1122
  ngDoCheck() {
@@ -1157,11 +1171,11 @@ class LoadingIndicatorDirective {
1157
1171
  }
1158
1172
  toggleLoadingIndicator() {
1159
1173
  if (this.ocxLoadingIndicator) {
1160
- if (this.overlayFullPage == false) {
1161
- this.elementLoader();
1174
+ if (this.overlayFullPage) {
1175
+ this.componentRef = this.viewContainerRef.createComponent(LoadingIndicatorComponent);
1162
1176
  }
1163
1177
  else {
1164
- this.componentRef = this.viewContainerRef.createComponent(LoadingIndicatorComponent);
1178
+ this.elementLoader();
1165
1179
  }
1166
1180
  }
1167
1181
  else {
@@ -4413,16 +4427,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
4413
4427
  class GroupByCountDiagramComponent {
4414
4428
  constructor() {
4415
4429
  this.translateService = inject(TranslateService);
4430
+ this._data$ = new BehaviorSubject([]);
4416
4431
  this.sumKey = 'SEARCH.SUMMARY_TITLE';
4417
4432
  this.diagramType = "PIE" /* DiagramType.PIE */;
4418
4433
  /**
4419
4434
  * This property determines if diagram should generate the colors for the data that does not have any set.
4420
4435
  *
4421
- * Setting this property to false will result in using the provided colors only if every data item has one. In the scenario where at least one item does not have a color set, diagram will generate all colors.
4436
+ * Setting this property to false will result in using the provided colors only if every data item has one.
4437
+ * In the scenario where at least one item does not have a color set, diagram will generate all colors.
4422
4438
  */
4423
4439
  this.fillMissingColors = true;
4424
4440
  this.supportedDiagramTypes = [];
4425
- this._data$ = new BehaviorSubject([]);
4441
+ this._allLabelKeys$ = new BehaviorSubject([]);
4442
+ this._showAllLabels$ = new BehaviorSubject(false);
4426
4443
  this._columnType$ = new BehaviorSubject(ColumnType.STRING);
4427
4444
  this._columnField$ = new BehaviorSubject('');
4428
4445
  this._colors$ = new BehaviorSubject({});
@@ -4430,6 +4447,18 @@ class GroupByCountDiagramComponent {
4430
4447
  this.diagramTypeChanged = new EventEmitter();
4431
4448
  this.componentStateChanged = new EventEmitter();
4432
4449
  }
4450
+ get allLabelKeys() {
4451
+ return this._allLabelKeys$.getValue();
4452
+ }
4453
+ set allLabelKeys(value) {
4454
+ this._allLabelKeys$.next(value);
4455
+ }
4456
+ get showAllLabels() {
4457
+ return this._showAllLabels$.getValue();
4458
+ }
4459
+ set showAllLabels(value) {
4460
+ this._showAllLabels$.next(value);
4461
+ }
4433
4462
  get data() {
4434
4463
  return this._data$.getValue();
4435
4464
  }
@@ -4462,13 +4491,39 @@ class GroupByCountDiagramComponent {
4462
4491
  this._colors$.next(value);
4463
4492
  }
4464
4493
  ngOnInit() {
4465
- this.diagramData$ = combineLatest([this._data$, this._columnField$, this._columnType$, this._colors$]).pipe(mergeMap(([data, columnField, columnType, colors]) => {
4494
+ this.diagramData$ = combineLatest([
4495
+ this._data$,
4496
+ this._columnField$,
4497
+ this._columnType$,
4498
+ this._colors$,
4499
+ this._allLabelKeys$,
4500
+ this._showAllLabels$,
4501
+ ]).pipe(mergeMap(([data, columnField, columnType, colors, allLabelKeys, showAllLabels]) => {
4466
4502
  const columnData = data.map((d) => ObjectUtils.resolveFieldData(d, columnField));
4467
- const occurrences = columnData.reduce((acc, current) => {
4468
- return acc.some((e) => e.label === current)
4469
- ? (acc.find((e) => e.label === current).value++, acc)
4470
- : [...acc, { label: current, value: 1, backgroundColor: colors[current.toString()] }];
4471
- }, []);
4503
+ let occurrences = [];
4504
+ if (showAllLabels && allLabelKeys.length > 0) {
4505
+ occurrences = allLabelKeys.map((label) => ({
4506
+ label: label,
4507
+ value: 0,
4508
+ backgroundColor: colors[label],
4509
+ }));
4510
+ columnData.forEach((current) => {
4511
+ const foundColumn = occurrences.find((e) => e.label === current);
4512
+ if (foundColumn) {
4513
+ foundColumn.value++;
4514
+ }
4515
+ else {
4516
+ occurrences.push({ label: current, value: 1, backgroundColor: colors[current.toString()] });
4517
+ }
4518
+ });
4519
+ }
4520
+ else {
4521
+ occurrences = columnData.reduce((acc, current) => {
4522
+ return acc.some((e) => e.label === current)
4523
+ ? (acc.find((e) => e.label === current).value++, acc)
4524
+ : [...acc, { label: current, value: 1, backgroundColor: colors[current.toString()] }];
4525
+ }, []);
4526
+ }
4472
4527
  if (columnType === ColumnType.TRANSLATION_KEY && occurrences.length > 0) {
4473
4528
  return this.translateService.get(occurrences.map((o) => o.label)).pipe(map((translations) => occurrences.map((o) => ({
4474
4529
  label: translations[o.label],
@@ -4476,9 +4531,7 @@ class GroupByCountDiagramComponent {
4476
4531
  backgroundColor: o.backgroundColor,
4477
4532
  }))));
4478
4533
  }
4479
- else {
4480
- return of(occurrences);
4481
- }
4534
+ return of(occurrences);
4482
4535
  }));
4483
4536
  }
4484
4537
  dataClicked(event) {
@@ -4492,7 +4545,7 @@ class GroupByCountDiagramComponent {
4492
4545
  });
4493
4546
  }
4494
4547
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: GroupByCountDiagramComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
4495
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.16", type: GroupByCountDiagramComponent, isStandalone: false, selector: "ocx-group-by-count-diagram", inputs: { sumKey: "sumKey", diagramType: "diagramType", fillMissingColors: "fillMissingColors", supportedDiagramTypes: "supportedDiagramTypes", data: "data", columnType: "columnType", columnField: "columnField", column: "column", colors: "colors" }, outputs: { dataSelected: "dataSelected", diagramTypeChanged: "diagramTypeChanged", componentStateChanged: "componentStateChanged" }, ngImport: i0, template: "<ocx-diagram\n [data]=\"(diagramData$ | async) || []\"\n [fillMissingColors]=\"fillMissingColors\"\n [sumKey]=\"sumKey\"\n [diagramType]=\"diagramType\"\n (onDataSelect)=\"dataClicked($event)\"\n [supportedDiagramTypes]=\"supportedDiagramTypes\"\n (diagramTypeChanged)=\"onDiagramTypeChanged($event)\"\n></ocx-diagram>\n", dependencies: [{ kind: "component", type: DiagramComponent, selector: "ocx-diagram", inputs: ["data", "sumKey", "fillMissingColors", "diagramType", "supportedDiagramTypes"], outputs: ["dataSelected", "diagramTypeChanged", "componentStateChanged"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }] }); }
4548
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.16", type: GroupByCountDiagramComponent, isStandalone: false, selector: "ocx-group-by-count-diagram", inputs: { sumKey: "sumKey", diagramType: "diagramType", fillMissingColors: "fillMissingColors", supportedDiagramTypes: "supportedDiagramTypes", allLabelKeys: "allLabelKeys", showAllLabels: "showAllLabels", data: "data", columnType: "columnType", columnField: "columnField", column: "column", colors: "colors" }, outputs: { dataSelected: "dataSelected", diagramTypeChanged: "diagramTypeChanged", componentStateChanged: "componentStateChanged" }, ngImport: i0, template: "<ocx-diagram\n [data]=\"(diagramData$ | async) || []\"\n [fillMissingColors]=\"fillMissingColors\"\n [sumKey]=\"sumKey\"\n [diagramType]=\"diagramType\"\n (onDataSelect)=\"dataClicked($event)\"\n [supportedDiagramTypes]=\"supportedDiagramTypes\"\n (diagramTypeChanged)=\"onDiagramTypeChanged($event)\"\n></ocx-diagram>\n", dependencies: [{ kind: "component", type: DiagramComponent, selector: "ocx-diagram", inputs: ["data", "sumKey", "fillMissingColors", "diagramType", "supportedDiagramTypes"], outputs: ["dataSelected", "diagramTypeChanged", "componentStateChanged"] }, { kind: "pipe", type: i1.AsyncPipe, name: "async" }] }); }
4496
4549
  }
4497
4550
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: GroupByCountDiagramComponent, decorators: [{
4498
4551
  type: Component,
@@ -4505,6 +4558,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
4505
4558
  type: Input
4506
4559
  }], supportedDiagramTypes: [{
4507
4560
  type: Input
4561
+ }], allLabelKeys: [{
4562
+ type: Input
4563
+ }], showAllLabels: [{
4564
+ type: Input
4508
4565
  }], data: [{
4509
4566
  type: Input
4510
4567
  }], columnType: [{
@@ -5529,6 +5586,7 @@ class PortalDialogService {
5529
5586
  this.dialogService = inject(DialogService);
5530
5587
  this.translateService = inject(TranslateService);
5531
5588
  this.router = inject(Router);
5589
+ this.logger = createLogger('PortalDialogService');
5532
5590
  this.skipStyleScoping = inject(SKIP_STYLE_SCOPING, { optional: true });
5533
5591
  this.remoteComponentConfig = inject(REMOTE_COMPONENT_CONFIG, { optional: true });
5534
5592
  this.appStateService = inject(AppStateService);
@@ -5593,7 +5651,7 @@ class PortalDialogService {
5593
5651
  },
5594
5652
  });
5595
5653
  if (!dialogRef) {
5596
- console.error('Dialog could not be opened, dialog creation failed.');
5654
+ this.logger.error('Dialog could not be opened, dialog creation failed.');
5597
5655
  return of(null);
5598
5656
  }
5599
5657
  const dialogComponent = this.dialogService.getInstance(dialogRef);
@@ -5601,7 +5659,7 @@ class PortalDialogService {
5601
5659
  this.setScopeIdentifier(dialogComponent);
5602
5660
  }
5603
5661
  else {
5604
- console.warn('Dialog component instance could not be found after creation. The displayed dialog may not function as expected.');
5662
+ this.logger.warn('Dialog component instance could not be found after creation. The displayed dialog may not function as expected.');
5605
5663
  }
5606
5664
  return dialogRef.onClose;
5607
5665
  }));
@@ -5611,7 +5669,7 @@ class PortalDialogService {
5611
5669
  this.dialogService.dialogComponentRefMap.forEach((_, dialogRef) => {
5612
5670
  const dialogComponent = this.dialogService.getInstance(dialogRef);
5613
5671
  if (!dialogComponent) {
5614
- console.warn('Dialog component instance could not be found during cleanup. The displayed dialog may not function as expected.');
5672
+ this.logger.warn('Dialog component instance could not be found during cleanup. The displayed dialog may not function as expected.');
5615
5673
  return;
5616
5674
  }
5617
5675
  dialogRef.close();
@@ -6276,65 +6334,66 @@ const atLeastOneFieldFilledValidator = (form) => {
6276
6334
  return null;
6277
6335
  };
6278
6336
 
6337
+ const logger = createLogger('DataOperationStrategy');
6279
6338
  /* eslint-disable @typescript-eslint/no-unused-vars */
6280
6339
  class DataOperationStrategy {
6281
6340
  endsWith(column, value, target) {
6282
- console.error('endsWith method not implemented');
6341
+ logger.error('endsWith method not implemented');
6283
6342
  return true;
6284
6343
  }
6285
6344
  startsWith(column, value, target) {
6286
- console.error('startsWith method not implemented');
6345
+ logger.error('startsWith method not implemented');
6287
6346
  return true;
6288
6347
  }
6289
6348
  contains(column, value, target) {
6290
- console.error('contains method not implemented');
6349
+ logger.error('contains method not implemented');
6291
6350
  return true;
6292
6351
  }
6293
6352
  notContains(column, value, target) {
6294
- console.error('notContains method not implemented');
6353
+ logger.error('notContains method not implemented');
6295
6354
  return true;
6296
6355
  }
6297
6356
  equals(column, value, target) {
6298
- console.error('equals method not implemented');
6357
+ logger.error('equals method not implemented');
6299
6358
  return true;
6300
6359
  }
6301
6360
  notEquals(column, value, target) {
6302
- console.error('notEquals method not implemented');
6361
+ logger.error('notEquals method not implemented');
6303
6362
  return true;
6304
6363
  }
6305
6364
  lessThan(column, value, target) {
6306
- console.error('lessThan method not implemented');
6365
+ logger.error('lessThan method not implemented');
6307
6366
  return true;
6308
6367
  }
6309
6368
  greaterThan(column, value, target) {
6310
- console.error('greaterThan method not implemented');
6369
+ logger.error('greaterThan method not implemented');
6311
6370
  return true;
6312
6371
  }
6313
6372
  lessThanOrEqual(column, value, target) {
6314
- console.error('lessThanOrEqual method not implemented');
6373
+ logger.error('lessThanOrEqual method not implemented');
6315
6374
  return true;
6316
6375
  }
6317
6376
  greaterThanOrEqual(column, value, target) {
6318
- console.error('greaterThanOrEqual method not implemented');
6377
+ logger.error('greaterThanOrEqual method not implemented');
6319
6378
  return true;
6320
6379
  }
6321
6380
  isEmpty(column, value) {
6322
- console.error('isEmpty method not implemented');
6381
+ logger.error('isEmpty method not implemented');
6323
6382
  return true;
6324
6383
  }
6325
6384
  isNotEmpty(column, value) {
6326
- console.error('isNotEmpty method not implemented');
6385
+ logger.error('isNotEmpty method not implemented');
6327
6386
  return true;
6328
6387
  }
6329
6388
  compare(a, b, column) {
6330
- console.error('compare method not implemented');
6389
+ logger.error('compare method not implemented');
6331
6390
  return 0;
6332
6391
  }
6333
6392
  filterOptions(hayStack, filterObject, columns) {
6334
6393
  const hayStackOptions = hayStack.map((item) => this.mapHaystackItemToValue(item, filterObject));
6335
6394
  const column = columns.find((c) => c.id === filterObject.columnId);
6336
6395
  if (!column) {
6337
- console.warn('Filter does not have a column id set. All items will be considered a valid option');
6396
+ logger.warn('Filter does not have a column id set. All items will be considered a valid option');
6338
6397
  return hayStackOptions;
6339
6398
  }
6340
6399
  return hayStackOptions.filter((item, index, self) => index === self.findIndex((t) => this.compare(t, item, column) === 0));
@@ -6342,12 +6401,12 @@ class DataOperationStrategy {
6342
6401
  filter(hayStack, filter, columns) {
6343
6402
  const { filterType, value } = filter;
6344
6403
  if (!filterType) {
6345
- console.warn('Filter does not have a type set. All items will resolve as true');
6404
+ logger.warn('Filter does not have a type set. All items will resolve as true');
6346
6405
  return hayStack;
6347
6406
  }
6348
6407
  const column = columns.find((c) => c.id === filter.columnId);
6349
6408
  if (!column) {
6350
- console.warn('Filter does not have a column id set. All items will be considered a valid option');
6409
+ logger.warn('Filter does not have a column id set. All items will be considered a valid option');
6351
6410
  return hayStack;
6352
6411
  }
6353
6412
  return hayStack.filter((item) => this[filterType](column, this.mapHaystackItemToValue(item, filter), value));