From 519ef0f40db442b63f9bd2a33b76c103bce16bce Mon Sep 17 00:00:00 2001 From: Ashutosh Sharma <45865775+spider0061@users.noreply.github.com> Date: Wed, 13 May 2020 11:13:37 +0530 Subject: [PATCH] feat: add create teller component (#591) Fixes: #160 --- .../organization-routing.module.ts | 9 ++ src/app/organization/organization.module.ts | 4 +- src/app/organization/organization.service.ts | 8 ++ .../create-teller.component.html | 81 ++++++++++++++++ .../create-teller.component.scss | 3 + .../create-teller.component.spec.ts | 25 +++++ .../create-teller/create-teller.component.ts | 93 +++++++++++++++++++ .../tellers/tellers.component.html | 2 +- 8 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 src/app/organization/tellers/create-teller/create-teller.component.html create mode 100644 src/app/organization/tellers/create-teller/create-teller.component.scss create mode 100644 src/app/organization/tellers/create-teller/create-teller.component.spec.ts create mode 100644 src/app/organization/tellers/create-teller/create-teller.component.ts diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index f24611bd4..0a4bf2fcd 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -31,6 +31,7 @@ import { CreatePaymentTypeComponent } from './payment-types/create-payment-type/ import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/create-adhoc-query.component'; import { HolidaysComponent } from './holidays/holidays.component'; import { EditEmployeeComponent } from './employees/edit-employee/edit-employee.component'; +import { CreateTellerComponent } from './tellers/create-teller/create-teller.component'; /** Custom Resolvers */ import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver'; @@ -205,6 +206,14 @@ const routes: Routes = [ tellers: TellersResolver } }, + { + path: 'create', + component: CreateTellerComponent, + data: { title: extract('Create Teller'), breadcrumb: 'Create' }, + resolve: { + offices: OfficesResolver + } + }, { path: ':id', component: ViewTellerComponent, diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index 9b888dfe3..a4a1f0e31 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -30,6 +30,7 @@ import { EditOfficeComponent } from './offices/edit-office/edit-office.component import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/create-adhoc-query.component'; import { HolidaysComponent } from './holidays/holidays.component'; import { EditEmployeeComponent } from './employees/edit-employee/edit-employee.component'; +import { CreateTellerComponent } from './tellers/create-teller/create-teller.component'; /** * Organization Module @@ -65,7 +66,8 @@ import { EditEmployeeComponent } from './employees/edit-employee/edit-employee.c CreateAdhocQueryComponent, HolidaysComponent, EditOfficeComponent, - EditEmployeeComponent + EditEmployeeComponent, + CreateTellerComponent ] }) export class OrganizationModule { } diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index fe1dbdaa7..9b9dc95cc 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -159,6 +159,14 @@ export class OrganizationService { return this.http.delete(`/tellers/${tellerId}`); } + /** + * @param {any} teller Teller to be created. + * @returns {Observable} + */ + createTeller(teller: any): Observable { + return this.http.post('/tellers', teller); + } + /** * @returns {Observable} Payment Types data */ diff --git a/src/app/organization/tellers/create-teller/create-teller.component.html b/src/app/organization/tellers/create-teller/create-teller.component.html new file mode 100644 index 000000000..05cf03236 --- /dev/null +++ b/src/app/organization/tellers/create-teller/create-teller.component.html @@ -0,0 +1,81 @@ +
+ + + +
+ + + +
+ + + Teller Name + + + Teller Name is required + + + Teller Name cannot begin with a special character or number + + + + + Office + + + {{ office.name }} + + + + Office is required + + + + + Description + + + + + Start Date + + + + + Start Date is required + + + + + End Date + + + + + + + Status + + + {{ tellerStatus.value }} + + + + Status is required + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/organization/tellers/create-teller/create-teller.component.scss b/src/app/organization/tellers/create-teller/create-teller.component.scss new file mode 100644 index 000000000..d774f68da --- /dev/null +++ b/src/app/organization/tellers/create-teller/create-teller.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/organization/tellers/create-teller/create-teller.component.spec.ts b/src/app/organization/tellers/create-teller/create-teller.component.spec.ts new file mode 100644 index 000000000..a39330292 --- /dev/null +++ b/src/app/organization/tellers/create-teller/create-teller.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateTellerComponent } from './create-teller.component'; + +describe('CreateTellerComponent', () => { + let component: CreateTellerComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreateTellerComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateTellerComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/tellers/create-teller/create-teller.component.ts b/src/app/organization/tellers/create-teller/create-teller.component.ts new file mode 100644 index 000000000..e8bdb4ea6 --- /dev/null +++ b/src/app/organization/tellers/create-teller/create-teller.component.ts @@ -0,0 +1,93 @@ +/** 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-create-teller', + templateUrl: './create-teller.component.html', + styleUrls: ['./create-teller.component.scss'] +}) +export class CreateTellerComponent 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; + + /** + * 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: { offices: any }) => { + this.officeData = data.offices; + }); + this.tellerStatusesData = [{'id': 300, 'code': '300', 'value': 'Active'}, + {'id': 400, 'code': '400', 'value': 'Inactive'}]; + } + + /** + * Creates the teller form. + */ + ngOnInit() { + this.createTellerForm(); + } + + /** + * Creates the teller form. + */ + createTellerForm() { + this.tellerForm = this.formBuilder.group({ + 'officeId': ['', Validators.required], + 'name': ['', [Validators.required, Validators.pattern('(^[A-z]).*')]], + 'description': [''], + 'startDate': ['', Validators.required], + 'endDate': [''], + 'status': ['', Validators.required], + }); + } + + /** + * Submits the teller form and creates 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.dateFormat = dateFormat; + this.organizationService.createTeller(teller).subscribe((response: any) => { + this.router.navigate(['../', response.resourceId], { relativeTo: this.route }); + }); + } + +} diff --git a/src/app/organization/tellers/tellers.component.html b/src/app/organization/tellers/tellers.component.html index ed708dda6..a0fd87332 100644 --- a/src/app/organization/tellers/tellers.component.html +++ b/src/app/organization/tellers/tellers.component.html @@ -1,6 +1,6 @@
-