Skip to content

Commit

Permalink
feat(products): add share products component (openMF#459)
Browse files Browse the repository at this point in the history
Add share products component to list all share products.

Fixes: #458
  • Loading branch information
abhaychawla committed Dec 1, 2019
1 parent 9d0e7d3 commit b6110a9
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/app/products/products-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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' },
Expand Down Expand Up @@ -207,6 +222,7 @@ const routes: Routes = [
SavingProductsTemplateResolver,
SavingProductResolver,
SavingProductAndTemplateResolver,
ShareProductsResolver,
RecurringDepositProductsResolver,
ChargesResolver,
FixedDepositProductsResolver,
Expand Down
2 changes: 1 addition & 1 deletion src/app/products/products.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h4 matLine>Savings Products</h4>
<p matLine>Add new savings product or modify or inactivate savings product</p>
</mat-list-item>

<mat-list-item>
<mat-list-item [routerLink]="['share-products']">
<mat-icon matListIcon>
<fa-icon icon="briefcase" size="sm"></fa-icon>
</mat-icon>
Expand Down
4 changes: 3 additions & 1 deletion src/app/products/products.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,7 +79,8 @@ import { EditSavingProductComponent } from './saving-products/edit-saving-produc
SavingProductPreviewStepComponent,
CreateSavingProductComponent,
ViewSavingProductComponent,
EditSavingProductComponent
EditSavingProductComponent,
ShareProductsComponent
],
entryComponents: [
],
Expand Down
7 changes: 7 additions & 0 deletions src/app/products/products.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export class ProductsService {
return this.http.put(`/savingsproducts/${savingProductId}`, savingProduct);
}

/**
* @returns {Observable<any>} Share products data
*/
getShareProducts(): Observable<any> {
return this.http.get('/products/share');
}

/**
* @returns {Observable<any>} Recurring deposit products data
*/
Expand Down
45 changes: 45 additions & 0 deletions src/app/products/share-products/share-products.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
<button mat-raised-button color="primary">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp;
Create Share Product
</button>
</div>

<div class="container">

<div fxLayout="row">
<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 shareProduct"> {{ shareProduct.name }} </td>
</ng-container>

<ng-container matColumnDef="shortName">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Short Name </th>
<td mat-cell *matCellDef="let shareProduct"> {{ shareProduct.shortName }} </td>
</ng-container>

<ng-container matColumnDef="totalShares">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Total Shares </th>
<td mat-cell *matCellDef="let shareProduct"> {{ shareProduct.totalShares }} </td>
</ng-container>

<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>

</table>

<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>

</div>

</div>
3 changes: 3 additions & 0 deletions src/app/products/share-products/share-products.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
table {
width: 100%;
}
25 changes: 25 additions & 0 deletions src/app/products/share-products/share-products.component.spec.ts
Original file line number Diff line number Diff line change
@@ -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<ShareProductsComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ShareProductsComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ShareProductsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
36 changes: 36 additions & 0 deletions src/app/products/share-products/share-products.component.ts
Original file line number Diff line number Diff line change
@@ -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<any>;

@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();
}

}
31 changes: 31 additions & 0 deletions src/app/products/share-products/share-products.resolver.ts
Original file line number Diff line number Diff line change
@@ -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<Object> {

/**
*
* @param {ProductsService} productsService Products service.
*/
constructor(private productsService: ProductsService) {}

/**
* Returns the share products data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.productsService.getShareProducts();
}

}

0 comments on commit b6110a9

Please sign in to comment.