@iapps/ng-dhis2-ui 1.2.99 → 1.2.100

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.
@@ -2891,6 +2891,7 @@ class OrganisationUnitSelectionConfig {
2891
2891
  this.allowSingleSelection = params?.allowSingleSelection || false;
2892
2892
  this.batchSize = params?.batchSize;
2893
2893
  this.additionalQueryFields = params?.additionalQueryFields;
2894
+ this.allowCaching = params?.allowCaching;
2894
2895
  }
2895
2896
  }
2896
2897
 
@@ -2899,10 +2900,10 @@ class OrganisationUnitSelectionConfig {
2899
2900
  // license that can be found in the LICENSE file.
2900
2901
 
2901
2902
  class OrganisationUnitSelectorComponent extends ReactWrapperModule {
2902
- constructor(elementRef, httpClient, ngZone) {
2903
+ constructor(elementRef, ngZone) {
2903
2904
  super(elementRef);
2904
- this.httpClient = httpClient;
2905
2905
  this.ngZone = ngZone;
2906
+ this.d2 = window.d2Web;
2906
2907
  this.selectedOrgUnits = [];
2907
2908
  this.orgUnitSelectionConfig = new OrganisationUnitSelectionConfig();
2908
2909
  this.selectOrgUnits = new EventEmitter();
@@ -2918,18 +2919,23 @@ class OrganisationUnitSelectorComponent extends ReactWrapperModule {
2918
2919
  this.reactDomRoot = ReactDOM.createRoot(this.elementRef.nativeElement);
2919
2920
  const rootOrgUnits = await this.getRootOrgUnits();
2920
2921
  const config = await this.getAppConfig();
2921
- this.component = () => (React__default.createElement(Provider, { config: config, plugin: false, parentAlertsAdd: undefined, showAlertsInPlugin: false }, React__default.createElement(OrgUnitDimension, { selected: this.selectedOrgUnits, hideGroupSelect: this.orgUnitSelectionConfig.hideGroupSelect, hideLevelSelect: this.orgUnitSelectionConfig.hideLevelSelect, hideUserOrgUnits: this.orgUnitSelectionConfig.hideUserOrgUnits, onSelect: (selectionEvent) => this.ngZone.run(() => {
2922
- this.onSelectItems(selectionEvent);
2923
- }), orgUnitGroupPromise: this.getOrgUnitGroups(), orgUnitLevelPromise: this.getOrgUnitLevels(), roots: rootOrgUnits })));
2924
- this.render();
2922
+ if (config) {
2923
+ this.component = () => (React__default.createElement(Provider, { config: config, plugin: false, parentAlertsAdd: undefined, showAlertsInPlugin: false }, React__default.createElement(OrgUnitDimension, { selected: this.selectedOrgUnits, hideGroupSelect: this.orgUnitSelectionConfig.hideGroupSelect, hideLevelSelect: this.orgUnitSelectionConfig.hideLevelSelect, hideUserOrgUnits: this.orgUnitSelectionConfig.hideUserOrgUnits, onSelect: (selectionEvent) => this.ngZone.run(() => {
2924
+ this.onSelectItems(selectionEvent);
2925
+ }), orgUnitGroupPromise: this.getOrgUnitGroups(), orgUnitLevelPromise: this.getOrgUnitLevels(), roots: rootOrgUnits })));
2926
+ this.render();
2927
+ }
2925
2928
  }
2926
2929
  async getAppConfig() {
2927
- const systemInfo = (await firstValueFrom(this.httpClient.systemInfo()));
2930
+ const systemInfo = this.d2.systemInfo;
2931
+ if (!systemInfo) {
2932
+ return systemInfo;
2933
+ }
2928
2934
  return {
2929
- baseUrl: (document?.location?.host?.includes('localhost')
2935
+ baseUrl: document?.location?.host?.includes('localhost')
2930
2936
  ? `${document.location.protocol}//${document.location.host}`
2931
- : systemInfo['contextPath']),
2932
- apiVersion: Number(((systemInfo['version'] || '')?.split('.') || [])[1]),
2937
+ : systemInfo.contextPath,
2938
+ apiVersion: systemInfo.apiVersion,
2933
2939
  };
2934
2940
  }
2935
2941
  getOrgUnitAttributeByUsage(usageType) {
@@ -2942,26 +2948,27 @@ class OrganisationUnitSelectorComponent extends ReactWrapperModule {
2942
2948
  return 'organisationUnits';
2943
2949
  }
2944
2950
  }
2945
- getRootOrgUnits() {
2951
+ async getRootOrgUnits() {
2946
2952
  const orgUnitAttribute = this.getOrgUnitAttributeByUsage(this.orgUnitSelectionConfig.usageType);
2947
- return firstValueFrom(this.httpClient
2948
- .me()
2949
- .pipe(map((user) => (user ? user[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id))));
2953
+ const currentUser = this.d2?.currentUser;
2954
+ return (currentUser ? currentUser[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id);
2950
2955
  }
2951
- getOrgUnitGroups() {
2952
- return firstValueFrom(this.httpClient
2953
- .get('organisationUnitGroups.json?fields=id,displayName,name&paging=false')
2954
- .pipe(map((res) => res?.['organisationUnitGroups'])));
2956
+ async getOrgUnitGroups() {
2957
+ const orgUnitGroupResponse = await this.d2?.httpInstance?.get('organisationUnitGroups.json?fields=id,displayName,name&paging=false', {
2958
+ useIndexDb: this.orgUnitSelectionConfig?.allowCaching,
2959
+ });
2960
+ return orgUnitGroupResponse?.data?.['organisationUnitGroups'] ?? [];
2955
2961
  }
2956
- getOrgUnitLevels() {
2957
- return firstValueFrom(this.httpClient
2958
- .get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false')
2959
- .pipe(map((res) => res?.['organisationUnitLevels'])));
2962
+ async getOrgUnitLevels() {
2963
+ const orgUnitLevelResponse = await this.d2?.httpInstance?.get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false', {
2964
+ useIndexDb: this.orgUnitSelectionConfig?.allowCaching,
2965
+ });
2966
+ return orgUnitLevelResponse?.data?.['organisationUnitLevels'] ?? [];
2960
2967
  }
2961
2968
  onSelectItems(selectionEvent) {
2962
2969
  this.selectOrgUnits.emit(selectionEvent.items);
2963
2970
  }
2964
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: OrganisationUnitSelectorComponent, deps: [{ token: i0.ElementRef }, { token: i1.NgxDhis2HttpClientService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); }
2971
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: OrganisationUnitSelectorComponent, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); }
2965
2972
  static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.1.8", type: OrganisationUnitSelectorComponent, isStandalone: false, selector: "ng-dhis2-ui-org-unit-selector", inputs: { selectedOrgUnits: "selectedOrgUnits", orgUnitSelectionConfig: "orgUnitSelectionConfig" }, outputs: { selectOrgUnits: "selectOrgUnits" }, usesInheritance: true, ngImport: i0, template: '<ng-container><ng-container>', isInline: true }); }
2966
2973
  }
2967
2974
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: OrganisationUnitSelectorComponent, decorators: [{
@@ -2971,7 +2978,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
2971
2978
  template: '<ng-container><ng-container>',
2972
2979
  standalone: false,
2973
2980
  }]
2974
- }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.NgxDhis2HttpClientService }, { type: i0.NgZone }], propDecorators: { selectedOrgUnits: [{
2981
+ }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.NgZone }], propDecorators: { selectedOrgUnits: [{
2975
2982
  type: Input
2976
2983
  }], orgUnitSelectionConfig: [{
2977
2984
  type: Input