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 @@
-
-
-