@iapps/ng-dhis2-ui 1.2.101 → 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
@@ -6409,7 +6408,6 @@ class BaseFormFieldComponent extends ReactWrapperModule {
6409
6408
  constructor() {
6410
6409
  super(...arguments);
6411
6410
  this.ngZone = inject(NgZone);
6412
- this.httpClient = inject(NgxDhis2HttpClientService);
6413
6411
  this.fieldType = 'textbox';
6414
6412
  this.field = input.required();
6415
6413
  this.fieldError = input();
@@ -7351,18 +7349,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
7351
7349
  class SelectionFiltersComponent extends ReactWrapperModule {
7352
7350
  constructor() {
7353
7351
  super(...arguments);
7352
+ this.d2 = window.d2Web;
7354
7353
  this.actionOptions = [];
7355
7354
  this.programAttributesFilters = [];
7356
7355
  this.programStageDataElementFilters = [];
7357
7356
  this.actionSelected = new EventEmitter();
7358
- this.httpClient = inject(NgxDhis2HttpClientService);
7359
7357
  this.ngZone = inject(NgZone);
7360
7358
  this.FieldOrgUnitSelector = (props) => {
7361
7359
  const { onSelectOrgUnit, onCancelOrgUnit } = props;
7362
7360
  const [selected, setSelected] = useState([]);
7363
7361
  const [rootOrgUnits, setRootOrgUnits] = useState();
7364
7362
  const [config, setConfig] = useState();
7365
- // TODO: START::: Improve approach on handling observables
7363
+ // TODO: START::: Improve approach on handling observables
7366
7364
  // useEffect(() => {
7367
7365
  // zip(this.getAppConfig(), this.getRootOrgUnits()).subscribe({
7368
7366
  // next: ([appConfig, rootOrgUnits]) => {
@@ -7372,7 +7370,7 @@ class SelectionFiltersComponent extends ReactWrapperModule {
7372
7370
  // error: (error) => console.error(error),
7373
7371
  // });
7374
7372
  // }, []);
7375
- // TODO: END::: Improve approach on handling observables
7373
+ // TODO: END::: Improve approach on handling observables
7376
7374
  useEffect(() => {
7377
7375
  const subscription = zip(this.getAppConfig(), this.getRootOrgUnits())
7378
7376
  .pipe(take(1)) // Ensures only one emission
@@ -7600,27 +7598,34 @@ class SelectionFiltersComponent extends ReactWrapperModule {
7600
7598
  React__default.createElement(Button$1, { onClick: handleSearch }, "Search"))))));
7601
7599
  };
7602
7600
  }
7603
- getAppConfig() {
7604
- return this.httpClient.systemInfo().pipe(map((response) => {
7605
- const systemInfo = response;
7606
- return {
7607
- baseUrl: (document?.location?.host?.includes('localhost')
7608
- ? `${document.location.protocol}//${document.location.host}`
7609
- : systemInfo['contextPath']),
7610
- apiVersion: Number(((systemInfo['version'] || '')?.split('.') || [])[1]),
7611
- };
7612
- }));
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
+ };
7613
7612
  }
7614
- getRootOrgUnits() {
7613
+ async getRootOrgUnits() {
7615
7614
  const orgUnitAttribute = this.getOrgUnitAttributeByUsage(this.orgUnitSelectionConfig.usageType);
7616
- return this.httpClient
7617
- .me()
7618
- .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);
7617
+ }
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'] ?? [];
7619
7623
  }
7620
- getOrgUnitLevels() {
7621
- return firstValueFrom(this.httpClient
7622
- .get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false')
7623
- .pipe(map((res) => res?.['organisationUnitLevels'])));
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'] ?? [];
7624
7629
  }
7625
7630
  onSelectOrgUnit(selectedOrgUnits) {
7626
7631
  this.showOrgUnitTree.set(false);
@@ -7628,11 +7633,6 @@ class SelectionFiltersComponent extends ReactWrapperModule {
7628
7633
  this.selectedOrgUnit.set(selectedOrgUnits[0]);
7629
7634
  }
7630
7635
  }
7631
- getOrgUnitGroups() {
7632
- return firstValueFrom(this.httpClient
7633
- .get('organisationUnitGroups.json?fields=id,displayName,name&paging=false')
7634
- .pipe(map((res) => res?.['organisationUnitGroups'])));
7635
- }
7636
7636
  getOrgUnitAttributeByUsage(usageType) {
7637
7637
  switch (usageType) {
7638
7638
  case 'DATA_ENTRY':