feat: add edit teller component (#598)

Fixes: #596
This commit is contained in:
Ashutosh Sharma
2020-05-14 12:25:27 +05:30
committed by GitHub
parent 519ef0f40d
commit 55d639f87a
8 changed files with 252 additions and 7 deletions
@@ -32,6 +32,7 @@ import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/crea
import { HolidaysComponent } from './holidays/holidays.component';
import { EditEmployeeComponent } from './employees/edit-employee/edit-employee.component';
import { CreateTellerComponent } from './tellers/create-teller/create-teller.component';
import { EditTellerComponent } from './tellers/edit-teller/edit-teller.component';
/** Custom Resolvers */
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver';
@@ -216,11 +217,25 @@ const routes: Routes = [
},
{
path: ':id',
component: ViewTellerComponent,
data: { title: extract('View Teller'), routeResolveBreadcrumb: ['teller', 'name'] },
resolve: {
teller: TellerResolver
}
data: { title: extract('View Teller'), routeParamBreadcrumb: 'id' },
children: [
{
path: '',
component: ViewTellerComponent,
resolve: {
teller: TellerResolver
},
},
{
path: 'edit',
component: EditTellerComponent,
data: { title: extract('Edit Teller'), breadcrumb: 'Edit', routeParamBreadcrumb: false },
resolve: {
teller: TellerResolver,
offices: OfficesResolver
}
}
]
}
]
},
+3 -1
View File
@@ -31,6 +31,7 @@ import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/crea
import { HolidaysComponent } from './holidays/holidays.component';
import { EditEmployeeComponent } from './employees/edit-employee/edit-employee.component';
import { CreateTellerComponent } from './tellers/create-teller/create-teller.component';
import { EditTellerComponent } from './tellers/edit-teller/edit-teller.component';
/**
* Organization Module
@@ -67,7 +68,8 @@ import { CreateTellerComponent } from './tellers/create-teller/create-teller.com
HolidaysComponent,
EditOfficeComponent,
EditEmployeeComponent,
CreateTellerComponent
CreateTellerComponent,
EditTellerComponent
]
})
export class OrganizationModule { }
@@ -274,4 +274,12 @@ export class OrganizationService {
return this.http.put(`/staff/${employeeId}`, employee);
}
/**
* @param {string} tellerId Teller ID of Teller to be edited.
* @returns {Observable<any>}
*/
updateTeller(tellerId: string, teller: any): Observable<any> {
return this.http.put(`/tellers/${tellerId}`, teller);
}
}
@@ -0,0 +1,78 @@
<div class="container">
<mat-card>
<form [formGroup]="tellerForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Teller Name</mat-label>
<input matInput required formControlName="name">
<mat-error *ngIf="tellerForm.controls.name.hasError('required')">
Teller Name is <strong>required</strong>
</mat-error>
<mat-error *ngIf="tellerForm.controls.name.hasError('pattern')">
Teller Name <strong>cannot</strong> begin with a special character or number
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Office</mat-label>
<mat-select formControlName="officeId">
<mat-option *ngFor="let office of officeData" [value]="office.id">
{{ office.name }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field>
<mat-label>Description</mat-label>
<input matInput formControlName="description">
</mat-form-field>
<mat-form-field>
<mat-label>Start Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="startDatePicker" required formControlName="startDate">
<mat-datepicker-toggle matSuffix [for]="startDatePicker"></mat-datepicker-toggle>
<mat-datepicker #startDatePicker></mat-datepicker>
<mat-error *ngIf="tellerForm.controls.startDate.hasError('required')">
Start Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>End Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="endDatePicker" formControlName="endDate">
<mat-datepicker-toggle matSuffix [for]="endDatePicker"></mat-datepicker-toggle>
<mat-datepicker #endDatePicker></mat-datepicker>
</mat-form-field>
<mat-form-field>
<mat-label>Status</mat-label>
<mat-select required formControlName="status">
<mat-option *ngFor="let tellerStatus of tellerStatusesData" [value]="tellerStatus.id">
{{ tellerStatus.value }}
</mat-option>
</mat-select>
<mat-error *ngIf="tellerForm.controls.status.hasError('required')">
Status 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]="!tellerForm.valid">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 { EditTellerComponent } from './edit-teller.component';
describe('EditTellerComponent', () => {
let component: EditTellerComponent;
let fixture: ComponentFixture<EditTellerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditTellerComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditTellerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,106 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Services */
import { OrganizationService } from '../../organization.service';
/**
* Create teller component.
*/
@Component({
selector: 'mifosx-edit-teller',
templateUrl: './edit-teller.component.html',
styleUrls: ['./edit-teller.component.scss']
})
export class EditTellerComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Teller form. */
tellerForm: FormGroup;
/** Office data. */
officeData: any;
/** TellerStatuses data. */
tellerStatusesData: any;
/** Teller data. */
tellerData: any;
/**
* Retrieves the offices data from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {OrganizationService} organizationService Organization Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {DatePipe} datePipe Date Pipe to format date.
*/
constructor(private formBuilder: FormBuilder,
private organizationService: OrganizationService,
private route: ActivatedRoute,
private router: Router,
private datePipe: DatePipe) {
this.route.data.subscribe((data: { teller: any, offices: any }) => {
this.tellerData = data.teller;
this.officeData = data.offices;
});
if (this.tellerData.status) {
if (this.tellerData.status === 'ACTIVE') {
this.tellerData.status = 300;
} else {
this.tellerData.status = 400;
}
}
this.tellerStatusesData = [ {'id': 300, 'code': '300', 'value': 'Active'},
{'id': 400, 'code': '400', 'value': 'Inactive'}];
}
/**
* Creates the Edit teller form.
*/
ngOnInit() {
this.createEditTellerForm();
}
/**
* Edit teller form.
*/
createEditTellerForm() {
this.tellerForm = this.formBuilder.group({
'officeId': [{value: this.tellerData.officeId, disabled: true}],
'name': [this.tellerData.name, [Validators.required, Validators.pattern('(^[A-z]).*')]],
'description': [this.tellerData.description],
'startDate': [this.tellerData.startDate && new Date(this.tellerData.startDate), Validators.required],
'endDate': [this.tellerData.endDate && new Date(this.tellerData.endDate)],
'status': [this.tellerData.status, Validators.required]
});
}
/**
* Submits the teller form and edits teller,
* if successful redirects to tellers.
*/
submit() {
const prevStartDate: Date = this.tellerForm.value.startDate;
const prevEndDate: Date = this.tellerForm.value.endDate;
// TODO: Update once language and date settings are setup
const dateFormat = 'yyyy-MM-dd';
this.tellerForm.patchValue({
startDate: this.datePipe.transform(prevStartDate, dateFormat),
endDate: this.datePipe.transform(prevEndDate, dateFormat)
});
const teller = this.tellerForm.value;
teller.locale = 'en';
teller.officeId = this.tellerData.officeId;
teller.dateFormat = dateFormat;
this.organizationService.updateTeller(this.tellerData.id, teller).subscribe((response: any) => {
this.router.navigate(['../../', response.resourceId], { relativeTo: this.route });
});
}
}
@@ -1,5 +1,5 @@
<div fxLayout="row" fxLayoutAlign="end" fxLayoutGap="2%" fxLayout.lt-md="column" class="container m-b-20">
<button mat-raised-button color="primary">
<button mat-raised-button color="primary" [routerLink]="['edit']">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;
Edit
</button>
@@ -17,6 +17,14 @@
<div fxLayout="row wrap" class="content">
<div fxFlex="50%" class="mat-body-strong">
Teller Name
</div>
<div fxFlex="50%">
{{ tellerData.name }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Office
</div>