feat: add charges component (#344)
This commit is contained in:
committed by
Abhay Chawla
parent
e40158bd6e
commit
6d125b3525
@@ -0,0 +1,57 @@
|
||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||
<button mat-raised-button color="primary">
|
||||
<fa-icon icon="plus"></fa-icon>
|
||||
Create Charge
|
||||
</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> Name </th>
|
||||
<td mat-cell *matCellDef="let charge"> {{ charge.name }} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="chargeAppliesTo">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Charge Applies To </th>
|
||||
<td mat-cell *matCellDef="let charge"> {{ charge.chargeAppliesTo.value }} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="penalty">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Is Penalty? </th>
|
||||
<td mat-cell *matCellDef="let charge">
|
||||
<fa-icon *ngIf="charge.penalty" icon="check-circle" size="lg" class="ispenalty" matTooltip="Yes" matTooltipPosition="right"></fa-icon>
|
||||
<fa-icon *ngIf="!charge.penalty" icon="times-circle" size="lg" class="nopenalty" matTooltip="No" matTooltipPosition="right"></fa-icon>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="active">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Status </th>
|
||||
<td mat-cell *matCellDef="let charge">
|
||||
<div [className]="charge.active === true ? 'true' : 'false'">
|
||||
<fa-icon matTooltip="{{ charge.active === 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,23 @@
|
||||
table {
|
||||
width: 100%;
|
||||
|
||||
.select-row:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.true {
|
||||
color: #32cd32;
|
||||
}
|
||||
|
||||
.false {
|
||||
color: #f44366;
|
||||
}
|
||||
|
||||
.ispenalty {
|
||||
color: #32cd32;
|
||||
}
|
||||
|
||||
.nopenalty {
|
||||
color: #f44366;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ChargesComponent } from './charges.component';
|
||||
|
||||
describe('ChargesComponent', () => {
|
||||
let component: ChargesComponent;
|
||||
let fixture: ComponentFixture<ChargesComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ChargesComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ChargesComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
/** Angular Imports */
|
||||
import { Component, ViewChild, OnInit } from '@angular/core';
|
||||
import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
/** rxjs Imports */
|
||||
import { of } from 'rxjs';
|
||||
|
||||
/**
|
||||
* Charges component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-charges',
|
||||
templateUrl: './charges.component.html',
|
||||
styleUrls: ['./charges.component.scss']
|
||||
})
|
||||
export class ChargesComponent implements OnInit {
|
||||
|
||||
/** Charge data. */
|
||||
chargeData: any;
|
||||
/** Columns to be displayed in charges table. */
|
||||
displayedColumns: string[] = ['name', 'chargeAppliesTo', 'penalty', 'active'];
|
||||
/** Data source for charges table. */
|
||||
dataSource: MatTableDataSource<any>;
|
||||
|
||||
/** Paginator for charges table. */
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
/** Sorter for charges table. */
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
|
||||
/**
|
||||
* Retrieves the charges data from `resolve`.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
*/
|
||||
constructor(private route: ActivatedRoute) {
|
||||
this.route.data.subscribe(( data: { charges: any }) => {
|
||||
this.chargeData = data.charges;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters data in charges table based on passed value.
|
||||
* @param {string} filterValue Value to filter data.
|
||||
*/
|
||||
applyFilter(filterValue: string) {
|
||||
this.dataSource.filter = filterValue.trim().toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the charges table.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.setCharges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the data source, paginator and sorter for charges table.
|
||||
*/
|
||||
setCharges() {
|
||||
this.dataSource = new MatTableDataSource(this.chargeData);
|
||||
this.dataSource.paginator = this.paginator;
|
||||
this.dataSource.sortingDataAccessor = (charge: any, property: any) => {
|
||||
switch (property) {
|
||||
case 'chargeAppliesTo': return charge.chargeAppliesTo.value;
|
||||
default: return charge[property];
|
||||
}
|
||||
};
|
||||
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 { ProductsService } from '../products.service';
|
||||
|
||||
/**
|
||||
* Charges data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class ChargesResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {ProductsService} productsService Products service.
|
||||
*/
|
||||
constructor(private productsService: ProductsService) {}
|
||||
|
||||
/**
|
||||
* Returns the products data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(): Observable<any> {
|
||||
return this.productsService.getCharges();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,9 +12,11 @@ import { extract } from '../core/i18n/i18n.service';
|
||||
import { ProductsComponent } from './products.component';
|
||||
import { ManageTaxConfigurationsComponent } from './manage-tax-configurations/manage-tax-configurations.component';
|
||||
import { RecurringDepositProductsComponent } from './recurring-deposit-products/recurring-deposit-products.component';
|
||||
import { ChargesComponent } from './charges/charges.component';
|
||||
|
||||
/** Custom Resolvers */
|
||||
import { RecurringDepositProductsResolver } from './recurring-deposit-products/recurring-deposit-products.resolver';
|
||||
import { ChargesResolver } from './charges/charges.resolver';
|
||||
|
||||
/** Products Routes */
|
||||
const routes: Routes = [
|
||||
@@ -40,6 +42,14 @@ const routes: Routes = [
|
||||
},
|
||||
data: { title: extract('Recurring Deposit Products'), breadcrumb: 'Recurring Deposit Products' },
|
||||
},
|
||||
{
|
||||
path: 'charges',
|
||||
component: ChargesComponent,
|
||||
resolve: {
|
||||
charges: ChargesResolver
|
||||
},
|
||||
data: { title: extract('Charges'), breadcrumb: 'Charges' },
|
||||
},
|
||||
]
|
||||
}
|
||||
])
|
||||
@@ -55,6 +65,7 @@ const routes: Routes = [
|
||||
exports: [RouterModule],
|
||||
providers: [
|
||||
RecurringDepositProductsResolver,
|
||||
ChargesResolver,
|
||||
]
|
||||
})
|
||||
export class ProductsRoutingModule { }
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
<p matLine>Add new share product or modify or inactivate share product</p>
|
||||
</mat-list-item>
|
||||
|
||||
<mat-list-item>
|
||||
<mat-list-item [routerLink]="['charges']">
|
||||
<mat-icon matListIcon>
|
||||
<fa-icon icon="money-bill-alt" size="sm"></fa-icon>
|
||||
</mat-icon>
|
||||
|
||||
@@ -9,6 +9,7 @@ import { ProductsRoutingModule } from './products-routing.module';
|
||||
import { ProductsComponent } from './products.component';
|
||||
import { ManageTaxConfigurationsComponent } from './manage-tax-configurations/manage-tax-configurations.component';
|
||||
import { RecurringDepositProductsComponent } from './recurring-deposit-products/recurring-deposit-products.component';
|
||||
import { ChargesComponent } from './charges/charges.component';
|
||||
|
||||
/**
|
||||
* Products Module
|
||||
@@ -23,7 +24,8 @@ import { RecurringDepositProductsComponent } from './recurring-deposit-products/
|
||||
declarations: [
|
||||
ProductsComponent,
|
||||
ManageTaxConfigurationsComponent,
|
||||
RecurringDepositProductsComponent
|
||||
RecurringDepositProductsComponent,
|
||||
ChargesComponent
|
||||
],
|
||||
entryComponents: [
|
||||
]
|
||||
|
||||
@@ -26,4 +26,12 @@ export class ProductsService {
|
||||
return this.http.get('/recurringdepositproducts');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} Fetches charges.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
getCharges(): Observable<any> {
|
||||
return this.http.get('/charges');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user