feat: add holidays component (#730)

Fixes: #153
This commit is contained in:
Rishabh Verma
2020-05-11 15:25:30 +05:30
committed by GitHub
parent 4d3e58016d
commit e3d5bd8156
8 changed files with 211 additions and 2 deletions
@@ -0,0 +1,67 @@
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
<button mat-raised-button color="primary">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;
Create Holiday
</button>
</div>
<div class="container">
<div fxLayout="row" fxLayoutGap="20px">
<mat-form-field fxFlex>
<mat-label>Filter</mat-label>
<input matInput (keyup)="applyFilter($event.target.value)">
</mat-form-field>
<mat-form-field>
<mat-label> Select Office </mat-label>
<mat-select [formControl]="officeSelector">
<mat-option *ngFor="let office of officeData" [value]="office.id">
{{ office.name }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div class="mat-elevation-z8" [hidden]="!officeSelector.value">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Holiday Name </th>
<td mat-cell *matCellDef="let holidays"> {{ holidays.name }} </td>
</ng-container>
<ng-container matColumnDef="fromDate">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Start Date </th>
<td mat-cell *matCellDef="let holidays"> {{ holidays.fromDate | date }} </td>
</ng-container>
<ng-container matColumnDef="toDate">
<th mat-header-cell *matHeaderCellDef mat-sort-header> End Date </th>
<td mat-cell *matCellDef="let holidays"> {{ holidays.toDate | date }} </td>
</ng-container>
<ng-container matColumnDef="repaymentsRescheduledTo">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Repayments Scheduled To </th>
<td mat-cell *matCellDef="let holidays"> {{ holidays.reschedulingType === 1 ? 'Next Repayment Date' : holidays.repaymentsRescheduledTo | date }} </td>
</ng-container>
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Status </th>
<td mat-cell *matCellDef="let holidays"> {{ holidays.status.value }} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" class="select-row"></tr>
</table>
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
</div>
</div>
@@ -0,0 +1,7 @@
table {
width: 100%;
.select-row:hover {
cursor: pointer;
}
}
@@ -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<HolidaysComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HolidaysComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(HolidaysComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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<any>;
/** 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;
}
}
@@ -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
}
}
]
}
@@ -16,7 +16,7 @@
<p matLine>Add new office or modify or deactivate office or modify hierarchy</p>
</mat-list-item>
<mat-list-item>
<mat-list-item [routerLink]="['holidays']">
<mat-icon matListIcon>
<fa-icon icon="calendar-alt" size="sm"></fa-icon>
</mat-icon>
+3 -1
View File
@@ -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 { }
@@ -227,4 +227,14 @@ export class OrganizationService {
return this.http.put('/workingdays', workingDays);
}
/*
* @param {string} officeId Office ID of Holidays.
* @returns {Observable<any>} Holidays data.
*/
getHolidays(officeId: string): Observable<any> {
const httpParams = new HttpParams()
.set('officeId', officeId.toString());
return this.http.get('/holidays', { params: httpParams });
}
}