feat: add edit share product component (#470)

- Update share product stepper components to support editing
- Add edit share product component

Fixes: #464
This commit is contained in:
Abhay Chawla
2019-12-01 23:20:51 +03:00
parent 409d0cfe30
commit 90be946675
17 changed files with 384 additions and 19 deletions
@@ -21,6 +21,7 @@ import { EditSavingProductComponent } from './saving-products/edit-saving-produc
import { ShareProductsComponent } from './share-products/share-products.component';
import { CreateShareProductComponent } from './share-products/create-share-product/create-share-product.component';
import { ViewShareProductComponent } from './share-products/view-share-product/view-share-product.component';
import { EditShareProductComponent } from './share-products/edit-share-product/edit-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';
@@ -40,6 +41,7 @@ import { SavingProductAndTemplateResolver } from './saving-products/edit-saving-
import { ShareProductsResolver } from './share-products/share-products.resolver';
import { ShareProductsTemplateResolver } from './share-products/share-products-template.resolver';
import { ShareProductResolver } from './share-products/share-product-resolver';
import { ShareProductAndTemplateResolver } from './share-products/edit-share-product/share-product-and-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';
@@ -171,6 +173,14 @@ const routes: Routes = [
shareProduct: ShareProductResolver
},
},
{
path: 'edit',
component: EditShareProductComponent,
data: { title: extract('Edit Share Product'), breadcrumb: 'Edit', routeParamBreadcrumb: false },
resolve: {
shareProductAndTemplate: ShareProductAndTemplateResolver
}
}
]
}
]
@@ -250,6 +260,7 @@ const routes: Routes = [
ShareProductsResolver,
ShareProductsTemplateResolver,
ShareProductResolver,
ShareProductAndTemplateResolver,
RecurringDepositProductsResolver,
ChargesResolver,
FixedDepositProductsResolver,
+3 -1
View File
@@ -48,6 +48,7 @@ import { ShareProductAccountingStepComponent } from './share-products/share-prod
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';
import { ViewShareProductComponent } from './share-products/view-share-product/view-share-product.component';
import { EditShareProductComponent } from './share-products/edit-share-product/edit-share-product.component';
/**
* Products Module
@@ -100,7 +101,8 @@ import { ViewShareProductComponent } from './share-products/view-share-product/v
ShareProductAccountingStepComponent,
ShareProductPreviewStepComponent,
CreateShareProductComponent,
ViewShareProductComponent
ViewShareProductComponent,
EditShareProductComponent
],
entryComponents: [
],
+7 -2
View File
@@ -81,8 +81,13 @@ export class ProductsService {
return this.http.get('/products/share/template');
}
getShareProduct(shareProductId: string): Observable<any> {
return this.http.get(`/products/share/${shareProductId}`);
getShareProduct(shareProductId: string, template: boolean = false): Observable<any> {
const httpParams = new HttpParams().set('template', template.toString());
return this.http.get(`/products/share/${shareProductId}`, { params: httpParams });
}
updateShareProduct(shareProductId: string, shareProduct: any): Observable<any> {
return this.http.put(`/products/share/${shareProductId}`, shareProduct);
}
/**
@@ -54,7 +54,7 @@
</mat-step>
<mat-step>
<mat-step [stepControl]="shareProductMarketPriceForm">
<ng-template matStepLabel>MARKET PRICE</ng-template>
@@ -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" completed>
<ng-template matStepLabel>DETAILS</ng-template>
<mifosx-share-product-details-step [shareProductsTemplate]="shareProductAndTemplate"></mifosx-share-product-details-step>
</mat-step>
<mat-step [stepControl]="shareProductCurrencyForm" completed>
<ng-template matStepLabel>CURRENCY</ng-template>
<mifosx-share-product-currency-step [shareProductsTemplate]="shareProductAndTemplate"></mifosx-share-product-currency-step>
</mat-step>
<mat-step [stepControl]="shareProductTermsForm" completed>
<ng-template matStepLabel>TERMS</ng-template>
<mifosx-share-product-terms-step [shareProductsTemplate]="shareProductAndTemplate"></mifosx-share-product-terms-step>
</mat-step>
<mat-step [stepControl]="shareProductSettingsForm" completed>
<ng-template matStepLabel>SETTINGS</ng-template>
<mifosx-share-product-settings-step [shareProductsTemplate]="shareProductAndTemplate"></mifosx-share-product-settings-step>
</mat-step>
<mat-step [stepControl]="shareProductMarketPriceForm" completed>
<ng-template matStepLabel>MARKET PRICE</ng-template>
<mifosx-share-product-market-price-step [shareProductsTemplate]="shareProductAndTemplate"></mifosx-share-product-market-price-step>
</mat-step>
<mat-step completed>
<ng-template matStepLabel>CHARGES</ng-template>
<mifosx-share-product-charges-step
[shareProductsTemplate]="shareProductAndTemplate"
[currencyCode]="shareProductCurrencyForm.get('currencyCode')"
>
</mifosx-share-product-charges-step>
</mat-step>
<mat-step [stepControl]="shareProductAccountingForm" completed>
<ng-template matStepLabel>ACCOUNTING</ng-template>
<mifosx-share-product-accounting-step
[shareProductsTemplate]="shareProductAndTemplate"
[accountingRuleData]="accountingRuleData"
[shareProductFormValid]="shareProductFormValidAndNotPristine"
>
</mifosx-share-product-accounting-step>
</mat-step>
<mat-step state="preview" *ngIf="shareProductFormValidAndNotPristine" completed>
<ng-template matStepLabel>PREVIEW</ng-template>
<mifosx-share-product-preview-step
[shareProductsTemplate]="shareProductAndTemplate"
[accountingRuleData]="accountingRuleData"
[shareProduct]="shareProduct"
(submit)="submit()"
>
</mifosx-share-product-preview-step>
</mat-step>
</mat-horizontal-stepper>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EditShareProductComponent } from './edit-share-product.component';
describe('EditShareProductComponent', () => {
let component: EditShareProductComponent;
let fixture: ComponentFixture<EditShareProductComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EditShareProductComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EditShareProductComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,112 @@
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-edit-share-product',
templateUrl: './edit-share-product.component.html',
styleUrls: ['./edit-share-product.component.scss']
})
export class EditShareProductComponent 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;
shareProductAndTemplate: any;
accountingRuleData = ['None', 'Cash'];
constructor(private route: ActivatedRoute,
private productsService: ProductsService,
private router: Router) {
this.route.data.subscribe((data: { shareProductAndTemplate: any }) => {
this.shareProductAndTemplate = data.shareProductAndTemplate;
});
}
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 shareProductFormValidAndNotPristine() {
return (
this.shareProductDetailsForm.valid &&
this.shareProductCurrencyForm.valid &&
this.shareProductTermsForm.valid &&
this.shareProductSettingsForm.valid &&
this.shareProductMarketPriceForm.valid &&
this.shareProductAccountingForm.valid &&
(
!this.shareProductDetailsForm.pristine ||
!this.shareProductCurrencyForm.pristine ||
!this.shareProductTermsForm.pristine ||
!this.shareProductSettingsForm.pristine ||
!this.shareProductMarketPriceForm.pristine ||
!this.shareProductChargesStep.pristine ||
!this.shareProductAccountingForm.pristine
)
);
}
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.updateShareProduct(this.shareProductAndTemplate.id, shareProduct)
.subscribe((response: any) => {
this.router.navigate(['../../', response.resourceId], { relativeTo: this.route });
});
}
}
@@ -0,0 +1,31 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { ProductsService } from '../../products.service';
/**
* Share product and template data resolver.
*/
@Injectable()
export class ShareProductAndTemplateResolver implements Resolve<Object> {
/**
* @param {ProductsService} productsService Products service.
*/
constructor(private productsService: ProductsService) {}
/**
* Returns the share product and template data.
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const shareProductId = route.paramMap.get('id');
return this.productsService.getShareProduct(shareProductId, true);
}
}
@@ -29,6 +29,21 @@ export class ShareProductAccountingStepComponent implements OnInit {
this.incomeAccountData = this.shareProductsTemplate.accountingMappingOptions.incomeAccountOptions || [];
this.equityAccountData = this.shareProductsTemplate.accountingMappingOptions.equityAccountOptions || [];
this.liabilityAccountData = this.shareProductsTemplate.accountingMappingOptions.liabilityAccountOptions || [];
if (this.shareProductsTemplate.accountingRule) {
this.shareProductAccountingForm.patchValue({
'accountingRule': this.shareProductsTemplate.accountingRule.id
});
if (this.shareProductsTemplate.accountingRule.id === 2) {
this.shareProductAccountingForm.patchValue({
'shareReferenceId': this.shareProductsTemplate.accountingMappings.shareReferenceId.id,
'shareSuspenseId': this.shareProductsTemplate.accountingMappings.shareSuspenseId.id,
'shareEquityId': this.shareProductsTemplate.accountingMappings.shareEquityId.id,
'incomeFromFeeAccountId': this.shareProductsTemplate.accountingMappings.incomeFromFeeAccountId.id
});
}
}
}
createShareProductAccountingForm() {
@@ -19,13 +19,16 @@ export class ShareProductChargesStepComponent implements OnInit {
chargesDataSource: {}[];
displayedColumns: string[] = ['name', 'chargeCalculationType', 'amount', 'chargeTimeType', 'action'];
pristine = true;
constructor(public dialog: MatDialog) {
}
ngOnInit() {
this.chargeData = this.shareProductsTemplate.chargeOptions;
this.chargesDataSource = [];
this.chargesDataSource = this.shareProductsTemplate.charges || [];
this.pristine = true;
this.currencyCode.valueChanges.subscribe(() => this.chargesDataSource = []);
}
@@ -33,6 +36,7 @@ export class ShareProductChargesStepComponent implements OnInit {
addCharge(charge: any) {
this.chargesDataSource = this.chargesDataSource.concat([charge.value]);
charge.value = '';
this.pristine = false;
}
deleteCharge(charge: any) {
@@ -43,6 +47,7 @@ export class ShareProductChargesStepComponent implements OnInit {
if (response.delete) {
this.chargesDataSource.splice(this.chargesDataSource.indexOf(charge), 1);
this.chargesDataSource = this.chargesDataSource.concat([]);
this.pristine = false;
}
});
}
@@ -21,10 +21,18 @@ export class ShareProductCurrencyStepComponent implements OnInit {
ngOnInit() {
this.currencyData = this.shareProductsTemplate.currencyOptions;
this.shareProductCurrencyForm.patchValue({
'currencyCode': this.currencyData[0].code,
'digitsAfterDecimal': 2
});
if (this.shareProductsTemplate.currency) {
this.shareProductCurrencyForm.patchValue({
'currencyCode': this.shareProductsTemplate.currency.code,
'digitsAfterDecimal': this.shareProductsTemplate.currency.decimalPlaces,
'inMultiplesOf': this.shareProductsTemplate.currency.inMultiplesOf
});
} else {
this.shareProductCurrencyForm.patchValue({
'currencyCode': this.currencyData[0].code,
'digitsAfterDecimal': 2
});
}
}
createShareProductCurrencyForm() {
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
@Component({
@@ -8,6 +8,8 @@ import { FormGroup, FormBuilder, Validators } from '@angular/forms';
})
export class ShareProductDetailsStepComponent implements OnInit {
@Input() shareProductsTemplate: any;
shareProductDetailsForm: FormGroup;
constructor(private formBuilder: FormBuilder) {
@@ -15,6 +17,13 @@ export class ShareProductDetailsStepComponent implements OnInit {
}
ngOnInit() {
if (this.shareProductsTemplate) {
this.shareProductDetailsForm.patchValue({
'name': this.shareProductsTemplate.name,
'shortName': this.shareProductsTemplate.shortName,
'description': this.shareProductsTemplate.description
});
}
}
createShareProductDetailsForm() {
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, Input } from '@angular/core';
import { DatePipe } from '@angular/common';
import { FormGroup, FormBuilder, FormArray } from '@angular/forms';
import { MatDialog } from '@angular/material';
@@ -17,6 +17,8 @@ import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base';
})
export class ShareProductMarketPriceStepComponent implements OnInit {
@Input() shareProductsTemplate: any;
shareProductMarketPriceForm: FormGroup;
displayedColumns: string[] = ['fromDate', 'shareValue', 'actions'];
@@ -28,6 +30,9 @@ export class ShareProductMarketPriceStepComponent implements OnInit {
}
ngOnInit() {
if (this.shareProductsTemplate) {
this.shareProductMarketPriceForm.setControl('marketPricePeriods', this.formBuilder.array((this.shareProductsTemplate.marketPrice)));
}
}
createShareProductMarketPriceForm() {
@@ -40,33 +45,42 @@ export class ShareProductMarketPriceStepComponent implements OnInit {
return this.shareProductMarketPriceForm.get('marketPricePeriods') as FormArray;
}
setShareProductMarketPriceFormDirty() {
if (this.shareProductMarketPriceForm.pristine) {
this.shareProductMarketPriceForm.markAsDirty();
}
}
addMarketPricePeriod() {
const data = this.getData();
const addVariationsForBorrowerCycleDialogRef = this.dialog.open(FormDialogComponent, { data });
addVariationsForBorrowerCycleDialogRef.afterClosed().subscribe((response: any) => {
const addMarketPricePeriodDialogRef = this.dialog.open(FormDialogComponent, { data });
addMarketPricePeriodDialogRef.afterClosed().subscribe((response: any) => {
if (response.data) {
this.marketPricePeriods.push(response.data);
this.setShareProductMarketPriceFormDirty();
}
});
}
editMarketPricePeriod(index: number) {
const data = { ...this.getData(this.marketPricePeriods.at(index).value), layout: { addButtonText: 'Edit' } };
const addVariationsForBorrowerCycleDialogRef = this.dialog.open(FormDialogComponent, { data });
addVariationsForBorrowerCycleDialogRef.afterClosed().subscribe((response: any) => {
const addMarketPricePeriodDialogRef = this.dialog.open(FormDialogComponent, { data });
addMarketPricePeriodDialogRef.afterClosed().subscribe((response: any) => {
if (response.data) {
this.marketPricePeriods.at(index).patchValue(response.data.value);
this.setShareProductMarketPriceFormDirty();
}
});
}
deleteMarketPricePeriod(index: number) {
const deleteVariationsForBorrowerCycleDialogRef = this.dialog.open(DeleteDialogComponent, {
const deleteMarketPricePeriodDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `this` }
});
deleteVariationsForBorrowerCycleDialogRef.afterClosed().subscribe((response: any) => {
deleteMarketPricePeriodDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.marketPricePeriods.removeAt(index);
this.setShareProductMarketPriceFormDirty();
}
});
}
@@ -22,6 +22,17 @@ export class ShareProductSettingsStepComponent implements OnInit {
ngOnInit() {
this.minimumActivePeriodFrequencyTypeData = this.shareProductsTemplate.minimumActivePeriodFrequencyTypeOptions;
this.lockinPeriodFrequencyTypeData = this.shareProductsTemplate.lockinPeriodFrequencyTypeOptions;
this.shareProductSettingsForm.patchValue({
'minimumShares': this.shareProductsTemplate.minimumShares,
'nominalShares': this.shareProductsTemplate.nominalShares,
'maximumShares': this.shareProductsTemplate.maximumShares,
'minimumActivePeriodForDividends': this.shareProductsTemplate.minimumActivePeriod,
'minimumactiveperiodFrequencyType': this.shareProductsTemplate.minimumActivePeriodForDividendsTypeEnum && this.shareProductsTemplate.minimumActivePeriodForDividendsTypeEnum.id,
'lockinPeriodFrequency': this.shareProductsTemplate.lockinPeriod,
'lockinPeriodFrequencyType': this.shareProductsTemplate.lockPeriodTypeEnum && this.shareProductsTemplate.lockPeriodTypeEnum.id,
'allowDividendCalculationForInactiveClients': this.shareProductsTemplate.allowDividendCalculationForInactiveClients
});
}
createShareProductSettingsForm() {
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { combineLatest } from 'rxjs';
@@ -9,6 +9,8 @@ import { combineLatest } from 'rxjs';
})
export class ShareProductTermsStepComponent implements OnInit {
@Input() shareProductsTemplate: any;
shareProductTermsForm: FormGroup;
constructor(private formBuilder: FormBuilder) {
@@ -22,6 +24,15 @@ export class ShareProductTermsStepComponent implements OnInit {
]).subscribe(([sharesIssued, unitPrice]: number[]) => {
this.shareProductTermsForm.get('shareCapital').setValue(sharesIssued * unitPrice);
});
if (this.shareProductsTemplate) {
this.shareProductTermsForm.patchValue({
'totalShares': this.shareProductsTemplate.totalShares,
'sharesIssued': this.shareProductsTemplate.totalSharesIssued,
'unitPrice': this.shareProductsTemplate.unitPrice,
'shareCapital': this.shareProductsTemplate.shareCapital
});
}
}
createShareProductTermsForm() {
@@ -1,5 +1,5 @@
<div fxLayout="row" fxLayoutAlign="end" fxLayoutGap="2%" fxLayout.lt-md="column" class="container m-b-20">
<button mat-raised-button color="primary">
<button mat-raised-button color="primary" [routerLink]="['edit']">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;
Edit
</button>