From e3d5bd81569ffcb5c848b75982f3e16231e7ce03 Mon Sep 17 00:00:00 2001 From: Rishabh Verma Date: Mon, 11 May 2020 15:25:30 +0530 Subject: [PATCH] feat: add holidays component (#730) Fixes: #153 --- .../holidays/holidays.component.html | 67 ++++++++++++++ .../holidays/holidays.component.scss | 7 ++ .../holidays/holidays.component.spec.ts | 25 ++++++ .../holidays/holidays.component.ts | 89 +++++++++++++++++++ .../organization-routing.module.ts | 9 ++ .../organization/organization.component.html | 2 +- src/app/organization/organization.module.ts | 4 +- src/app/organization/organization.service.ts | 10 +++ 8 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 src/app/organization/holidays/holidays.component.html create mode 100644 src/app/organization/holidays/holidays.component.scss create mode 100644 src/app/organization/holidays/holidays.component.spec.ts create mode 100644 src/app/organization/holidays/holidays.component.ts diff --git a/src/app/organization/holidays/holidays.component.html b/src/app/organization/holidays/holidays.component.html new file mode 100644 index 000000000..1123f9342 --- /dev/null +++ b/src/app/organization/holidays/holidays.component.html @@ -0,0 +1,67 @@ +
+ + + +
+ +
+ +
+ + + Filter + + + + Select Office + + + {{ office.name }} + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Holiday Name {{ holidays.name }} Start Date {{ holidays.fromDate | date }} End Date {{ holidays.toDate | date }} Repayments Scheduled To {{ holidays.reschedulingType === 1 ? 'Next Repayment Date' : holidays.repaymentsRescheduledTo | date }} Status {{ holidays.status.value }}
+ + + +
+ +
diff --git a/src/app/organization/holidays/holidays.component.scss b/src/app/organization/holidays/holidays.component.scss new file mode 100644 index 000000000..85d24ea7d --- /dev/null +++ b/src/app/organization/holidays/holidays.component.scss @@ -0,0 +1,7 @@ +table { + width: 100%; + + .select-row:hover { + cursor: pointer; + } +} diff --git a/src/app/organization/holidays/holidays.component.spec.ts b/src/app/organization/holidays/holidays.component.spec.ts new file mode 100644 index 000000000..a3e55a9fb --- /dev/null +++ b/src/app/organization/holidays/holidays.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HolidaysComponent } from './holidays.component'; + +describe('HolidaysComponent', () => { + let component: HolidaysComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ HolidaysComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(HolidaysComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/holidays/holidays.component.ts b/src/app/organization/holidays/holidays.component.ts new file mode 100644 index 000000000..113abd8ca --- /dev/null +++ b/src/app/organization/holidays/holidays.component.ts @@ -0,0 +1,89 @@ +/** Angular Imports */ +import { Component, OnInit, ViewChild } from '@angular/core'; +import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material'; +import { ActivatedRoute } from '@angular/router'; +import { FormControl } from '@angular/forms'; + +/** rxjs Imports */ +import { of } from 'rxjs'; + +/** Custom Services */ +import { OrganizationService } from '../organization.service'; + +/** + * Holidays component. + */ +@Component({ + selector: 'mifosx-holidays', + templateUrl: './holidays.component.html', + styleUrls: ['./holidays.component.scss'] +}) +export class HolidaysComponent implements OnInit { + + /** Office selector. */ + officeSelector = new FormControl(); + /** Holidays data. */ + holidaysData: any; + /** Offices data. */ + officeData: any; + /** Columns to be displayed in holidays table. */ + displayedColumns: string[] = ['name', 'fromDate', 'toDate', 'repaymentsRescheduledTo', 'status']; + /** Data source for holidays table. */ + dataSource: MatTableDataSource; + + /** Paginator for holidays table. */ + @ViewChild(MatPaginator) paginator: MatPaginator; + /** Sorter for holidays table. */ + @ViewChild(MatSort) sort: MatSort; + + /** + * Retrieves the offices data from `resolve`. + * @param {OrganizationService} organizationService Organization Service. + * @param {ActivatedRoute} route Activated Route. + * @param {FormBuilder} formBuilder Form Builder. + */ + constructor(private organizationService: OrganizationService, + private route: ActivatedRoute) { + this.route.data.subscribe(( data: { offices: any }) => { + this.officeData = data.offices; + }); + } + + /** + * Filters data in holidays table based on passed value. + * @param {string} filterValue Value to filter data. + */ + applyFilter(filterValue: string) { + this.dataSource.filter = filterValue.trim().toLowerCase(); + } + + /** + * Retrieves holidays data on changing office. + */ + ngOnInit() { + this.onChangeOffice(); + } + + /** + * Retrieves the holidays data on changing office and sets the holidays table. + */ + onChangeOffice() { + this.officeSelector.valueChanges.subscribe((officeId = this.officeSelector.value) => { + this.holidaysData = []; + this.organizationService.getHolidays(officeId).subscribe((holidays: any) => { + this.holidaysData = holidays; + this.setHolidays(); + }); + }); + } + + /** + * Initializes the data source, paginator and sorter for holidays table. + */ + setHolidays() { + this.dataSource = new MatTableDataSource(this.holidaysData); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + } + +} diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index 61208b68a..17a266f55 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -29,6 +29,7 @@ import { WorkingDaysComponent } from './working-days/working-days.component'; import { CreateOfficeComponent } from './offices/create-office/create-office.component'; import { CreatePaymentTypeComponent } from './payment-types/create-payment-type/create-payment-type.component'; import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/create-adhoc-query.component'; +import { HolidaysComponent } from './holidays/holidays.component'; /** Custom Resolvers */ import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver'; @@ -242,6 +243,14 @@ const routes: Routes = [ { path: 'bulk-import', loadChildren: '../bulk-import/bulk-import.module#BulkImportModule' + }, + { + path: 'holidays', + component: HolidaysComponent, + data: { title: extract('Manage Holidays'), breadcrumb: 'Manage Holidays' }, + resolve: { + offices: OfficesResolver + } } ] } diff --git a/src/app/organization/organization.component.html b/src/app/organization/organization.component.html index 1782e8c7f..6c7c7f20b 100644 --- a/src/app/organization/organization.component.html +++ b/src/app/organization/organization.component.html @@ -16,7 +16,7 @@

Add new office or modify or deactivate office or modify hierarchy

- + diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index bde684e94..4f9ffc581 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -27,6 +27,7 @@ import { CreateEmployeeComponent } from './employees/create-employee/create-empl import { CreatePaymentTypeComponent } from './payment-types/create-payment-type/create-payment-type.component'; import { ViewEmployeeComponent } from './employees/view-employee/view-employee.component'; import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/create-adhoc-query.component'; +import { HolidaysComponent } from './holidays/holidays.component'; /** * Organization Module @@ -59,7 +60,8 @@ import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/crea CreateEmployeeComponent, CreatePaymentTypeComponent, ViewEmployeeComponent, - CreateAdhocQueryComponent + CreateAdhocQueryComponent, + HolidaysComponent ] }) export class OrganizationModule { } diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index 0b94f8951..607c5f54a 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -227,4 +227,14 @@ export class OrganizationService { return this.http.put('/workingdays', workingDays); } + /* + * @param {string} officeId Office ID of Holidays. + * @returns {Observable} Holidays data. + */ + getHolidays(officeId: string): Observable { + const httpParams = new HttpParams() + .set('officeId', officeId.toString()); + return this.http.get('/holidays', { params: httpParams }); + } + }