Skip to content

Commit

Permalink
feat: add create share product component (openMF#462)
Browse files Browse the repository at this point in the history
- Add share product stepper components
- Add create share product component
- Add datepicker-base.ts

Fixes: #190
  • Loading branch information
abhaychawla committed Dec 1, 2019
1 parent 5436c10 commit c3dcd48
Show file tree
Hide file tree
Showing 44 changed files with 1,691 additions and 28 deletions.
11 changes: 11 additions & 0 deletions src/app/products/products-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CreateSavingProductComponent } from './saving-products/create-saving-pr
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 { CreateShareProductComponent } from './share-products/create-share-product/create-share-product.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 @@ -36,6 +37,7 @@ import { SavingProductsTemplateResolver } from './saving-products/saving-product
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 { ShareProductsTemplateResolver } from './share-products/share-products-template.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 @@ -147,6 +149,14 @@ const routes: Routes = [
resolve: {
shareProducts: ShareProductsResolver
}
},
{
path: 'create',
component: CreateShareProductComponent,
data: { title: extract('Create Share Product'), breadcrumb: 'Create' },
resolve: {
shareProductsTemplate: ShareProductsTemplateResolver
}
}
]
},
Expand Down Expand Up @@ -223,6 +233,7 @@ const routes: Routes = [
SavingProductResolver,
SavingProductAndTemplateResolver,
ShareProductsResolver,
ShareProductsTemplateResolver,
RecurringDepositProductsResolver,
ChargesResolver,
FixedDepositProductsResolver,
Expand Down
20 changes: 19 additions & 1 deletion src/app/products/products.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ import { CreateSavingProductComponent } from './saving-products/create-saving-pr
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 { ShareProductDetailsStepComponent } from './share-products/share-product-stepper/share-product-details-step/share-product-details-step.component';
import { ShareProductCurrencyStepComponent } from './share-products/share-product-stepper/share-product-currency-step/share-product-currency-step.component';
import { ShareProductTermsStepComponent } from './share-products/share-product-stepper/share-product-terms-step/share-product-terms-step.component';
import { ShareProductSettingsStepComponent } from './share-products/share-product-stepper/share-product-settings-step/share-product-settings-step.component';
import { ShareProductMarketPriceStepComponent } from './share-products/share-product-stepper/share-product-market-price-step/share-product-market-price-step.component';
import { ShareProductChargesStepComponent } from './share-products/share-product-stepper/share-product-charges-step/share-product-charges-step.component';
import { ShareProductAccountingStepComponent } from './share-products/share-product-stepper/share-product-accounting-step/share-product-accounting-step.component';
import { ShareProductPreviewStepComponent } from './share-products/share-product-stepper/share-product-preview-step/share-product-preview-step.component';
import { CreateShareProductComponent } from './share-products/create-share-product/create-share-product.component';

/**
* Products Module
Expand Down Expand Up @@ -80,7 +89,16 @@ import { ShareProductsComponent } from './share-products/share-products.componen
CreateSavingProductComponent,
ViewSavingProductComponent,
EditSavingProductComponent,
ShareProductsComponent
ShareProductsComponent,
ShareProductDetailsStepComponent,
ShareProductCurrencyStepComponent,
ShareProductTermsStepComponent,
ShareProductSettingsStepComponent,
ShareProductMarketPriceStepComponent,
ShareProductChargesStepComponent,
ShareProductAccountingStepComponent,
ShareProductPreviewStepComponent,
CreateShareProductComponent
],
entryComponents: [
],
Expand Down
8 changes: 8 additions & 0 deletions src/app/products/products.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ export class ProductsService {
return this.http.get('/products/share');
}

createShareProduct(shareProduct: string): Observable<any> {
return this.http.post('/products/share', shareProduct);
}

getShareProductsTemplate(): Observable<any> {
return this.http.get('/products/share/template');
}

/**
* @returns {Observable<any>} Recurring deposit products data
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<div class="container">

<mat-horizontal-stepper class="mat-elevation-z8" labelPosition="bottom" #shareProductStepper>

<ng-template matStepperIcon="number">
<fa-icon icon="pencil-alt" size="sm"></fa-icon>
</ng-template>

<ng-template matStepperIcon="edit">
<fa-icon icon="pencil-alt" size="sm"></fa-icon>
</ng-template>

<ng-template matStepperIcon="done">
<fa-icon icon="check" size="sm"></fa-icon>
</ng-template>

<ng-template matStepperIcon="error">
<fa-icon icon="exclamation-triangle" size="lg"></fa-icon>
</ng-template>

<ng-template matStepperIcon="preview">
<fa-icon icon="eye" size="sm"></fa-icon>
</ng-template>

<mat-step [stepControl]="shareProductDetailsForm">

<ng-template matStepLabel>DETAILS</ng-template>

<mifosx-share-product-details-step></mifosx-share-product-details-step>

</mat-step>

<mat-step [stepControl]="shareProductCurrencyForm">

<ng-template matStepLabel>CURRENCY</ng-template>

<mifosx-share-product-currency-step [shareProductsTemplate]="shareProductsTemplate"></mifosx-share-product-currency-step>

</mat-step>

<mat-step [stepControl]="shareProductTermsForm">

<ng-template matStepLabel>TERMS</ng-template>

<mifosx-share-product-terms-step></mifosx-share-product-terms-step>

</mat-step>

<mat-step [stepControl]="shareProductSettingsForm">

<ng-template matStepLabel>SETTINGS</ng-template>

<mifosx-share-product-settings-step [shareProductsTemplate]="shareProductsTemplate"></mifosx-share-product-settings-step>

</mat-step>

<mat-step>

<ng-template matStepLabel>MARKET PRICE</ng-template>

<mifosx-share-product-market-price-step></mifosx-share-product-market-price-step>

</mat-step>

<mat-step>

<ng-template matStepLabel>CHARGES</ng-template>

<mifosx-share-product-charges-step
[shareProductsTemplate]="shareProductsTemplate"
[currencyCode]="shareProductCurrencyForm.get('currencyCode')"
>
</mifosx-share-product-charges-step>

</mat-step>

<mat-step [stepControl]="shareProductAccountingForm">

<ng-template matStepLabel>ACCOUNTING</ng-template>

<mifosx-share-product-accounting-step
[shareProductsTemplate]="shareProductsTemplate"
[accountingRuleData]="accountingRuleData"
[shareProductFormValid]="shareProductFormValid"
>
</mifosx-share-product-accounting-step>

</mat-step>

<mat-step state="preview" *ngIf="shareProductFormValid" completed>

<ng-template matStepLabel>PREVIEW</ng-template>

<mifosx-share-product-preview-step
[shareProductsTemplate]="shareProductsTemplate"
[accountingRuleData]="accountingRuleData"
[shareProduct]="shareProduct"
(submit)="submit()"
>
</mifosx-share-product-preview-step>

</mat-step>

</mat-horizontal-stepper>

</div>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { CreateShareProductComponent } from './create-share-product.component';

describe('CreateShareProductComponent', () => {
let component: CreateShareProductComponent;
let fixture: ComponentFixture<CreateShareProductComponent>;

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

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';

import { ShareProductDetailsStepComponent } from '../share-product-stepper/share-product-details-step/share-product-details-step.component';
import { ShareProductCurrencyStepComponent } from '../share-product-stepper/share-product-currency-step/share-product-currency-step.component';
import { ShareProductTermsStepComponent } from '../share-product-stepper/share-product-terms-step/share-product-terms-step.component';
import { ShareProductSettingsStepComponent } from '../share-product-stepper/share-product-settings-step/share-product-settings-step.component';
import { ShareProductMarketPriceStepComponent } from '../share-product-stepper/share-product-market-price-step/share-product-market-price-step.component';
import { ShareProductChargesStepComponent } from '../share-product-stepper/share-product-charges-step/share-product-charges-step.component';
import { ShareProductAccountingStepComponent } from '../share-product-stepper/share-product-accounting-step/share-product-accounting-step.component';

import { ProductsService } from 'app/products/products.service';

@Component({
selector: 'mifosx-create-share-product',
templateUrl: './create-share-product.component.html',
styleUrls: ['./create-share-product.component.scss']
})
export class CreateShareProductComponent implements OnInit {

@ViewChild(ShareProductDetailsStepComponent) shareProductDetailsStep: ShareProductDetailsStepComponent;
@ViewChild(ShareProductCurrencyStepComponent) shareProductCurrencyStep: ShareProductCurrencyStepComponent;
@ViewChild(ShareProductTermsStepComponent) shareProductTermsStep: ShareProductTermsStepComponent;
@ViewChild(ShareProductSettingsStepComponent) shareProductSettingsStep: ShareProductSettingsStepComponent;
@ViewChild(ShareProductMarketPriceStepComponent) shareProductMarketPriceStep: ShareProductMarketPriceStepComponent;
@ViewChild(ShareProductChargesStepComponent) shareProductChargesStep: ShareProductChargesStepComponent;
@ViewChild(ShareProductAccountingStepComponent) shareProductAccountingStep: ShareProductAccountingStepComponent;

shareProductsTemplate: any;
accountingRuleData = ['None', 'Cash'];

constructor(private route: ActivatedRoute,
private productsService: ProductsService,
private router: Router) {
this.route.data.subscribe((data: { shareProductsTemplate: any }) => {
this.shareProductsTemplate = data.shareProductsTemplate;
});
}

ngOnInit() {
}

get shareProductDetailsForm() {
return this.shareProductDetailsStep.shareProductDetailsForm;
}

get shareProductCurrencyForm() {
return this.shareProductCurrencyStep.shareProductCurrencyForm;
}

get shareProductTermsForm() {
return this.shareProductTermsStep.shareProductTermsForm;
}

get shareProductSettingsForm() {
return this.shareProductSettingsStep.shareProductSettingsForm;
}

get shareProductMarketPriceForm() {
return this.shareProductMarketPriceStep.shareProductMarketPriceForm;
}

get shareProductAccountingForm() {
return this.shareProductAccountingStep.shareProductAccountingForm;
}

get shareProductFormValid() {
return (
this.shareProductDetailsForm.valid &&
this.shareProductCurrencyForm.valid &&
this.shareProductTermsForm.valid &&
this.shareProductSettingsForm.valid &&
this.shareProductMarketPriceForm.valid &&
this.shareProductAccountingForm.valid
);
}

get shareProduct() {
return {
...this.shareProductDetailsStep.shareProductDetails,
...this.shareProductCurrencyStep.shareProductCurrency,
...this.shareProductTermsStep.shareProductTerms,
...this.shareProductSettingsStep.shareProductSettings,
...this.shareProductMarketPriceStep.shareProductMarketPrice,
...this.shareProductChargesStep.shareProductCharges,
...this.shareProductAccountingStep.shareProductAccounting
};
}

submit() {
// TODO: Update once language and date settings are setup
const shareProduct = {
...this.shareProduct,
chargesSelected: this.shareProduct.chargesSelected.map((charge: any) => ({ id: charge.id })),
locale: 'en' // locale required for digitsAfterDecimal
};
this.productsService.createShareProduct(shareProduct)
.subscribe((response: any) => {
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
});
}

}
Loading

0 comments on commit c3dcd48

Please sign in to comment.