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 });
});
}
}