committed by
Abhay Chawla
parent
4234208539
commit
0991df4b18
@@ -0,0 +1,59 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="officeForm" (ngSubmit)="submit()">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="column">
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Office</mat-label>
|
||||
<input required matInput formControlName="name">
|
||||
<mat-error *ngIf="officeForm.controls.name.hasError('required')">
|
||||
Office is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Parent Office</mat-label>
|
||||
<mat-select required formControlName="parentId">
|
||||
<mat-option *ngFor="let office of officeData" [value]="office.id">
|
||||
{{ office.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="officeForm.controls.parentId.hasError('required')">
|
||||
Parent Office is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Opened On</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" formControlName="openingDate" required [matDatepicker]="openedOnDatePicker">
|
||||
<mat-datepicker-toggle matSuffix [for]="openedOnDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #openedOnDatePicker></mat-datepicker>
|
||||
<mat-error *ngIf="officeForm.controls.openingDate.hasError('required')">
|
||||
Opening 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>
|
||||
|
||||
</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]="!officeForm.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 { CreateOfficeComponent } from './create-office.component';
|
||||
|
||||
describe('CreateOfficeComponent', () => {
|
||||
let component: CreateOfficeComponent;
|
||||
let fixture: ComponentFixture<CreateOfficeComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CreateOfficeComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CreateOfficeComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -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 });
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
Tree View
|
||||
</button>
|
||||
|
||||
<button mat-raised-button color="primary">
|
||||
<button mat-raised-button color="primary" [routerLink]="['create']">
|
||||
<fa-icon icon="plus"></fa-icon>
|
||||
Create Office
|
||||
</button>
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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 { }
|
||||
|
||||
@@ -32,6 +32,14 @@ export class OrganizationService {
|
||||
return this.http.get('/offices');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} office Office to be created.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
createOffice(office: any): Observable<any> {
|
||||
return this.http.post('/offices', office);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Observable<any>} Employees data
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user