@iapps/ng-dhis2-ui 1.2.99 → 1.2.101

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
@@ -2980,9 +2987,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
2980
2987
  }] } });
2981
2988
 
2982
2989
  class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
2983
- constructor(elementRef, httpClient) {
2990
+ constructor(elementRef) {
2984
2991
  super(elementRef);
2985
- this.httpClient = httpClient;
2992
+ this.d2 = window.d2Web;
2986
2993
  this.selectedOrgUnits = [];
2987
2994
  this.orgUnitSelectionConfig = new OrganisationUnitSelectionConfig();
2988
2995
  this.selectOrgUnits = new EventEmitter();
@@ -3000,24 +3007,26 @@ class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
3000
3007
  this.reactDomRoot = ReactDOM.createRoot(this.elementRef.nativeElement);
3001
3008
  const rootOrgUnits = await this.getRootOrgUnits();
3002
3009
  const config = await this.getAppConfig();
3003
- this.component = () => {
3004
- const [selected, setSelected] = useState(this.selectedOrgUnits);
3005
- return (React__default.createElement(Provider, { config: config, plugin: false, parentAlertsAdd: undefined, showAlertsInPlugin: false }, React__default.createElement(Modal$1, { position: "middle", large: true },
3006
- React__default.createElement(ModalTitle$1, null, "Organisation unit"),
3007
- React__default.createElement(ModalContent$1, null,
3008
- React__default.createElement(OrgUnitDimension, { selected: selected, hideGroupSelect: this.orgUnitSelectionConfig.hideGroupSelect, hideLevelSelect: this.orgUnitSelectionConfig.hideLevelSelect, hideUserOrgUnits: this.orgUnitSelectionConfig.hideUserOrgUnits, onSelect: (selectionEvent) => {
3009
- setSelected(selectionEvent.items);
3010
- }, orgUnitGroupPromise: this.getOrgUnitGroups(), orgUnitLevelPromise: this.getOrgUnitLevels(), roots: rootOrgUnits })),
3011
- React__default.createElement(ModalActions$1, null,
3012
- React__default.createElement(ButtonStrip$1, { end: true },
3013
- React__default.createElement(Button$1, { onClick: () => {
3014
- this.onCancel();
3015
- } }, "Cancel"),
3016
- React__default.createElement(Button$1, { primary: true, disabled: selected.length === 0, onClick: () => {
3017
- this.onConfirm(selected);
3018
- } }, "Confirm"))))));
3019
- };
3020
- this.render();
3010
+ if (config) {
3011
+ this.component = () => {
3012
+ const [selected, setSelected] = useState(this.selectedOrgUnits);
3013
+ return (React__default.createElement(Provider, { config: config, plugin: false, parentAlertsAdd: undefined, showAlertsInPlugin: false }, React__default.createElement(Modal$1, { position: "middle", large: true },
3014
+ React__default.createElement(ModalTitle$1, null, "Organisation unit"),
3015
+ React__default.createElement(ModalContent$1, null,
3016
+ React__default.createElement(OrgUnitDimension, { selected: selected, hideGroupSelect: this.orgUnitSelectionConfig.hideGroupSelect, hideLevelSelect: this.orgUnitSelectionConfig.hideLevelSelect, hideUserOrgUnits: this.orgUnitSelectionConfig.hideUserOrgUnits, onSelect: (selectionEvent) => {
3017
+ setSelected(selectionEvent.items);
3018
+ }, orgUnitGroupPromise: this.getOrgUnitGroups(), orgUnitLevelPromise: this.getOrgUnitLevels(), roots: rootOrgUnits })),
3019
+ React__default.createElement(ModalActions$1, null,
3020
+ React__default.createElement(ButtonStrip$1, { end: true },
3021
+ React__default.createElement(Button$1, { onClick: () => {
3022
+ this.onCancel();
3023
+ } }, "Cancel"),
3024
+ React__default.createElement(Button$1, { primary: true, disabled: selected.length === 0, onClick: () => {
3025
+ this.onConfirm(selected);
3026
+ } }, "Confirm"))))));
3027
+ };
3028
+ this.render();
3029
+ }
3021
3030
  }
3022
3031
  onCancel() {
3023
3032
  this.cancel.emit();
@@ -3026,12 +3035,15 @@ class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
3026
3035
  this.confirm.emit(selectedItems);
3027
3036
  }
3028
3037
  async getAppConfig() {
3029
- const systemInfo = (await firstValueFrom(this.httpClient.systemInfo()));
3038
+ const systemInfo = this.d2.systemInfo;
3039
+ if (!systemInfo) {
3040
+ return systemInfo;
3041
+ }
3030
3042
  return {
3031
- baseUrl: (document?.location?.host?.includes('localhost')
3043
+ baseUrl: document?.location?.host?.includes('localhost')
3032
3044
  ? `${document.location.protocol}//${document.location.host}`
3033
- : systemInfo['contextPath']),
3034
- apiVersion: Number(((systemInfo['version'] || '')?.split('.') || [])[1]),
3045
+ : systemInfo.contextPath,
3046
+ apiVersion: systemInfo.apiVersion,
3035
3047
  };
3036
3048
  }
3037
3049
  getOrgUnitAttributeByUsage(usageType) {
@@ -3044,32 +3056,33 @@ class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
3044
3056
  return 'organisationUnits';
3045
3057
  }
3046
3058
  }
3047
- getRootOrgUnits() {
3059
+ async getRootOrgUnits() {
3048
3060
  const orgUnitAttribute = this.getOrgUnitAttributeByUsage(this.orgUnitSelectionConfig.usageType);
3049
- return firstValueFrom(this.httpClient
3050
- .me()
3051
- .pipe(map((user) => (user ? user[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id))));
3061
+ const currentUser = this.d2?.currentUser;
3062
+ return (currentUser ? currentUser[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id);
3052
3063
  }
3053
- getOrgUnitGroups() {
3054
- return firstValueFrom(this.httpClient
3055
- .get('organisationUnitGroups.json?fields=id,displayName,name&paging=false')
3056
- .pipe(map((res) => res?.['organisationUnitGroups'])));
3064
+ async getOrgUnitGroups() {
3065
+ const orgUnitGroupResponse = await this.d2?.httpInstance?.get('organisationUnitGroups.json?fields=id,displayName,name&paging=false', {
3066
+ useIndexDb: this.orgUnitSelectionConfig?.allowCaching,
3067
+ });
3068
+ return orgUnitGroupResponse?.data?.['organisationUnitGroups'] ?? [];
3057
3069
  }
3058
- getOrgUnitLevels() {
3059
- return firstValueFrom(this.httpClient
3060
- .get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false')
3061
- .pipe(map((res) => res?.['organisationUnitLevels'])));
3070
+ async getOrgUnitLevels() {
3071
+ const orgUnitLevelResponse = await this.d2?.httpInstance?.get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false', {
3072
+ useIndexDb: this.orgUnitSelectionConfig?.allowCaching,
3073
+ });
3074
+ return orgUnitLevelResponse?.data?.['organisationUnitLevels'] ?? [];
3062
3075
  }
3063
3076
  onSelectItems(selectionEvent) {
3064
3077
  this.selectOrgUnits.emit(selectionEvent.items);
3065
3078
  }
3066
- 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 }); }
3079
+ 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 }); }
3067
3080
  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"] }); }
3068
3081
  }
3069
3082
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: OrganisationUnitSelectorModalComponent, decorators: [{
3070
3083
  type: Component,
3071
3084
  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"] }]
3072
- }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.NgxDhis2HttpClientService }], propDecorators: { selectedOrgUnits: [{
3085
+ }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { selectedOrgUnits: [{
3073
3086
  type: Input
3074
3087
  }], orgUnitSelectionConfig: [{
3075
3088
  type: Input