Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions packages/survey-core/src/base-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@ import { CreateCustomChoiceItemEvent, DragDropAllowEvent } from "./survey-events
import { PopupModel } from "./popup";
import { ItemValue } from "./itemvalue";

export interface ISurveyData {
getValue(name: string): any;
setValue(
name: string,
newValue: any,
locNotification: any,
allowNotifyValueChanged?: boolean,
questionName?: string
): any;
export interface ISurveyVariables {
getVariable(name: string): any;
setVariable(name: string, newValue: any): void;
}
export interface ISurveyDataGetEditingObj {
getEditingSurveyElement(): Base;
}
export interface ISurveyData {
getValue(name: string): any;
setValue(name: string, newValue: any, locNotification: boolean | "text", allowNotifyValueChanged?: boolean, questionName?: string): any;
getComment(name: string): string;
setComment(name: string, newValue: string, locNotification: any): any;
getAllValues(): any;
setComment(name: string, newValue: string, locNotification: boolean | "text"): any;
getFilteredProperties(): any;
findQuestionByName(name: string): IQuestion;
getEditingSurveyElement(): Base;
}
export interface ITextProcessorProp {
text: string;
Expand Down
10 changes: 5 additions & 5 deletions packages/survey-core/src/calculatedValue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HashTable, Helpers } from "./helpers";
import { Base } from "./base";
import { ISurvey, ISurveyData } from "./base-interfaces";
import { ISurvey, ISurveyVariables } from "./base-interfaces";
import { ExpressionRunner } from "./conditions";
import { Serializer } from "./jsonobject";

Expand All @@ -12,7 +12,7 @@ import { Serializer } from "./jsonobject";
* You may set includeIntoResult property to true to store this calculated value into survey result.
*/
export class CalculatedValue extends Base {
private data: ISurveyData;
private data: ISurveyVariables;
private expressionIsRunning: boolean = false;
private expressionRunner: ExpressionRunner;
constructor(name: string = null, expression: string = null) {
Expand All @@ -24,7 +24,7 @@ export class CalculatedValue extends Base {
this.expression = expression;
}
}
public setOwner(data: ISurveyData) {
public setOwner(data: ISurveyVariables) {
this.data = data;
this.rerunExpression();
}
Expand All @@ -36,7 +36,7 @@ export class CalculatedValue extends Base {
? (<any>this.data).getSurvey()
: null;
}
public get owner(): ISurveyData {
public get owner(): ISurveyVariables {
return this.data;
}
/**
Expand Down Expand Up @@ -106,7 +106,7 @@ export class CalculatedValue extends Base {
}
private rerunExpression() {
if (!this.canRunExpression) return;
this.runExpression(this.data.getFilteredProperties());
this.runExpression({ survey: this.getSurvey() });
}
private runExpressionCore(calculatedValues: Array<CalculatedValue>, properties: HashTable<any>) {
if (!this.canRunExpression || !this.ensureExpression()) return;
Expand Down
6 changes: 1 addition & 5 deletions packages/survey-core/src/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3031,7 +3031,7 @@ export class Question extends SurveyElement<Question>
public get isInputTextUpdate(): boolean {
return this.getIsInputTextUpdate() && this.isTextValue();
}
protected setNewValueInData(newValue: any): void {
private setNewValueInData(newValue: any): void {
newValue = this.valueToData(newValue);
if (!this.isValueChangedInSurvey) {
this.setValueCore(newValue);
Expand Down Expand Up @@ -3247,10 +3247,6 @@ export class Question extends SurveyElement<Question>
set validatedValue(val: any) {
this.value = val;
}
getAllValues(): any {
return !!this.data ? this.data.getAllValues() : null;
}

public processPopupVisiblilityChanged(popupModel: PopupModel, visible: boolean): void {
this.survey.processPopupVisiblityChanged(this, popupModel, visible);
}
Expand Down
27 changes: 9 additions & 18 deletions packages/survey-core/src/question_custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ export abstract class QuestionCustomModelBase extends Question
getValue(name: string): any {
return this.value;
}
setValue(name: string, newValue: any, locNotification: any, allowNotifyValueChanged?: boolean): any {
setValue(name: string, newValue: any, locNotification: boolean | "text", allowNotifyValueChanged?: boolean): any {
if (!this.data) return;
if (!!this.customQuestion) {
this.customQuestion.onValueChanged(this, name, newValue);
Expand Down Expand Up @@ -727,32 +727,19 @@ export abstract class QuestionCustomModelBase extends Question
protected convertDataValue(name: string, newValue: any): any {
return newValue;
}
getVariable(name: string): any {
return !!this.data ? this.data.getVariable(name) : null;
}
setVariable(name: string, newValue: any): void {
if (!this.data) return;
this.data.setVariable(name, newValue);
}
getComment(name: string): string {
return !!this.data ? this.data.getComment(this.getValueName()) : "";
}
setComment(name: string, newValue: string, locNotification: any): any {
setComment(name: string, newValue: string, locNotification: boolean | "text"): any {
if (!this.data) return;
this.data.setComment(this.getValueName(), newValue, locNotification);
}
getAllValues(): any {
return !!this.data ? this.data.getAllValues() : {};
}
getFilteredProperties(): any {
return !!this.data ? this.data.getFilteredProperties() : {};
}
findQuestionByName(name: string): IQuestion {
return !!this.data ? this.data.findQuestionByName(name) : null;
}
getEditingSurveyElement(): Base {
return undefined;
}
//IPanel
addElement(element: IElement, index: number) { }
removeElement(element: IElement): boolean {
Expand Down Expand Up @@ -857,7 +844,7 @@ export class QuestionCustomModel extends QuestionCustomModelBase {
}
return super.getDefaultTitle();
}
setValue(name: string, newValue: any, locNotification: any, allowNotifyValueChanged?: boolean): any {
setValue(name: string, newValue: any, locNotification: boolean | "text", allowNotifyValueChanged?: boolean): any {
if (this.isValueChanging(name, newValue)) return;
super.setValue(name, newValue, locNotification, allowNotifyValueChanged);
}
Expand Down Expand Up @@ -1123,7 +1110,11 @@ export class QuestionCompositeModel extends QuestionCustomModelBase {
private editingObjValue: Base;
private onEditingObjPropertyChanged: (sender: Base, options: any) => void;
private updateEditingObj(): Base {
const obj = this.data?.getEditingSurveyElement();
let survey = <any>this.survey;
if (survey && typeof survey.getEditingSurveyElement !== "function") {
survey = null;
}
const obj = survey?.getEditingSurveyElement();
if (!obj) return undefined;
let newObj: Base = (<any>obj)[this.getValueName()];
if (!!newObj && !newObj.onPropertyChanged) {
Expand Down Expand Up @@ -1287,7 +1278,7 @@ export class QuestionCompositeModel extends QuestionCustomModelBase {
this.runCondition(this.getFilteredProperties());
}
}
setComment(name: string, newValue: string, locNotification: any): any {
setComment(name: string, newValue: string): any {
let val = this.getUnbindValue(this.value);
const commentName = this.getCommentName(name);
if (!val && !newValue || !!newValue && !!val && val[commentName] === newValue) return;
Expand Down
8 changes: 2 additions & 6 deletions packages/survey-core/src/question_matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,17 +648,13 @@ export class QuestionMatrixModel
const row = this.getRowByName(name);
return !!row ? row.value : undefined;
}
setValue(name: string, newValue: any, locNotification: any, allowNotifyValueChanged?: boolean, questionName?: string): any {
setValue(name: string, newValue: any): any {
this.getRowByName(name).value = newValue;
}
getVariable(name: string): any { return this.data?.getVariable(name); }
setVariable(name: string, newValue: any): void { this.data?.setVariable(name, newValue); }
getComment(name: string): string { return this.data?.getComment(name); }
setComment(name: string, newValue: string, locNotification: any): any { this.data?.setComment(name, newValue, locNotification); }
getAllValues(): any { return this.data?.getAllValues(); }
setComment(name: string, newValue: string, locNotification: boolean | "text"): any { this.data?.setComment(name, newValue, locNotification); }
getFilteredProperties(): any { return this.data?.getFilteredProperties(); }
findQuestionByName(name: string): IQuestion { return this.data?.findQuestionByName(name); }
getEditingSurveyElement(): Base { return this.data?.getEditingSurveyElement(); }
//#endregion
protected sortVisibleRows(array: Array<MatrixRowModel>): Array<MatrixRowModel> {
if (!!this.survey && this.survey.isDesignMode)
Expand Down
5 changes: 0 additions & 5 deletions packages/survey-core/src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,10 +544,6 @@ export class MatrixDropdownRowModelBase implements ISurveyData, ISurveyImpl, ILo
public setValue(name: string, newColumnValue: any) {
this.setValueCore(name, newColumnValue, false);
}
getVariable(name: string): any {
return undefined;
}
setVariable(name: string, newValue: any) { }
public getComment(name: string): string {
var question = this.getQuestionByName(name);
return !!question ? question.comment : "";
Expand All @@ -564,7 +560,6 @@ export class MatrixDropdownRowModelBase implements ISurveyData, ISurveyImpl, ILo
const survey = this.getSurvey();
return !!survey ? survey.getQuestionByName(name) : null;
}
getEditingSurveyElement(): Base { return undefined; }
private setValueCore(name: string, newColumnValue: any, isComment: boolean) {
if (this.isSettingValue || this.isCreatingDetailPanel) return;
this.updateQuestionsValue(name, newColumnValue, isComment);
Expand Down
13 changes: 0 additions & 13 deletions packages/survey-core/src/question_multipletext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class MultipleTextValueGetterContext extends ValueGetterContextCore {
export interface IMultipleTextData extends ILocalizableOwner, IPanel {
getSurvey(): ISurvey;
getTextProcessor(): ITextProcessor;
getAllValues(): any;
getMultipleTextValue(name: string): any;
setMultipleTextValue(name: string, value: any): any;
getItemDefaultValue(name: string): any;
Expand Down Expand Up @@ -393,26 +392,17 @@ export class MultipleTextItemModel extends Base
this.data.setMultipleTextValue(name, value);
}
}
getVariable(name: string): any {
return undefined;
}
setVariable(name: string, newValue: any) { }
getComment(name: string): string {
return null;
}
setComment(name: string, newValue: string) { }
getAllValues(): any {
if (this.data) return this.data.getAllValues();
return this.value;
}
getFilteredProperties(): any {
return { survey: this.getSurvey() };
}
findQuestionByName(name: string): IQuestion {
const survey = this.getSurvey();
return !!survey ? survey.getQuestionByName(name) : null;
}
getEditingSurveyElement(): Base { return undefined; }
//IValidatorOwner
getValidatorTitle(): string {
return this.title;
Expand Down Expand Up @@ -832,9 +822,6 @@ export class QuestionMultipleTextModel extends Question
getTextProcessor(): ITextProcessor {
return this.textProcessor;
}
getAllValues() {
return this.data ? this.data.getAllValues() : null;
}
//IPanel
addElement(element: IElement, index: number) { }
removeElement(element: IElement): boolean {
Expand Down
7 changes: 1 addition & 6 deletions packages/survey-core/src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,11 @@ export class QuestionPanelDynamicItem implements ISurveyData, ISurveyImpl, IObje
q.runTriggers(triggerName, newValue);
}
}
getVariable(name: string): any {
return undefined;
}
setVariable(name: string, newValue: any) { }
public getComment(name: string): string {
var result = this.getValue(name + settings.commentSuffix);
return result ? result : "";
}
public setComment(name: string, newValue: string, locNotification: any) {
public setComment(name: string, newValue: string, locNotification: boolean | "text") {
this.setValue(name + settings.commentSuffix, newValue);
}
findQuestionByName(name: string): IQuestion {
Expand All @@ -225,7 +221,6 @@ export class QuestionPanelDynamicItem implements ISurveyData, ISurveyImpl, IObje
const survey = this.getSurvey();
return !!survey ? survey.getQuestionByName(name) : null;
}
getEditingSurveyElement(): Base { return undefined; }
getAllValues(): any {
return this.data.getPanelItemData(this);
}
Expand Down
16 changes: 9 additions & 7 deletions packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Base, EventBase, ComputedUpdater, EventAsync } from "./base";
import {
ISurvey,
ISurveyData,
ISurveyVariables,
ISurveyDataGetEditingObj,
ISurveyImpl,
ITextProcessor,
IQuestion,
Expand Down Expand Up @@ -158,6 +160,8 @@ export class SurveyModel extends SurveyElementCore
implements
ISurvey,
ISurveyData,
ISurveyVariables,
ISurveyDataGetEditingObj,
ISurveyImpl,
ISurveyTriggerOwner,
ISurveyErrorOwner,
Expand Down Expand Up @@ -3548,9 +3552,6 @@ export class SurveyModel extends SurveyElementCore
}
}
}
getAllValues(): any {
return this.data;
}
/**
* Returns survey results as an array of objects in which the question name, title, value, and other parameters are stored as individual properties.
*
Expand Down Expand Up @@ -6558,8 +6559,9 @@ export class SurveyModel extends SurveyElementCore
this.onValueChanging.fire(this, options);
return options.value;
}
private getLocNotification(loc: boolean, value: any, oldValue: any): boolean {
return loc || Helpers.isTwoValueEquals(value, oldValue, false, true, false);
private getLocNotification(loc: boolean | "text", value: any, oldValue: any): boolean | "text" {
if (loc === false && Helpers.isTwoValueEquals(value, oldValue, false, true, false)) return true;
return loc;
}
protected updateQuestionValue(valueName: string, newValue: any) {
if (this.isLoadingFromJson) return;
Expand Down Expand Up @@ -7170,7 +7172,7 @@ export class SurveyModel extends SurveyElementCore
public setValue(
name: string,
newQuestionValue: any,
locNotification: any = false,
locNotification: boolean | "text" = false,
allowNotifyValueChanged: boolean = true,
questionName?: string
): void {
Expand Down Expand Up @@ -7362,7 +7364,7 @@ export class SurveyModel extends SurveyElementCore
* @param locNotification For internal use.
* @see getComment
*/
public setComment(name: string, newValue: string, locNotification: any = false): void {
public setComment(name: string, newValue: string, locNotification: boolean | "text" = false): void {
if (!newValue) newValue = "";
if (this.isTwoValueEquals(newValue, this.getComment(name))) return;
const commentName = name + this.commentSuffix;
Expand Down