@iapps/ng-dhis2-ui 1.2.100 → 1.2.102

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.
@@ -4,7 +4,6 @@ import * as i0 from '@angular/core';
4
4
  import { NgModule, Directive, Input, ContentChild, Component, EventEmitter, Output, inject, NgZone, input, ChangeDetectionStrategy, Injectable, model, computed, signal, effect, ViewChildren } from '@angular/core';
5
5
  import { useDataQuery, useConfig, useAlert, clearSensitiveCaches, DataProvider, useDataEngine, Provider } from '@dhis2/app-runtime';
6
6
  import * as i1 from '@iapps/ngx-dhis2-http-client';
7
- import { NgxDhis2HttpClientService } from '@iapps/ngx-dhis2-http-client';
8
7
  import * as React from 'react';
9
8
  import React__default, { useState, useCallback, useRef, useEffect, createContext, useContext, useMemo } from 'react';
10
9
  import * as ReactDOM from 'react-dom/client';
@@ -2392,9 +2391,9 @@ PeriodDimension.defaultProps = {
2392
2391
  };
2393
2392
 
2394
2393
  class PeriodSelectorModalComponent extends ReactWrapperModule {
2395
- constructor(elementRef, httpClient) {
2394
+ constructor(elementRef) {
2396
2395
  super(elementRef);
2397
- this.httpClient = httpClient;
2396
+ this.d2 = window.d2Web;
2398
2397
  this.selectedPeriods = [];
2399
2398
  this.cancel = new EventEmitter();
2400
2399
  this.confirm = new EventEmitter();
@@ -2422,7 +2421,7 @@ class PeriodSelectorModalComponent extends ReactWrapperModule {
2422
2421
  if (!this.elementRef)
2423
2422
  throw new Error('No element ref');
2424
2423
  this.reactDomRoot = ReactDOM.createRoot(this.elementRef.nativeElement);
2425
- const systemInfo = await firstValueFrom(this.httpClient.systemInfo());
2424
+ const systemInfo = this.d2.systemInfo;
2426
2425
  const excludedPeriodTypes = this.getExcludedPeriodTypes(systemInfo);
2427
2426
  this.component = () => {
2428
2427
  const [selected, setSelected] = useState(this.selectedPeriods);
@@ -2447,13 +2446,13 @@ class PeriodSelectorModalComponent extends ReactWrapperModule {
2447
2446
  onConfirm(selectedItems) {
2448
2447
  this.confirm.emit(selectedItems);
2449
2448
  }
2450
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: PeriodSelectorModalComponent, deps: [{ token: i0.ElementRef }, { token: i1.NgxDhis2HttpClientService }], target: i0.ɵɵFactoryTarget.Component }); }
2449
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: PeriodSelectorModalComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); }
2451
2450
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.1.8", type: PeriodSelectorModalComponent, isStandalone: false, selector: "ng-dhis2-ui-period-selector-modal", inputs: { selectedPeriods: "selectedPeriods" }, outputs: { cancel: "cancel", confirm: "confirm" }, usesInheritance: true, ngImport: i0, template: `<ng-container></ng-container>`, isInline: true, styles: ["::ng-deep .layer{z-index:2!important}\n"] }); }
2452
2451
  }
2453
2452
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: PeriodSelectorModalComponent, decorators: [{
2454
2453
  type: Component,
2455
2454
  args: [{ selector: 'ng-dhis2-ui-period-selector-modal', template: `<ng-container></ng-container>`, standalone: false, styles: ["::ng-deep .layer{z-index:2!important}\n"] }]
2456
- }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.NgxDhis2HttpClientService }], propDecorators: { selectedPeriods: [{
2455
+ }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { selectedPeriods: [{
2457
2456
  type: Input
2458
2457
  }], cancel: [{
2459
2458
  type: Output
@@ -2462,10 +2461,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
2462
2461
  }] } });
2463
2462
 
2464
2463
  class PeriodSelectorComponent extends ReactWrapperModule {
2465
- constructor(elementRef, httpClient, ngZone) {
2464
+ constructor(elementRef, ngZone) {
2466
2465
  super(elementRef);
2467
- this.httpClient = httpClient;
2468
2466
  this.ngZone = ngZone;
2467
+ this.d2 = window.d2Web;
2469
2468
  this.selectedPeriods = [];
2470
2469
  this.selectPeriods = new EventEmitter();
2471
2470
  this.props = {
@@ -2497,7 +2496,7 @@ class PeriodSelectorComponent extends ReactWrapperModule {
2497
2496
  if (!this.elementRef)
2498
2497
  throw new Error('No element ref');
2499
2498
  this.reactDomRoot = ReactDOM.createRoot(this.elementRef.nativeElement);
2500
- const systemInfo = await firstValueFrom(this.httpClient.systemInfo());
2499
+ const systemInfo = this.d2.systemInfo;
2501
2500
  const excludedPeriodTypes = this.getExcludedPeriodTypes(systemInfo);
2502
2501
  this.component = () => (React__default.createElement(DataProvider, null, React__default.createElement(PeriodDimension, { selectedPeriods: this.selectedPeriods, onSelect: (selectionEvent) => this.ngZone.run(() => {
2503
2502
  this.onSelectItems(selectionEvent);
@@ -2507,13 +2506,13 @@ class PeriodSelectorComponent extends ReactWrapperModule {
2507
2506
  onSelectItems(selectionEvent) {
2508
2507
  this.selectPeriods.emit(selectionEvent.items);
2509
2508
  }
2510
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: PeriodSelectorComponent, deps: [{ token: i0.ElementRef }, { token: i1.NgxDhis2HttpClientService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); }
2509
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: PeriodSelectorComponent, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); }
2511
2510
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.1.8", type: PeriodSelectorComponent, isStandalone: false, selector: "ng-dhis2-ui-period-selector", inputs: { selectedPeriods: "selectedPeriods" }, outputs: { selectPeriods: "selectPeriods" }, usesInheritance: true, ngImport: i0, template: `<ng-container></ng-container>`, isInline: true, styles: ["::ng-deep .content-container{z-index:0!important}\n"] }); }
2512
2511
  }
2513
2512
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: PeriodSelectorComponent, decorators: [{
2514
2513
  type: Component,
2515
2514
  args: [{ selector: 'ng-dhis2-ui-period-selector', template: `<ng-container></ng-container>`, standalone: false, styles: ["::ng-deep .content-container{z-index:0!important}\n"] }]
2516
- }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.NgxDhis2HttpClientService }, { type: i0.NgZone }], propDecorators: { selectedPeriods: [{
2515
+ }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.NgZone }], propDecorators: { selectedPeriods: [{
2517
2516
  type: Input
2518
2517
  }], selectPeriods: [{
2519
2518
  type: Output
@@ -2987,9 +2986,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
2987
2986
  }] } });
2988
2987
 
2989
2988
  class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
2990
- constructor(elementRef, httpClient) {
2989
+ constructor(elementRef) {
2991
2990
  super(elementRef);
2992
- this.httpClient = httpClient;
2991
+ this.d2 = window.d2Web;
2993
2992
  this.selectedOrgUnits = [];
2994
2993
  this.orgUnitSelectionConfig = new OrganisationUnitSelectionConfig();
2995
2994
  this.selectOrgUnits = new EventEmitter();
@@ -3007,24 +3006,26 @@ class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
3007
3006
  this.reactDomRoot = ReactDOM.createRoot(this.elementRef.nativeElement);
3008
3007
  const rootOrgUnits = await this.getRootOrgUnits();
3009
3008
  const config = await this.getAppConfig();
3010
- this.component = () => {
3011
- const [selected, setSelected] = useState(this.selectedOrgUnits);
3012
- return (React__default.createElement(Provider, { config: config, plugin: false, parentAlertsAdd: undefined, showAlertsInPlugin: false }, React__default.createElement(Modal$1, { position: "middle", large: true },
3013
- React__default.createElement(ModalTitle$1, null, "Organisation unit"),
3014
- React__default.createElement(ModalContent$1, null,
3015
- React__default.createElement(OrgUnitDimension, { selected: selected, hideGroupSelect: this.orgUnitSelectionConfig.hideGroupSelect, hideLevelSelect: this.orgUnitSelectionConfig.hideLevelSelect, hideUserOrgUnits: this.orgUnitSelectionConfig.hideUserOrgUnits, onSelect: (selectionEvent) => {
3016
- setSelected(selectionEvent.items);
3017
- }, orgUnitGroupPromise: this.getOrgUnitGroups(), orgUnitLevelPromise: this.getOrgUnitLevels(), roots: rootOrgUnits })),
3018
- React__default.createElement(ModalActions$1, null,
3019
- React__default.createElement(ButtonStrip$1, { end: true },
3020
- React__default.createElement(Button$1, { onClick: () => {
3021
- this.onCancel();
3022
- } }, "Cancel"),
3023
- React__default.createElement(Button$1, { primary: true, disabled: selected.length === 0, onClick: () => {
3024
- this.onConfirm(selected);
3025
- } }, "Confirm"))))));
3026
- };
3027
- this.render();
3009
+ if (config) {
3010
+ this.component = () => {
3011
+ const [selected, setSelected] = useState(this.selectedOrgUnits);
3012
+ return (React__default.createElement(Provider, { config: config, plugin: false, parentAlertsAdd: undefined, showAlertsInPlugin: false }, React__default.createElement(Modal$1, { position: "middle", large: true },
3013
+ React__default.createElement(ModalTitle$1, null, "Organisation unit"),
3014
+ React__default.createElement(ModalContent$1, null,
3015
+ React__default.createElement(OrgUnitDimension, { selected: selected, hideGroupSelect: this.orgUnitSelectionConfig.hideGroupSelect, hideLevelSelect: this.orgUnitSelectionConfig.hideLevelSelect, hideUserOrgUnits: this.orgUnitSelectionConfig.hideUserOrgUnits, onSelect: (selectionEvent) => {
3016
+ setSelected(selectionEvent.items);
3017
+ }, orgUnitGroupPromise: this.getOrgUnitGroups(), orgUnitLevelPromise: this.getOrgUnitLevels(), roots: rootOrgUnits })),
3018
+ React__default.createElement(ModalActions$1, null,
3019
+ React__default.createElement(ButtonStrip$1, { end: true },
3020
+ React__default.createElement(Button$1, { onClick: () => {
3021
+ this.onCancel();
3022
+ } }, "Cancel"),
3023
+ React__default.createElement(Button$1, { primary: true, disabled: selected.length === 0, onClick: () => {
3024
+ this.onConfirm(selected);
3025
+ } }, "Confirm"))))));
3026
+ };
3027
+ this.render();
3028
+ }
3028
3029
  }
3029
3030
  onCancel() {
3030
3031
  this.cancel.emit();
@@ -3033,12 +3034,15 @@ class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
3033
3034
  this.confirm.emit(selectedItems);
3034
3035
  }
3035
3036
  async getAppConfig() {
3036
- const systemInfo = (await firstValueFrom(this.httpClient.systemInfo()));
3037
+ const systemInfo = this.d2.systemInfo;
3038
+ if (!systemInfo) {
3039
+ return systemInfo;
3040
+ }
3037
3041
  return {
3038
- baseUrl: (document?.location?.host?.includes('localhost')
3042
+ baseUrl: document?.location?.host?.includes('localhost')
3039
3043
  ? `${document.location.protocol}//${document.location.host}`
3040
- : systemInfo['contextPath']),
3041
- apiVersion: Number(((systemInfo['version'] || '')?.split('.') || [])[1]),
3044
+ : systemInfo.contextPath,
3045
+ apiVersion: systemInfo.apiVersion,
3042
3046
  };
3043
3047
  }
3044
3048
  getOrgUnitAttributeByUsage(usageType) {
@@ -3051,32 +3055,33 @@ class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
3051
3055
  return 'organisationUnits';
3052
3056
  }
3053
3057
  }
3054
- getRootOrgUnits() {
3058
+ async getRootOrgUnits() {
3055
3059
  const orgUnitAttribute = this.getOrgUnitAttributeByUsage(this.orgUnitSelectionConfig.usageType);
3056
- return firstValueFrom(this.httpClient
3057
- .me()
3058
- .pipe(map((user) => (user ? user[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id))));
3060
+ const currentUser = this.d2?.currentUser;
3061
+ return (currentUser ? currentUser[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id);
3059
3062
  }
3060
- getOrgUnitGroups() {
3061
- return firstValueFrom(this.httpClient
3062
- .get('organisationUnitGroups.json?fields=id,displayName,name&paging=false')
3063
- .pipe(map((res) => res?.['organisationUnitGroups'])));
3063
+ async getOrgUnitGroups() {
3064
+ const orgUnitGroupResponse = await this.d2?.httpInstance?.get('organisationUnitGroups.json?fields=id,displayName,name&paging=false', {
3065
+ useIndexDb: this.orgUnitSelectionConfig?.allowCaching,
3066
+ });
3067
+ return orgUnitGroupResponse?.data?.['organisationUnitGroups'] ?? [];
3064
3068
  }
3065
- getOrgUnitLevels() {
3066
- return firstValueFrom(this.httpClient
3067
- .get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false')
3068
- .pipe(map((res) => res?.['organisationUnitLevels'])));
3069
+ async getOrgUnitLevels() {
3070
+ const orgUnitLevelResponse = await this.d2?.httpInstance?.get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false', {
3071
+ useIndexDb: this.orgUnitSelectionConfig?.allowCaching,
3072
+ });
3073
+ return orgUnitLevelResponse?.data?.['organisationUnitLevels'] ?? [];
3069
3074
  }
3070
3075
  onSelectItems(selectionEvent) {
3071
3076
  this.selectOrgUnits.emit(selectionEvent.items);
3072
3077
  }
3073
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: OrganisationUnitSelectorModalComponent, deps: [{ token: i0.ElementRef }, { token: i1.NgxDhis2HttpClientService }], target: i0.ɵɵFactoryTarget.Component }); }
3078
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: OrganisationUnitSelectorModalComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); }
3074
3079
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.1.8", type: OrganisationUnitSelectorModalComponent, isStandalone: false, selector: "ng-dhis2-ui-org-unit-selector-modal", inputs: { selectedOrgUnits: "selectedOrgUnits", orgUnitSelectionConfig: "orgUnitSelectionConfig" }, outputs: { selectOrgUnits: "selectOrgUnits", cancel: "cancel", confirm: "confirm" }, usesInheritance: true, ngImport: i0, template: '<ng-container><ng-container>', isInline: true, styles: ["::ng-deep .layer{z-index:2!important}\n"] }); }
3075
3080
  }
3076
3081
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: OrganisationUnitSelectorModalComponent, decorators: [{
3077
3082
  type: Component,
3078
3083
  args: [{ selector: 'ng-dhis2-ui-org-unit-selector-modal', template: '<ng-container><ng-container>', standalone: false, styles: ["::ng-deep .layer{z-index:2!important}\n"] }]
3079
- }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.NgxDhis2HttpClientService }], propDecorators: { selectedOrgUnits: [{
3084
+ }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { selectedOrgUnits: [{
3080
3085
  type: Input
3081
3086
  }], orgUnitSelectionConfig: [{
3082
3087
  type: Input
@@ -6403,7 +6408,6 @@ class BaseFormFieldComponent extends ReactWrapperModule {
6403
6408
  constructor() {
6404
6409
  super(...arguments);
6405
6410
  this.ngZone = inject(NgZone);
6406
- this.httpClient = inject(NgxDhis2HttpClientService);
6407
6411
  this.fieldType = 'textbox';
6408
6412
  this.field = input.required();
6409
6413
  this.fieldError = input();
@@ -7345,18 +7349,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
7345
7349
  class SelectionFiltersComponent extends ReactWrapperModule {
7346
7350
  constructor() {
7347
7351
  super(...arguments);
7352
+ this.d2 = window.d2Web;
7348
7353
  this.actionOptions = [];
7349
7354
  this.programAttributesFilters = [];
7350
7355
  this.programStageDataElementFilters = [];
7351
7356
  this.actionSelected = new EventEmitter();
7352
- this.httpClient = inject(NgxDhis2HttpClientService);
7353
7357
  this.ngZone = inject(NgZone);
7354
7358
  this.FieldOrgUnitSelector = (props) => {
7355
7359
  const { onSelectOrgUnit, onCancelOrgUnit } = props;
7356
7360
  const [selected, setSelected] = useState([]);
7357
7361
  const [rootOrgUnits, setRootOrgUnits] = useState();
7358
7362
  const [config, setConfig] = useState();
7359
- // TODO: START::: Improve approach on handling observables
7363
+ // TODO: START::: Improve approach on handling observables
7360
7364
  // useEffect(() => {
7361
7365
  // zip(this.getAppConfig(), this.getRootOrgUnits()).subscribe({
7362
7366
  // next: ([appConfig, rootOrgUnits]) => {
@@ -7366,7 +7370,7 @@ class SelectionFiltersComponent extends ReactWrapperModule {
7366
7370
  // error: (error) => console.error(error),
7367
7371
  // });
7368
7372
  // }, []);
7369
- // TODO: END::: Improve approach on handling observables
7373
+ // TODO: END::: Improve approach on handling observables
7370
7374
  useEffect(() => {
7371
7375
  const subscription = zip(this.getAppConfig(), this.getRootOrgUnits())
7372
7376
  .pipe(take(1)) // Ensures only one emission
@@ -7594,27 +7598,34 @@ class SelectionFiltersComponent extends ReactWrapperModule {
7594
7598
  React__default.createElement(Button$1, { onClick: handleSearch }, "Search"))))));
7595
7599
  };
7596
7600
  }
7597
- getAppConfig() {
7598
- return this.httpClient.systemInfo().pipe(map((response) => {
7599
- const systemInfo = response;
7600
- return {
7601
- baseUrl: (document?.location?.host?.includes('localhost')
7602
- ? `${document.location.protocol}//${document.location.host}`
7603
- : systemInfo['contextPath']),
7604
- apiVersion: Number(((systemInfo['version'] || '')?.split('.') || [])[1]),
7605
- };
7606
- }));
7601
+ async getAppConfig() {
7602
+ const systemInfo = this.d2.systemInfo;
7603
+ if (!systemInfo) {
7604
+ return systemInfo;
7605
+ }
7606
+ return {
7607
+ baseUrl: document?.location?.host?.includes('localhost')
7608
+ ? `${document.location.protocol}//${document.location.host}`
7609
+ : systemInfo.contextPath,
7610
+ apiVersion: systemInfo.apiVersion,
7611
+ };
7607
7612
  }
7608
- getRootOrgUnits() {
7613
+ async getRootOrgUnits() {
7609
7614
  const orgUnitAttribute = this.getOrgUnitAttributeByUsage(this.orgUnitSelectionConfig.usageType);
7610
- return this.httpClient
7611
- .me()
7612
- .pipe(map((user) => (user ? user[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id)));
7615
+ const currentUser = this.d2?.currentUser;
7616
+ return (currentUser ? currentUser[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id);
7613
7617
  }
7614
- getOrgUnitLevels() {
7615
- return firstValueFrom(this.httpClient
7616
- .get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false')
7617
- .pipe(map((res) => res?.['organisationUnitLevels'])));
7618
+ async getOrgUnitGroups() {
7619
+ const orgUnitGroupResponse = await this.d2?.httpInstance?.get('organisationUnitGroups.json?fields=id,displayName,name&paging=false', {
7620
+ useIndexDb: this.orgUnitSelectionConfig?.allowCaching,
7621
+ });
7622
+ return orgUnitGroupResponse?.data?.['organisationUnitGroups'] ?? [];
7623
+ }
7624
+ async getOrgUnitLevels() {
7625
+ const orgUnitLevelResponse = await this.d2?.httpInstance?.get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false', {
7626
+ useIndexDb: this.orgUnitSelectionConfig?.allowCaching,
7627
+ });
7628
+ return orgUnitLevelResponse?.data?.['organisationUnitLevels'] ?? [];
7618
7629
  }
7619
7630
  onSelectOrgUnit(selectedOrgUnits) {
7620
7631
  this.showOrgUnitTree.set(false);
@@ -7622,11 +7633,6 @@ class SelectionFiltersComponent extends ReactWrapperModule {
7622
7633
  this.selectedOrgUnit.set(selectedOrgUnits[0]);
7623
7634
  }
7624
7635
  }
7625
- getOrgUnitGroups() {
7626
- return firstValueFrom(this.httpClient
7627
- .get('organisationUnitGroups.json?fields=id,displayName,name&paging=false')
7628
- .pipe(map((res) => res?.['organisationUnitGroups'])));
7629
- }
7630
7636
  getOrgUnitAttributeByUsage(usageType) {
7631
7637
  switch (usageType) {
7632
7638
  case 'DATA_ENTRY':