From 6d125b3525b72d11eebd6e2d52744f88e3ff1678 Mon Sep 17 00:00:00 2001
From: Jonathan Zhang <41968151+jonathanzhang53@users.noreply.github.com>
Date: Sun, 9 Dec 2018 09:48:16 -0600
Subject: [PATCH] feat: add charges component (#344)
---
.../products/charges/charges.component.html | 57 +++++++++++++++
.../products/charges/charges.component.scss | 23 ++++++
.../charges/charges.component.spec.ts | 25 +++++++
src/app/products/charges/charges.component.ts | 71 +++++++++++++++++++
src/app/products/charges/charges.resolver.ts | 30 ++++++++
src/app/products/products-routing.module.ts | 11 +++
src/app/products/products.component.html | 2 +-
src/app/products/products.module.ts | 4 +-
src/app/products/products.service.ts | 8 +++
9 files changed, 229 insertions(+), 2 deletions(-)
create mode 100644 src/app/products/charges/charges.component.html
create mode 100644 src/app/products/charges/charges.component.scss
create mode 100644 src/app/products/charges/charges.component.spec.ts
create mode 100644 src/app/products/charges/charges.component.ts
create mode 100644 src/app/products/charges/charges.resolver.ts
diff --git a/src/app/products/charges/charges.component.html b/src/app/products/charges/charges.component.html
new file mode 100644
index 000000000..23493cbca
--- /dev/null
+++ b/src/app/products/charges/charges.component.html
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+ Filter
+
+
+
+
+
+
+
+
+
+ | Name |
+ {{ charge.name }} |
+
+
+
+ Charge Applies To |
+ {{ charge.chargeAppliesTo.value }} |
+
+
+
+ Is Penalty? |
+
+
+
+ |
+
+
+
+ Status |
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/app/products/charges/charges.component.scss b/src/app/products/charges/charges.component.scss
new file mode 100644
index 000000000..678bf8f3d
--- /dev/null
+++ b/src/app/products/charges/charges.component.scss
@@ -0,0 +1,23 @@
+table {
+ width: 100%;
+
+ .select-row:hover {
+ cursor: pointer;
+ }
+}
+
+.true {
+ color: #32cd32;
+}
+
+.false {
+ color: #f44366;
+}
+
+.ispenalty {
+ color: #32cd32;
+}
+
+.nopenalty {
+ color: #f44366;
+}
diff --git a/src/app/products/charges/charges.component.spec.ts b/src/app/products/charges/charges.component.spec.ts
new file mode 100644
index 000000000..ddd24e84d
--- /dev/null
+++ b/src/app/products/charges/charges.component.spec.ts
@@ -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;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ ChargesComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(ChargesComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/products/charges/charges.component.ts b/src/app/products/charges/charges.component.ts
new file mode 100644
index 000000000..fd7f00f54
--- /dev/null
+++ b/src/app/products/charges/charges.component.ts
@@ -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;
+
+ /** 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;
+ }
+
+}
diff --git a/src/app/products/charges/charges.resolver.ts b/src/app/products/charges/charges.resolver.ts
new file mode 100644
index 000000000..eca5b1c5c
--- /dev/null
+++ b/src/app/products/charges/charges.resolver.ts
@@ -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