@rangertechnologies/ngnxt
Version:
This library was used for creating dymanic UI based on the input JSON/data
1,246 lines (1,245 loc) • 487 kB
JavaScript
import { Component, Input, Output, EventEmitter, ViewEncapsulation, } from "@angular/core";
import * as moment from 'moment';
import { ChangeService } from '../../services/change.service';
import { Question, AnswerWrapper, OptionValue, AttachmentWrapper, Attachment, LocalQuestion } from "../../wrapper";
import { ErrorWrapper } from "../../model/errorWrapper";
import { DTQUESTION, TESTQB } from "../../sample";
import * as i0 from "@angular/core";
import * as i1 from "../../services/salesforce.service";
import * as i2 from "../../services/data.service";
import * as i3 from "../../services/change.service";
import * as i4 from "../../services/shared.service";
import * as i5 from "@angular/router";
import * as i6 from "@angular/platform-browser";
import * as i7 from "ngx-spinner";
import * as i8 from "@angular/forms";
import * as i9 from "ngx-device-detector";
import * as i10 from "../../i18n.service";
import * as i11 from "../../components/custom-rich-text/custom-rich-text.component";
import * as i12 from "@angular/common";
import * as i13 from "../../components/datatable/datatable.component";
import * as i14 from "ng-circle-progress";
import * as i15 from "../../components/pick-location/pick-location.component";
import * as i16 from "../../components/custom-input/custom-input.component";
import * as i17 from "../../components/custom-text-area/custom-text-area.component";
import * as i18 from "../../components/custom-date-picker/custom-date-picker.component";
import * as i19 from "../../components/dropdown-with-flag/dropdown-with-flag.component";
import * as i20 from "../../components/custom-dropdown/custom-dropdown.component";
import * as i21 from "../../components/custom-label/custom-label.component";
import * as i22 from "../../i18n.pipe";
export class QuestionnaireComponent {
sfService;
dataService;
changeService;
sharedService;
route;
sanitizer;
spinner;
_formBuilder;
deviceService;
i18nService;
qbId;
insuranceStartDate;
serv;
tkn;
api; // VD getting the api as input
handleEvent = new EventEmitter();
handlePage = new EventEmitter();
handleQuestion = new EventEmitter();
handleBook = new EventEmitter();
handleSubmit = new EventEmitter();
params;
deviceInfo = null;
abItem;
qbItem;
questionItem;
answerWrap;
// CONDITIONAL TYPES
radioFlag = false;
dataFlag = false;
// OPTIONONLY TYPES
dropdownFlag = false;
checkboxFlag = false;
// UNCONDITIONAL TYPES
textFlag = false;
taFlag = false;
rtaFlag = false;
dtFlag = false;
timeFlag = false;
dateFlag = false;
fileFlag = false;
emailFlag = false;
numberFlag = false;
alphanumericFlag = false;
bookFlag = false;
listFlag = false;
//Back button
backButtonFlag = false;
// VD disabled
isButtonDisabled = false;
optionValues = [];
subQuestions = [];
inpValue;
answerMap = new Map();
dateMap = new Map();
selectedhourMap = new Map();
selectedminuteMap = new Map();
attachmentsMap = new Map();
sqOptions = new Map();
subAnsMap = new Map();
localSubQuestions = [];
questionStack = [];
questionName = [];
attachments = [];
attachmentIdList = [];
attachmentId = "";
attachment;
allowedFileExtension;
fileExceededLimit = false;
fileTypeIncorrect = false;
back = false;
backicon = true;
check;
pop;
localDate;
currentName;
pathquestion;
percent;
count;
taFocusOut = false;
notValidAccNum = false;
splCCBackClick = false;
summary = [];
localSubQMap = new Map();
keyIndex = 0;
//public sques: string;
selDate = {};
selectDate;
today = new Date();
el;
innerhtml;
possibilities;
innerhtml1;
summaryData = [];
hours = [
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12",
];
minutes = [
"00",
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"35",
"36",
"37",
"38",
"39",
"40",
"41",
"42",
"43",
"44",
"45",
"46",
"47",
"48",
"49",
"50",
"51",
"52",
"53",
"54",
"55",
"56",
"57",
"58",
"59",
];
selectedHour = "";
selectedMinute = "";
selectedMeridiem = "";
valueName = "";
valueName1 = "";
bookFlagAccept;
recordId;
currentQuestionId;
spinnerType;
spinnerName;
nextValue = '';
start_date;
//search component
tempoAddress = [];
selectedValue;
selectedPostalcode;
selectedProvince;
selectedCity;
selectedArea;
localaddress = [];
allAddress = [];
PostalCode;
places = [];
province = [];
// REQ-01 PROGRESS BAR
progressStyle = "0%";
answerCount = 0;
indexCount = 0;
addFlag = true;
myDatePickerOptions = {};
individualBookButton;
allInputValues = []; // HA 02FEB24 To store all the input values
constructor(sfService, dataService, changeService, sharedService, route, sanitizer, spinner, _formBuilder,
//private dbService: NgxIndexedDBService,
deviceService, el, i18nService) {
this.sfService = sfService;
this.dataService = dataService;
this.changeService = changeService;
this.sharedService = sharedService;
this.route = route;
this.sanitizer = sanitizer;
this.spinner = spinner;
this._formBuilder = _formBuilder;
this.deviceService = deviceService;
this.i18nService = i18nService;
// VD 10Aug24-spinner changes
this.spinnerName = "sp1";
this.spinnerType = "ball-spin-clockwise-fade";
}
// HA 02FEB24 On date change need to store the changed value so passing the question
// RS 09DEC24 Changed keys
onDateChanged(event, ques) {
//console.log('Inside the onDateChanged');
//to change the border color
if (this.qbItem.progressBar) {
//console.log('Inside the progressBar cond');
this.inpValue =
event.date.day + "/" + event.date.month + "/" + event.date.year;
if (this.questionItem.type == "Book") {
this.selectDate = event.date.day + "/" + event.date.month + "/" + event.date.year;
}
}
else {
//console.log('Inside the ELSE of progressBar cond');
if (this.questionItem.type == "Book") {
this.selectDate = event.date.day + "-" + event.date.month + "-" + event.date.year;
}
this.inpValue =
event.date.year + "-" + event.date.month + "-" + event.date.day;
}
const htmlElement = window.document.getElementsByClassName("mydp");
htmlElement
.item(0)
.setAttribute("style", "border-color:#87be1c;width:100%");
this.dateMap.set(this.questionItem.id, event);
if (event.date.day === 0 &&
event.date.month === 0 &&
event.date.year === 0) {
this.dateMap.delete(this.questionItem.id);
this.answerMap.delete(this.questionItem.id);
}
//console.log('this.inpValue = '+this.inpValue);
//console.log('this.selectDate = '+this.selectDate);
// HA 02FEB24 Assigning input value to ques input
ques.input = this.inpValue;
}
ngOnInit() {
this.deviceInfo = this.deviceService.getDeviceInfo();
this.route.queryParams.subscribe((params) => {
if (params['id']) {
this.individualBookButton = true;
}
else if (params['bookletId']) {
this.individualBookButton = false;
}
});
this.inpValue = "";
this.selectedMeridiem = "AM";
this.processQB();
//console.log(localStorage.getItem('address'));
if (localStorage.getItem("address")) {
this.localaddress = JSON.parse(localStorage.getItem("address"));
//console.log('Length='+this.localaddress.length);
this.allAddress = this.localaddress.filter((item, index) => {
if (this.localaddress.indexOf(item) == index) {
return item;
}
});
this.allAddress.sort(function (a, b) {
return a.zipCode - b.zipCode;
});
}
else if (this.deviceInfo.os === 'iOS') {
let openRequest = indexedDB.open("addressDB");
openRequest.onsuccess = (event) => {
const targetNew = event.target;
let dbNew = targetNew.result;
const requestNew = dbNew.transaction('addressTable')
.objectStore('addressTable')
.get(1);
requestNew.onsuccess = () => {
const tempVar = requestNew.result;
this.localaddress = JSON.parse(tempVar.wholeAddressString);
this.allAddress = this.localaddress.filter((item, index) => {
if (this.localaddress.indexOf(item) == index) {
return item;
}
});
this.allAddress.sort(function (a, b) {
return a.zipCode - b.zipCode;
});
};
};
}
}
ngAfterViewInit() {
// SKS20MAR25 Ensure the child component is available before calling the method
// AP-25MAR25 Empty string replace null
setTimeout(() => {
this.subQuestions.forEach(ques => {
let input;
if (ques.type == 'Dropdown' || ques.type == 'Radio' || ques.type == 'Location') {
input = {};
input['valueObj'] = ques.input || null;
input['referenceField'] = ques.referenceField || null;
input['fromQuestionId'] = ques.id || null;
}
else if (ques.type == 'Date' || ques.type == 'DateTime') {
input = {};
input['value'] = ques.input || null;
}
else if (ques.type == 'List') {
input = {};
ques['subText'] = typeof ques?.subText === 'object' ? ques?.subText : JSON.parse(ques['subText']);
let apiObj = ques.subText;
input['valueObj'] = ques.input || null;
input['field'] = apiObj.defaultField || apiObj.field[0] || apiObj.field || null;
}
else {
input = ques.input || null;
}
this.childEventCapture(input, ques);
});
});
}
// call when bookId changes
ngOnChanges(simplechanges) {
if (simplechanges['qbId']) {
this.processQB();
}
}
// RS 09DEC24 Changed keys
date_TimeMap() {
this.selectedhourMap.set(this.questionItem.id, this.selectedHour);
this.selectedminuteMap.set(this.questionItem.id, this.selectedMinute);
}
day() {
this.myDatePickerOptions = {
dateFormat: "dd.mm.yyyy",
sunHighlight: false,
disableDateRanges: [],
showClearDateBtn: false,
disableSince: {
year: 0,
month: 0,
day: 0,
},
disableUntil: {
year: 0,
month: 0,
day: 0,
},
showTodayBtn: false,
dayLabels: {
su: "Dom",
mo: "Lun",
tu: "Mar",
we: "Mié",
th: "Jue",
fr: "Vie",
sa: "Sáb",
},
monthLabels: {
1: "Ene",
2: "Feb",
3: "Mar",
4: "Abr",
5: "Mayo",
6: "Jun",
7: "Jul",
8: "Ago",
9: "Sep",
10: "Oct",
11: "Nov",
12: "Dic",
},
};
}
change() {
const htmlElement = window.document.getElementsByClassName("mydp");
if (this.selDate === null || this.inpValue.length === 0) {
htmlElement
.item(0)
.setAttribute("style", "width:100%;border: 1px solid red");
}
else {
htmlElement
.item(0)
.setAttribute("style", "border: 1px solid #87be1c ;width:100%");
}
}
processQB() {
console.log('ProcessQB');
//this.qbItem
console.log(this.qbId);
//console.log('Version in process is 8bf11efa7f91a391d957bf6b5078edc7e656b67c');
if (this.qbId) {
if (this.qbId.length == 18) {
this.readQuestionBook(this.qbId);
}
else {
//console.log('Inside the else part');
//console.log('Setting the Question Directly for testing');
this.questionItem = DTQUESTION;
this.qbItem = TESTQB;
this.processQuestion();
}
}
}
trimLastDummy(input) {
return (input = input.substring(0, input.length - 6));
}
getProperTime(def, input) {
return input === "" ? def : input;
}
// RS 09DEC24 Changed keys
//Summary Question Clickable Logic
handleEditClick(value) {
this.backicon = false;
if (this.abItem?.status == "Pending") {
if (value == null) {
return;
}
this.readQuestion(value);
//console.log(' in side summaryopen'+ this.summary.length);
//Assign question stack length from summary part
var arrayLength = this.questionStack.length;
var lengthValue = this.questionStack.indexOf(value);
for (let i = arrayLength; i > lengthValue; i--) {
this.questionStack.pop();
}
if (this.qbItem.progressBar === true) {
var arrayLength1 = this.questionName.length;
for (let j = arrayLength1; j > lengthValue; j--) {
this.questionName.pop();
}
}
this.summary = [];
this.summaryData = [];
}
}
handleNextClick() {
// this.sharedService.showLoader();
this.spinner.show(this.spinnerName);
this.isButtonDisabled = true;
this.backButtonFlag = false;
this.AnswerSave();
}
AnswerSave() {
//this.updateProgress();
if (this.currentQuestionId === null) {
return;
}
var questionTxt = '';
this.clearError();
this.handleEvent.emit(this.qbItem.nextTrackingId);
this.recordId = null;
var cQuestion = new Question();
cQuestion = this.questionItem;
// MR 30JAN24 - Added Condition for this.questionItem.Questions__r (Book Question and Non-Book)
if (this.questionItem.subQuestions) {
// Create an array of objects to store the values
for (var i = 0; i < this.questionItem.subQuestions.length; i++) {
if (this.questionItem.subQuestions[i].questionText) {
var questionText = this.questionItem.subQuestions[i].questionText.replace(/<[^>]+>/g, ''); // Remove HTML tags from the questionText value
}
else {
questionText = 'undefined';
}
const input = this.questionItem.subQuestions[i].input;
const obj = { [questionText]: input }; // Create an object with the questionText as the key and the input as the value
this.summaryData.push(obj); // Add the object to the data array
}
}
else {
var questionText = this.questionItem.questionText.replace(/<[^>]+>/g, '');
const input = this.questionItem.input;
const obj = { [questionText]: input }; // Create an object with the questionText as the key and the input as the value
this.summaryData.push(obj); // Add the object to the data array
}
var typ = cQuestion.type;
// this.sques += cQuestion.question + '@@##$$';
var quesValue = cQuestion.questionText;
var mailformat = "^[^.][a-zA-Z0-9!#$%&'*+-/=?^_`{|}~]+[^.]@[^-][a-zA-Z0-9.-]+[^-].[a-zA-Z]{2,}$";
// Process Inputs
if (this.checkboxFlag) {
this.inpValue = "";
// Save all the selected options in the inpValue
for (var ov of this.optionValues.filter((item) => item.checked)) {
this.inpValue += ov.value + "@@##$$";
this.recordId = ov.nextQuestion;
}
this.inpValue = this.trimLastDummy(this.inpValue);
}
else if (this.emailFlag) {
if (this.inpValue && this.inpValue.match(mailformat)) {
this.recordId = this.questionItem.nextQuestion;
}
else {
this.questionItem.error = new ErrorWrapper();
return;
}
}
else if (this.alphanumericFlag) {
var isNotValidAccNum = this.isNotValidAccNumber(this.inpValue);
if (isNotValidAccNum) {
this.notValidAccNum = true;
this.recordId = this.questionItem.nextQuestion;
return;
}
this.notValidAccNum = false;
}
else if (this.numberFlag) {
if (this.inpValue) {
this.recordId = this.questionItem.nextQuestion;
}
else {
this.questionItem.error = new ErrorWrapper();
return;
}
}
else if (this.bookFlag) {
this.inpValue = "";
var hasMissingInput = false;
for (var item of this.questionItem.subQuestions) {
var count = 0;
if (item.type == "Date" || item.type == "Time") {
//this one
this.change();
if (item.type == "Date") {
//console.log('Inside the date type cond = '+this.selectDate);
this.inpValue = this.selectDate;
//console.log(this.inpValue)
//console.log(this.selectDate)
}
if (item.type == "Time") {
//console.log(this.selectedHour+this.selectedMeridiem+this.selectedMinute)
if (this.questionItem.x24Hours === false) {
this.questionItem.input =
(this.selectedMeridiem === "PM" && this.selectedHour != "12"
? Number(this.selectedHour) + 12
: this.selectedHour) +
":" +
this.selectedMinute + " PM";
if (this.selectedMeridiem === "AM" && this.selectedHour === "12") {
this.questionItem.input = "00" + ":" + this.selectedMinute + " AM";
}
if (this.qbItem.progressBar) {
if (this.selectDate) {
this.inpValue = this.selectDate + " " + this.questionItem.input;
}
else {
this.inpValue = " " + this.questionItem.input;
}
}
else {
if (this.selectDate) {
this.inpValue = this.selectDate + " " + this.questionItem.input;
}
else {
this.inpValue = " " + this.questionItem.input;
}
}
}
if (this.questionItem.x24Hours === true) {
this.questionItem.input =
this.selectedHour + ":" + this.selectedMinute;
if (this.qbItem.progressBar) {
this.inpValue = this.questionItem.input;
}
else {
this.inpValue = this.questionItem.input;
}
}
}
// HA 31-JAN-24 Removed the selectHour and selectMinute condition
if (this.selDate === null || this.selDate === undefined || !this.inpValue || !this.selectDate) {
//console.log('Inside the null condition of input');
this.questionItem.error = new ErrorWrapper();
const htmlElement = window.document.getElementsByClassName("mydp");
htmlElement
.item(0)
.setAttribute("style", "width:100%;border-bottom: 1px solid red !important;");
return;
}
this.date_TimeMap();
}
// HA 31-JAN-24 Added text error condition
if (item.type == "Text") {
if (!item.input) {
item.input = "";
item.error = new ErrorWrapper();
hasMissingInput = true;
}
// this.inpValue = item.input; 634
}
if (!item.isOptional &&
// ((item.type != "File" && !item.input && item.type != 'Date' && item.type != 'Time') ||
// (item.type == "File" && this.attachments.length == 0))
(item.type == "File" && this.attachments.length == 0)) {
item.error = new ErrorWrapper();
hasMissingInput = true;
}
if (item.type == "Radio") {
if (!item.input) {
item.error = new ErrorWrapper();
hasMissingInput = true;
}
}
if (item.type == "Dropdown") {
if (!item.input) {
item.input = "";
item.error = new ErrorWrapper();
hasMissingInput = true;
}
}
if (item.type == "Email") {
if (item.input && item.input.match(mailformat)) {
this.recordId = cQuestion.nextQuestion;
}
else {
item.error = new ErrorWrapper();
hasMissingInput = true;
}
}
if (item.type == "File" && this.attachments.length > 0) {
for (var attachmentItem of this.attachments) {
this.inpValue +=
attachmentItem.attachmentId +
"@#$" +
attachmentItem.attachmentName +
",";
if (item.input == this.inpValue) {
this.recordId = cQuestion.nextQuestion;
//console.log('inside' + recordId);
}
}
// this.attachments = [];
} //item.input == this.inpValue;
this.inpValue += (item.input != undefined ? item.input : "") + "@@##$$";
questionTxt += item.question + "@@##$$";
//console.log('inside book1' + this.inpValue)
}
if (hasMissingInput) {
return;
}
this.inpValue = this.trimLastDummy(this.inpValue);
questionTxt = questionTxt ? this.trimLastDummy(questionTxt) : questionTxt;
}
else if (this.listFlag) {
this.inpValue = '';
var hasMissingInput = false;
if (this.localSubQMap.has(this.questionItem.id)) {
this.subAnsMap = new Map();
for (var localQues of this.localSubQMap.get(this.questionItem.id)) {
if (!localQues.input) {
localQues.error = new ErrorWrapper();
hasMissingInput = true;
}
if (!this.subAnsMap.has(localQues.id)) {
// console.log('inside ans map')
this.subAnsMap.set(localQues.id, localQues.input);
}
else {
// console.log('inside ans map else')
this.subAnsMap.set(localQues.id, this.subAnsMap.get(localQues.id) + '$$@@##' + localQues.input);
}
}
if (hasMissingInput) {
//console.log('file two')
return;
}
this.subAnsMap.forEach((value, key) => {
// console.log('inside Map' );
// console.log(value);
this.inpValue += (value != undefined ? value : '') + '@@##$$';
});
this.inpValue = this.trimLastDummy(this.inpValue);
}
}
else if (this.dropdownFlag) {
if (this.inpValue.length <= 1) {
this.inpValue = ".";
this.questionItem.error = new ErrorWrapper();
}
}
else if (this.dtFlag && this.dateFlag && this.timeFlag) {
//this one
this.change();
if (this.inpValue) {
this.selectedHour = this.getProperTime("12", this.selectedHour);
this.selectedMinute = this.getProperTime("00", this.selectedMinute);
this.selectedMeridiem = this.getProperTime("AM", this.selectedMeridiem);
//console.log(this.inpValue.length);
if (this.questionItem.x24Hours === false) {
this.questionItem.input =
(this.selectedMeridiem === "PM" && this.selectedHour != "12"
? Number(this.selectedHour) + 12
: this.selectedHour) +
":" +
this.selectedMinute + " PM";
if (this.selectedMeridiem === "AM" && this.selectedHour === "12") {
this.questionItem.input = "00" + ":" + this.selectedMinute + " AM";
}
if (this.qbItem.progressBar) {
this.inpValue = this.inpValue + " " + this.questionItem.input;
}
else {
this.inpValue = this.inpValue + "T" + this.questionItem.input;
}
}
if (this.questionItem.x24Hours === true) {
this.questionItem.input =
this.selectedHour + ":" + this.selectedMinute;
if (this.qbItem.progressBar) {
this.inpValue = this.inpValue + " " + this.questionItem.input;
}
else {
this.inpValue = this.inpValue + "T" + this.questionItem.input;
}
}
if (this.qbItem.progressBar) {
//console.log("ans => " + this.inpValue);
var date1 = this.inpValue.split(" ");
date1 = date1[0].split("/");
date1 = [date1[2], date1[1], date1[0]].join("-");
date1 = new Date(date1);
//console.log(date1)
var date2 = this.insuranceStartDate.split(" ");
date2 = new Date(date2[0]);
//console.log(date2);
if (date1 < date2) {
this.questionItem.error = new ErrorWrapper();
this.questionItem.error.errorMsg =
"No es posible dar de alta la reclamación debido a que la fecha del incidente es anterior a la fecha de contratación de la póliza";
//console.log('inside')
return;
}
}
if (this.selDate === null || !this.inpValue) {
this.questionItem.error = new ErrorWrapper();
return;
}
this.date_TimeMap();
}
}
else if (this.timeFlag && this.dtFlag && !this.dateFlag) {
this.date_TimeMap();
if (this.questionItem.x24Hours === false) {
this.inpValue =
(this.selectedMeridiem === "PM" && this.selectedHour != "12"
? Number(this.selectedHour) + 12
: this.selectedHour) +
":" +
this.selectedMinute;
}
else {
this.inpValue = this.selectedHour + ":" + this.selectedMinute;
}
if (this.inpValue.length < 5) {
this.questionItem.error = new ErrorWrapper();
return;
}
}
else if (this.dateFlag && this.dtFlag && !this.timeFlag) {
this.change();
if (this.inpValue.length < 7 || this.selDate === null) {
this.questionItem.error = new ErrorWrapper();
return;
}
}
else if (this.fileFlag) {
//console.log('four')
this.inpValue = "";
if (this.attachments.length > 0) {
for (var attachmentItem of this.attachments) {
this.inpValue +=
attachmentItem.attachmentId +
"@#$" +
attachmentItem.attachmentName +
",";
}
//console.log('inside filesss' + this.inpValue);
this.inpValue = this.inpValue.substr(0, this.inpValue.length - 1);
}
else {
this.questionItem.error = new ErrorWrapper();
return;
}
}
// Check for the answer before saving to the DB
if (!this.questionItem.isOptional && !this.inpValue) {
// Show error that the question must be answered
this.questionItem.error = new ErrorWrapper();
// VD disabled
//this.sharedService.hideLoader();
this.spinner.hide(this.spinnerName);
this.isButtonDisabled = false;
return;
}
// Save the Answer in the DB
this.answerWrap = new AnswerWrapper();
this.answerWrap.abId = this.abItem.id;
this.answerWrap.quesId = cQuestion.id;
this.answerWrap.quesValue = quesValue;
this.answerWrap.qTyp = typ;
// HA 02FEB24 To display the values in summary using this
this.allInputValues = [];
this.subQuestions.forEach(element => {
var inputValue = {};
inputValue['Id'] = element?.id;
inputValue['type'] = element?.type;
inputValue['referenceField'] = element?.referenceField;
inputValue['questionText'] = element?.questionText;
inputValue['input'] = element?.input;
inputValue ? this.allInputValues.push(inputValue) : this.allInputValues;
});
this.answerWrap.myVal = this.allInputValues;
this.answerWrap.ansValue = this.inpValue;
this.answerWrap.groupText = cQuestion.groupName;
console.log('this.answerWrap.qTyp', this.answerWrap.qTyp);
if (this.answerWrap.qTyp == "Alphanumeric") {
this.answerWrap.ansValue = 'ES' + this.inpValue;
// console.log('Bank condition');
// console.log(this.answerWrap.ansValue);
}
/*if (cQuestion.type == 'Book'){
for (var qb of cQuestion.Questions__r.records){
//console.log(qb.question+'****'+"@@##$$")
}
}*/
//this.answerWrap.squesValue = cQuestion.question;
this.questionItem.input = this.inpValue;
// emit the current question with input to parent
let questionAns = {};
questionAns['questionDetail'] = this.questionItem;
questionAns['answerBookDetail'] = this.abItem;
console.log(questionAns);
this.handleQuestion.emit(questionAns);
console.log('questionItem-->');
console.log(this.questionItem);
this.answerWrap.squesValue = questionTxt ? questionTxt : cQuestion.question;
this.saveAnswer();
}
// RS 09DEC24 Changed keys
next() {
var cQuestion = new Question();
cQuestion = this.questionItem;
var typ = cQuestion.type;
// If no error then move to next steps
if (this.questionItem.error) {
return;
}
this.questionStack.push(cQuestion.id);
// this.questionName.push(cQuestion.Name);
// CONDITIONAL vs OPTIONONLY & UNCONDITIONAL
// HA 31-JAN-24 Added ternary even in else conditions below
if (cQuestion?.RecordType?.Name == "CONDITIONAL") {
for (var cOpt of cQuestion.options) {
// Radio / Data
//console.log('Option => ' + cOpt.value + ' matching with ' + ansVal);
if (cOpt.value == this.inpValue) {
//console.log('Match Found using ' + cOpt.nextQuestion);
if (cOpt.nextQuestion) {
this.recordId = cOpt.nextQuestion;
}
else {
this.recordId = cQuestion.nextQuestion;
}
//console.log('conditional record id'+ this.recordId);
}
}
// Could be of type Data and existing value
if (this.recordId && typ == "Data") {
this.recordId = cQuestion.nextQuestion;
}
}
else if (cQuestion?.RecordType?.Name == "OPTIONONLY") {
// OPTIONONLY logic
this.recordId = cQuestion.nextQuestion;
}
else if (cQuestion?.RecordType?.Name == "UNCONDITIONAL") {
//Unconditional logic
//console.log("inside unconditional");
//inside Book Type
if (cQuestion.type == "Book" && cQuestion.questionNumber != '6') {
//console.log("inside book");
for (let opt of cQuestion.subQuestions) {
//console.log(opt.type);
if (opt.type == "Dropdown" || opt.type == "Radio") {
for (var opt1 of opt.options) {
if (this.valueName == opt1.value) {
this.recordId = opt1.nextQuestion || cQuestion.nextQuestion;
}
else {
//console.log('Else'+this.recordId)
this.recordId = cQuestion.nextQuestion;
}
}
}
else {
this.recordId = cQuestion.nextQuestion;
}
}
}
else if (cQuestion.type == "Book" && cQuestion.questionNumber == '6') {
for (let opt of cQuestion.subQuestions) {
if (opt.type == "Dropdown" || opt.type == "Radio") {
for (var opt1 of opt.options) {
if (this.valueName == opt1.value) {
this.recordId = opt1.nextQuestion;
}
}
}
}
}
else {
this.recordId = cQuestion.nextQuestion;
}
}
// HA 31-JAN-24 Added else to keep the assignment default
else {
this.recordId = cQuestion.nextQuestion;
}
// CATEGORIZATION
//this.stepperCateg();
// Calling the progres bar update function
this.answerCount++;
this.updateProgress();
// CATEGORIZATION
//this.stepperCateg();
if (this.recordId) {
this.readQuestion(this.recordId);
this.pop = true;
}
else {
this.pop = false;
// VD disabled
// this.sharedService.hideLoader();
this.spinner.hide(this.spinnerName);
this.isButtonDisabled = false;
// Reset the Variables
this.inpValue = "";
this.answerWrap = new AnswerWrapper();
this.optionValues = [];
this.subQuestions = [];
this.resetFlag(typ);
this.questionItem = null;
// Show Summary
for (var q of this.questionStack) {
//console.log('Handling Question => ' + q);
var ansWrap = this.answerMap.get(q);
if (ansWrap) {
//console.log('Handling Answer for ' + ansWrap.quesId + ' of type ' + ansWrap.qTyp);
if (ansWrap.qTyp == 'File' || ansWrap.qTyp == 'Book' || ansWrap.qTyp == 'List' || ansWrap.qTyp == 'Checkbox') {
var newStr = '';
for (var ansStr of ansWrap.ansValue.split('@@##$$')) {
for (var ansStr1 of ansStr.split('$$@@##')) {
// if(ansStr1.includes('answerString')){ //remove the answer string
// const withoutAnswerString = ansStr1.replace("answerString: ", "");
// ansStr1 = withoutAnswerString;
// }
if (ansStr1.length > 0) {
if (newStr.length == 0) {
newStr = ansStr1;
}
else {
newStr += '; ' + ansStr1; //comma(,) changed as semi colon(;) because of address contains comma(,)
if (this.attachmentsMap.has(ansWrap.quesId)) {
for (var att of this.attachmentsMap.get(ansWrap.quesId)) {
newStr = newStr.replace(att.attachmentId, '');
}
}
newStr = (newStr.replace(',,', ', ')).replace(', ,', ', ');
newStr = newStr.startsWith(',') ? newStr.substring(1, newStr.length) : (newStr.endsWith(',') ? newStr.substring(0, newStr.length - 1) : newStr);
}
}
}
}
ansWrap.ansValue = newStr;
ansWrap.myVal = this.allInputValues;
}
// VD Check if the summary already contains an entry for the same quesId
const existingAnsWrap = this.summary.find(item => item.quesId === ansWrap.quesId);
if (existingAnsWrap) {
// If it exists, update the ansValue and myVal
existingAnsWrap.ansValue = ansWrap.ansValue;
existingAnsWrap.myVal = ansWrap.myVal;
}
else {
// If it doesn't exist, push the ansWrap to the summary array
this.summary.push(ansWrap);
}
this.backicon = true;
}
}
}
}
getText(value) {
var doc = new DOMParser().parseFromString(value, "text/html");
//console.log( doc.documentElement.textContent);
return this.sanitizer.bypassSecurityTrustHtml(doc.documentElement.textContent);
}
handleBackClick() {
this.back = true;
if (this.pop === true) {
this.questionName.pop();
}
this.handleEvent.emit(this.qbItem.backTrackingId);
var cQuestion = new Question();
cQuestion = this.questionItem;
if (cQuestion.questionNumber == '1') {
this.handleEvent.emit(this.qbItem.back);
}
this.answerCount--;
this.updateProgress();
// CATEGORIZATION
//this.stepperCateg();
if (this.summary) {
//console.log('summary true');
this.summary = [];
}
if (this.summaryData) {
this.summaryData = [];
}
// Read the previous question from DB
// VD disabled
// this.sharedService.showLoader();
this.spinner.show(this.spinnerName);
this.isButtonDisabled = true;
this.readQuestion(this.questionStack.pop());
//console.log(this.questionStack);
}
handleBackClickNew() {
this.handleEvent.emit(this.qbItem.edit);
}
//updating status once Q&A completed.
updateAnswerBook = (uuid) => {
if (this.serv == "api") {
// this.dataService.getAPIData(
// this.tkn,
// ["AnswerBook", "Update", uuid],
// this.successupdateAB,
// this.failureupdateAB
// );
let paramMap = { createAnswerBookFlag: false };
// HA 09FEB24 to clear the error: createAnswerBook is false
paramMap['c__qb_id'] = uuid;
paramMap["c__record_id"] = '';
this.dataService.getAPIFromNode('AnswerBook', 'Update', uuid, JSON.stringify(paramMap), this.api).subscribe((data) => {
console.log('updated succussfully');
console.log(data);
this.successupdateAB(JSON.parse(data));
}, (error) => {
console.error('Failed to fetch question books', error);
});
}
else {
// VD 15FEB24 - used processNew method
// VD 31NOV24 param changes with new method
let paramMap = { createAnswerBookFlag: false };
paramMap['c__qb_id'] = uuid;
paramMap["c__record_id"] = '';
let para = {
dataType: "AnswerBook",
operation: "Update",
param1: uuid,
paramJSON: JSON.stringify(paramMap),
languageCode: ''
};
// VD 12Jun24 - translation changes
this.sfService.remoteAction("NxtController.processData", [JSON.stringify(para)], this.successupdateAB, this.failureupdateAB);
}
};
successupdateAB = (response) => {
console.log(response);
let data = response;
if (data) {
this.handleSubmit.emit(data);
this.abItem.status = "Completed";
this.deleteAnswers(data.AnswerBook);
}
};
// VD for delete answers
deleteAnswers(answerbook) {
if (this.serv == "api") {
if (answerbook && answerbook.status == 'Completed') {
const ansBookId = answerbook.id;
let paramMap = { createAnswerBookFlag: false };
// HA 09FEB24 to clear the error: createAnswerBook is false
paramMap['c__qb_id'] = '';
paramMap["c__record_id"] = '';
this.dataService.getAPIFromNode('AnswerBook', 'delete', ansBookId, JSON.stringify(paramMap), this.api).subscribe((data) => {
console.log(data);
this.successDeleteAB(JSON.parse(data));
}, (error) => {
console.error('Failed to fetch question books', error);
});
}
}
}
// VD for delete answers
successDeleteAB = (response) => {
console.log(response);
if (response.status == 'success') {
console.log(response.message);
}
else {
console.error('error', response.message);
}
};
failureupdateAB = (response) => {
//console.log('status failed')
};
readQuestionBook = (uuid) => {
if (this.serv == "api") {
// this.dataService.getAPIData(
// this.tkn,
// ["QuestionBook", "read", uuid],
// this.successReadBook,
// this.failureReadBook
// );
//this.sharedService.showLoader();
this.spinner.show(this.spinnerName);
let paramMap = { createAnswerBookFlag: true };
// HA 09FEB24 to clear the error: createAnswerBook is false
paramMap['c__qb_id'] = uuid;
paramMap["c__record_id"] = '';
this.dataService.getAPIFromNode('QuestionBook', 'read', uuid, JSON.stringify(paramMap), this.api).subscribe((data) => {
// this.sharedService.hideLoader();
// this.spinner.hide(this.spinnerName);
// VD disabled
this.isButtonDisabled = false;
console.log(data);
// this.sharedService.hide();
this.successReadBook(JSON.parse(data));
}, (error) => {
console.error('Failed to fetch question books', error);
});
}
else {
// MR 30JAN24 - Passing flag from NGNXT
let paramMap = { createAnswerBookFlag: true };
// HA 09FEB24 to clear the error: createAnswerBook is false
// VD 31NOV24 param changes with new method
paramMap['c__qb_id'] = uuid;
paramMap["c__record_id"] = '';
let para1 = {
dataType: "QuestionBook",
operation: "read",
param1: uuid,
paramJSON: JSON.stringify(paramMap),
languageCode: ''
};
// , JSON.stringify(paramMap)
// VD 12Jun24 - translation changes
this.sfService.remoteAction(
// HA 09FEB24 to clear the error: createAnswerBook is false
"NxtController.processData", [JSON.stringify(para1)], this.successReadBook, this.failureReadBook);
}
};
successReadBook = (response) => {
console.log('Inside the successReadBook');
console.log(response);
if (response != null || response != undefined) {
this.qbItem = response.questionbook;
this.abItem = response.answerbook;
this.handleBook.emit(response);
}
// console.log('readingQuestion using ' + this.qbItem);
if (this.abItem?.status == "Pending") {
if (this.abItem.answers == null ||
this.abItem.answers.length == 0) {
this.readQuestion(this.qbItem.firstQuestion);
}
else {
// Populate the existing answers
var lastQuestionId = "";
for (var ansObject of this.abItem.answers) {
lastQuestionId = ansObject.quesId;
this.questionStack.push(ansObject.quesId);
this.answerMap.set(ansObject.quesId, {
quesValue: ansObject.quesValue,
ansValue: ansObject.ansValue,
quesId: ansObject.quesId,
qTyp: ansObject.qTyp,
groupText: ansObject.groupText,
});
//console.log(this.questionStack)
if (ansObject.qTyp == "Book") {
var av1 = ansObject.ansValue.split("@@##$$");
// //console.log("book log");
// //console.log("bookid" + av1[0]);
this.attachmentsMap.set(ansObject.quesId, [
{ attachmentName: av1[1], attachmentId: av1[0] },
]);
// //console.log(this.attachmentsMap);
}
else if (ansObject.qTyp == "File") {
// //console.log("inside if");
var attList;
var att;
for (var attVar of ansObject.ansValue.split(",")) {
var attIdName = attVar.split("@@##$$");
att.attachmentName = attIdName[1];
att.attachmentId = attIdName[0];