feat: group actions (activate) (#1033)

Fixes: #1032
This commit is contained in:
Karan Takalkar
2020-07-08 17:10:50 +05:30
committed by GitHub
parent 0e69e8ea1e
commit f0a2978db5
9 changed files with 149 additions and 3 deletions
@@ -0,0 +1,30 @@
<div class="container">
<mat-card>
<form [formGroup]="activateGroupForm" (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="activateGroupForm.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]="!activateGroupForm.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 { ActivateGroupComponent } from './activate-group.component';
describe('ActivateGroupComponent', () => {
let component: ActivateGroupComponent;
let fixture: ComponentFixture<ActivateGroupComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ActivateGroupComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ActivateGroupComponent);
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 { GroupsService } from 'app/groups/groups.service';
/**
* Activate Group Component
*/
@Component({
selector: 'mifosx-activate-group',
templateUrl: './activate-group.component.html',
styleUrls: ['./activate-group.component.scss']
})
export class ActivateGroupComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Activate group form. */
activateGroupForm: FormGroup;
/** Group Account Id */
groupId: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {groupsService} groupsService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private groupsService: GroupsService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.groupId = this.route.parent.snapshot.params['groupId'];
}
/**
* Creates the activate group form.
*/
ngOnInit() {
this.createActivateGroupForm();
}
/**
* Creates the activate group form.
*/
createActivateGroupForm() {
this.activateGroupForm = this.formBuilder.group({
'activationDate': ['', Validators.required]
});
}
/**
* Submits the form and activates the group,
* if successful redirects to the group.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevactivationDate: Date = this.activateGroupForm.value.activationDate;
this.activateGroupForm.patchValue({
activationDate: this.datePipe.transform(prevactivationDate, dateFormat),
});
const data = {
...this.activateGroupForm.value,
dateFormat,
locale
};
this.groupsService.executeGroupCommand(this.groupId, 'activate', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -1,2 +1,3 @@
<mifosx-group-assign-staff *ngIf="actions['Assign Staff']"></mifosx-group-assign-staff>
<mifosx-close-group *ngIf="actions['Close']"></mifosx-close-group>
<mifosx-activate-group *ngIf="actions['Activate']"></mifosx-activate-group>
@@ -16,9 +16,11 @@ export class GroupActionsComponent {
actions: {
'Assign Staff': boolean
'Close': boolean
'Activate': boolean
} = {
'Assign Staff': false,
'Close': false
'Close': false,
'Activate': false
};
/**
@@ -54,7 +54,7 @@
<mat-card-actions class="group-actions" *ngIf="!(groupViewData.status.value==='Closed')">
<span *ngIf="!(groupViewData.status.value==='Active')">
<button mat-raised-button *mifosxHasPermission="'UPDATE_GROUP'">
<button mat-raised-button *mifosxHasPermission="'UPDATE_GROUP'" (click)="doAction('Activate')">
<i class="fa fa-check-sign"></i>Activate</button>
</span>
<button mat-raised-button *mifosxHasPermission="'UPDATE_GROUP'">
@@ -46,6 +46,7 @@ export class GroupsViewComponent {
switch (name) {
case 'Assign Staff':
case 'Close':
case 'Activate':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Unassign Staff':
+3 -1
View File
@@ -24,6 +24,7 @@ import { GroupActionsComponent } from './groups-view/group-actions/group-actions
import { GroupAssignStaffComponent } from './groups-view/group-actions/group-assign-staff/group-assign-staff.component';
import { UnassignStaffDialogComponent } from './groups-view/custom-dialogs/unassign-staff-dialog/unassign-staff-dialog.component';
import { CloseGroupComponent } from './groups-view/group-actions/close-group/close-group.component';
import { ActivateGroupComponent } from './groups-view/group-actions/activate-group/activate-group.component';
/**
* Groups Module
@@ -52,7 +53,8 @@ import { CloseGroupComponent } from './groups-view/group-actions/close-group/clo
GroupActionsComponent,
GroupAssignStaffComponent,
UnassignStaffDialogComponent,
CloseGroupComponent
CloseGroupComponent,
ActivateGroupComponent
],
entryComponents: [
UnassignRoleDialogComponent,