diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index 0a4bf2fcd..9875886a3 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -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 + } + } + ] } ] }, diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index a4a1f0e31..55d86b4bf 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -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 { } diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index 9b9dc95cc..64d90f1ec 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -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} + */ + updateTeller(tellerId: string, teller: any): Observable { + return this.http.put(`/tellers/${tellerId}`, teller); + } + } diff --git a/src/app/organization/tellers/edit-teller/edit-teller.component.html b/src/app/organization/tellers/edit-teller/edit-teller.component.html new file mode 100644 index 000000000..ac5992151 --- /dev/null +++ b/src/app/organization/tellers/edit-teller/edit-teller.component.html @@ -0,0 +1,78 @@ +
+ + + +
+ + + +
+ + + Teller Name + + + Teller Name is required + + + Teller Name cannot begin with a special character or number + + + + + Office + + + {{ office.name }} + + + + + + Description + + + + + Start Date + + + + + Start Date is required + + + + + End Date + + + + + + + Status + + + {{ tellerStatus.value }} + + + + Status is required + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/organization/tellers/edit-teller/edit-teller.component.scss b/src/app/organization/tellers/edit-teller/edit-teller.component.scss new file mode 100644 index 000000000..2cc8df4d2 --- /dev/null +++ b/src/app/organization/tellers/edit-teller/edit-teller.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; + } diff --git a/src/app/organization/tellers/edit-teller/edit-teller.component.spec.ts b/src/app/organization/tellers/edit-teller/edit-teller.component.spec.ts new file mode 100644 index 000000000..433844959 --- /dev/null +++ b/src/app/organization/tellers/edit-teller/edit-teller.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ EditTellerComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditTellerComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/tellers/edit-teller/edit-teller.component.ts b/src/app/organization/tellers/edit-teller/edit-teller.component.ts new file mode 100644 index 000000000..cde547059 --- /dev/null +++ b/src/app/organization/tellers/edit-teller/edit-teller.component.ts @@ -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 }); + }); + } + +} diff --git a/src/app/organization/tellers/view-teller/view-teller.component.html b/src/app/organization/tellers/view-teller/view-teller.component.html index 219536225..723cfa2a5 100644 --- a/src/app/organization/tellers/view-teller/view-teller.component.html +++ b/src/app/organization/tellers/view-teller/view-teller.component.html @@ -1,5 +1,5 @@
- @@ -17,6 +17,14 @@
+
+ Teller Name +
+ +
+ {{ tellerData.name }} +
+
Office