feat: add offices component (#498)

Fixes: #148
This commit is contained in:
pwai
2019-12-08 00:51:18 +03:00
committed by Abhay Chawla
parent 36843a1ae8
commit e87a247254
9 changed files with 212 additions and 3 deletions
@@ -0,0 +1,65 @@
/** Angular Imports */
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
import { ActivatedRoute } from '@angular/router';
/** rxjs Imports */
import { of } from 'rxjs';
/**
* Offices component.
*/
@Component({
selector: 'mifosx-offices',
templateUrl: './offices.component.html',
styleUrls: ['./offices.component.scss']
})
export class OfficesComponent implements OnInit {
/** Offices data. */
officesData: any;
/** Columns to be displayed in offices table. */
displayedColumns: string[] = ['name', 'externalId', 'parentName', 'openingDate'];
/** Data source for offices table. */
dataSource: MatTableDataSource<any>;
/** Paginator for offices table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for offices table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the offices data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private route: ActivatedRoute) {
this.route.data.subscribe(( data: { offices: any }) => {
this.officesData = data.offices;
});
}
/**
* Filters data in offices table based on passed value.
* @param {string} filterValue Value to filter data.
*/
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
/**
* Sets the offices table.
*/
ngOnInit() {
this.setOffices();
}
/**
* Initializes the data source, paginator and sorter for offices table.
*/
setOffices() {
this.dataSource = new MatTableDataSource(this.officesData);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
}