Skip to content

Commit

Permalink
feat: add support to request multiple organisation units for one program
Browse files Browse the repository at this point in the history
  • Loading branch information
josephatJ committed Oct 9, 2023
1 parent 0d41d5a commit 30cd275
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/app/core/helpers/organisation-units.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function duduceTheHighetLevelFromOus(organisationUnits: any[]): number {
let hightestLevel: number = 1;
organisationUnits.forEach((ou: any) => {
(organisationUnits || [])?.forEach((ou: any) => {
if (ou?.level > hightestLevel) {
hightestLevel = ou?.level;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/services/datastore.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export class DataStoreDataService {
'Please remove the following datasets on the org unit',
formRequestMessageHeaderKey: 'FORM REQUEST',
addMessageFacilitiesFormRequestKey:
'Please add the following org units on dataset',
'Please add the following org units on',
removeMessageFacilitiesFormRequestKey:
'Please un-assign the following org units on a dataset',
'Please un-assign the following org units on',
messageChangePrefixKey: 'There are changes',
Remove: 'Remove',
Assign: 'Assign',
Expand Down
46 changes: 45 additions & 1 deletion src/app/core/services/programs.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { NgxDhis2HttpClientService } from '@iapps/ngx-dhis2-http-client';
import * as moment from 'moment';
import { Observable, of } from 'rxjs';
import { catchError, map } from 'rxjs/operators';

Expand All @@ -26,7 +27,35 @@ export class ProgramsService {
}`
)
.pipe(
map((response) => response),
map((response) => {
const filteredPrograms = response?.programs;
return {
...response,
programs: filteredPrograms.map((dataSet) => {
const matchedKeys =
paginationDetails?.userSupportDataStoreKeys.filter(
(key) => key.indexOf(dataSet?.id) > -1
) || [];
return {
...dataSet,
hasPendingRequest: matchedKeys?.length > 0,

keys: matchedKeys,
timeSinceResponseSent:
matchedKeys.length > 0
? moment(
Number(matchedKeys[0].split('_')[0].replace('DS', ''))
).fromNow()
: '',
date:
matchedKeys.length > 0
? Date.now() -
Number(matchedKeys[0].split('_')[0].replace('DS', ''))
: null,
};
}),
};
}),
catchError((error: any) => of(error))
);
}
Expand All @@ -46,4 +75,19 @@ export class ProgramsService {
catchError((error: any) => of(error))
);
}

getProgramById(id: string, fields?: string): Observable<any> {
return this.httpClient
.get(
`programs/${id}.json?fields=${
fields ? fields : 'id,name,organisationUnits[id,name]'
}`
)
.pipe(
map((response) => {
return response;
}),
catchError((error) => of(error))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<div
class="w-100 mt-2"
*ngIf="
showConfirmButtons && dataRow?.id === currentOrgUnit?.id
showConfirmButtons && dataSet?.id === currentDataSet?.id
"
>
<div class="w-100">
Expand Down Expand Up @@ -121,7 +121,7 @@
mat-button
[disabled]="!reasonForCancellingRequest"
class="ml-2 btn-success"
(click)="onCancelAll($event, dataRow, dataRow, true)"
(click)="onCancelAll($event, dataSet, true)"
>
{{ 'Confirm' | translate }}
</button>
Expand All @@ -131,7 +131,7 @@
</div>
<div
class="w-100"
*ngIf="updating && dataRow?.id === currentOrgUnit?.id"
*ngIf="updating && dataSet.id === currentDataSet?.id"
>
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ export class DatasetsListComponent implements OnInit {
) {}

ngOnInit(): void {
this.getDataSetsList();
}

getDataSetsList(): void {
this.dataSetsDetails$ = this.dataSetsService.getDatasetsPaginated(
{
page: this.page,
pageSize: this.pageSize,
searchingText: this.searchingText,
userSupportDataStoreKeys: this.userSupportDataStoreKeys,
},
this.configurations?.datasetClosedDateAttribute
Expand All @@ -56,42 +61,20 @@ export class DatasetsListComponent implements OnInit {
searchDataset(event: any): void {
this.searchingText = event.target.value;
this.page = 1;
this.dataSetsDetails$ = this.dataSetsService.getDatasetsPaginated(
{
page: this.page,
pageSize: this.pageSize,
searchingText: this.searchingText,
userSupportDataStoreKeys: this.userSupportDataStoreKeys,
},
this.configurations?.datasetClosedDateAttribute
);
this.getDataSetsList();
}

getItemsPerPage(event: any, pager: any): void {
this.pageSize = Number(event.target.value);
this.page = 1;
this.itemPerPage = this.pageSize;
this.dataSetsDetails$ = this.dataSetsService.getDatasetsPaginated(
{
page: this.page,
pageSize: this.pageSize,
userSupportDataStoreKeys: this.userSupportDataStoreKeys,
},
this.configurations?.datasetClosedDateAttribute
);
this.getDataSetsList();
}

getDataSets(event: Event, actionType, pager: any): void {
event.stopPropagation();
this.page = actionType === 'next' ? pager?.page + 1 : pager?.page - 1;
this.dataSetsDetails$ = this.dataSetsService.getDatasetsPaginated(
{
page: this.page,
pageSize: this.pageSize,
userSupportDataStoreKeys: this.userSupportDataStoreKeys,
},
this.configurations?.datasetClosedDateAttribute
);
this.getDataSetsList();
}

onRequestDataSet(event: Event, dataSet: any): void {
Expand All @@ -109,13 +92,6 @@ export class DatasetsListComponent implements OnInit {
.afterClosed()
.subscribe((res) => {
this.dataStoreChanged.emit(res);
// this.dataSetsDetails$ = this.dataSetsService.getDatasetsPaginated({
// page: this.page,
// pageSize: this.pageSize,
// searchingText: this.searchingText,
// userSupportDataStoreKeys: this.userSupportDataStoreKeys,
// },
// this.configurations?.datasetClosedDateAttribute);
});
}

Expand Down Expand Up @@ -146,6 +122,7 @@ export class DatasetsListComponent implements OnInit {
);

// this.dataStoreChanged.emit(true);
this.getDataSetsList();
setTimeout(() => {
this._snackBar.dismiss();
}, 2000);
Expand All @@ -157,4 +134,9 @@ export class DatasetsListComponent implements OnInit {
this.showConfirmButtons = true;
}
}

onUnConfirm(event: Event): void {
event.stopPropagation();
this.showConfirmButtons = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
[configurations]="configurations"
[systemConfigs]="systemConfigs"
[userSupportDataStoreKeys]="params?.userSupportKeys"
(dataStoreChanged)="onDataStoreChange($event, 'dataset')"
(dataStoreChanged)="onDataStoreChange($event, 'dataset', 2)"
></app-datasets-list>
</div>
</mat-tab>
Expand All @@ -77,7 +77,7 @@
[configurations]="configurations"
[systemConfigs]="systemConfigs"
[userSupportDataStoreKeys]="params?.userSupportKeys"
(dataStoreChanged)="onDataStoreChange($event, 'dataset')"
(dataStoreChanged)="onDataStoreChange($event, 'program', 3)"
></app-programs-list>
</div>
</mat-tab>
Expand Down Expand Up @@ -146,7 +146,7 @@
[configurations]="configurations"
[systemConfigs]="systemConfigs"
[userSupportDataStoreKeys]="params?.userSupportKeys"
(dataStoreChanged)="onDataStoreChange($event, 'dataset')"
(dataStoreChanged)="onDataStoreChange($event, 'dataset', 2)"
></app-datasets-list>
</div>
</mat-tab>
Expand All @@ -163,7 +163,7 @@
[configurations]="configurations"
[systemConfigs]="systemConfigs"
[userSupportDataStoreKeys]="params?.userSupportKeys"
(dataStoreChanged)="onDataStoreChange($event, 'dataset')"
(dataStoreChanged)="onDataStoreChange($event, 'program', 3)"
></app-programs-list>
</div>
</mat-tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ export class FeedbackContainerComponent implements OnInit {
this.selectedTab.setValue(val);
}

onDataStoreChange(event: boolean, type: string): void {
onDataStoreChange(event: boolean, type: string, tabIndex?: number): void {
if (event) {
this.userSupportKeys$ = this.dataStoreService.getDataStoreKeys();
} else {
}
if (!type) {
this.selectedTab.setValue(0);
} else {
this.selectedTab.setValue(1);
this.selectedTab.setValue(tabIndex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,48 @@
<div *ngIf="!savingData && !savedData">
<div
*ngIf="{
dataSetDetails: dataSetDetails$ | async,
reportingToolDetails: reportingToolDetails$ | async,
allDataForUserSupport: allDataForUserSupport$ | async
} as params"
>
<h4>
{{ 'Assign or Remove Facilities for' | translate }}
{{ dialogData?.dataSet?.name }}
{{
dialogData?.dataSet?.name
? dialogData?.dataSet?.name
: dialogData?.reportingTool?.name
}}
</h4>
<mat-progress-bar
mode="indeterminate"
*ngIf="!params?.dataSetDetails || !params?.allDataForUserSupport"
*ngIf="!params?.reportingToolDetails || !params?.allDataForUserSupport"
></mat-progress-bar>
<app-selection-filter
*ngIf="params?.dataSetDetails && params?.allDataForUserSupport"
[dataSetDetails]="params?.dataSetDetails"
*ngIf="params?.reportingToolDetails && params?.allDataForUserSupport"
[reportingToolDetails]="params?.reportingToolDetails"
[allDataForUserSupport]="params?.allDataForUserSupport"
(selectedOus)="onGetSelectedOus($event, params?.dataSetDetails)"
(selectedOus)="onGetSelectedOus($event, params?.reportingToolDetails)"
></app-selection-filter>
<div class="w-100 d-flex justify-content-end mt-2">
<button mat-button (click)="onClose($event)">
<button mat-stroked-button (click)="onClose($event)">
{{ 'Close' | translate }}
</button>
<button
class="ml-2"
mat-stroked-button
color="primary"
mat-flat-button
[disabled]="
!assignmentDetails ||
(assignmentDetails?.deletions?.length === 0 &&
assignmentDetails?.additions?.length === 0)
"
(click)="
saveRequest($event, selectedOrgUnitItems, dialogData?.currentUser)
saveRequest(
$event,
selectedOrgUnitItems,
dialogData?.currentUser,
params?.reportingToolDetails
)
"
>
{{ 'Send' | translate }}
Expand Down
Loading

0 comments on commit 30cd275

Please sign in to comment.