feat: add view teller component (#554)

Fixes: #535
This commit is contained in:
Rishabh Verma
2020-01-12 00:33:52 +03:00
committed by Abhay Chawla
parent d4281628ea
commit d6edcf0554
9 changed files with 233 additions and 6 deletions
@@ -0,0 +1,31 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { OrganizationService } from 'app/organization/organization.service';
/**
* Teller data resolver.
*/
@Injectable()
export class TellerResolver implements Resolve<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
constructor(private organizationService: OrganizationService) {}
/**
* Returns the teller data.
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const tellerId = route.paramMap.get('id');
return this.organizationService.getTeller(tellerId);
}
}
@@ -46,7 +46,7 @@
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let teller">
<td mat-cell *matCellDef="let teller" (click)="$event.stopPropagation()">
<button mat-button color="primary">
<fa-icon icon="eye"></fa-icon>&nbsp;&nbsp;View Cashiers
</button>
@@ -54,7 +54,7 @@
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" class="select-row"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="[row.id]" class="select-row"></tr>
</table>
@@ -0,0 +1,66 @@
<div fxLayout="row" fxLayoutAlign="end" fxLayoutGap="2%" fxLayout.lt-md="column" class="container m-b-20">
<button mat-raised-button color="primary">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;
Edit
</button>
<button mat-raised-button color="warn" (click)="deleteTeller()">
<fa-icon icon="trash"></fa-icon>&nbsp;&nbsp;
Delete
</button>
</div>
<div class="container">
<mat-card>
<mat-card-content>
<div fxLayout="row wrap" class="content">
<div fxFlex="50%" class="mat-body-strong">
Office
</div>
<div fxFlex="50%">
{{ tellerData.officeName }}
</div>
<div fxFlex="50%" class="mat-body-strong" *ngIf="tellerData.description">
Description
</div>
<div fxFlex="50%" *ngIf="tellerData.description">
{{ tellerData.description }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Start Date
</div>
<div fxFlex="50%">
{{ tellerData.startDate | date }}
</div>
<div fxFlex="50%" class="mat-body-strong" *ngIf="tellerData.endDate">
End Date
</div>
<div fxFlex="50%" *ngIf="tellerData.endDate">
{{ tellerData.endDate | date }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Status
</div>
<div fxFlex="50%">
{{ tellerData.status | titlecase }}
</div>
</div>
</mat-card-content>
</mat-card>
</div>
@@ -0,0 +1,10 @@
.container {
max-width: 37rem;
.content {
div {
margin: 1rem 0;
word-wrap: break-word;
}
}
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ViewTellerComponent } from './view-teller.component';
describe('ViewTellerComponent', () => {
let component: ViewTellerComponent;
let fixture: ComponentFixture<ViewTellerComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ViewTellerComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ViewTellerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,61 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material';
/** Custom Services */
import { OrganizationService } from 'app/organization/organization.service';
/** Custom Components */
import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component';
/**
* View Teller Component.
*/
@Component({
selector: 'mifosx-view-teller',
templateUrl: './view-teller.component.html',
styleUrls: ['./view-teller.component.scss']
})
export class ViewTellerComponent implements OnInit {
/** Teller data. */
tellerData: any;
/**
* Retrieves the Teller data from `resolve`.
* @param {OrganizationService} organizationService Organization Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {MatDialog} dialog Dialog reference.
*/
constructor(private organizationService: OrganizationService,
private route: ActivatedRoute,
private router: Router,
public dialog: MatDialog) {
this.route.data.subscribe((data: { teller: any }) => {
this.tellerData = data.teller;
});
}
ngOnInit() {
}
/**
* Deletes the teller and redirects to tellers.
*/
deleteTeller() {
const deleteTellerDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `teller ${this.tellerData.id}` }
});
deleteTellerDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.organizationService.deleteTeller(this.tellerData.id)
.subscribe(() => {
this.router.navigate(['/organization/tellers']);
});
}
});
}
}