feat: add manage hooks component (#339)

Fixes #179
This commit is contained in:
Jonathan Zhang
2018-12-08 21:34:28 +05:30
committed by Abhay Chawla
parent 0229cf2515
commit 40e328ceb4
9 changed files with 207 additions and 3 deletions
@@ -0,0 +1,49 @@
<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 Hook
</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="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Hook Template </th>
<td mat-cell *matCellDef="let hook"> {{ hook.name }} </td>
</ng-container>
<ng-container matColumnDef="displayName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Hook Name </th>
<td mat-cell *matCellDef="let hook"> {{ hook.displayName }} </td>
</ng-container>
<ng-container matColumnDef="isActive">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Status </th>
<td mat-cell *matCellDef="let hook">
<div [className]="hook.isActive === true ? 'true' : 'false'">
<fa-icon matTooltip="{{ hook.isActive === true ? 'Active' : 'Inactive' }}" matTooltipPosition="right" icon="circle" size="lg"></fa-icon>
</div>
</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,15 @@
table {
width: 100%;
.select-row:hover {
cursor: pointer;
}
}
.true {
color: #32cd32;
}
.false {
color: #f44366;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ManageHooksComponent } from './manage-hooks.component';
describe('ManageHooksComponent', () => {
let component: ManageHooksComponent;
let fixture: ComponentFixture<ManageHooksComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ManageHooksComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ManageHooksComponent);
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 Hooks component.
*/
@Component({
selector: 'mifosx-manage-hooks',
templateUrl: './manage-hooks.component.html',
styleUrls: ['./manage-hooks.component.scss']
})
export class ManageHooksComponent implements OnInit {
/** Hook data. */
hookData: any;
/** Columns to be displayed in manage hooks table. */
displayedColumns: string[] = ['name', 'displayName', 'isActive'];
/** Data source for manage hooks table. */
dataSource: MatTableDataSource<any>;
/** Paginator for manage hooks table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for manage hooks table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the hooks data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private route: ActivatedRoute) {
this.route.data.subscribe(( data: { hooks: any }) => {
this.hookData = data.hooks;
});
}
/**
* 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 hooks table.
*/
ngOnInit() {
this.setHooks();
}
/**
* Initializes the data source, paginator and sorter for manage hooks table.
*/
setHooks() {
this.dataSource = new MatTableDataSource(this.hookData);
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 hooks data resolver.
*/
@Injectable()
export class ManageHooksResolver implements Resolve<Object> {
/**
* @param {SystemService} systemService System service.
*/
constructor(private systemService: SystemService) {}
/**
* Returns the manage hooks data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.systemService.getHooks();
}
}