@@ -0,0 +1,69 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="editGroupForm">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="column">
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput required formControlName="name">
|
||||
<mat-error *ngIf="editGroupForm.controls.name.hasError('required')">
|
||||
Group Name is <strong>required</strong>
|
||||
</mat-error>
|
||||
<mat-error *ngIf="editGroupForm.controls.name.hasError('pattern')">
|
||||
Group Name <strong>cannot</strong> begin with a special character or number
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Staff</mat-label>
|
||||
<mat-select formControlName="staffId">
|
||||
<mat-option *ngFor="let staff of staffData" [value]="staff.id">
|
||||
{{ staff.displayName }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field *ngIf="this.editGroupForm.contains('activationDate')">
|
||||
<mat-label>Activation 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="editGroupForm.controls.activationDate.hasError('required')">
|
||||
Activation Date is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>External id</mat-label>
|
||||
<input matInput formControlName="externalId">
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Submitted on</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="submittedOnDatePicker" required formControlName="submittedOnDate">
|
||||
<mat-datepicker-toggle matSuffix [for]="submittedOnDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #submittedOnDatePicker></mat-datepicker>
|
||||
<mat-error *ngIf="editGroupForm.controls.submittedOnDate.hasError('required')">
|
||||
Submission Date 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="primary" [disabled]="!editGroupForm.valid" (click)="submit()">Submit</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 { EditGroupComponent } from './edit-group.component';
|
||||
|
||||
describe('EditGroupComponent', () => {
|
||||
let component: EditGroupComponent;
|
||||
let fixture: ComponentFixture<EditGroupComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ EditGroupComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(EditGroupComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,112 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
/** Custom Services */
|
||||
import { GroupsService } from '../groups.service';
|
||||
|
||||
/**
|
||||
* Edit Group component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-edit-group',
|
||||
templateUrl: './edit-group.component.html',
|
||||
styleUrls: ['./edit-group.component.scss']
|
||||
})
|
||||
export class EditGroupComponent implements OnInit {
|
||||
|
||||
/** Minimum date allowed. */
|
||||
minDate = new Date(2000, 0, 1);
|
||||
/** Maximum date allowed. */
|
||||
maxDate = new Date();
|
||||
/** Group form. */
|
||||
editGroupForm: FormGroup;
|
||||
/** Staff data. */
|
||||
staffData: any;
|
||||
/** Group Data */
|
||||
groupData: any;
|
||||
/** Submitted On Date */
|
||||
submittedOnDate: any;
|
||||
|
||||
/**
|
||||
* Retrieves the offices data from `resolve`.
|
||||
* @param {FormBuilder} formBuilder Form Builder.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {Router} router Router for navigation.
|
||||
* @param {GroupsService} groupService GroupsService.
|
||||
* @param {DatePipe} datePipe Date Pipe to format date.
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private groupService: GroupsService,
|
||||
private datePipe: DatePipe) {
|
||||
this.route.data.subscribe( (data: { groupAndTemplateData: any, groupViewData: any } ) => {
|
||||
this.staffData = data.groupAndTemplateData.staffOptions;
|
||||
this.groupData = data.groupAndTemplateData;
|
||||
this.submittedOnDate = data.groupViewData.timeline.submittedOnDate && new Date(data.groupViewData.timeline.submittedOnDate);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and sets the group form.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.createEditGroupForm();
|
||||
this.editGroupForm.patchValue({
|
||||
'name': this.groupData.name,
|
||||
'submittedOnDate': this.submittedOnDate,
|
||||
'staffId': this.groupData.staffId,
|
||||
'externalId': this.groupData.externalId
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the group form.
|
||||
*/
|
||||
createEditGroupForm() {
|
||||
this.editGroupForm = this.formBuilder.group({
|
||||
'name': ['', [Validators.required, Validators.pattern('(^[A-z]).*')]],
|
||||
'submittedOnDate': ['', Validators.required],
|
||||
'staffId': [''],
|
||||
'externalId': ['']
|
||||
});
|
||||
this.buildDependencies();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds form control Activation Date if group is active.
|
||||
*/
|
||||
buildDependencies() {
|
||||
if (this.groupData.active) {
|
||||
this.editGroupForm.addControl('activationDate', new FormControl('', Validators.required));
|
||||
this.editGroupForm.get('activationDate').patchValue(this.groupData.activationDate && new Date(this.groupData.activationDate));
|
||||
} else {
|
||||
this.editGroupForm.removeControl('activationDate');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the group form and creates group,
|
||||
* if successful redirects to groups.
|
||||
*/
|
||||
submit() {
|
||||
const submittedOnDate: Date = this.editGroupForm.value.submittedOnDate;
|
||||
const activationDate: Date = this.editGroupForm.value.activationDate;
|
||||
// TODO: Update once language and date settings are setup
|
||||
const dateFormat = 'dd MMMM yyyy';
|
||||
this.editGroupForm.patchValue({
|
||||
submittedOnDate: this.datePipe.transform(submittedOnDate, dateFormat),
|
||||
activationDate: activationDate && this.datePipe.transform(activationDate, dateFormat)
|
||||
});
|
||||
const group = this.editGroupForm.value;
|
||||
group.locale = 'en';
|
||||
group.dateFormat = dateFormat;
|
||||
this.groupService.updateGroup(group, this.groupData.id).subscribe((response: any) => {
|
||||
this.router.navigate(['../'], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user