@iapps/ng-dhis2-ui 1.2.100 → 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.
@@ -2987,9 +2987,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImpor
2987
2987
  }] } });
2988
2988
 
2989
2989
  class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
2990
- constructor(elementRef, httpClient) {
2990
+ constructor(elementRef) {
2991
2991
  super(elementRef);
2992
- this.httpClient = httpClient;
2992
+ this.d2 = window.d2Web;
2993
2993
  this.selectedOrgUnits = [];
2994
2994
  this.orgUnitSelectionConfig = new OrganisationUnitSelectionConfig();
2995
2995
  this.selectOrgUnits = new EventEmitter();
@@ -3007,24 +3007,26 @@ class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
3007
3007
  this.reactDomRoot = ReactDOM.createRoot(this.elementRef.nativeElement);
3008
3008
  const rootOrgUnits = await this.getRootOrgUnits();
3009
3009
  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();
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
+ }
3028
3030
  }
3029
3031
  onCancel() {
3030
3032
  this.cancel.emit();
@@ -3033,12 +3035,15 @@ class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
3033
3035
  this.confirm.emit(selectedItems);
3034
3036
  }
3035
3037
  async getAppConfig() {
3036
- const systemInfo = (await firstValueFrom(this.httpClient.systemInfo()));
3038
+ const systemInfo = this.d2.systemInfo;
3039
+ if (!systemInfo) {
3040
+ return systemInfo;
3041
+ }
3037
3042
  return {
3038
- baseUrl: (document?.location?.host?.includes('localhost')
3043
+ baseUrl: document?.location?.host?.includes('localhost')
3039
3044
  ? `${document.location.protocol}//${document.location.host}`
3040
- : systemInfo['contextPath']),
3041
- apiVersion: Number(((systemInfo['version'] || '')?.split('.') || [])[1]),
3045
+ : systemInfo.contextPath,
3046
+ apiVersion: systemInfo.apiVersion,
3042
3047
  };
3043
3048
  }
3044
3049
  getOrgUnitAttributeByUsage(usageType) {
@@ -3051,32 +3056,33 @@ class OrganisationUnitSelectorModalComponent extends ReactWrapperModule {
3051
3056
  return 'organisationUnits';
3052
3057
  }
3053
3058
  }
3054
- getRootOrgUnits() {
3059
+ async getRootOrgUnits() {
3055
3060
  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))));
3061
+ const currentUser = this.d2?.currentUser;
3062
+ return (currentUser ? currentUser[orgUnitAttribute] : []).map((orgUnit) => orgUnit.id);
3059
3063
  }
3060
- getOrgUnitGroups() {
3061
- return firstValueFrom(this.httpClient
3062
- .get('organisationUnitGroups.json?fields=id,displayName,name&paging=false')
3063
- .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'] ?? [];
3064
3069
  }
3065
- getOrgUnitLevels() {
3066
- return firstValueFrom(this.httpClient
3067
- .get('organisationUnitLevels.json?fields=id,level,displayName,name&paging=false')
3068
- .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'] ?? [];
3069
3075
  }
3070
3076
  onSelectItems(selectionEvent) {
3071
3077
  this.selectOrgUnits.emit(selectionEvent.items);
3072
3078
  }
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 }); }
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 }); }
3074
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"] }); }
3075
3081
  }
3076
3082
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.8", ngImport: i0, type: OrganisationUnitSelectorModalComponent, decorators: [{
3077
3083
  type: Component,
3078
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"] }]
3079
- }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i1.NgxDhis2HttpClientService }], propDecorators: { selectedOrgUnits: [{
3085
+ }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { selectedOrgUnits: [{
3080
3086
  type: Input
3081
3087
  }], orgUnitSelectionConfig: [{
3082
3088
  type: Input