@iapps/ng-dhis2-ui 1.2.101 → 1.2.103

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
@@ -3471,6 +3470,9 @@ const FilterToolbar = ({ orgUnitLabel, selectedOrgUnit, setSelectedOrgUnit, setO
3471
3470
  }, style: { display: 'inline-flex', alignItems: 'center' } },
3472
3471
  React__default.createElement(ClearIcon, { className: "my-icon-class" })))));
3473
3472
  }
3473
+ {
3474
+ /* TODO: I HAVE DUPLICATED DROPDOWN AND CLEAR ICON IN MULTIPLE PLACES REQUIRED TO CREATE A REUSABLE DROPDOWN COMPONENT WITH THE CLEAR ICON TO AVOID DUPLICATION */
3475
+ }
3474
3476
  if (options && options.options.length > 0) {
3475
3477
  return (React__default.createElement(DropdownButton, { name: "customDropdown", open: openDropdownKey === key, onClick: () => {
3476
3478
  setOpenDropdownKey(openDropdownKey === key ? null : key);
@@ -3622,6 +3624,49 @@ function formatDateForDisplay(dateString) {
3622
3624
  return 'dd-mm-yyyy';
3623
3625
  }
3624
3626
  }
3627
+ // case 'date':
3628
+ // case 'date-time':
3629
+ // return (
3630
+ // // <InputField
3631
+ // // error={hasError}
3632
+ // // validationText={validationError}
3633
+ // // type={this.field().type as any}
3634
+ // // inputWidth={inputWidth}
3635
+ // // required={this.field().required}
3636
+ // // name={this.field().id}
3637
+ // // label={this.label()}
3638
+ // // min={this.field().min?.toString()}
3639
+ // // max={this.field().max?.toString()}
3640
+ // // placeholder={this.placeholder()}
3641
+ // // value={value}
3642
+ // // readOnly={disabled}
3643
+ // // onChange={(event: any) => {
3644
+ // // onValueChange(event.value);
3645
+ // // }}
3646
+ // // onBlur={() => {
3647
+ // // checkValueUniqueness();
3648
+ // // }}
3649
+ // // />
3650
+ // <CalendarInput
3651
+ // label={this.label()}
3652
+ // error={hasError}
3653
+ // validationText={validationError}
3654
+ // date={value}
3655
+ // readOnly={disabled}
3656
+ // min={this.field().min?.toString()}
3657
+ // max={this.field().max?.toString()}
3658
+ // placeholder={this.placeholder()}
3659
+ // onDateSelect={(selectedDate: any) => {
3660
+ // onValueChange(selectedDate.calendarDateString);
3661
+ // }}
3662
+ // disabled={disabled}
3663
+ // inputWidth={inputWidth}
3664
+ // required={this.field().required}
3665
+ // calendar="gregory"
3666
+ // locale="en-GB"
3667
+ // timeZone="Africa/Dar_es_Salaam"
3668
+ // />
3669
+ // );
3625
3670
 
3626
3671
  const TableHeader = ({ columns, allSelected, onSelectAll, selectable, showActionButtons, }) => {
3627
3672
  const handleCheckboxChange = () => {
@@ -3977,7 +4022,7 @@ const getTrackedEntityTableData = (response, programId, pager, metaData, searche
3977
4022
  const attributeColumns = metaData.displayInListTrackedEntityAttributes
3978
4023
  .sort((a, b) => a.sortOrder - b.sortOrder)
3979
4024
  .map((trackedEntityAttribute) => ({
3980
- label: trackedEntityAttribute.formName ?? trackedEntityAttribute.name,
4025
+ label: trackedEntityAttribute.name ?? trackedEntityAttribute.formName,
3981
4026
  key: trackedEntityAttribute.id,
3982
4027
  }));
3983
4028
  const tableSearcheableDataElements = metaData
@@ -3986,7 +4031,7 @@ const getTrackedEntityTableData = (response, programId, pager, metaData, searche
3986
4031
  .programStageDataElements.filter((psde) => psde.displayInReports)
3987
4032
  .sort((a, b) => a.sortOrder - b.sortOrder)
3988
4033
  .map((psde) => ({
3989
- label: psde.dataElement.formName || psde.dataElement.name,
4034
+ label: psde.dataElement.name || psde.dataElement.formName || 'default',
3990
4035
  key: psde.dataElement.id,
3991
4036
  valueType: psde.dataElement.valueType,
3992
4037
  options: psde.dataElement.optionSet,
@@ -3999,7 +4044,7 @@ const getTrackedEntityTableData = (response, programId, pager, metaData, searche
3999
4044
  .programStageDataElements.filter((psde) => psde.displayInReports)
4000
4045
  .sort((a, b) => a.sortOrder - b.sortOrder) // Sorts data elements within stage
4001
4046
  .map((psde) => ({
4002
- label: psde.dataElement.formName || psde.dataElement.name,
4047
+ label: psde.dataElement.name || psde.dataElement.formName || 'default',
4003
4048
  key: psde.dataElement.id,
4004
4049
  })));
4005
4050
  const dataElementOptions = metaData.displayInListDataElements.map((element) => ({
@@ -6409,7 +6454,6 @@ class BaseFormFieldComponent extends ReactWrapperModule {
6409
6454
  constructor() {
6410
6455
  super(...arguments);
6411
6456
  this.ngZone = inject(NgZone);
6412
- this.httpClient = inject(NgxDhis2HttpClientService);
6413
6457
  this.fieldType = 'textbox';
6414
6458
  this.field = input.required();
6415
6459
  this.fieldError = input();
@@ -7351,18 +7395,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
7351
7395
  class SelectionFiltersComponent extends ReactWrapperModule {
7352
7396
  constructor() {
7353
7397
  super(...arguments);
7398
+ this.d2 = window.d2Web;
7354
7399
  this.actionOptions = [];
7355
7400
  this.programAttributesFilters = [];
7356
7401
  this.programStageDataElementFilters = [];
7357
7402
  this.actionSelected = new EventEmitter();
7358
- this.httpClient = inject(NgxDhis2HttpClientService);
7359
7403
  this.ngZone = inject(NgZone);
7360
7404
  this.FieldOrgUnitSelector = (props) => {
7361
7405
  const { onSelectOrgUnit, onCancelOrgUnit } = props;
7362
7406
  const [selected, setSelected] = useState([]);
7363
7407
  const [rootOrgUnits, setRootOrgUnits] = useState();
7364
7408
  const [config, setConfig] = useState();
7365
- // TODO: START::: Improve approach on handling observables
7409
+ // TODO: START::: Improve approach on handling observables
7366
7410
  // useEffect(() => {
7367
7411
  // zip(this.getAppConfig(), this.getRootOrgUnits()).subscribe({
7368
7412
  // next: ([appConfig, rootOrgUnits]) => {
@@ -7372,7 +7416,7 @@ class SelectionFiltersComponent extends ReactWrapperModule {
7372
7416
  // error: (error) => console.error(error),
7373
7417
  // });
7374
7418
  // }, []);
7375
- // TODO: END::: Improve approach on handling observables
7419
+ // TODO: END::: Improve approach on handling observables
7376
7420
  useEffect(() => {
7377
7421
  const subscription = zip(this.getAppConfig(), this.getRootOrgUnits())
7378
7422
  .pipe(take(1)) // Ensures only one emission
@@ -7600,27 +7644,34 @@ class SelectionFiltersComponent extends ReactWrapperModule {
7600
7644
  React__default.createElement(Button$1, { onClick: handleSearch }, "Search"))))));
7601
7645
  };
7602
7646
  }
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
- }));
7647
+ async getAppConfig() {
7648
+ const systemInfo = this.d2.systemInfo;
7649
+ if (!systemInfo) {
7650
+ return systemInfo;
7651
+ }
7652
+ return {
7653
+ baseUrl: document?.location?.host?.includes('localhost')
7654
+ ? `${document.location.protocol}//${document.location.host}`
7655
+ : systemInfo.contextPath,
7656
+ apiVersion: systemInfo.apiVersion,
7657
+ };
7613
7658
  }
7614
- getRootOrgUnits() {
7659
+ async getRootOrgUnits() {
7615
7660
  const orgUnitAttribute = this.getOrgUnitAttributeByUsage(this.orgUnitSelectionConfig.usageType);
7616
- return this.httpClient
7617
- .me()
7618
- .pipe(map((user) => (user ? user[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id)));
7661
+ const currentUser = this.d2?.currentUser;
7662
+ return (currentUser ? currentUser[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id);
7619
7663
  }
7620
- getOrgUnitLevels() {
7621
- return firstValueFrom(this.httpClient
7622
- .get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false')
7623
- .pipe(map((res) => res?.['organisationUnitLevels'])));
7664
+ async getOrgUnitGroups() {
7665
+ const orgUnitGroupResponse = await this.d2?.httpInstance?.get('organisationUnitGroups.json?fields=id,displayName,name&paging=false', {
7666
+ useIndexDb: this.orgUnitSelectionConfig?.allowCaching,
7667
+ });
7668
+ return orgUnitGroupResponse?.data?.['organisationUnitGroups'] ?? [];
7669
+ }
7670
+ async getOrgUnitLevels() {
7671
+ const orgUnitLevelResponse = await this.d2?.httpInstance?.get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false', {
7672
+ useIndexDb: this.orgUnitSelectionConfig?.allowCaching,
7673
+ });
7674
+ return orgUnitLevelResponse?.data?.['organisationUnitLevels'] ?? [];
7624
7675
  }
7625
7676
  onSelectOrgUnit(selectedOrgUnits) {
7626
7677
  this.showOrgUnitTree.set(false);
@@ -7628,11 +7679,6 @@ class SelectionFiltersComponent extends ReactWrapperModule {
7628
7679
  this.selectedOrgUnit.set(selectedOrgUnits[0]);
7629
7680
  }
7630
7681
  }
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
7682
  getOrgUnitAttributeByUsage(usageType) {
7637
7683
  switch (usageType) {
7638
7684
  case 'DATA_ENTRY':
@@ -8195,8 +8241,17 @@ class ProgramEntryFormModule {
8195
8241
  this.FormLoader = () => {
8196
8242
  return React__default.createElement(CircularLoader$1, { small: true });
8197
8243
  };
8244
+ // dataId = computed(() => {
8245
+ // return this.instance()?.trackedEntity || this.instance()?.event;
8246
+ // });
8198
8247
  this.dataId = computed(() => {
8199
- return this.instance()?.trackedEntity || this.instance()?.event;
8248
+ if (this.config().formType === 'EVENT') {
8249
+ return this.instance()?.event;
8250
+ }
8251
+ if (this.config().formType === 'TRACKER') {
8252
+ return this.instance()?.trackedEntity;
8253
+ }
8254
+ return undefined;
8200
8255
  });
8201
8256
  this.FormActionButtons = computed(() => {
8202
8257
  if (this.config().hideActionButtons) {