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 16e1c1011..c44109d59 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,7 +1,3 @@ - - -
@@ -24,46 +20,12 @@ Weightage Required.!
- +
- 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 2bd2f071a..d49a929c1 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 @@ -9,6 +9,11 @@ import { NotifierService } from 'angular-notifier'; import { TemplatesService } from './../../../../service/templates/templates.service'; import { MastersService } from './../../../../service/masters/masters.service'; +/* +* Question Cagegory add and edit functionality with dynamic form creation with validation +* : kdk +*/ + @Component({ selector: 'app-template-edit-category', templateUrl: './edit-category.component.html', @@ -48,14 +53,6 @@ export class EditCategoryComponent implements OnInit, OnDestroy, AfterViewInit { // 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); - // } - // } } ngAfterViewInit() { @@ -77,7 +74,6 @@ export class EditCategoryComponent implements OnInit, OnDestroy, AfterViewInit { } } - // Dynamic Form field creation Functionality : START ===> initAnswers(data) { return this._formBuilder.group({ @@ -112,9 +108,6 @@ export class EditCategoryComponent implements OnInit, OnDestroy, AfterViewInit { 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; } @@ -150,30 +143,6 @@ export class EditCategoryComponent implements OnInit, OnDestroy, AfterViewInit { // 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 categoryList = [{ - 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({ @@ -186,9 +155,16 @@ export class EditCategoryComponent implements OnInit, OnDestroy, AfterViewInit { // 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); + let value = (this._editTempCategoryFrom.controls['temp_category']).at(i).get('template_category_weightage_id').value; + if (value == null) { + const control = this._editTempCategoryFrom.controls['temp_category']; + control.removeAt(i); + } else { + this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + } + } // END ===> @@ -200,17 +176,14 @@ export class EditCategoryComponent implements OnInit, OnDestroy, AfterViewInit { this.submitted = true; // stop here if form is invalid if (this._editTempCategoryFrom.invalid) { - alert('no'); + this.notifier.notify('warning', 'Should Fill Required Fields.!'); 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( @@ -231,10 +204,10 @@ export class EditCategoryComponent implements OnInit, OnDestroy, AfterViewInit { this.errorMessage = "Some Thing Wents Wrong Try Again.!"; }); } else { - alert("duplication records occured.!"); + this.notifier.notify('warning', 'duplication records occured.!'); } } else { - alert("value should equal to 100") + this.notifier.notify('warning', 'value should equal to 100.!'); } } @@ -248,8 +221,8 @@ export class EditCategoryComponent implements OnInit, OnDestroy, AfterViewInit { 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){ + 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; @@ -264,6 +237,4 @@ export class EditCategoryComponent implements OnInit, OnDestroy, AfterViewInit { //Called once, before the instance is destroyed. //Add 'implements OnDestroy' to the class. } - - } 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 44294fcb1..042c179f7 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,10 +1,3 @@ - - -
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 bc95d91cb..781a76274 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 @@ -1,6 +1,6 @@ import { Component, ViewChild, OnInit, OnDestroy, Input } 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'; @@ -9,6 +9,10 @@ import { NotifierService } from 'angular-notifier'; import { TemplatesService } from './../../../../service/templates/templates.service'; import { MastersService } from './../../../../service/masters/masters.service'; +/* +* Question Lender Details Get Multi drop-down and dynamic form with validation +* : kdk +*/ @Component({ selector: 'app-template-edit-lender', @@ -17,31 +21,31 @@ import { MastersService } from './../../../../service/masters/masters.service'; }) export class EditLenderComponent implements OnInit { - - @Input() questionId: number; + + @Input() questionId: number; public noTemplateLendersFound: boolean; public templateLenderRecord: any; public errorMessage; - public m_lender : any; + public m_lender: any; public m_product: any; - public m_customerSegment : any; + public m_customerSegment: any; public _editTempLenderFrom: FormGroup; public submitted = false; - + /** * Notifier service */ - private notifier : NotifierService; + private notifier: NotifierService; constructor( notifier: NotifierService, private templatesService: TemplatesService, private mastersService: MastersService, private _formBuilder: FormBuilder) { - this.notifier = notifier; + this.notifier = notifier; } ngOnInit() { @@ -51,51 +55,51 @@ export class EditLenderComponent implements OnInit { this.getCustomerSegmentMasters(); this._editTempLenderFrom = this._formBuilder.group({ - temp_lender: this._formBuilder.array([ + temp_lender: this._formBuilder.array([ // this.initAnswers(), ]) - }) + }) } - setFormDatas(record){ - if (record.length > 0) { + 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, + 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; - } - } - ); + 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 => { + getLenderMasters() { + this.templatesService.getLenderMasterListDetails().subscribe( + data => { this.m_lender = data.records; }, error => { @@ -105,9 +109,9 @@ export class EditLenderComponent implements OnInit { ); } - getProductsMasters(){ - this.templatesService.getProductsMasterListDetails().subscribe( - data => { + getProductsMasters() { + this.templatesService.getProductsMasterListDetails().subscribe( + data => { this.m_product = data.records; }, error => { @@ -118,8 +122,8 @@ export class EditLenderComponent implements OnInit { } getCustomerSegmentMasters() { - this.templatesService.getCustomerSegmentsMasterListDetails().subscribe( - data => { + this.templatesService.getCustomerSegmentsMasterListDetails().subscribe( + data => { this.m_customerSegment = data.records; }, error => { @@ -129,31 +133,22 @@ export class EditLenderComponent implements OnInit { ); } - // convenience getter for easy access to form fields + // convenience getter for easy access to form fields get f() { return this._editTempLenderFrom.controls; } - - public entityOptions = [{ - fk_lender_id: 1, - name: 'Lender1' - },{ - fk_lender_id: 2, - name: 'Lender2' - }]; - - // Dynamic Form field creation Functionality : START ===> + // Dynamic Form field creation Functionality : START ===> initAnswers(data) { return this._formBuilder.group({ - 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], + 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(data, e) { - if(data == null){ + if (data == null) { let newDate = { template_lender_map_id: null, fk_template_id: this.questionId, @@ -176,7 +171,6 @@ export class EditLenderComponent implements OnInit { // END ===> - /** To Save/Edited Popup Data */ onSubmit() { this.submitted = true; @@ -189,49 +183,46 @@ export class EditLenderComponent implements OnInit { //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 => { + 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 = "Some Thing 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.!"); + this.notifier.notify('warning', '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; - } + 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; + } + 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.ts b/ng6-seed/src/app/template/templates/templates-list/edit/edit-question-answer/category-question-answer/category-question-answer.component.ts index b585f3ffb..ea00eaaad 100644 --- 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 @@ -1,6 +1,6 @@ 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 { 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'; @@ -17,6 +17,11 @@ export interface DialogData { /**sweet alert */ // import Swal from 'sweetalert2'; +/* +* Templates Category Question list with answers , with multiple question with answer dynamic form validation +* : kdk +*/ + @Component({ selector: 'app-category-question-answer', templateUrl: './category-question-answer.component.html', @@ -24,17 +29,16 @@ export interface DialogData { }) export class CategoryQuestionAnswerComponent implements OnInit { - countries = ['d', 'd', 'd', 'd', 'd' ,'d']; + countries = ['d', 'd', 'd', 'd', 'd', 'd']; regularDistribution = 100 / 3; - @Input() CaterogyQuesAns: any; + @Input() CaterogyQuesAns: any; _editquestionAnswerForm: FormGroup; - public panelOpenState : boolean; + public panelOpenState: boolean; // secondFormGroup: FormGroup; - /** * Notifier service */ @@ -46,57 +50,53 @@ export class CategoryQuestionAnswerComponent implements OnInit { 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: '' - // }); + 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); + this.setFirstFormDate(this.CaterogyQuesAns.questions); } // setFirstFormDate(records){ // alert(JSON.stringify(records)); // } - animal: string; - name: string; - - openDialog(): void { + openDialog(): void { const dialogRef = this.dialog.open(DialogOverviewExampleDialog, { - data: {category_id: this.CaterogyQuesAns.fk_question_category_id, template_id: this.CaterogyQuesAns.fk_template_id} + 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){ + 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); + 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) { @@ -107,11 +107,11 @@ export class CategoryQuestionAnswerComponent implements OnInit { 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, + 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, + question_answerable_by: val.question_answerable_by, + isactive: val.isactive == null ? 1 : val.isactive, answers: val.answers }; this.addLanguage(vals, null); @@ -119,48 +119,44 @@ export class CategoryQuestionAnswerComponent implements OnInit { } } - 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); - } + 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); + const control = (this._editquestionAnswerForm.controls['temp_questions']).at(ix).get('answers') as FormArray; + // alert(control); control.push(this.initAnswerData(data)); } - initAnswerData(data){ + initAnswerData(data) { return this._formBuilder.group({ - answer:[data.answer], + 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] + 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({ @@ -174,14 +170,14 @@ export class CategoryQuestionAnswerComponent implements OnInit { isactive: [data.isactive], question_answerable_by: [data.question_answerable_by], answers: this._formBuilder.array([ - // this.setAnswers(data.answers) + // this.setAnswers(data.answers) ]) }); } addLanguage(data, e) { if (data == null) { let newDate = { - question:null, + question: null, template_question_id: null, fk_template_id: null, fk_question_category_id: null, @@ -191,11 +187,8 @@ export class CategoryQuestionAnswerComponent implements OnInit { 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); } } @@ -203,23 +196,22 @@ export class CategoryQuestionAnswerComponent implements OnInit { 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){ + // 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(); + } else { + this.notifier.notify('warning', 'Something Wents Wrong Try Again.!'); + } } - // alert(JSON.stringify(value)); -} submitted: boolean; onSubmit() { this.submitted = true; // stop here if form is invalid if (this._editquestionAnswerForm.invalid) { - alert('no'); + this.notifier.notify('warning', 'Please Should Fill Required Fields.!'); return; } else { var formValues = this._editquestionAnswerForm.value; @@ -236,10 +228,7 @@ alert(); 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.!"; @@ -249,13 +238,12 @@ alert(); // this.errorMessage = "Some Thing Wents Wrong Try Again.!"; }); } else { - alert("duplication records occured.!"); + this.notifier.notify('warning', 'duplication records occured.!'); } } else { - // Swal('value should equal to 100.!','error'); - alert("value should equal to 100"); + // Swal('value should equal to 100.!','error'); + this.notifier.notify('warning', 'value should equal to 100.!'); } - } } @@ -264,11 +252,10 @@ alert(); 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){ + 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; @@ -283,7 +270,7 @@ alert(); @Component({ selector: 'dialog-overview-example-dialog', - styles:[` + styles: [` .listHover: hover { background: yellow; }` @@ -292,44 +279,34 @@ alert(); }) 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; + 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); - } + private mastersService: MastersService) { + this.getCategoryRemainingQuesMasters(); + } - errorRecord : string; - noRecordFound: boolean; + onNoClick(ques): void { + this.dialogRef.close(ques); + } - getCategoryRemainingQuesMasters() { + errorRecord: string; + noRecordFound: boolean; + + getCategoryRemainingQuesMasters() { this.templatesService.getRemaningQuestionCategory(this.data).subscribe( data => { - if(data.status === 200 && data.dataStatus){ - this.noRecordFound = true; - this.m_questions = data.records; + if (data.status === 200 && data.dataStatus) { + this.noRecordFound = true; + this.m_questions = data.records; } else { - this.noRecordFound = false; + this.noRecordFound = false; } }, error => { - this.noRecordFound = true; - // this.notifier.notify('warning', 'No Category Master Records Found.!'); - // this.m_category = "No Category Master Records Found."; + this.noRecordFound = true; } ); } 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 f7daefbc0..597dbd848 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,5 +1,4 @@ - @@ -14,16 +13,5 @@ - \ 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 16645663d..e253d386a 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 @@ -20,110 +20,27 @@ export class EditQuestionAnswerComponent implements OnInit { @Input() questionId: number; - 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) { - // alert(JSON.stringify(val)); - let vals = val; - this.addLanguage(vals['fk_category_id'], vals['name'], vals['weightage'], null); - } - } } - setFormQuestionData(record) { - // alert(JSON.stringify(record)); - } - - initalLoadFormData(){ - this._editTempCategoryFrom = this._formBuilder.group({ - temp_category: this._formBuilder.array([ - // this.initAnswers(), - ]) - }) - } - - // 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 categoryList = [{ - 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)); - } - removeLanguage(i: number) { - const control = this._editTempCategoryFrom.controls['temp_category']; - control.removeAt(i); - } - - // 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; }