feat: add data tables component (#336)

Fixes #170
This commit is contained in:
Jonathan Zhang
2018-12-07 23:49:47 +05:30
committed by Abhay Chawla
parent 1c8e953e38
commit 0229cf2515
9 changed files with 191 additions and 2 deletions
@@ -0,0 +1,40 @@
<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 Data Table
</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>
</div>
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="registeredTableName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Data Table Name </th>
<td mat-cell *matCellDef="let dataTable"> {{ dataTable.registeredTableName }} </td>
</ng-container>
<ng-container matColumnDef="applicationTableName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Associated With </th>
<td mat-cell *matCellDef="let dataTable"> {{ dataTable.applicationTableName }} </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 { ManageDataTablesComponent } from './manage-data-tables.component';
describe('ManageDataTablesComponent', () => {
let component: ManageDataTablesComponent;
let fixture: ComponentFixture<ManageDataTablesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ManageDataTablesComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ManageDataTablesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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';
/**
* Manage Data Tables component.
*/
@Component({
selector: 'mifosx-manage-data-tables',
templateUrl: './manage-data-tables.component.html',
styleUrls: ['./manage-data-tables.component.scss']
})
export class ManageDataTablesComponent implements OnInit {
/** Data table data. */
dataTableData: any;
/** Columns to be displayed in manage data tables table. */
displayedColumns: string[] = ['registeredTableName', 'applicationTableName'];
/** Data source for manage data tables table. */
dataSource: MatTableDataSource<any>;
/** Paginator for manage data tables table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for manage data tables table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the data tables data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private route: ActivatedRoute) {
this.route.data.subscribe(( data: { dataTables: any }) => {
this.dataTableData = data.dataTables;
});
}
/**
* Filters data in manage data tables table based on passed value.
* @param {string} filterValue Value to filter data.
*/
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
/**
* Sets the manage data tables table.
*/
ngOnInit() {
this.setDataTables();
}
/**
* Initializes the data source, paginator and sorter for manage data tables table.
*/
setDataTables() {
this.dataSource = new MatTableDataSource(this.dataTableData);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
}
@@ -0,0 +1,30 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { SystemService } from '../system.service';
/**
* Manage data tables data resolver.
*/
@Injectable()
export class ManageDataTablesResolver implements Resolve<Object> {
/**
* @param {SystemService} systemService System service.
*/
constructor(private systemService: SystemService) {}
/**
* Returns the manage data tables data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.systemService.getDataTables();
}
}