From b6110a9c8a518b967aab615aa8b5ae6988e3fcca Mon Sep 17 00:00:00 2001 From: Abhay Chawla Date: Tue, 30 Jul 2019 23:06:09 +0530 Subject: [PATCH] feat(products): add share products component (#459) Add share products component to list all share products. Fixes: #458 --- src/app/products/products-routing.module.ts | 16 +++++++ src/app/products/products.component.html | 2 +- src/app/products/products.module.ts | 4 +- src/app/products/products.service.ts | 7 +++ .../share-products.component.html | 45 +++++++++++++++++++ .../share-products.component.scss | 3 ++ .../share-products.component.spec.ts | 25 +++++++++++ .../share-products.component.ts | 36 +++++++++++++++ .../share-products/share-products.resolver.ts | 31 +++++++++++++ 9 files changed, 167 insertions(+), 2 deletions(-) create mode 100644 src/app/products/share-products/share-products.component.html create mode 100644 src/app/products/share-products/share-products.component.scss create mode 100644 src/app/products/share-products/share-products.component.spec.ts create mode 100644 src/app/products/share-products/share-products.component.ts create mode 100644 src/app/products/share-products/share-products.resolver.ts diff --git a/src/app/products/products-routing.module.ts b/src/app/products/products-routing.module.ts index f8deb0c995..a7f121c391 100644 --- a/src/app/products/products-routing.module.ts +++ b/src/app/products/products-routing.module.ts @@ -18,6 +18,7 @@ import { SavingProductsComponent } from './saving-products/saving-products.compo import { CreateSavingProductComponent } from './saving-products/create-saving-product/create-saving-product.component'; import { ViewSavingProductComponent } from './saving-products/view-saving-product/view-saving-product.component'; import { EditSavingProductComponent } from './saving-products/edit-saving-product/edit-saving-product.component'; +import { ShareProductsComponent } from './share-products/share-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'; @@ -34,6 +35,7 @@ import { SavingProductsResolver } from './saving-products/saving-products.resolv import { SavingProductsTemplateResolver } from './saving-products/saving-products-template.resolver'; import { SavingProductResolver } from './saving-products/saving-product.resolver'; import { SavingProductAndTemplateResolver } from './saving-products/edit-saving-product/saving-product-and-template.resolver'; +import { ShareProductsResolver } from './share-products/share-products.resolver'; import { RecurringDepositProductsResolver } from './recurring-deposit-products/recurring-deposit-products.resolver'; import { ChargesResolver } from './charges/charges.resolver'; import { FixedDepositProductsResolver } from './fixed-deposit-products/fixed-deposit-products.resolver'; @@ -135,6 +137,19 @@ const routes: Routes = [ } ] }, + { + path: 'share-products', + data: { title: extract('Share Products'), breadcrumb: 'Share Products' }, + children: [ + { + path: '', + component: ShareProductsComponent, + resolve: { + shareProducts: ShareProductsResolver + } + } + ] + }, { path: 'tax-configurations', data: { title: extract('Manage Tax Configurations'), breadcrumb: 'Manage Tax Configurations' }, @@ -207,6 +222,7 @@ const routes: Routes = [ SavingProductsTemplateResolver, SavingProductResolver, SavingProductAndTemplateResolver, + ShareProductsResolver, RecurringDepositProductsResolver, ChargesResolver, FixedDepositProductsResolver, diff --git a/src/app/products/products.component.html b/src/app/products/products.component.html index 7cdcda6522..30a4637c72 100644 --- a/src/app/products/products.component.html +++ b/src/app/products/products.component.html @@ -24,7 +24,7 @@

Savings Products

Add new savings product or modify or inactivate savings product

- + diff --git a/src/app/products/products.module.ts b/src/app/products/products.module.ts index 6425707d81..4e3aa54a29 100644 --- a/src/app/products/products.module.ts +++ b/src/app/products/products.module.ts @@ -37,6 +37,7 @@ import { SavingProductPreviewStepComponent } from './saving-products/saving-prod import { CreateSavingProductComponent } from './saving-products/create-saving-product/create-saving-product.component'; import { ViewSavingProductComponent } from './saving-products/view-saving-product/view-saving-product.component'; import { EditSavingProductComponent } from './saving-products/edit-saving-product/edit-saving-product.component'; +import { ShareProductsComponent } from './share-products/share-products.component'; /** * Products Module @@ -78,7 +79,8 @@ import { EditSavingProductComponent } from './saving-products/edit-saving-produc SavingProductPreviewStepComponent, CreateSavingProductComponent, ViewSavingProductComponent, - EditSavingProductComponent + EditSavingProductComponent, + ShareProductsComponent ], entryComponents: [ ], diff --git a/src/app/products/products.service.ts b/src/app/products/products.service.ts index 478783c08b..226ad60e10 100644 --- a/src/app/products/products.service.ts +++ b/src/app/products/products.service.ts @@ -66,6 +66,13 @@ export class ProductsService { return this.http.put(`/savingsproducts/${savingProductId}`, savingProduct); } + /** + * @returns {Observable} Share products data + */ + getShareProducts(): Observable { + return this.http.get('/products/share'); + } + /** * @returns {Observable} Recurring deposit products data */ diff --git a/src/app/products/share-products/share-products.component.html b/src/app/products/share-products/share-products.component.html new file mode 100644 index 0000000000..2bd1af9cf0 --- /dev/null +++ b/src/app/products/share-products/share-products.component.html @@ -0,0 +1,45 @@ +
+ +
+ +
+ +
+ + Filter + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + +
Name {{ shareProduct.name }} Short Name {{ shareProduct.shortName }} Total Shares {{ shareProduct.totalShares }}
+ + + +
+ +
diff --git a/src/app/products/share-products/share-products.component.scss b/src/app/products/share-products/share-products.component.scss new file mode 100644 index 0000000000..1922e7ffa3 --- /dev/null +++ b/src/app/products/share-products/share-products.component.scss @@ -0,0 +1,3 @@ +table { + width: 100%; +} diff --git a/src/app/products/share-products/share-products.component.spec.ts b/src/app/products/share-products/share-products.component.spec.ts new file mode 100644 index 0000000000..ec64f768cd --- /dev/null +++ b/src/app/products/share-products/share-products.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ShareProductsComponent } from './share-products.component'; + +describe('ShareProductsComponent', () => { + let component: ShareProductsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ShareProductsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ShareProductsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/products/share-products/share-products.component.ts b/src/app/products/share-products/share-products.component.ts new file mode 100644 index 0000000000..c3988d8562 --- /dev/null +++ b/src/app/products/share-products/share-products.component.ts @@ -0,0 +1,36 @@ +/** Angular Imports */ +import { Component, OnInit, ViewChild } from '@angular/core'; +import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material'; +import { ActivatedRoute } from '@angular/router'; + +@Component({ + selector: 'mifosx-share-products', + templateUrl: './share-products.component.html', + styleUrls: ['./share-products.component.scss'] +}) +export class ShareProductsComponent implements OnInit { + + shareProductsData: any; + displayedColumns: string[] = ['name', 'shortName', 'totalShares']; + dataSource: MatTableDataSource; + + @ViewChild(MatPaginator) paginator: MatPaginator; + @ViewChild(MatSort) sort: MatSort; + + constructor(private route: ActivatedRoute) { + this.route.data.subscribe((data: { shareProducts: any }) => { + this.shareProductsData = data.shareProducts.pageItems; + }); + } + + ngOnInit() { + this.dataSource = new MatTableDataSource(this.shareProductsData); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + } + + applyFilter(filterValue: string) { + this.dataSource.filter = filterValue.trim().toLowerCase(); + } + +} diff --git a/src/app/products/share-products/share-products.resolver.ts b/src/app/products/share-products/share-products.resolver.ts new file mode 100644 index 0000000000..bf44229f8f --- /dev/null +++ b/src/app/products/share-products/share-products.resolver.ts @@ -0,0 +1,31 @@ +/** 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'; + +/** + * Share products data resolver. + */ +@Injectable() +export class ShareProductsResolver implements Resolve { + + /** + * + * @param {ProductsService} productsService Products service. + */ + constructor(private productsService: ProductsService) {} + + /** + * Returns the share products data. + * @returns {Observable} + */ + resolve(): Observable { + return this.productsService.getShareProducts(); + } + +}