From 7716564fc34d6ea6319821ad78f4bee4b56d94db Mon Sep 17 00:00:00 2001 From: sriram-at-840620226347 Date: Thu, 23 Jan 2020 15:16:52 +0530 Subject: [PATCH] add pd dropdown autofill added --- .../list-pd/add-pd/add-pd.component.ts | 43 +++--- .../entity-other-preference.component.html | 31 ++++- .../entity-other-preference.component.ts | 128 +++++++++++++++++- 3 files changed, 173 insertions(+), 29 deletions(-) diff --git a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/add-pd/add-pd.component.ts b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/add-pd/add-pd.component.ts index 15bb2fb61..7c2c5c5aa 100755 --- a/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/add-pd/add-pd.component.ts +++ b/ng6-seed/src/app/personal-discussion/manage-pd/list-pd/add-pd/add-pd.component.ts @@ -102,6 +102,11 @@ export class AddPdComponent implements OnInit, OnDestroy { console.log(selectLender); this.selectedLender(selectLender) + this._PDtriggerForm.controls['fk_product_id'].setValue(res['records'].default_product); + this._PDtriggerForm.controls['fk_customer_segment'].setValue(res['records'].default_customer_segment); + this._PDtriggerForm.controls['fk_pd_type'].setValue(res['records'].default_pd_type); + this.getSubproductList(res['records'].default_product) + } else{ this.notifier.notify("success","Something went wrong Reopen the window and Try again"); @@ -185,20 +190,20 @@ export class AddPdComponent implements OnInit, OnDestroy { this._PDtriggerForm.controls['fk_customer_segment'].setValue(''); this._PDtriggerForm.controls['loan_amount'].setValue(''); - if(this.lenderShortName == "IIB"){ //FOR INDUSLAND BANK - // console.log("entered"); - this._PDtriggerForm.controls['fk_product_id'].setValue("3") - this._PDtriggerForm.controls['fk_pd_type'].setValue("1"); - this.getSubproductList("3") - } - else if(this.lenderShortName == 'HHFL'){ - this.getSubproductList("1") - this._PDtriggerForm.controls['fk_product_id'].setValue('1'); - this._PDtriggerForm.controls['fk_subproduct_id'].setValue('1'); - this._PDtriggerForm.controls['fk_customer_segment'].setValue('5'); - this._PDtriggerForm.controls['fk_pd_type'].setValue('1'); - this._PDtriggerForm.controls['loan_amount'].setValue(0); - } + // if(this.lenderShortName == "IIB"){ //FOR INDUSLAND BANK + // // console.log("entered"); + // this._PDtriggerForm.controls['fk_product_id'].setValue("3") + // this._PDtriggerForm.controls['fk_pd_type'].setValue("1"); + // this.getSubproductList("3") + // } + // else if(this.lenderShortName == 'HHFL'){ + // this.getSubproductList("1") + // this._PDtriggerForm.controls['fk_product_id'].setValue('1'); + // this._PDtriggerForm.controls['fk_subproduct_id'].setValue('1'); + // this._PDtriggerForm.controls['fk_customer_segment'].setValue('5'); + // this._PDtriggerForm.controls['fk_pd_type'].setValue('1'); + // this._PDtriggerForm.controls['loan_amount'].setValue(0); + // } // console.log("len",lender) } @@ -298,11 +303,11 @@ export class AddPdComponent implements OnInit, OnDestroy { break; } - if(this.lenderShortName == 'CLIX' && productabbr != ''){ - this._PDtriggerForm.controls['fk_pd_type'].setValue('1'); - this._PDtriggerForm.controls['fk_customer_segment'].setValue('5'); - this._PDtriggerForm.controls['loan_amount'].setValue(0); - } + // if(this.lenderShortName == 'CLIX' && productabbr != ''){ + // this._PDtriggerForm.controls['fk_pd_type'].setValue('1'); + // this._PDtriggerForm.controls['fk_customer_segment'].setValue('5'); + // this._PDtriggerForm.controls['loan_amount'].setValue(0); + // } } diff --git a/ng6-seed/src/app/settings/entity/entity-edit/entity-other-preference/entity-other-preference.component.html b/ng6-seed/src/app/settings/entity/entity-edit/entity-other-preference/entity-other-preference.component.html index f7cfadd1b..eee013730 100644 --- a/ng6-seed/src/app/settings/entity/entity-edit/entity-other-preference/entity-other-preference.component.html +++ b/ng6-seed/src/app/settings/entity/entity-edit/entity-other-preference/entity-other-preference.component.html @@ -1,26 +1,45 @@
- + Products - Select All - {{option.product_name}} + Select All Default + + {{option.product_name}} + + + + + + + + Customer Segments Select All - {{option.customer_segment}} + + {{option.customer_segment}} + + + + - + PD Types Select All - {{option.type_name}} + + {{option.type_name}} + + + + diff --git a/ng6-seed/src/app/settings/entity/entity-edit/entity-other-preference/entity-other-preference.component.ts b/ng6-seed/src/app/settings/entity/entity-edit/entity-other-preference/entity-other-preference.component.ts index d283c03f1..8f0de0ade 100644 --- a/ng6-seed/src/app/settings/entity/entity-edit/entity-other-preference/entity-other-preference.component.ts +++ b/ng6-seed/src/app/settings/entity/entity-edit/entity-other-preference/entity-other-preference.component.ts @@ -1,8 +1,9 @@ import { Component, OnInit, Input } from '@angular/core'; -import { FormGroup, FormBuilder } from '@angular/forms'; +import { FormGroup, FormBuilder, FormArray, FormControl } from '@angular/forms'; import { EntityService } from 'app/settings/service/entity/entity.service'; import { NotifierService } from 'angular-notifier'; import { AwsService } from 'app/AwsService/aws.service'; +import { MatSlideToggleChange } from '@angular/material'; @Component({ selector: 'app-entity-other-preference', @@ -21,24 +22,56 @@ export class EntityOtherPreferenceComponent implements OnInit { constructor(private entityService:EntityService,private _fb:FormBuilder,notifier:NotifierService,private awsService:AwsService) { this.notifier=notifier this.users=this.awsService.getlocale() + this.getDropdownValues() } ngOnInit() { - this.getDropdownValues() + this._otherPreferenceForm=this._fb.group({ products:[''], customer_segments:[''], pd_types:[''], fk_entity_id:[this.entityId], fk_createdby:[this.users], - fk_updatedby:[this.users] + fk_updatedby:[this.users], + products_default:this._fb.array([]), + customer_segments_default:this._fb.array([]), + pd_types_default:this._fb.array([]) }) + setTimeout(() => { this.getvalueFromApi() + }); + } getvalueFromApi(){ this.entityService.getEntityOtherPreferences(this.entityId).subscribe(res=>{ if(res['dataStatus']){ - this._otherPreferenceForm.patchValue(res['records']) + this.productList.forEach((element,index) => { + if(element.product_id == res['records'].products_default){ + let event={checked:true} + this.default_toggle(event,element.product_id,index,1) + } + }); + this.customerSegmentList.forEach((element,index) => { + if(element.customer_segment_id == res['records'].customer_segments_default){ + let event={checked:true} + this.default_toggle(event,element.customer_segment_id,index,2) + } + }); + this.pdTypeList.forEach((element,index) => { + if(element.pd_type_id == res['records'].pd_types_default){ + let event={checked:true} + this.default_toggle(event,element.pd_type_id,index,3) + } + }); + delete res['records'].products_default + delete res['records'].customer_segments_default + delete res['records'].pd_types_default + console.log(this._otherPreferenceForm.value); + setTimeout(() => { + this._otherPreferenceForm.patchValue(res['records']) + }); + } }) } @@ -46,16 +79,22 @@ export class EntityOtherPreferenceComponent implements OnInit { this.entityService.getListOfProducts().subscribe(res=>{ if(res['dataStatus']){ this.productList=res['records'] + this.initslidetoggle(1) + console.log(this._otherPreferenceForm.value); } }) this.entityService.getListOfCustomerSegments().subscribe(res=>{ if(res['dataStatus']){ this.customerSegmentList=res['records'] + this.initslidetoggle(2) + console.log(this._otherPreferenceForm.value); } }) this.entityService.getListOfPDAllocationTypes().subscribe(res=>{ if(res['dataStatus']){ this.pdTypeList=res['records'].pd_type + this.initslidetoggle(3) + console.log(this._otherPreferenceForm.value); } }) @@ -77,6 +116,8 @@ export class EntityOtherPreferenceComponent implements OnInit { } } else{ + let array_name = option+'_default' + this.changeToogletoFalse(array_name) this._otherPreferenceForm.controls[option].patchValue('') this.selectedAll[option]=false } @@ -87,6 +128,25 @@ export class EntityOtherPreferenceComponent implements OnInit { console.log(this._otherPreferenceForm.value) let records=this._otherPreferenceForm.value records.fk_updatedby=this.users + records.products_default = records.products_default.filter(prod_filter =>prod_filter != false) + if(records.products_default.length > 0){ + records.products_default=records.products_default[0] + }else{ + records.products_default= null + } + records.customer_segments_default = records.customer_segments_default.filter(prod_filter =>prod_filter != false) + if(records.customer_segments_default.length > 0){ + records.customer_segments_default=records.customer_segments_default[0] + }else{ + records.customer_segments_default= null + } + records.pd_types_default = records.pd_types_default.filter(prod_filter =>prod_filter != false) + if(records.pd_types_default.length > 0){ + records.pd_types_default=records.pd_types_default[0] + }else{ + records.pd_types_default= null + } + console.log('records',records); this.entityService.saveEntityOtherPreferences(records).subscribe(res=>{ if(res['dataStatus']){ this.notifier.notify("success","Saved Successfully..!"); @@ -97,5 +157,65 @@ export class EntityOtherPreferenceComponent implements OnInit { }) } + default_toggle(event,prod_id,index,flag){ + console.log(event.checked,prod_id,this._otherPreferenceForm.value.products_default,index) + if(flag == 1){ + if(event.checked){ + this.changeToogletoFalse('products_default') + const control=this._otherPreferenceForm.controls['products_default']['controls'][index] + control.setValue(prod_id) + console.log("set true",this._otherPreferenceForm.value.products_default) + } + } + if(flag == 2){ + if(event.checked){ + this.changeToogletoFalse('customer_segments_default') + const control=this._otherPreferenceForm.controls['customer_segments_default']['controls'][index] + control.setValue(prod_id) + console.log("set true",this._otherPreferenceForm.value.customer_segments_default) + } + } + if(flag == 3){ + if(event.checked){ + this.changeToogletoFalse('pd_types_default') + const control=this._otherPreferenceForm.controls['pd_types_default']['controls'][index] + control.setValue(prod_id) + console.log("set true",this._otherPreferenceForm.value.pd_types_default) + } + } + + } + changeToogletoFalse(array_name){ + const control=this._otherPreferenceForm.controls[array_name]['controls'] + console.log(control) + control.forEach((val,index)=>{ + control[index].setValue(false) + }) + console.log("set False",this._otherPreferenceForm.value[array_name]) + } + initslidetoggle(flag){ + if(flag == 1){ + const formArray = this._otherPreferenceForm.get('products_default') as FormArray; + this.productList.forEach(x => formArray.push(new FormControl(false))); + } + if(flag == 2){ + const formArray = this._otherPreferenceForm.get('customer_segments_default') as FormArray; + this.customerSegmentList.forEach(x => formArray.push(new FormControl(false))); + } + if(flag == 3){ + const formArray = this._otherPreferenceForm.get('pd_types_default') as FormArray; + this.pdTypeList.forEach(x => formArray.push(new FormControl(false))); + } + + } + checkDisableToggle(select_value, curr_id){ + // console.log("bvvvv",select_value,select_value.length > 0) + if(select_value.length > 0){ + return select_value.filter(val=>val == curr_id).length == 0 + } + else{ + return true + } + } }