@@ -0,0 +1,31 @@
|
||||
/** Angular Imports */
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
|
||||
|
||||
/** rxjs Imports */
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
/** Custom Services */
|
||||
import { OrganizationService } from '../organization.service';
|
||||
|
||||
/**
|
||||
* Employees data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class EditEmployeeResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {OrganizationService} organizationService Organization service.
|
||||
*/
|
||||
constructor(private organizationService: OrganizationService) {}
|
||||
|
||||
/**
|
||||
* Returns the employees data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||
const employeeId = route.paramMap.get('id');
|
||||
return this.organizationService.getEmployee(employeeId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="editEmployeeForm" (ngSubmit)="submit()">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="column">
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Office</mat-label>
|
||||
<mat-select required formControlName="officeId">
|
||||
<mat-option *ngFor="let office of officeData" [value]="office.id">
|
||||
{{ office.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<mat-error *ngIf="editEmployeeForm.controls.officeId.hasError('required')">
|
||||
Office is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>First Name</mat-label>
|
||||
<input matInput required formControlName="firstname">
|
||||
<mat-error *ngIf="editEmployeeForm.controls.firstname.hasError('required')">
|
||||
First Name is <strong>required</strong>
|
||||
</mat-error>
|
||||
<mat-error *ngIf="editEmployeeForm.controls.firstname.hasError('pattern')">
|
||||
First Name <strong>cannot</strong> begin with a special character or number
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Last Name</mat-label>
|
||||
<input matInput required formControlName="lastname">
|
||||
<mat-error *ngIf="editEmployeeForm.controls.lastname.hasError('required')">
|
||||
Last Name is <strong>required</strong>
|
||||
</mat-error>
|
||||
<mat-error *ngIf="editEmployeeForm.controls.lastname.hasError('pattern')">
|
||||
Last Name <strong>cannot</strong> begin with a special character or number
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-checkbox labelPosition="before" formControlName="isLoanOfficer" class="m-b-10">
|
||||
Is Loan Officer
|
||||
</mat-checkbox>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Mobile Number for SMS</mat-label>
|
||||
<input matInput formControlName="mobileNo">
|
||||
</mat-form-field>
|
||||
|
||||
<mat-checkbox labelPosition="before" formControlName="isActive">
|
||||
Active
|
||||
</mat-checkbox>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Joining Date</mat-label>
|
||||
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="joiningDatePicker" required formControlName="joiningDate">
|
||||
<mat-datepicker-toggle matSuffix [for]="joiningDatePicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #joiningDatePicker></mat-datepicker>
|
||||
<mat-error *ngIf="editEmployeeForm.controls.joiningDate.hasError('required')">
|
||||
Joining Date 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]="!editEmployeeForm.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 { EditEmployeeComponent } from './edit-employee.component';
|
||||
|
||||
describe('EditEmployeeComponent', () => {
|
||||
let component: EditEmployeeComponent;
|
||||
let fixture: ComponentFixture<EditEmployeeComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ EditEmployeeComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(EditEmployeeComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,91 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
/** Custom Services */
|
||||
import { OrganizationService } from '../../organization.service';
|
||||
|
||||
/**
|
||||
* Edit Employee Component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-edit-employee',
|
||||
templateUrl: './edit-employee.component.html',
|
||||
styleUrls: ['./edit-employee.component.scss']
|
||||
})
|
||||
export class EditEmployeeComponent implements OnInit {
|
||||
|
||||
/** Employee data. */
|
||||
employeeData: any;
|
||||
/** Minimum joining date allowed. */
|
||||
minDate = new Date(2000, 0, 1);
|
||||
/** Maximum joining date allowed. */
|
||||
maxDate = new Date();
|
||||
/** Employee form. */
|
||||
editEmployeeForm: FormGroup;
|
||||
/** Office data. */
|
||||
officeData: 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: { employee: any, offices: any }) => {
|
||||
this.employeeData = data.employee;
|
||||
this.officeData = data.employee.allowedOffices;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the edit employee form.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.createEditEmployeeForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the employee form.
|
||||
*/
|
||||
createEditEmployeeForm() {
|
||||
this.editEmployeeForm = this.formBuilder.group({
|
||||
'officeId': [this.employeeData.officeId, Validators.required],
|
||||
'firstname': [this.employeeData.firstname, [Validators.required, Validators.pattern('(^[A-z]).*')]],
|
||||
'lastname': [this.employeeData.lastname, [Validators.required, Validators.pattern('(^[A-z]).*')]],
|
||||
'isLoanOfficer': [this.employeeData.isLoanOfficer],
|
||||
'mobileNo': [this.employeeData.mobileNo],
|
||||
'isActive': [this.employeeData.isActive],
|
||||
'joiningDate': [this.employeeData.joiningDate && new Date(this.employeeData.joiningDate), Validators.required]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the employee form and edits employee,
|
||||
* if successful redirects to the employee edited.
|
||||
*/
|
||||
submit() {
|
||||
const prevJoiningDate: Date = this.editEmployeeForm.value.joiningDate;
|
||||
// TODO: Update once language and date settings are setup
|
||||
const dateFormat = 'yyyy-MM-dd';
|
||||
this.editEmployeeForm.patchValue({
|
||||
joiningDate: this.datePipe.transform(prevJoiningDate, dateFormat)
|
||||
});
|
||||
const employee = this.editEmployeeForm.value;
|
||||
employee.locale = 'en';
|
||||
employee.dateFormat = dateFormat;
|
||||
this.organizationService.updateEmployee(this.employeeData.id, employee).subscribe((response: any) => {
|
||||
this.router.navigate(['../../', response.resourceId], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||
<button mat-raised-button color="primary">
|
||||
<button mat-raised-button color="primary" [routerLink]="['edit']">
|
||||
<fa-icon icon="edit"></fa-icon>
|
||||
Edit
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user