Skip to content

Commit

Permalink
#9212 SurveyModel: renamings - onGet...Actions, onProgressText (#9220)
Browse files Browse the repository at this point in the history
* #9212 SurveyModel: renamings - onGet...Actions, onProgressText
Fixes #9212

* #9212 - change definitions

* #912 - fix test

* #9212 - work

* Add deprecation messages

---------

Co-authored-by: RomanTsukanov <[email protected]>
Co-authored-by: RomanTsukanov <[email protected]>
  • Loading branch information
3 people authored Dec 30, 2024
1 parent ccbc787 commit d715209
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
9 changes: 7 additions & 2 deletions packages/survey-core/src/survey-events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export interface GetTitleActionsEventMixin {
/**
* An array of [actions](https://surveyjs.io/form-library/documentation/iaction) associated with the processed element.
*/
titleActions: Array<IAction>;
actions: Array<IAction>;
/**
* Obsolete. Use `options.actions` instead.
*/
titleActions?: Array<IAction>;
}
export interface GetActionsEventMixin {
/**
Expand Down Expand Up @@ -410,7 +414,7 @@ export interface GetPageNumberEvent extends PageEventMixin {
*/
number: string;
}
export interface ProgressTextEvent {
export interface GetProgressTextEvent {
/**
* The number of questions with input fields. [Image](https://surveyjs.io/form-library/examples/add-image-and-video-to-survey/), [HTML](https://surveyjs.io/form-library/examples/questiontype-html/), and [Expression](https://surveyjs.io/form-library/examples/questiontype-expression/) questions are not counted.
*/
Expand All @@ -432,6 +436,7 @@ export interface ProgressTextEvent {
*/
text: string;
}
export interface ProgressTextEvent extends GetProgressTextEvent { }

export interface TextProcessingEvent {
/**
Expand Down
40 changes: 27 additions & 13 deletions packages/survey-core/src/survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import {
TriggerExecutedEvent, CompletingEvent, CompleteEvent, ShowingPreviewEvent, NavigateToUrlEvent, CurrentPageChangingEvent, CurrentPageChangedEvent,
ValueChangingEvent, ValueChangedEvent, VariableChangedEvent, QuestionVisibleChangedEvent, PageVisibleChangedEvent, PanelVisibleChangedEvent, QuestionCreatedEvent,
QuestionAddedEvent, QuestionRemovedEvent, PanelAddedEvent, PanelRemovedEvent, PageAddedEvent, ValidateQuestionEvent, SettingQuestionErrorsEvent, ValidatePanelEvent,
ErrorCustomTextEvent, ValidatedErrorsOnCurrentPageEvent, ProcessHtmlEvent, GetQuestionTitleEvent, GetTitleTagNameEvent, GetQuestionNumberEvent, GetPageNumberEvent, ProgressTextEvent,
ErrorCustomTextEvent, ValidatedErrorsOnCurrentPageEvent, ProcessHtmlEvent, GetQuestionTitleEvent, GetTitleTagNameEvent, GetQuestionNumberEvent, GetPageNumberEvent, GetProgressTextEvent,
TextMarkdownEvent, TextRenderAsEvent, SendResultEvent, GetResultEvent, UploadFilesEvent, DownloadFileEvent, ClearFilesEvent, LoadChoicesFromServerEvent,
ProcessTextValueEvent, UpdateQuestionCssClassesEvent, UpdatePanelCssClassesEvent, UpdatePageCssClassesEvent, UpdateChoiceItemCssEvent, AfterRenderSurveyEvent,
AfterRenderPageEvent, AfterRenderQuestionEvent, AfterRenderQuestionInputEvent, AfterRenderPanelEvent, FocusInQuestionEvent, FocusInPanelEvent,
Expand All @@ -69,8 +69,7 @@ import {
GetPanelTitleActionsEvent, GetPageTitleActionsEvent, GetPanelFooterActionsEvent, GetMatrixRowActionsEvent, GetExpressionDisplayValueEvent,
ServerValidateQuestionsEvent, MultipleTextItemAddedEvent, MatrixColumnAddedEvent, GetQuestionDisplayValueEvent, PopupVisibleChangedEvent, ChoicesSearchEvent,
OpenFileChooserEvent, OpenDropdownMenuEvent, ResizeEvent,
ScrollingElementToTopEvent,
IsAnswerCorrectEvent
GetTitleActionsEventMixin, ProgressTextEvent, ScrollingElementToTopEvent, IsAnswerCorrectEvent
} from "./survey-events-api";
import { QuestionMatrixDropdownModelBase } from "./question_matrixdropdownbase";
import { QuestionMatrixDynamicModel } from "./question_matrixdynamic";
Expand Down Expand Up @@ -445,7 +444,12 @@ export class SurveyModel extends SurveyElementCore
* @see showProgressBar
* @see progressBarType
*/
public onProgressText: EventBase<SurveyModel, ProgressTextEvent> = this.addEvent<SurveyModel, ProgressTextEvent>();
public onGetProgressText: EventBase<SurveyModel, GetProgressTextEvent> = this.addEvent<SurveyModel, GetProgressTextEvent>();
/**
* Obsolete. Use the [`onGetProgressText`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onGetProgressText) event instead.
* @deprecated
*/
public onProgressText: EventBase<SurveyModel, ProgressTextEvent> = this.onGetProgressText;
/**
* An event that is raised to convert Markdown content to HTML.
*
Expand Down Expand Up @@ -983,7 +987,7 @@ export class SurveyModel extends SurveyElementCore
this.onGetQuestionNumber.onCallbacksChanged = () => {
this.resetVisibleIndexes();
};
this.onProgressText.onCallbacksChanged = () => {
this.onGetProgressText.onCallbacksChanged = () => {
this.updateProgressText();
};
this.onTextMarkdown.onCallbacksChanged = () => {
Expand Down Expand Up @@ -4904,7 +4908,7 @@ export class SurveyModel extends SurveyElementCore
return SurveyElement.getProgressInfoByElements(pages, false);
}
/**
* Returns text displayed by the progress bar (for instance, "Page 2 of 3" or "Answered 3/8 questions"). Handle the [`onProgressText`](#onProgressText) event to change this text.
* Returns text displayed by the progress bar (for instance, "Page 2 of 3" or "Answered 3/8 questions"). Handle the [`onGetProgressText`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onGetProgressText) event to change this text.
* @see progressValue
* @see showProgressBar
* @see progressBarType
Expand All @@ -4923,7 +4927,7 @@ export class SurveyModel extends SurveyElementCore
if (
onValueChanged &&
this.progressBarType == "pages" &&
this.onProgressText.isEmpty
this.onGetProgressText.isEmpty
)
return;
this.isCalculatingProgressText = true;
Expand All @@ -4933,7 +4937,7 @@ export class SurveyModel extends SurveyElementCore
}
public getProgressText(): string {
if (!this.isDesignMode && this.currentPage == null) return "";
const options: ProgressTextEvent = {
const options: GetProgressTextEvent = {
questionCount: 0,
answeredQuestionCount: 0,
requiredQuestionCount: 0,
Expand All @@ -4945,7 +4949,7 @@ export class SurveyModel extends SurveyElementCore
type === "questions" ||
type === "requiredquestions" ||
type === "correctquestions" ||
!this.onProgressText.isEmpty
!this.onGetProgressText.isEmpty
) {
var info = this.getProgressInfo();
options.questionCount = info.questionCount;
Expand All @@ -4956,7 +4960,7 @@ export class SurveyModel extends SurveyElementCore
}

options.text = this.getProgressTextCore(options);
this.onProgressText.fire(this, options);
this.onGetProgressText.fire(this, options);
return options.text;
}
private getProgressTextCore(info: IProgressInfo): string {
Expand Down Expand Up @@ -5344,16 +5348,24 @@ export class SurveyModel extends SurveyElementCore
return this.getUpdatedPanelTitleActions(<PanelModel>element, titleActions);
return this.getUpdatedQuestionTitleActions(<Question>element, titleActions);
}

private getTitleActionsResult(titleActions: Array<IAction>, options: GetTitleActionsEventMixin) {
if (titleActions != options.actions) return options.actions;
if (titleActions != options.titleActions) return options.titleActions;
return titleActions;
}

private getUpdatedQuestionTitleActions(
question: Question,
titleActions: Array<IAction>
) {
const options: GetQuestionTitleActionsEvent = {
question: question,
actions: titleActions,
titleActions: titleActions,
};
this.onGetQuestionTitleActions.fire(this, options);
return options.titleActions;
return this.getTitleActionsResult(titleActions, options);
}

private getUpdatedPanelTitleActions(
Expand All @@ -5362,21 +5374,23 @@ export class SurveyModel extends SurveyElementCore
) {
const options: GetPanelTitleActionsEvent = {
panel: panel,
actions: titleActions,
titleActions: titleActions,
};
this.onGetPanelTitleActions.fire(this, options);
return options.titleActions;
return this.getTitleActionsResult(titleActions, options);
}
private getUpdatedPageTitleActions(
page: PageModel,
titleActions: Array<IAction>
) {
var options: GetPageTitleActionsEvent = {
page: page,
actions: titleActions,
titleActions: titleActions,
};
this.onGetPageTitleActions.fire(this, options);
return options.titleActions;
return this.getTitleActionsResult(titleActions, options);
}

getUpdatedMatrixRowActions(
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/tests/question_paneldynamic_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5077,7 +5077,7 @@ QUnit.test("Bindings to panelCount performance issue #2 reduce recalc visibleInd
],
});
var counter = 0;
survey.onProgressText.add((sender, options) => {
survey.onGetProgressText.add((sender, options) => {
counter ++;
});
counter = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/survey-core/tests/surveytests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14560,7 +14560,7 @@ QUnit.test("Check onGetQuestionTitleActions event", (assert) => {
});
var testActions = [{ title: "simple" }, { title: "simple2" }];
survey.onGetQuestionTitleActions.add((sender, options) => {
options.titleActions = testActions;
options.actions = testActions;
});
var question = <Question>survey.getQuestionByName("text1");
assert.deepEqual(question.getTitleActions(), testActions);
Expand Down

0 comments on commit d715209

Please sign in to comment.