feat: add tellers component (#520)

Fixes: #159
This commit is contained in:
punwai
2019-12-23 21:31:24 +03:00
committed by Abhay Chawla
parent 6b250f081a
commit 34e1f4da36
9 changed files with 224 additions and 4 deletions
@@ -0,0 +1,65 @@
<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 Teller
</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="officeName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Branch </th>
<td mat-cell *matCellDef="let teller"> {{ teller.officeName }} </td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Teller Name </th>
<td mat-cell *matCellDef="let teller"> {{ teller.name }} </td>
</ng-container>
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Status </th>
<td mat-cell *matCellDef="let teller">
<div [className]="teller.status === 'ACTIVE' ? 'true' : 'false'">
<fa-icon matTooltip="{{ teller.status === 'ACTIVE' ? 'Active' : 'Inactive' }}" matTooltipPosition="right" icon="circle" size="lg"></fa-icon>
</div>
</td>
</ng-container>
<ng-container matColumnDef="startDate">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Started On </th>
<td mat-cell *matCellDef="let teller"> {{ teller.startDate | date }} </td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let teller">
<button mat-button color="primary">
<fa-icon icon="eye"></fa-icon>&nbsp;&nbsp;View Cashiers
</button>
</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 { TellersComponent } from './tellers.component';
describe('TellersComponent', () => {
let component: TellersComponent;
let fixture: ComponentFixture<TellersComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TellersComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TellersComponent);
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';
/**
* Tellers component.
*/
@Component({
selector: 'mifosx-tellers',
templateUrl: './tellers.component.html',
styleUrls: ['./tellers.component.scss']
})
export class TellersComponent implements OnInit {
/** Tellers data. */
tellersData: any;
/** Columns to be displayed in tellers table. */
displayedColumns: string[] = ['officeName', 'name', 'status', 'startDate', 'actions'];
/** Data source for tellers table. */
dataSource: MatTableDataSource<any>;
/** Paginator for tellers table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for tellers table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the tellers data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private route: ActivatedRoute) {
this.route.data.subscribe(( data: { tellers: any }) => {
this.tellersData = data.tellers;
});
}
/**
* Filters data in tellers table based on passed value.
* @param {string} filterValue Value to filter data.
*/
applyFilter(filterValue: string) {
this.dataSource.filter = filterValue.trim().toLowerCase();
}
/**
* Sets the tellers table.
*/
ngOnInit() {
this.setTellers();
}
/**
* Initializes the data source, paginator and sorter for tellers table.
*/
setTellers() {
this.dataSource = new MatTableDataSource(this.tellersData);
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 { OrganizationService } from '../organization.service';
/**
* Tellers data resolver.
*/
@Injectable()
export class TellersResolver implements Resolve<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
constructor(private organizationService: OrganizationService) {}
/**
* Returns the Tellers data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.organizationService.getTellers();
}
}