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,62 @@
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
<button mat-raised-button color="primary">
<fa-icon icon="sitemap"></fa-icon>&nbsp;&nbsp;
Tree View
</button>
<button mat-raised-button color="primary">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;
Create Office
</button>
<button mat-raised-button color="primary">
<fa-icon icon="upload"></fa-icon>&nbsp;&nbsp;
Import Offices
</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> Office Name </th>
<td mat-cell *matCellDef="let offices"> {{ offices.name }} </td>
</ng-container>
<ng-container matColumnDef="externalId">
<th mat-header-cell *matHeaderCellDef mat-sort-header> External ID </th>
<td mat-cell *matCellDef="let offices"> {{ offices.externalId }} </td>
</ng-container>
<ng-container matColumnDef="parentName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Parent Office </th>
<td mat-cell *matCellDef="let offices"> {{ offices.parentName }} </td>
</ng-container>
<ng-container matColumnDef="openingDate">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Opened On </th>
<td mat-cell *matCellDef="let offices"> {{ offices.openingDate | date }} </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 { OfficesComponent } from './offices.component';
describe('OfficesComponent', () => {
let component: OfficesComponent;
let fixture: ComponentFixture<OfficesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ OfficesComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(OfficesComponent);
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';
/**
* 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;
}
}
@@ -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';
/**
* Manage Offices data resolver.
*/
@Injectable()
export class OfficesResolver implements Resolve<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
constructor(private organizationService: OrganizationService) {}
/**
* Returns the offices data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.organizationService.getOffices();
}
}