From 6154d876e478edc922c0f9ffcd85836f06ac50e6 Mon Sep 17 00:00:00 2001 From: dineshkumarkannan Date: Wed, 17 Oct 2018 15:54:04 +0530 Subject: [PATCH] templates edit screens added : kdk --- ng6-seed/package-lock.json | 41 +-- .../service/templates/templates.service.ts | 114 ++++++- .../edit-category.component.html | 57 +++- .../edit-category/edit-category.component.ts | 264 ++++++++++++--- .../edit-lender/edit-lender.component.html | 40 ++- .../edit/edit-lender/edit-lender.component.ts | 185 +++++++++- .../category-question-answer.component.html | 102 ++++++ .../category-question-answer.component.scss | 8 + ...category-question-answer.component.spec.ts | 25 ++ .../category-question-answer.component.ts | 316 ++++++++++++++++++ .../dialog-category-question-list.html | 5 + .../edit-question-answer.component.html | 97 +----- .../edit-question-answer.component.ts | 47 ++- .../edit/templates.edit.component.html | 22 +- .../edit/templates.edit.component.ts | 97 +++++- .../templates.list.component.ts | 60 ++-- .../template/templates/templates.module.ts | 13 +- 17 files changed, 1250 insertions(+), 243 deletions(-) create mode 100644 ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.html create mode 100644 ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.scss create mode 100644 ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.spec.ts create mode 100644 ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.ts create mode 100644 ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/dialog-category-question-list.html diff --git a/ng6-seed/package-lock.json b/ng6-seed/package-lock.json index 179ae916f..12de058af 100644 --- a/ng6-seed/package-lock.json +++ b/ng6-seed/package-lock.json @@ -4273,8 +4273,7 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "aproba": { "version": "1.2.0", @@ -4295,14 +4294,12 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4317,20 +4314,17 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "core-util-is": { "version": "1.0.2", @@ -4447,8 +4441,7 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "ini": { "version": "1.3.5", @@ -4460,7 +4453,6 @@ "version": "1.0.0", "bundled": true, "dev": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4475,7 +4467,6 @@ "version": "3.0.4", "bundled": true, "dev": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4483,14 +4474,12 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -4509,7 +4498,6 @@ "version": "0.5.1", "bundled": true, "dev": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -4590,8 +4578,7 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "object-assign": { "version": "4.1.1", @@ -4603,7 +4590,6 @@ "version": "1.4.0", "bundled": true, "dev": true, - "optional": true, "requires": { "wrappy": "1" } @@ -4689,8 +4675,7 @@ "safe-buffer": { "version": "5.1.1", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -4726,7 +4711,6 @@ "version": "1.0.2", "bundled": true, "dev": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4746,7 +4730,6 @@ "version": "3.0.1", "bundled": true, "dev": true, - "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4790,14 +4773,12 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true }, "yallist": { "version": "3.0.2", "bundled": true, - "dev": true, - "optional": true + "dev": true } } }, diff --git a/ng6-seed/src/app/template/service/templates/templates.service.ts b/ng6-seed/src/app/template/service/templates/templates.service.ts index 875551de0..149cd3265 100644 --- a/ng6-seed/src/app/template/service/templates/templates.service.ts +++ b/ng6-seed/src/app/template/service/templates/templates.service.ts @@ -1,9 +1,121 @@ import { Injectable } from '@angular/core'; +import { HttpClient, HttpParams } from '@angular/common/http'; +import { Observable } from 'rxjs/Observable'; +import { catchError } from 'rxjs/operators'; +import { of } from 'rxjs'; +import 'rxjs/add/operator/map'; + +/** Imported Service Files Are., */ +import { AwsService } from '../../../AwsService/aws.service'; +/** Consant Value For Created Date And Updated Date */ +const currentdate = new Date().toJSON().slice(0, 19).replace('T', ' '); + @Injectable({ providedIn: 'root' }) export class TemplatesService { + private apiUrl = "http://ssa.sineedge.com/sparqapi/api/"; + + constructor(private _http: HttpClient, + private _aws: AwsService) { } + + // get templates master details list + getTemplatesMasterListDetails(cid: any): Observable { + // Add safe, URL encoded search parameter if there is a search term + const options = cid ? + { params: new HttpParams().set('cid', cid) } : {}; + return this._http.get(this.apiUrl + "listAllTemplates/any", options); + } + + getTemplateIDNameDetails(temp_id: number): Observable{ + // Add safe, URL encoded search parameter if there is a search term + return this._http.post(this.apiUrl + "getTemplateMaster", {'template_id': temp_id }); + } + + updateTempateIDNameDetails(Records: any): Observable{ + Records.fk_updatedby = this._aws.getlocale();//to get user id for who is created the Record + Records.updatedon = currentdate;//to get Current date and Time for when the Record is created + return this._http.post(this.apiUrl + "saveNewTemplateName", {'records': Records }); + } + + getTemplateIDLenderDetails(temp_id: number): Observable{ + // Add safe, URL encoded search parameter if there is a search term + return this._http.post(this.apiUrl + "getTemplateLenders", {'template_id': temp_id }); + } + + updateTempateIDLenderDetails(Records: any): Observable{ + + let records = Records.map(item=>{ + item.fk_updatedby = this._aws.getlocale();//to get user id for who is created the Record + item.updatedon = currentdate;//to get Current date and Time for when the Record is created + return item; + }); + return this._http.post(this.apiUrl + "saveTemplateLenderDetails", {'records': records }); + } + + + getTemplateIDCategoryDetails(temp_id: number): Observable{ + // Add safe, URL encoded search parameter if there is a search term + return this._http.post(this.apiUrl + "getTemplateCategories", {'template_id': temp_id }); + } + + updateTempateIDCategoryDetails(Records: any): Observable{ + + let records = Records.map(item=>{ + item.fk_updatedby = this._aws.getlocale();//to get user id for who is created the Record + item.updatedon = currentdate;//to get Current date and Time for when the Record is created + return item; + }); + return this._http.post(this.apiUrl + "saveTemplateCategoryDetails", {'records': records }); + } + + + getTemplateIDQuesAnsDetails(temp_id: number): Observable{ + // Add safe, URL encoded search parameter if there is a search term + return this._http.post(this.apiUrl + "getTemplateQuestionAnswers", {'template_id': temp_id }); + } + + + updateTempateIDQuesAnsDetails(Records: any): Observable{ + let records = Records.map(item=>{ + item.fk_updatedby = this._aws.getlocale();//to get user id for who is created the Record + item.updatedon = currentdate; + // item.answers = item.answers.map(subItem=>{ + // subItem.fk_updatedby = this._aws.getlocale();//to get user id for who is created the Record + // subItem.updatedon = currentdate; + // })//to get Current date and Time for when the Record is created + return item; + }); + return this._http.post(this.apiUrl + "saveTemplateQuestionAnswers", {'records': records }); + } + + getRemaningQuestionCategory(data: any): Observable{ + // Add safe, URL encoded search parameter if there is a search term + return this._http.post(this.apiUrl + "getQuestionsForTemplateCreation", {"template_id": data.template_id, "category_id": data.category_id}); + } + + + + // get Master Details ============================== + + + // get templates master details list + getLenderMasterListDetails(): Observable { + return this._http.get(this.apiUrl + "getListOfLenders"); + } + + getProductsMasterListDetails(): Observable { + return this._http.get(this.apiUrl + "getListOfProducts "); + } + + getCustomerSegmentsMasterListDetails(): Observable { + return this._http.get(this.apiUrl + "getListOfCustomerSegments"); + } + + getCategoryMasterListDetails(): Observable { + return this._http.get(this.apiUrl + "getListOfCategories"); + } + - constructor() { } } diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-category/edit-category.component.html b/ng6-seed/src/app/template/templates/templates-list/edit/edit-category/edit-category.component.html index 217c94345..0aa387ce1 100644 --- a/ng6-seed/src/app/template/templates/templates-list/edit/edit-category/edit-category.component.html +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-category/edit-category.component.html @@ -1,16 +1,20 @@ + + +
- - -
+ + + + +
+
- - {{ category.name }} + + {{ category.category_name }} - + This Category Already Exist.!
@@ -23,13 +27,46 @@
- +
- - + This Category Already Exist.! +
+ + +
diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-category/edit-category.component.ts b/ng6-seed/src/app/template/templates/templates-list/edit/edit-category/edit-category.component.ts index 2687c5cf1..2bd2f071a 100644 --- a/ng6-seed/src/app/template/templates/templates-list/edit/edit-category/edit-category.component.ts +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-category/edit-category.component.ts @@ -1,85 +1,191 @@ -import { Component, ViewChild, OnInit, OnDestroy, Input } from '@angular/core'; +import { Component, ViewChild, OnInit, OnDestroy, Input, AfterViewInit } from '@angular/core'; import { MatPaginator, MatSort, MatTableDataSource, MatDialog, PageEvent } from '@angular/material'; -import { FormGroup, FormControl, FormBuilder, Validators , FormArray} from '@angular/forms'; +import { FormGroup, FormControl, FormBuilder, Validators, FormArray } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import { DataSource } from '@angular/cdk/table'; import { Observable } from 'rxjs/Observable'; +import { NotifierService } from 'angular-notifier'; +import { TemplatesService } from './../../../../service/templates/templates.service'; +import { MastersService } from './../../../../service/masters/masters.service'; + @Component({ selector: 'app-template-edit-category', templateUrl: './edit-category.component.html', styleUrls: ['./edit-category.component.scss'] }) -export class EditCategoryComponent implements OnInit, OnDestroy { +export class EditCategoryComponent implements OnInit, OnDestroy, AfterViewInit { - @Input() questionId: number; + @Input() questionId: number; public _editTempCategoryFrom: FormGroup; public submitted = false; + public templateCategoryRecord: any; + + public m_category: any; + + /** + * Notifier service + */ + private notifier: NotifierService; + constructor( - private _formBuilder: FormBuilder, - public dialog: MatDialog) { + notifier: NotifierService, + private templatesService: TemplatesService, + private mastersService: MastersService, + private _formBuilder: FormBuilder) { + this.notifier = notifier; } ngOnInit() { - this.initalLoadFormData(); - if(this.categoryList.length > 0){ - for (let val of this.categoryList) { - // alert(JSON.stringify(val)); - let vals = val; - this.addLanguage(vals['fk_category_id'], vals['name'], vals['weightage'], null); - } - } + this.initalLoadFormData(); + this.getCategoryMasters(); + this.getTemplateCategoryDetails(); + + this._editTempCategoryFrom = this._formBuilder.group({ + temp_category: this._formBuilder.array([ + // this.initAnswers(), + ]) + }) + + // if(this.categoryList.length > 0){ + // for (let val of this.categoryList) { + // // alert(JSON.stringify(val)); + // let vals = val; + // this.addLanguage(vals['fk_category_id'], vals['name'], vals['weightage'], null); + // } + // } } - initalLoadFormData(){ + ngAfterViewInit() { + // this.getTemplateCategoryDetails(); + } + + setFormDatas(record) { + if (record.length > 0) { + for (let val of record) { + let vals = { + template_category_weightage_id: val.template_category_weightage_id, + fk_question_category_id: val.fk_question_category_id, + fk_template_id: val.fk_template_id, + weightage: val.weightage, + isactive: val.isactive, + }; + this.addLanguage(vals, null); + } + } + } + + + // Dynamic Form field creation Functionality : START ===> + initAnswers(data) { + return this._formBuilder.group({ + template_category_weightage_id: [data.template_category_weightage_id], + fk_question_category_id: [data.fk_question_category_id, Validators.compose([Validators.required])], + fk_template_id: [data.fk_template_id], + weightage: [data.weightage, Validators.compose([Validators.required])], + isactive: [data.isactive], + }); + } + addLanguage(data, e) { + if (data == null) { + let newDate = { + template_category_weightage_id: null, + fk_template_id: this.questionId, + fk_question_category_id: null, + weightage: null, + isactive: 1, + } + const control = this._editTempCategoryFrom.controls['temp_category']; + control.push(this.initAnswers(newDate)); + } else { + const control = this._editTempCategoryFrom.controls['temp_category']; + control.push(this.initAnswers(data)); + } + } + + getTemplateCategoryDetails() { + this.templatesService.getTemplateIDCategoryDetails(this.questionId).subscribe( + data => { + if (data) { + if (data.records) { + this.templateCategoryRecord = data.records; + this.setFormDatas(this.templateCategoryRecord); + // this.templateListData = data.records; + // this.dataLength = data.records.length; + // this.dataSource.data = this.templateListData; + } else { + // this.noTemplateLendersFound = true; + } + } else { + // this.noTemplateLendersFound = true; + } + } + ); + } + + getCategoryMasters() { + this.templatesService.getCategoryMasterListDetails().subscribe( + data => { + this.m_category = data.records; + }, + error => { + this.notifier.notify('warning', 'No Category Master Records Found.!'); + // this.m_category = "No Category Master Records Found."; + } + ); + } + + + + initalLoadFormData() { this._editTempCategoryFrom = this._formBuilder.group({ - temp_category: this._formBuilder.array([ + temp_category: this._formBuilder.array([ // this.initAnswers(), ]) }) } - // convenience getter for easy access to form fields + // convenience getter for easy access to form fields get f() { return this._editTempCategoryFrom.controls; } - public m_categoryList = [{ - fk_category_id: 1, - name: 'Category List 1', - weightage: 2, - },{ - fk_category_id: 2, - name: 'Category List 2', - weightage: 5, - },{ - fk_category_id: 3, - name: 'Category List 2', - weightage: 5, + public m_categoryList = [{ + fk_category_id: 1, + name: 'Category List 1', + weightage: 2, + }, { + fk_category_id: 2, + name: 'Category List 2', + weightage: 5, + }, { + fk_category_id: 3, + name: 'Category List 2', + weightage: 5, }]; public categoryList = [{ - fk_category_id: 1, - name: 'Category List 1', - weightage: 2, - },{ - fk_category_id: 2, - name: 'Category List 2', - weightage: 5, + fk_category_id: 1, + name: 'Category List 1', + weightage: 2, + }, { + fk_category_id: 2, + name: 'Category List 2', + weightage: 5, }]; - // Dynamic Form field creation Functionality : START ===> - initAnswers(fk_cat_id, name, weightage) { - return this._formBuilder.group({ - fk_category_id: [fk_cat_id, Validators.compose([Validators.required])], - name: [name, Validators.compose([Validators.required])], - weightage: [weightage, Validators.compose([Validators.required])], - }); - } - addLanguage(fk_cat_id, name, weightage, e) { - const control = this._editTempCategoryFrom.controls['temp_category']; - control.push(this.initAnswers(fk_cat_id, name, weightage)); - } + // Dynamic Form field creation Functionality : START ===> + // initAnswers(fk_cat_id, name, weightage) { + // return this._formBuilder.group({ + // fk_category_id: [fk_cat_id, Validators.compose([Validators.required])], + // name: [name, Validators.compose([Validators.required])], + // weightage: [weightage, Validators.compose([Validators.required])], + // }); + // } + // addLanguage(fk_cat_id, name, weightage, e) { + // const control = this._editTempCategoryFrom.controls['temp_category']; + // control.push(this.initAnswers(fk_cat_id, name, weightage)); + // } removeLanguage(i: number) { const control = this._editTempCategoryFrom.controls['temp_category']; control.removeAt(i); @@ -87,11 +193,71 @@ export class EditCategoryComponent implements OnInit, OnDestroy { // END ===> - + public errorMessage: string; + /** To Save/Edited Popup Data */ onSubmit() { this.submitted = true; // stop here if form is invalid + if (this._editTempCategoryFrom.invalid) { + alert('no'); + return; + } else { + var formValues = this._editTempCategoryFrom.value; + //To Remove The "Null" With Key also + Object.keys(formValues).forEach((key) => (formValues[key] == null) && delete formValues[key]); + + let val = formValues.temp_category; + + let totalScore = val.map(value => { return Number(value.weightage); }).reduce((acc, value) => { return acc + value; }, 0); + + if (totalScore == 100) { + if (!this.checkDuplicateInObject(formValues.temp_category)) { + this.templatesService.updateTempateIDCategoryDetails(formValues.temp_category).subscribe( + dataresult => { + if (dataresult.status == 200) { + console.log(dataresult); + this.notifier.notify('success', 'Your Changes Updated.!'); + const arr = this._editTempCategoryFrom.controls.temp_category; + arr.controls.splice(0); + this.getTemplateCategoryDetails(); + } + 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.!"; + }); + } else { + alert("duplication records occured.!"); + } + } else { + alert("value should equal to 100") + } + + } + } + + public dublicateRerdIndex = -1; + + checkDuplicateInObject(inputArray) { + this.dublicateRerdIndex = -1; + let seenDuplicate = false; + + inputArray.map((item, index) => { + let currentVal = inputArray[index]; + for(let i = index+1 ; i < inputArray.length ; i++ ){ + if(currentVal.fk_question_category_id === inputArray[i].fk_question_category_id){ + console.log('duplication: ' + i); + this.dublicateRerdIndex = i; + seenDuplicate = true; + } + } + console.log(index); + }); + return seenDuplicate; } ngOnDestroy(): void { diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-lender/edit-lender.component.html b/ng6-seed/src/app/template/templates/templates-list/edit/edit-lender/edit-lender.component.html index af969774d..c1a06d41c 100644 --- a/ng6-seed/src/app/template/templates/templates-list/edit/edit-lender/edit-lender.component.html +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-lender/edit-lender.component.html @@ -1,3 +1,10 @@ + + +
@@ -5,39 +12,38 @@
- {{ enti.name }} + {{ lend.full_name }} - You must Select Lender Type. + - {{ enti.name }} + {{ prcd.product_name }} - You must Select Product. + - - {{ enti.name }} + + {{ cusSeg.customer_segment }} - You must Select Category Segment. + - - + +
+ + - + +
+
- +
diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-lender/edit-lender.component.ts b/ng6-seed/src/app/template/templates/templates-list/edit/edit-lender/edit-lender.component.ts index 7c8ba8437..bc95d91cb 100644 --- a/ng6-seed/src/app/template/templates/templates-list/edit/edit-lender/edit-lender.component.ts +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-lender/edit-lender.component.ts @@ -5,6 +5,11 @@ import { ActivatedRoute, Router } from '@angular/router'; import { DataSource } from '@angular/cdk/table'; import { Observable } from 'rxjs/Observable'; +import { NotifierService } from 'angular-notifier'; +import { TemplatesService } from './../../../../service/templates/templates.service'; +import { MastersService } from './../../../../service/masters/masters.service'; + + @Component({ selector: 'app-template-edit-lender', templateUrl: './edit-lender.component.html', @@ -14,20 +19,115 @@ export class EditLenderComponent implements OnInit { @Input() questionId: number; + public noTemplateLendersFound: boolean; + public templateLenderRecord: any; + public errorMessage; + + public m_lender : any; + public m_product: any; + public m_customerSegment : any; public _editTempLenderFrom: FormGroup; public submitted = false; + + + /** + * Notifier service + */ + private notifier : NotifierService; + constructor( + notifier: NotifierService, + private templatesService: TemplatesService, + private mastersService: MastersService, private _formBuilder: FormBuilder) { + this.notifier = notifier; } ngOnInit() { - this._editTempLenderFrom = this._formBuilder.group({ + this.getTemplateLenderDetails(); + this.getLenderMasters(); + this.getProductsMasters(); + this.getCustomerSegmentMasters(); + + this._editTempLenderFrom = this._formBuilder.group({ temp_lender: this._formBuilder.array([ - this.initAnswers(), + // this.initAnswers(), ]) }) } + setFormDatas(record){ + if (record.length > 0) { + for (let val of record) { + let vals = { + template_lender_map_id: val.template_lender_map_id, + fk_template_id: val.fk_template_id, + fk_lender_id: val.fk_lender_id, + fk_product_id: val.fk_product_id, + fk_customer_segment: val.fk_customer_segment, + isactive: val.isactive, + }; + this.addLanguage(vals, null); + } + } + } + + getTemplateLenderDetails(){ + this.templatesService.getTemplateIDLenderDetails(this.questionId).subscribe( + data => { + if (data) { + if (data.records) { + this.noTemplateLendersFound = false; + this.templateLenderRecord = data.records; + this.setFormDatas(this.templateLenderRecord); + // this.templateListData = data.records; + // this.dataLength = data.records.length; + // this.dataSource.data = this.templateListData; + } else { + this.noTemplateLendersFound = true; + } + } else { + this.noTemplateLendersFound = true; + } + } + ); + } + + getLenderMasters(){ + this.templatesService.getLenderMasterListDetails().subscribe( + data => { + this.m_lender = data.records; + }, + error => { + this.notifier.notify('warning', 'No Lender Master Records Found.!'); + this.errorMessage = "No Lender Master Record Found."; + } + ); + } + + getProductsMasters(){ + this.templatesService.getProductsMasterListDetails().subscribe( + data => { + this.m_product = data.records; + }, + error => { + this.notifier.notify('warning', 'No Products Master Records Found.!'); + this.errorMessage = "No Products Master Record Found."; + } + ); + } + + getCustomerSegmentMasters() { + this.templatesService.getCustomerSegmentsMasterListDetails().subscribe( + data => { + this.m_customerSegment = data.records; + }, + error => { + this.notifier.notify('warning', 'No Customer Segment Master Records Found.!'); + this.errorMessage = "No Customer Segment Master Record Found."; + } + ); + } // convenience getter for easy access to form fields get f() { return this._editTempLenderFrom.controls; } @@ -42,16 +142,32 @@ export class EditLenderComponent implements OnInit { }]; // Dynamic Form field creation Functionality : START ===> - initAnswers() { + initAnswers(data) { return this._formBuilder.group({ - fk_lender_id: ['', Validators.compose([Validators.required])], - fk_product_id: ['', Validators.compose([Validators.required])], - fk_category_segment_id: ['', Validators.compose([Validators.required])], + template_lender_map_id: [data.template_lender_map_id], + fk_template_id: [data.fk_template_id], + fk_lender_id: [data.fk_lender_id, Validators.compose([Validators.required])], + fk_product_id: [data.fk_product_id , Validators.compose([Validators.required])], + fk_customer_segment: [data.fk_customer_segment, Validators.compose([Validators.required])], + isactive: [data.isactive], }); } - addLanguage(e) { - const control = this._editTempLenderFrom.controls['temp_lender']; - control.push(this.initAnswers()); + addLanguage(data, e) { + if(data == null){ + let newDate = { + template_lender_map_id: null, + fk_template_id: this.questionId, + fk_lender_id: null, + fk_product_id: null, + fk_customer_segment: null, + isactive: 1, + } + const control = this._editTempLenderFrom.controls['temp_lender']; + control.push(this.initAnswers(newDate)); + } else { + const control = this._editTempLenderFrom.controls['temp_lender']; + control.push(this.initAnswers(data)); + } } removeLanguage(i: number) { const control = this._editTempLenderFrom.controls['temp_lender']; @@ -65,6 +181,57 @@ export class EditLenderComponent implements OnInit { onSubmit() { this.submitted = true; // stop here if form is invalid + if (this._editTempLenderFrom.invalid) { + this.errorMessage = "Please Fill All Mandate Fields."; + return; + } else { + var formValues = this._editTempLenderFrom.value; + //To Remove The "Null" With Key also + Object.keys(formValues).forEach((key) => (formValues[key] == null) && delete formValues[key]); + // alert(JSON.stringify(formValues.temp_lender)); + + if(!this.checkDuplicateInObject(formValues.temp_lender)) { + this.templatesService.updateTempateIDLenderDetails(formValues.temp_lender).subscribe( + dataresult => { + if (dataresult.status == 200) { + console.log(dataresult); + this.notifier.notify('success', 'Your Changes Updated.!'); + const arr = this._editTempLenderFrom.controls.temp_lender; + arr.controls.splice(0); + this.getTemplateLenderDetails(); + } + 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.!"; + }); + } else { + alert("duplication records occured.!"); + } + + } + } + + + checkDuplicateInObject(inputArray) { + let seenDuplicate = false; + + inputArray.map(function(item, index) { + let currentVal = inputArray[index]; + for(let i = index+1 ; i < inputArray.length ; i++ ){ + if(currentVal.fk_lender_id === inputArray[i].fk_lender_id + && currentVal.fk_product_id === inputArray[i].fk_product_id + && currentVal.fk_customer_segment === inputArray[i].fk_customer_segment){ + console.log('duplication: ' + i); + seenDuplicate = true; + } + } + console.log(index); + }); + return seenDuplicate; } ngOnDestroy(): void { diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.html b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.html new file mode 100644 index 000000000..a5c7e95da --- /dev/null +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.html @@ -0,0 +1,102 @@ + + + + + +
+ +
+ +
+ + + + +
+
+ +
+
+ +
+
+ + + % +
+
+ +
+
+
+
+ + +
+
+
+
+ + + + +
+
+ + + +
+
+
+
+ + + + + +
+
+ This Category Already Exist.! +
+
+
+ +
+ \ No newline at end of file diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.scss b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.scss new file mode 100644 index 000000000..98477e01a --- /dev/null +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.scss @@ -0,0 +1,8 @@ +.container { + min-height: 100%; + width: 100%; +} +.card-picture { + width: 23%; + margin-bottom: 2%; +} \ No newline at end of file diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.spec.ts b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.spec.ts new file mode 100644 index 000000000..b9d1cd04f --- /dev/null +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CategoryQuestionAnswerComponent } from './category-question-answer.component'; + +describe('CategoryQuestionAnswerComponent', () => { + let component: CategoryQuestionAnswerComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CategoryQuestionAnswerComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CategoryQuestionAnswerComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.ts b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.ts new file mode 100644 index 000000000..d75b7680b --- /dev/null +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.ts @@ -0,0 +1,316 @@ +import { Component, ViewChild, OnInit, OnDestroy, Input, Inject } from '@angular/core'; +import { MatPaginator, MatSort, MatTableDataSource, MatDialog, MatDialogRef, MAT_DIALOG_DATA, PageEvent } from '@angular/material'; +import { FormGroup, FormControl, FormBuilder, Validators , FormArray} from '@angular/forms'; +import { ActivatedRoute, Router } from '@angular/router'; +import { DataSource } from '@angular/cdk/table'; +import { Observable } from 'rxjs/Observable'; + +import { NotifierService } from 'angular-notifier'; +import { TemplatesService } from './../../../../../service/templates/templates.service'; +import { MastersService } from './../../../../../service/masters/masters.service'; + +export interface DialogData { + animal: string; + name: string; +} + +@Component({ + selector: 'app-category-question-answer', + templateUrl: './category-question-answer.component.html', + styleUrls: ['./category-question-answer.component.scss'] +}) +export class CategoryQuestionAnswerComponent implements OnInit { + + @Input() CaterogyQuesAns: any; + + _editquestionAnswerForm: FormGroup; + + public panelOpenState : boolean; + // secondFormGroup: FormGroup; + + + /** + * Notifier service + */ + private notifier: NotifierService; + + constructor( + notifier: NotifierService, + private templatesService: TemplatesService, + private mastersService: MastersService, + private _formBuilder: FormBuilder, + public dialog: MatDialog) { + this.notifier = notifier; + this._editquestionAnswerForm = this._formBuilder.group({ + temp_questions: this._formBuilder.array([ + // this.initAnswers(), + ]) + }); + // this.secondFormGroup = this._formBuilder.group({ + // secondCtrl: '' + // }); + } + + ngOnInit() { + this.setFirstFormDate(this.CaterogyQuesAns.questions); + } + + // setFirstFormDate(records){ + // alert(JSON.stringify(records)); + // } + + animal: string; + name: string; + + + openDialog(): void { + const dialogRef = this.dialog.open(DialogOverviewExampleDialog, { + data: {category_id: this.CaterogyQuesAns.fk_question_category_id, template_id: this.CaterogyQuesAns.fk_template_id} + }); + + dialogRef.afterClosed().subscribe(result => { + console.log('The dialog was closed'); + this.animal = result; + this.setModelFirstFormDate(result); + // alert(result); + }); + } + + setModelFirstFormDate(record){ + let val = record; + let vals = { + question_id: val.question_id, + question: val.question, + template_question_id: val.template_question_id, + fk_template_id: val.fk_template_id == null ? this.CaterogyQuesAns.fk_template_id : val.fk_template_id, + fk_question_id: val.fk_question_id == null ? val.question_id: val.fk_question_id, + question_weightage: val.question_weightage, + fk_template_question_category_id: val.fk_template_question_category_id == null ? this.CaterogyQuesAns.fk_question_category_id : val.fk_template_question_category_id, + question_answerable_by:val.question_answerable_by, + isactive: val.isactive == null? 1 : val.isactive, + answers: val.answers + }; + this.addLanguage(vals, null); + } + + setFirstFormDate(record) { + if (record.length > 0) { + for (let val of record) { + let vals = { + question_id: val.question_id, + question: val.question, + template_question_id: val.template_question_id, + fk_template_id: val.fk_template_id == null ? this.CaterogyQuesAns.fk_template_id : val.fk_template_id, + fk_question_id: val.fk_question_id == null ? val.question_id: val.fk_question_id, + question_weightage: val.question_weightage, + fk_template_question_category_id: val.fk_template_question_category_id == null ? this.CaterogyQuesAns.fk_template_question_category_id : val.fk_template_question_category_id, + question_answerable_by:val.question_answerable_by, + isactive: val.isactive == null? 1 : val.isactive, + answers: val.answers + }; + this.addLanguage(vals, null); + } + } + } + + setAnswers(record, i){ + for (let val of record) { + let vals = { + question_answer_id: val.question_answer_id, + answer: val.answer, + template_answer_weightage_id: val.template_answer_weightage_id, + fk_template_question_id: val.fk_template_question_id, + fk_question_answer_id: val.fk_question_answer_id == null ? val.question_answer_id : val.fk_question_answer_id , + template_answer_weightage: val.template_answer_weightage, + template_answer_remark: val.template_answer_remark, + isactive: val.isactive + }; + this.addAnswerData(vals, null, i); + } + } + + // ================== Dynamic Form set for Answers + + addAnswerData(data, e, ix) { + // const control = this._editquestionAnswerForm.controls['temp_questions'].get('answers'); + // let id = 0; + + const control = (this._editquestionAnswerForm.controls['temp_questions']).at(ix).get('answers') as FormArray; +// alert(control); + control.push(this.initAnswerData(data)); + } + + initAnswerData(data){ + return this._formBuilder.group({ + answer:[data.answer], + template_answer_weightage_id: [data.template_answer_weightage_id], + fk_template_question_id: [data.fk_template_question_id], + fk_question_answer_id: [data.fk_question_answer_id], + template_answer_weightage: [data.template_answer_weightage, Validators.compose([Validators.required])], + template_answer_remark: [data.template_answer_remark], + isactive: [data.isactive] + }); + } + + // ============================================= + + + // Dynamic Form field creation Functionality : START ===> + initAnswers(data) { + return this._formBuilder.group({ + question_id: [data.question_id], + question: [data.question], + template_question_id: [data.template_question_id], + fk_template_id: [data.fk_template_id], + fk_question_id: [data.fk_question_id], + question_weightage: [data.question_weightage, Validators.compose([Validators.required])], + fk_template_question_category_id: [data.fk_template_question_category_id], + isactive: [data.isactive], + question_answerable_by: [data.question_answerable_by], + answers: this._formBuilder.array([ + // this.setAnswers(data.answers) + ]) + }); + } + addLanguage(data, e) { + if (data == null) { + let newDate = { + question:null, + template_question_id: null, + fk_template_id: null, + fk_question_category_id: null, + question_weightage: null, + isactive: 1, + } + const control = this._editquestionAnswerForm.controls['temp_questions']; + control.push(this.initAnswers(newDate)); + } else { + // alert(JSON.stringify(data)); + const control = this._editquestionAnswerForm.controls['temp_questions']; + control.push(this.initAnswers(data)); + // alert(control.length); + // alert(JSON.stringify(this._editquestionAnswerForm.controls.temp_questions['controls'])); + this.setAnswers(data.answers, control.length - 1); + } + } + // =========== : END + + + removeLanguage(inx) { + // let value = this._editquestionAnswerForm.controls['temp_questions'].indexOf(inx); + let value = (this._editquestionAnswerForm.controls['temp_questions']).at(inx).get('template_question_id').value; + if(value == null){ + const control = this._editquestionAnswerForm.controls['temp_questions']; + control.removeAt(inx); + } else { +alert(); + } + // alert(JSON.stringify(value)); +} + + submitted: boolean; + onSubmit() { + this.submitted = true; + // stop here if form is invalid + if (this._editquestionAnswerForm.invalid) { + alert('no'); + return; + } else { + var formValues = this._editquestionAnswerForm.value; + //To Remove The "Null" With Key also + Object.keys(formValues).forEach((key) => (formValues[key] == null) && delete formValues[key]); + + let val = formValues.temp_questions; + let totalScore = val.map(value => { return Number(value.question_weightage); }).reduce((acc, value) => { return acc + value; }, 0); + + if (totalScore == 100) { + if (!this.checkDuplicateInObject(formValues.temp_questions)) { + this.templatesService.updateTempateIDQuesAnsDetails(formValues.temp_questions).subscribe( + dataresult => { + if (dataresult.status == 200) { + console.log(dataresult); + this.notifier.notify('success', 'Your Changes Updated.!'); + // const arr = this._editquestionAnswerForm.controls.temp_questions; + // arr.controls.splice(0); + // this.getTemplateCategoryDetails(); + } + 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.!"; + }); + } else { + alert("duplication records occured.!"); + } + } else { + alert("value should equal to 100") + } + + } + } + + public dublicateRerdIndex = -1; + + checkDuplicateInObject(inputArray) { + this.dublicateRerdIndex = -1; + let seenDuplicate = false; + + inputArray.map((item, index) => { + let currentVal = inputArray[index]; + for(let i = index+1 ; i < inputArray.length ; i++ ){ + if(currentVal.question_id === inputArray[i].question_id){ + console.log('duplication: ' + i); + this.dublicateRerdIndex = i; + seenDuplicate = true; + } + } + console.log(index); + }); + return seenDuplicate; + } + +} + +@Component({ + selector: 'dialog-overview-example-dialog', + templateUrl: './dialog-category-question-list.html' +}) +export class DialogOverviewExampleDialog { + +// typesOfShoes: string[] = [ +// 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, ', +// 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, ', +// 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, ', +// 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, ', +// 'It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, ' +// ]; + + public m_questions:any; + constructor( + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: DialogData, + private templatesService: TemplatesService, + private mastersService: MastersService,) { + this.getCategoryRemainingQuesMasters(); + } + + onNoClick(ques): void { + this.dialogRef.close(ques); + } + + getCategoryRemainingQuesMasters() { + this.templatesService.getRemaningQuestionCategory(this.data).subscribe( + data => { + this.m_questions = data.records; + }, + error => { + // this.notifier.notify('warning', 'No Category Master Records Found.!'); + // this.m_category = "No Category Master Records Found."; + } + ); + } + +} diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/dialog-category-question-list.html b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/dialog-category-question-list.html new file mode 100644 index 000000000..1a0eee7f0 --- /dev/null +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/dialog-category-question-list.html @@ -0,0 +1,5 @@ +
+ + {{question.question}} + +
\ No newline at end of file diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/edit-question-answer.component.html b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/edit-question-answer.component.html index c8a3175eb..f7daefbc0 100644 --- a/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/edit-question-answer.component.html +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/edit-question-answer.component.html @@ -1,91 +1,20 @@ - + - - - - Category 1 + + + + {{ data.category_name }} - - 50% + + {{ data.weightage }} - - + + + - + - + \ No newline at end of file diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/edit-question-answer.component.ts b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/edit-question-answer.component.ts index 7c53dca47..16645663d 100644 --- a/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/edit-question-answer.component.ts +++ b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/edit-question-answer.component.ts @@ -5,6 +5,11 @@ import { ActivatedRoute, Router } from '@angular/router'; import { DataSource } from '@angular/cdk/table'; import { Observable } from 'rxjs/Observable'; +import { NotifierService } from 'angular-notifier'; +import { TemplatesService } from './../../../../service/templates/templates.service'; +import { MastersService } from './../../../../service/masters/masters.service'; + + @Component({ selector: 'app-template-edit-question-answer', templateUrl: './edit-question-answer.component.html', @@ -18,13 +23,29 @@ export class EditQuestionAnswerComponent implements OnInit { public _editTempCategoryFrom: FormGroup; public submitted = false; public panelOpenState : boolean; + public templateQuesAnsRecord: any; + + firstFormGroup: FormGroup; + secondFormGroup: FormGroup; + constructor( + notifier: NotifierService, + private templatesService: TemplatesService, + private mastersService: MastersService, private _formBuilder: FormBuilder, public dialog: MatDialog) { + this.firstFormGroup = this._formBuilder.group({ + temp_questions: this._formBuilder.array([ + // this.initAnswers(), + ]) + }); + this.secondFormGroup = this._formBuilder.group({ + secondCtrl: '' + }); } - ngOnInit() { + this.getTemplateQuesAnsDetails(); this.initalLoadFormData(); if(this.categoryList.length > 0){ for (let val of this.categoryList) { @@ -35,6 +56,10 @@ export class EditQuestionAnswerComponent implements OnInit { } } + setFormQuestionData(record) { + // alert(JSON.stringify(record)); + } + initalLoadFormData(){ this._editTempCategoryFrom = this._formBuilder.group({ temp_category: this._formBuilder.array([ @@ -89,6 +114,26 @@ export class EditQuestionAnswerComponent implements OnInit { // END ===> + getTemplateQuesAnsDetails() { + this.templatesService.getTemplateIDQuesAnsDetails(this.questionId).subscribe( + data => { + if (data) { + if (data.records) { + this.templateQuesAnsRecord = data.records; + this.setFormQuestionData(this.templateQuesAnsRecord); + // this.templateListData = data.records; + // this.dataLength = data.records.length; + // this.dataSource.data = this.templateListData; + } else { + // this.noTemplateLendersFound = true; + } + } else { + // this.noTemplateLendersFound = true; + } + } + ); + } + /** To Save/Edited Popup Data */ onSubmit() { diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/templates.edit.component.html b/ng6-seed/src/app/template/templates/templates-list/edit/templates.edit.component.html index abf8dcde4..36c6cc3bf 100644 --- a/ng6-seed/src/app/template/templates/templates-list/edit/templates.edit.component.html +++ b/ng6-seed/src/app/template/templates/templates-list/edit/templates.edit.component.html @@ -7,31 +7,43 @@
Template Name

-
+ +
+
- - + + You must Include Template Name.
- +
+
+
No Template Name Found.
+ + + + - + + + + + diff --git a/ng6-seed/src/app/template/templates/templates-list/edit/templates.edit.component.ts b/ng6-seed/src/app/template/templates/templates-list/edit/templates.edit.component.ts index 9f15b1428..888795e67 100644 --- a/ng6-seed/src/app/template/templates/templates-list/edit/templates.edit.component.ts +++ b/ng6-seed/src/app/template/templates/templates-list/edit/templates.edit.component.ts @@ -1,14 +1,16 @@ import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core'; import { MatPaginator, MatSort, MatTableDataSource, MatDialog, PageEvent } from '@angular/material'; -import { FormGroup, FormControl, FormBuilder } from '@angular/forms'; +import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; import { DataSource } from '@angular/cdk/table'; import { Observable } from 'rxjs/Observable'; +import { NotifierService } from 'angular-notifier'; import { TemplateListComponent } from './../templates.list.component'; +import { TemplatesService } from './../../../service/templates/templates.service'; /* -* Template Edit component +* Edit Template Name component * : kdk */ @Component({ @@ -16,18 +18,70 @@ import { TemplateListComponent } from './../templates.list.component'; templateUrl: './templates.edit.component.html' }) export class TemplateEditComponent implements OnInit, OnDestroy { - public pageTitle: string = "Edit Template"; + public pageTitle: string = "Edit Template"; public question_id : number; public submitted: boolean = false; + public _editTempNameFrom: FormGroup; + public templateNameRecord: any; + public noTemplateNameFound: boolean; - constructor( private route: ActivatedRoute, + /** + * Notifier service + */ + private notifier : NotifierService; + + constructor( + notifier: NotifierService, + private route: ActivatedRoute, private router: Router, - private templateListComponent : TemplateListComponent) { + private templateListComponent : TemplateListComponent, + private templatesService: TemplatesService, + private _formBuilder: FormBuilder,) { + this.notifier = notifier; this.question_id = this.route.snapshot.params['question-id']; + this.getTemplateNameDetails(this.question_id); } ngOnInit() { this.templateListComponent.showListView(false); + // this._editTempNameFrom = this._formBuilder.group({ + // template_name: [this.templateNameDetails.template_name, Validators.compose([Validators.required]) ] + // }) + } + + setFormDatas(){ + // alert(this.templateNameDetails.template_name); + this._editTempNameFrom = this._formBuilder.group({ + template_id: [this.templateNameRecord.template_id], + template_name: [this.templateNameRecord.template_name, Validators.compose([Validators.required]) ], + isactive: [this.templateNameRecord.isactive] + }) + } + + + // convenience getter for easy access to form fields + get f() { return this._editTempNameFrom.controls; } + + // get Template name details + getTemplateNameDetails(q_id){ + this.templatesService.getTemplateIDNameDetails(q_id).subscribe( + data => { + if (data) { + if (data.records) { + this.noTemplateNameFound = false; + this.templateNameRecord = data.records[0]; + this.setFormDatas(); + // this.templateListData = data.records; + // this.dataLength = data.records.length; + // this.dataSource.data = this.templateListData; + } else { + this.noTemplateNameFound = true; + } + } else { + this.noTemplateNameFound = true; + } + } + ); } backToList(){ @@ -35,10 +89,41 @@ export class TemplateEditComponent implements OnInit, OnDestroy { this.router.navigate([ '../../' ], { relativeTo: this.route }); } + public errorMessage; + /** To Save/Edited Popup Data */ onSubmit() { - this.submitted = true; + this.submitted = true; // stop here if form is invalid + if (this._editTempNameFrom.invalid) { + this.errorMessage = "Please Fill All Mandate Fields."; + return; + } else { + var formValues = this._editTempNameFrom.value; + //To Remove The "Null" With Key also + Object.keys(formValues).forEach((key) => (formValues[key] == null) && delete formValues[key]); + + this.templatesService.updateTempateIDNameDetails(formValues).subscribe( + dataresult => { + if (dataresult.status == 200) { + console.log(dataresult); + this.notifier.notify('success', 'Your Changes Updated.!'); + this.getTemplateNameDetails(this.question_id); + } + 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.!"; + }); + } + } + + /** To Reset Popup Data */ + onReset() { + this.setFormDatas(); } ngOnDestroy(): void { diff --git a/ng6-seed/src/app/template/templates/templates-list/templates.list.component.ts b/ng6-seed/src/app/template/templates/templates-list/templates.list.component.ts index 12501d0ab..f2c7aefba 100644 --- a/ng6-seed/src/app/template/templates/templates-list/templates.list.component.ts +++ b/ng6-seed/src/app/template/templates/templates-list/templates.list.component.ts @@ -5,6 +5,8 @@ import { FormGroup, FormControl, FormBuilder } from '@angular/forms'; import { DataSource } from '@angular/cdk/table'; import { Observable } from 'rxjs/Observable'; +import { TemplatesService } from './../../service/templates/templates.service'; + /* * Template List component * : kdk @@ -20,6 +22,7 @@ export class TemplateListComponent implements OnInit, OnDestroy { public listView: boolean; public names: string; public noTemplMasterRecrdFound: boolean = false; + public search_cid : any; // pagination variable details length = 50; @@ -38,7 +41,8 @@ export class TemplateListComponent implements OnInit, OnDestroy { constructor( private route: ActivatedRoute, - private router: Router) { + private router: Router, + private templatesService: TemplatesService) { this.listView = true; // this.names = 'dinesh'; } @@ -51,34 +55,34 @@ export class TemplateListComponent implements OnInit, OnDestroy { // get question master list details getTemplateMastersListDetails() { - this.templateList = this.m_templateList.records; - this.templateListData = this.m_templateList.records; - this.dataLength = this.m_templateList.records.length; - this.dataSource.data = this.templateListData; - - // this.noTemplMasterRecrdFound = false; - // this.search_cid = this.filterFormGroupCtrl.controls.category.value; - // console.log(this.search_cid + ", " + this.filterFormGroupCtrl); - // this.questionsService.getQuestionMasterDetails(this.search_cid).subscribe( - // data => { - // if (data) { - // if (data.records) { - // this.templateList = data.records; - // this.templateListData = data.records; - // this.dataLength = data.records.length; + // this.templateList = this.m_templateList.records; + // this.templateListData = this.m_templateList.records; + // this.dataLength = this.m_templateList.records.length; // this.dataSource.data = this.templateListData; - // } else { - // this.templateList = []; - // this.dataLength = null; - // this.noTemplMasterRecrdFound = true; - // } - // } else { - // this.templateList = []; - // this.dataLength = null; - // this.noTemplMasterRecrdFound = true; - // } - // } - // ) + + this.noTemplMasterRecrdFound = false; + this.search_cid = ''; + // console.log(this.search_cid + ", " + this.filterFormGroupCtrl); + this.templatesService.getTemplatesMasterListDetails(this.search_cid).subscribe( + data => { + if (data) { + if (data.records) { + this.templateList = data.records; + this.templateListData = data.records; + this.dataLength = data.records.length; + this.dataSource.data = this.templateListData; + } else { + this.templateList = []; + this.dataLength = null; + this.noTemplMasterRecrdFound = true; + } + } else { + this.templateList = []; + this.dataLength = null; + this.noTemplMasterRecrdFound = true; + } + } + ) } diff --git a/ng6-seed/src/app/template/templates/templates.module.ts b/ng6-seed/src/app/template/templates/templates.module.ts index a7c1b6938..4a9106265 100644 --- a/ng6-seed/src/app/template/templates/templates.module.ts +++ b/ng6-seed/src/app/template/templates/templates.module.ts @@ -29,7 +29,11 @@ import { EditCategoryComponent } from './templates-list/edit/edit-category/edit- import { EditLenderComponent } from './templates-list/edit/edit-lender/edit-lender.component'; import { EditQuestionAnswerComponent } from './templates-list/edit/edit-question-answer/edit-question-answer.component'; -// import { QuestionsService } from './../service/questions/questions.service'; + +import { TemplatesService } from './../service/templates/templates.service'; +import { CategoryQuestionAnswerComponent } from './templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component'; +import { DialogOverviewExampleDialog } from './templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component'; + /* * Question Master Module details * : kdk @@ -105,12 +109,15 @@ const customNotifierOptions: NotifierOptions = { TemplateEditComponent, EditCategoryComponent, EditLenderComponent, - EditQuestionAnswerComponent + EditQuestionAnswerComponent, + CategoryQuestionAnswerComponent, + DialogOverviewExampleDialog ], entryComponents: [ + DialogOverviewExampleDialog ], providers: [ - // QuestionsService + TemplatesService ] }) export class TemplatesModule { }