feat: add center actions (close and delete) (#1093)

Fixes: #1092
This commit is contained in:
Muskan Khedia
2020-07-14 16:15:48 +05:30
committed by GitHub
parent 96f881e909
commit ffea1b5eaf
10 changed files with 192 additions and 5 deletions
@@ -1,2 +1,3 @@
<mifosx-activate-center *ngIf="actions['Activate']"></mifosx-activate-center>
<mifosx-center-assign-staff *ngIf="actions['Assign Staff']" ></mifosx-center-assign-staff>
<mifosx-close-center *ngIf="actions['Close']"></mifosx-close-center>
@@ -15,10 +15,12 @@ export class CenterActionsComponent {
/** Flag object to store possible actions and render appropriate UI to the user */
actions: {
'Activate': boolean,
'Assign Staff': boolean
'Assign Staff': boolean,
'Close': boolean
} = {
'Activate': false,
'Assign Staff': false
'Assign Staff': false,
'Close': false
};
/**
@@ -0,0 +1,46 @@
<div class="container">
<mat-card>
<form [formGroup]="closeCenterForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Closed On Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="closureDatePicker" required formControlName="closureDate">
<mat-datepicker-toggle matSuffix [for]="closureDatePicker"></mat-datepicker-toggle>
<mat-datepicker #closureDatePicker></mat-datepicker>
<mat-error *ngIf="closeCenterForm.controls.closureDate.hasError('required')">
Closed On Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex="48%">
<mat-label>Closure Reason</mat-label>
<mat-select formControlName="closureReasonId">
<mat-option *ngFor="let reason of closureData" [value]="reason.id">
{{ reason.name }}
</mat-option>
</mat-select>
<mat-error *ngIf="closeCenterForm.controls.closureReasonId.hasError('required')">
CLosure Reason is <strong>required</strong>
</mat-error>
</mat-form-field>
</div>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../../']">Cancel</button>
<button mat-raised-button color="warn" [disabled]="!closeCenterForm.valid">Confirm</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CloseCenterComponent } from './close-center.component';
describe('CloseCenterComponent', () => {
let component: CloseCenterComponent;
let fixture: ComponentFixture<CloseCenterComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CloseCenterComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CloseCenterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,84 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { CentersService } from 'app/centers/centers.service';
/**
* Close Center Component
*/
@Component({
selector: 'mifosx-close-center',
templateUrl: './close-center.component.html',
styleUrls: ['./close-center.component.scss']
})
export class CloseCenterComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Close Share Account form. */
closeCenterForm: FormGroup;
/** Center Data */
closureData: any;
/** Center Id */
centerId: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {CentersService} centersService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private centersService: CentersService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe((data: { centeractionData: any }) => {
this.closureData = data.centeractionData.closureReasons;
});
this.centerId = this.route.parent.snapshot.params['centerId'];
}
ngOnInit() {
this.createCloseCenterForm();
}
/**
* Creates the close centers form.
*/
createCloseCenterForm() {
this.closeCenterForm = this.formBuilder.group({
'closureDate': ['', Validators.required],
'closureReasonId': ['', Validators.required]
});
}
/**
* Submits the form and closes the center.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevClosedDate: Date = this.closeCenterForm.value.closureDate;
this.closeCenterForm.patchValue({
closureDate: this.datePipe.transform(prevClosedDate, dateFormat),
});
const data = {
...this.closeCenterForm.value,
dateFormat,
locale
};
this.centersService.executeCenterActionCommand(this.centerId, 'close', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -71,9 +71,9 @@
<button mat-menu-item *mifosxHasPermission="'UNASSIGNSTAFF_GROUP'" (click)="doAction('Unassign Staff')"> Unassign Staff </button>
</span>
<span *ngIf="centerViewData.status.value==='Active'">
<button mat-menu-item *mifosxHasPermission="'DELETE_CENTER'" > Delete </button>
<button mat-menu-item *mifosxHasPermission="'DELETE_CENTER'" (click)="doAction('Delete')"> Delete </button>
</span>
<button mat-menu-item *mifosxHasPermission="'CLOSE_CENTER'" > Close </button>
<button mat-menu-item *mifosxHasPermission="'CLOSE_CENTER'" (click)="doAction('Close')"> Close </button>
<span *ngIf="centerViewData.status.value==='Active' && !(centerViewData.collectionMeetingCalendar)">
<button mat-menu-item *mifosxHasPermission="'CREATE_MEETING'"> Attach Meeting </button>
</span>
@@ -8,6 +8,7 @@ import { ConfirmationDialogComponent } from 'app/shared/confirmation-dialog/conf
/** Custom Services */
import { CentersService } from '../centers.service';
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
/**
* Create Center View
@@ -57,11 +58,14 @@ export class CentersViewComponent implements OnInit {
switch (name) {
case 'Activate':
case 'Assign Staff':
case 'Close':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Unassign Staff':
this.centersUnassignStaff();
break;
case 'Delete':
this.deleteCenter();
}
}
@@ -82,6 +86,22 @@ export class CentersViewComponent implements OnInit {
});
}
/**
* Deletes the center
*/
private deleteCenter() {
const deleteGroupDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `center with id: ${this.centerViewData.id}` }
});
deleteGroupDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.centersService.deleteCenter(this.centerViewData.id).subscribe(() => {
this.router.navigate(['/centers'], { relativeTo: this.route });
});
}
});
}
/**
* Refetches data for the component
* TODO: Replace by a custom reload component instead of hard-coded back-routing.
+3 -1
View File
@@ -19,6 +19,7 @@ import { SingleRowComponent } from './centers-view/datatable-tab/single-row/sing
import { CenterActionsComponent } from './centers-view/center-actions/center-actions.component';
import { ActivateCenterComponent } from './centers-view/center-actions/activate-center/activate-center.component';
import { CenterAssignStaffComponent } from './centers-view/center-actions/center-assign-staff/center-assign-staff.component';
import { CloseCenterComponent } from './centers-view/center-actions/close-center/close-center.component';
/**
* Centers Module
@@ -43,7 +44,8 @@ import { CenterAssignStaffComponent } from './centers-view/center-actions/center
SingleRowComponent,
CenterActionsComponent,
ActivateCenterComponent,
CenterAssignStaffComponent
CenterAssignStaffComponent,
CloseCenterComponent
]
})
export class CentersModule { }
+4
View File
@@ -209,4 +209,8 @@ export class CentersService {
return this.http.get(`/groups/${centerId}`, { params: httpParams });
}
deleteCenter(centerId: any): Observable<any> {
return this.http.delete(`/centers/${centerId}`);
}
}