From 98226b9551ee48f4d554710aef05e43043d7e377 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Tue, 9 Jul 2024 16:27:11 +0200 Subject: [PATCH 1/2] chore(code quality): improve some types and some loops --- src/question.ts | 2 +- src/question_checkbox.ts | 2 +- src/survey.ts | 34 +++++++++++++++++----------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/question.ts b/src/question.ts index acefde8a35..bfd8a97b3e 100644 --- a/src/question.ts +++ b/src/question.ts @@ -1540,7 +1540,7 @@ export class Question extends SurveyElement } public get hasFilteredValue(): boolean { return false; } public getFilteredValue(): any { return this.value; } - public getFilteredName(): any { return this.getValueName(); } + public getFilteredName(): string { return this.getValueName(); } public get valueForSurvey(): any { if (!!this.valueToDataCallback) { return this.valueToDataCallback(this.value); diff --git a/src/question_checkbox.ts b/src/question_checkbox.ts index d4e43fa414..31b20b3711 100644 --- a/src/question_checkbox.ts +++ b/src/question_checkbox.ts @@ -252,7 +252,7 @@ export class QuestionCheckboxModel extends QuestionCheckboxBase { } public get selectedItems(): Array { return this.selectedChoices; } public get hasFilteredValue(): boolean { return !!this.valuePropertyName; } - public getFilteredName(): any { + public getFilteredName(): string { let res = super.getFilteredName(); if(this.hasFilteredValue) { res += "-unwrapped"; diff --git a/src/survey.ts b/src/survey.ts index 5931895545..48cacab41a 100644 --- a/src/survey.ts +++ b/src/survey.ts @@ -3073,31 +3073,31 @@ export class SurveyModel extends SurveyElementCore } return result; } - getFilteredValues(): any { - var values: { [index: string]: any } = {}; - for (var key in this.variablesHash) values[key] = this.variablesHash[key]; + + getFilteredValues(): Record { + const values: { [index: string]: any } = { + ...this.variablesHash, + + }; this.addCalculatedValuesIntoFilteredValues(values); - var keys = this.getValuesKeys(); - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; + for (let key of this.getValuesKeys()) { values[key] = this.getDataValueCore(this.valuesHash, key); } - this.getAllQuestions().forEach(q => { - if (q.hasFilteredValue) { - values[q.getFilteredName()] = q.getFilteredValue(); - } - }); - + for (let question of this.getAllQuestions()) { + if (question.hasFilteredValue) { + values[question.getFilteredName()] = question.getFilteredValue(); + } + } return values; } private addCalculatedValuesIntoFilteredValues(values: { - [index: string]: any, + [index: string]: CalculatedValue['value'], }) { - var caclValues = this.calculatedValues; - for (var i = 0; i < caclValues.length; i++) - values[caclValues[i].name] = caclValues[i].value; + for (let calculatedValue of this.calculatedValues) { + values[calculatedValue.name] = calculatedValue.value; + } } - getFilteredProperties(): any { + getFilteredProperties(): { survey: SurveyModel } { return { survey: this }; } private getValuesKeys(): Array { From 6b36be95d88cb0f4f7f1de6e2e5072f812f5cde2 Mon Sep 17 00:00:00 2001 From: Sam Mousa Date: Tue, 9 Jul 2024 16:53:33 +0200 Subject: [PATCH 2/2] chore(cs): fix indenting and quoting --- src/survey.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/survey.ts b/src/survey.ts index 48cacab41a..9800a8310a 100644 --- a/src/survey.ts +++ b/src/survey.ts @@ -3084,14 +3084,14 @@ export class SurveyModel extends SurveyElementCore values[key] = this.getDataValueCore(this.valuesHash, key); } for (let question of this.getAllQuestions()) { - if (question.hasFilteredValue) { - values[question.getFilteredName()] = question.getFilteredValue(); - } + if (question.hasFilteredValue) { + values[question.getFilteredName()] = question.getFilteredValue(); + } } return values; } private addCalculatedValuesIntoFilteredValues(values: { - [index: string]: CalculatedValue['value'], + [index: string]: CalculatedValue["value"], }) { for (let calculatedValue of this.calculatedValues) { values[calculatedValue.name] = calculatedValue.value;