diff --git a/src/app/organization/offices/create-office/create-office.component.html b/src/app/organization/offices/create-office/create-office.component.html new file mode 100644 index 000000000..47be8051e --- /dev/null +++ b/src/app/organization/offices/create-office/create-office.component.html @@ -0,0 +1,59 @@ +
+ + + +
+ + + +
+ + + Office + + + Office is required + + + + + Parent Office + + + {{ office.name }} + + + + Parent Office is required + + + + + Opened On + + + + + Opening Date is required + + + + + External ID + + + +
+ +
+ + + + + + +
+ +
+ +
diff --git a/src/app/organization/offices/create-office/create-office.component.scss b/src/app/organization/offices/create-office/create-office.component.scss new file mode 100644 index 000000000..1915ad6d3 --- /dev/null +++ b/src/app/organization/offices/create-office/create-office.component.scss @@ -0,0 +1,3 @@ +.container { + max-width: 37rem; +} diff --git a/src/app/organization/offices/create-office/create-office.component.spec.ts b/src/app/organization/offices/create-office/create-office.component.spec.ts new file mode 100644 index 000000000..b5c5e596d --- /dev/null +++ b/src/app/organization/offices/create-office/create-office.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CreateOfficeComponent } from './create-office.component'; + +describe('CreateOfficeComponent', () => { + let component: CreateOfficeComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreateOfficeComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateOfficeComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/offices/create-office/create-office.component.ts b/src/app/organization/offices/create-office/create-office.component.ts new file mode 100644 index 000000000..a28727c5c --- /dev/null +++ b/src/app/organization/offices/create-office/create-office.component.ts @@ -0,0 +1,81 @@ +/** 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 Office component. + */ +@Component({ + selector: 'mifosx-create-office', + templateUrl: './create-office.component.html', + styleUrls: ['./create-office.component.scss'] +}) +export class CreateOfficeComponent implements OnInit { + + /** Office form. */ + officeForm: FormGroup; + /** Office Data */ + officeData: any; + /** Minimum Date allowed. */ + minDate = new Date(2000, 0, 1); + /** Maximum Date allowed. */ + maxDate = new Date(); + + /** + * 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 router: Router, + private route: ActivatedRoute, + private datePipe: DatePipe) { + this.route.data.subscribe((data: { offices: any }) => { + this.officeData = data.offices; + }); + } + + ngOnInit() { + this.createofficeForm(); + } + + /** + * Creates the Office Form + */ + createofficeForm() { + this.officeForm = this.formBuilder.group({ + 'name': ['', Validators.required], + 'parentId': ['', Validators.required], + 'openingDate': ['', Validators.required], + 'externalId': [''], + }); + } + + /** + * Submits the office form and creates office. + * if successful redirects to offices + */ + submit() { + const prevOpeningDate: Date = this.officeForm.value.openingDate; + // TODO: Update once language and date settings are setup + const dateFormat = 'yyyy-MM-dd'; + this.officeForm.patchValue({ + openingDate: this.datePipe.transform(prevOpeningDate, dateFormat) + }); + const office = this.officeForm.value; + office.locale = 'en'; + office.dateFormat = dateFormat; + this.organizationService.createOffice(office).subscribe(response => { + this.router.navigate(['../'], { relativeTo: this.route }); + }); + } +} diff --git a/src/app/organization/offices/offices.component.html b/src/app/organization/offices/offices.component.html index cab6452c0..50e48c9c8 100644 --- a/src/app/organization/offices/offices.component.html +++ b/src/app/organization/offices/offices.component.html @@ -5,7 +5,7 @@ Tree View - diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index 68c38eba1..e444a3596 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -21,6 +21,7 @@ import { PaymentTypesComponent } from './payment-types/payment-types.component'; import { PasswordPreferencesComponent } from './password-preferences/password-preferences.component'; import { EntityDataTableChecksComponent } from './entity-data-table-checks/entity-data-table-checks.component'; import { WorkingDaysComponent } from './working-days/working-days.component'; +import { CreateOfficeComponent } from './offices/create-office/create-office.component'; /** Custom Resolvers */ import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver'; @@ -56,11 +57,24 @@ const routes: Routes = [ }, { path: 'offices', - component: OfficesComponent, data: { title: extract('Manage Offices'), breadcrumb: 'Manage Offices' }, - resolve: { - offices: OfficesResolver - } + children: [ + { + path: '', + component: OfficesComponent, + resolve: { + offices: OfficesResolver + } + }, + { + path: 'create', + component: CreateOfficeComponent, + data: { title: extract('Create Office'), breadcrumb: 'Create Office' }, + resolve: { + offices: OfficesResolver, + } + } + ] }, { path: 'employees', diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index d7f0006a8..18c37d3f4 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -19,6 +19,7 @@ import { PaymentTypesComponent } from './payment-types/payment-types.component'; import { PasswordPreferencesComponent } from './password-preferences/password-preferences.component'; import { EntityDataTableChecksComponent } from './entity-data-table-checks/entity-data-table-checks.component'; import { WorkingDaysComponent } from './working-days/working-days.component'; +import { CreateOfficeComponent } from './offices/create-office/create-office.component'; /** * Organization Module @@ -43,7 +44,8 @@ import { WorkingDaysComponent } from './working-days/working-days.component'; PaymentTypesComponent, PasswordPreferencesComponent, EntityDataTableChecksComponent, - WorkingDaysComponent + WorkingDaysComponent, + CreateOfficeComponent ] }) export class OrganizationModule { } diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index f1d74acbf..785d34377 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -32,6 +32,14 @@ export class OrganizationService { return this.http.get('/offices'); } + /** + * @param {any} office Office to be created. + * @returns {Observable} + */ + createOffice(office: any): Observable { + return this.http.post('/offices', office); + } + /** * @returns {Observable} Employees data */