feat: add centers action (activate) (#1085)

Fixes: #1084
This commit is contained in:
Muskan Khedia
2020-07-14 10:42:53 +05:30
committed by GitHub
parent 6c081eb724
commit f861e466bf
15 changed files with 276 additions and 37 deletions
+42 -31
View File
@@ -24,6 +24,7 @@ import { CenterSummaryResolver } from './common-resolvers/center-summary.resolve
import { CenterNotesResolver } from './common-resolvers/center-notes.resolver';
import { CenterDatatableResolver } from './common-resolvers/center-datatable.resolver';
import { CenterDatatablesResolver } from './common-resolvers/center-datatables.resolver';
import { CenterActionsComponent } from './centers-view/center-actions/center-actions.component';
const routes: Routes = [
Route.withShell([
@@ -46,42 +47,52 @@ const routes: Routes = [
},
{
path: ':centerId',
component: CentersViewComponent,
data: { title: extract('Centers View'), routeParamBreadcrumb: 'centerId' },
resolve: {
centerViewData: CenterViewResolver,
centerDatatables: CenterDatatablesResolver
},
children: [
{
path: 'general',
component: GeneralTabComponent,
data: { title: extract('General'), breadcrumb: 'General', routeParamBreadcrumb: false },
path: '',
component: CentersViewComponent,
resolve: {
centerSummaryData: CenterSummaryResolver,
centerViewData: CenterResourceResolver,
savingsAccountData: SavingsAccountResolver
}
},
{
path: 'notes',
component: NotesTabComponent,
data: { title: extract('Notes'), breadcrumb: 'Notes', routeParamBreadcrumb: false },
resolve: {
centerNotes: CenterNotesResolver
}
},
{
path: 'datatables',
children: [{
path: ':datatableName',
component: DatatableTabComponent,
data: { title: extract('Data Table View'), routeParamBreadcrumb: 'datatableName' },
resolve: {
centerDatatable: CenterDatatableResolver
centerViewData: CenterViewResolver,
centerDatatables: CenterDatatablesResolver
},
children: [
{
path: 'general',
component: GeneralTabComponent,
data: { title: extract('General'), breadcrumb: 'General', routeParamBreadcrumb: false },
resolve: {
centerSummaryData: CenterSummaryResolver,
centerViewData: CenterResourceResolver,
savingsAccountData: SavingsAccountResolver
}
},
{
path: 'notes',
component: NotesTabComponent,
data: { title: extract('Notes'), breadcrumb: 'Notes', routeParamBreadcrumb: false },
resolve: {
centerNotes: CenterNotesResolver
}
},
{
path: 'datatables',
children: [{
path: ':datatableName',
component: DatatableTabComponent,
data: { title: extract('Data Table View'), routeParamBreadcrumb: 'datatableName' },
resolve: {
centerDatatable: CenterDatatableResolver
}
}]
}
}]
}
]
},
{
path: 'actions/:name',
data: { title: extract('Center Actions'), routeParamBreadcrumb: 'name' },
component: CenterActionsComponent
},
]
}
]
@@ -0,0 +1,30 @@
<div class="container">
<mat-card>
<form [formGroup]="activateCenterForm" (ngSubmit)="submit()">
<mat-card-content>
<mat-form-field fxFlex>
<mat-label>Activated On Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="activationDatePicker" required formControlName="activationDate">
<mat-datepicker-toggle matSuffix [for]="activationDatePicker"></mat-datepicker-toggle>
<mat-datepicker #activationDatePicker></mat-datepicker>
<mat-error *ngIf="activateCenterForm.controls.activationDate.hasError('required')">
Activated On Date is <strong>required</strong>
</mat-error>
</mat-form-field>
</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="accent" [disabled]="!activateCenterForm.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 { ActivateCenterComponent } from './activate-center.component';
describe('ActivateCenterComponent', () => {
let component: ActivateCenterComponent;
let fixture: ComponentFixture<ActivateCenterComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ActivateCenterComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ActivateCenterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,82 @@
/** 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';
/**
* Activate Center Component
*/
@Component({
selector: 'mifosx-activate-center',
templateUrl: './activate-center.component.html',
styleUrls: ['./activate-center.component.scss']
})
export class ActivateCenterComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Activate center form. */
activateCenterForm: FormGroup;
/** Group Account 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.centerId = this.route.parent.snapshot.params['centerId'];
}
/**
* Creates the activate center form.
*/
ngOnInit() {
this.createActivateCenterForm();
}
/**
* Creates the activate center form.
*/
createActivateCenterForm() {
this.activateCenterForm = this.formBuilder.group({
'activationDate': [new Date(), Validators.required]
});
}
/**
* Submits the form and activates the center,
* if successful redirects to the center.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevactivationDate: Date = this.activateCenterForm.value.activationDate;
this.activateCenterForm.patchValue({
activationDate: this.datePipe.transform(prevactivationDate, dateFormat),
});
const data = {
...this.activateCenterForm.value,
dateFormat,
locale
};
this.centersService.executeCenterActionCommand(this.centerId, 'activate', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -0,0 +1 @@
<mifosx-activate-center *ngIf="actions['Activate']"></mifosx-activate-center>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CenterActionsComponent } from './center-actions.component';
describe('CenterActionsComponent', () => {
let component: CenterActionsComponent;
let fixture: ComponentFixture<CenterActionsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ CenterActionsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CenterActionsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,32 @@
/** Angular Imports */
import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
/**
* Center actions component.
*/
@Component({
selector: 'mifosx-center-actions',
templateUrl: './center-actions.component.html',
styleUrls: ['./center-actions.component.scss']
})
export class CenterActionsComponent {
/** Flag object to store possible actions and render appropriate UI to the user */
actions: {
'Activate': boolean
} = {
'Activate': false,
};
/**
* @param {ActivatedRoute} route Activated Route
*/
constructor(private route: ActivatedRoute,
private router: Router) {
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
const name = this.route.snapshot.params['name'];
this.actions[name] = true;
}
}
@@ -51,7 +51,7 @@
</mat-card-title-group>
<mat-card-actions class="center-actions" *ngIf="!(centerViewData.status.value==='Closed')">
<span *ngIf="!(centerViewData.status.value=='Active')">
<button mat-raised-button *mifosxHasPermission="'ACTIVATE_CENTER'" ><i class="fa fa-check-sign"></i> Activate </button>
<button mat-raised-button *mifosxHasPermission="'ACTIVATE_CENTER'" (click)="doAction('Activate')"><i class="fa fa-check-sign"></i> Activate </button>
</span>
<button mat-raised-button *mifosxHasPermission="'UPDATE_CENTER'"><i class="fa fa-edit"></i> Edit </button>
<button mat-raised-button *mifosxHasPermission="'CREATE_GROUP'"><i class="fa fa-plus"></i> Add Group </button>
@@ -1,6 +1,7 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material';
/**
* Create Center View
@@ -23,7 +24,9 @@ export class CentersViewComponent implements OnInit {
* Retrieves the data for center
* @param route route Activated Route.
*/
constructor(private route: ActivatedRoute) {
constructor(private route: ActivatedRoute,
private router: Router,
public dialog: MatDialog) {
this.route.data.subscribe((data: {
centerViewData: any,
centerDatatables: any
@@ -39,4 +42,16 @@ export class CentersViewComponent implements OnInit {
} else { this.meetingData = false; }
}
/**
* Performs action button/option action.
* @param {string} name action name.
*/
doAction(name: string) {
switch (name) {
case 'Activate':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
}
}
}
+1 -1
View File
@@ -40,7 +40,7 @@
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef> Status </th>
<td mat-cell *matCellDef="let row">
<div [ngClass]="row.active|statusLookup">
<div [ngClass]="row.status.code|statusLookup">
<fa-icon icon="stop"></fa-icon>
</div>
</td>
+5 -1
View File
@@ -16,6 +16,8 @@ import { NotesTabComponent } from './centers-view/notes-tab/notes-tab.component'
import { DatatableTabComponent } from './centers-view/datatable-tab/datatable-tab.component';
import { MultiRowComponent } from './centers-view/datatable-tab/multi-row/multi-row.component';
import { SingleRowComponent } from './centers-view/datatable-tab/single-row/single-row.component';
import { CenterActionsComponent } from './centers-view/center-actions/center-actions.component';
import { ActivateCenterComponent } from './centers-view/center-actions/activate-center/activate-center.component';
/**
* Centers Module
@@ -37,7 +39,9 @@ import { SingleRowComponent } from './centers-view/datatable-tab/single-row/sing
NotesTabComponent,
DatatableTabComponent,
MultiRowComponent,
SingleRowComponent
SingleRowComponent,
CenterActionsComponent,
ActivateCenterComponent
]
})
export class CentersModule { }
+11
View File
@@ -176,4 +176,15 @@ export class CentersService {
return this.http.delete(`/datatables/${datatableName}/${centerId}`, { params: httpParams });
}
/**
* @param {string} centerId Center Id
* @param {string} command Command
* @param {any} data Data
* @returns {Observable<any>}
*/
executeCenterActionCommand(centerId: string, command: string, data: any): Observable<any> {
const httpParams = new HttpParams().set('command', command);
return this.http.post(`/centers/${centerId}`, data, { params: httpParams });
}
}
+1 -1
View File
@@ -33,7 +33,7 @@
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef> Status </th>
<td mat-cell *matCellDef="let row">
<div [ngClass]="row.active|statusLookup">
<div [ngClass]="row.status.code|statusLookup">
<fa-icon icon="stop"></fa-icon>
</div>
</td>