From b7c1800ff627db57af62239cb4b1812f0480b887 Mon Sep 17 00:00:00 2001 From: dineshkumarkannan Date: Sat, 15 Dec 2018 10:26:38 +0530 Subject: [PATCH 1/2] entity add , edit branch details changes : kdk --- .../entity-branch-add.component.html | 86 +++++++--- .../entity-branch-add.component.ts | 147 ++++++++++++++++-- .../entity-edit/entity.edit.component.html | 12 +- 3 files changed, 204 insertions(+), 41 deletions(-) diff --git a/ng6-seed/src/app/settings/entity/entity-edit/entity-branch-add/entity-branch-add.component.html b/ng6-seed/src/app/settings/entity/entity-edit/entity-branch-add/entity-branch-add.component.html index 3042b3c1c..b93b0a92e 100644 --- a/ng6-seed/src/app/settings/entity/entity-edit/entity-branch-add/entity-branch-add.component.html +++ b/ng6-seed/src/app/settings/entity/entity-edit/entity-branch-add/entity-branch-add.component.html @@ -1,27 +1,73 @@ -
- - - check -
-
- - - - - - edit - check - delete - - - - + + +
+
+ + +
+
+ + + Branch Name Required.! + + + + + {{ city.name }} + + City Required.! + +
+ + + +
+
+
+
+
+
+
+ + + + +
+
diff --git a/ng6-seed/src/app/settings/entity/entity-edit/entity-branch-add/entity-branch-add.component.ts b/ng6-seed/src/app/settings/entity/entity-edit/entity-branch-add/entity-branch-add.component.ts index a6b927778..517aad7ac 100644 --- a/ng6-seed/src/app/settings/entity/entity-edit/entity-branch-add/entity-branch-add.component.ts +++ b/ng6-seed/src/app/settings/entity/entity-edit/entity-branch-add/entity-branch-add.component.ts @@ -18,9 +18,15 @@ import { EntityService } from './../../../service/entity/entity.service'; export class EntityBranchAddComponent implements OnInit { @Input() public entityId: number; - public newElement = { name: '' }; + public newElement: any= {}; + public listofCity = []; public listOfBranch = []; + public m_city: any = []; + + public _addEntityBranchFrom: FormGroup; + public submitted = false; + /** * Notifier service */ @@ -32,18 +38,89 @@ export class EntityBranchAddComponent implements OnInit { private mastersService: MastersService, private _formBuilder: FormBuilder) { this.notifier = notifier; + this._addEntityBranchFrom = this._formBuilder.group({ + branch_details: this._formBuilder.array([ + // this.addRegionFormData(null, null), + ]) + }) } ngOnInit() { this.entityService.getEntityBranchList(this.entityId).subscribe(data => { if (data.dataStatus) { - this.listOfBranch = data.records; + this.listofCity = data.records; + this.m_city = data.records.city_master; + // this.listOfBranch = data.records; + this.setFormDatas(data.records.branch_details); } }, err => { - }) } + setFormDatas(record) { + if (record.length > 0) { + for (let val of record) { + let vals = { + entity_lender_branch_id: val.entity_lender_branch_id, + branch_name: val.branch_name, + fk_entity_id: val.fk_entity_id, + fk_region_id: val.fk_region_id, + fk_city_id: val.fk_city_id, + fk_updatedby: val.fk_updatedby, + fk_createdby: val.fk_createdby, + isactive: val.isactive, + }; + this.addRegionFormData(vals, null); + } + } + } + + // convenience getter for easy access to form fields + get f() { return this._addEntityBranchFrom.controls; } + + // Dynamic Form field creation Functionality : START ===> + initRegionFormLoad(data) { + return this._formBuilder.group({ + entity_lender_branch_id: [data.entity_lender_branch_id], + branch_name: [data.branch_name, Validators.compose([Validators.required])], + fk_city_id: [data.fk_city_id, Validators.compose([Validators.required])], + fk_entity_id: [data.fk_entity_id], + fk_updatedby: [data.fk_updatedby], + fk_createdby: [data.fk_createdby], + isactive: [data.isactive], + }); + } + addRegionFormData(data, e) { + if (data == null) { + let newDate = { + entity_lender_branch_id: null, + branch_name:null, + fk_entity_id: this.entityId, + fk_createdby: null, + fk_updatedby: null, + fk_city_id: null, + isactive: 1, + } + const control = this._addEntityBranchFrom.controls['branch_details']; + control.push(this.initRegionFormLoad(newDate)); + } else { + const control = this._addEntityBranchFrom.controls['branch_details']; + control.push(this.initRegionFormLoad(data)); + } + } + + deleteEntityBranch(inx, e) { + e.stopPropagation(); + const control = this._addEntityBranchFrom.controls['branch_details']; + // let dataS = control.controls[inx].value; + if(control.controls[inx].value['entity_lender_branch_id'] !== null){ + console.log( this._addEntityBranchFrom.controls['branch_details']['controls'][inx].controls.isactive); + this._addEntityBranchFrom.controls['branch_details']['controls'][inx].controls.isactive.setValue("0"); + console.log( this._addEntityBranchFrom.controls['branch_details']['controls'][inx].controls.isactive.value); + } else { + control.removeAt(inx); + } + } // public listOfBranch = [ // { @@ -72,17 +149,17 @@ export class EntityBranchAddComponent implements OnInit { // } // ]; - addItem(): void { - let data = { - "entity_lender_branch_id": null, - "branch_name": this.newElement.name, - "isactive": "1", - "fk_createdby": null, - "fk_updatedby": null, - "fk_entity_id": this.entityId.toString() - } - this.listOfBranch.push(data); - this.newElement.name = ''; + addItem(prop): void { + // let data = { + // "entity_lender_branch_id": null, + // "branch_name": this.newElement.name, + // "isactive": "1", + // "fk_createdby": null, + // "fk_updatedby": null, + // "fk_entity_id": this.entityId.toString() + // } + // this.listOfBranch.push(data); + // this.newElement.name = ''; } public currentElement = -1; @@ -98,8 +175,48 @@ export class EntityBranchAddComponent implements OnInit { } } + /** To Save/Edited Popup Data */ + onSubmit() { + alert(); + this.submitted = true; + // stop here if form is invalid + if (this._addEntityBranchFrom.invalid) { + // this.errorMessage = "Please Fill All Mandate Fields."; + return; + } else { + var formValues = this._addEntityBranchFrom.value; + //To Remove The "Null" With Key also + Object.keys(formValues).forEach((key) => (formValues[key] == null) && delete formValues[key]); + alert(JSON.stringify(formValues.branch_details)); + // this.entityService.updateEntityIdRegionInfoDetails(formValues.region_lender).subscribe( + // dataresult => { + // if (dataresult.status == 200) { + // console.log(dataresult); + // this.notifier.notify('success', 'Your Changes Updated.!'); + // const arr = this._editEntityRegionFrom.controls.region_lender; + // arr.controls.splice(0); + // // this.getEntityIDRegionInfoDetails(); + // } + // else { + // this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + // // this.errorMessage = "Something Wents Wrong Try Again.!"; + // } + // }, error => { + // this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + // // this.errorMessage = "Some Thing Wents Wrong Try Again.!"; + // }); + } + } + + saveBranch(): void { - this.entityService.updateEntityIdBranchInfoDetails(this.listOfBranch).subscribe(data => { +// alert(); + var formValues = this._addEntityBranchFrom.value; + //To Remove The "Null" With Key also + Object.keys(formValues).forEach((key) => (formValues[key] == null) && delete formValues[key]); + // alert(JSON.stringify(formValues.branch_details)); + + this.entityService.updateEntityIdBranchInfoDetails(formValues.branch_details).subscribe(data => { if (data.dataStatus) { this.notifier.notify('success', 'Your Changes Updated.!'); } else { diff --git a/ng6-seed/src/app/settings/entity/entity-edit/entity.edit.component.html b/ng6-seed/src/app/settings/entity/entity-edit/entity.edit.component.html index 90a324cf4..17b31563b 100755 --- a/ng6-seed/src/app/settings/entity/entity-edit/entity.edit.component.html +++ b/ng6-seed/src/app/settings/entity/entity-edit/entity.edit.component.html @@ -234,18 +234,18 @@ - - - - - - + + + + + +