Skip to content

Commit

Permalink
#9212 SurveyModel: renamings - onGet...Actions, onProgressText
Browse files Browse the repository at this point in the history
Fixes #9212
  • Loading branch information
novikov82 committed Dec 27, 2024
1 parent 6b1a212 commit 35565bb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
7 changes: 6 additions & 1 deletion packages/survey-core/src/survey-events-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export interface GetTitleActionsEventMixin {
/**
* An array of [actions](https://surveyjs.io/form-library/documentation/iaction) associated with the processed element.
*/
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
36 changes: 25 additions & 11 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 @@ -68,7 +68,8 @@ import {
DynamicPanelGetTabTitleEvent, DynamicPanelCurrentIndexChangedEvent, IsAnswerCorrectEvent, DragDropAllowEvent, ScrollingElementToTopEvent, GetQuestionTitleActionsEvent,
GetPanelTitleActionsEvent, GetPageTitleActionsEvent, GetPanelFooterActionsEvent, GetMatrixRowActionsEvent, GetExpressionDisplayValueEvent,
ServerValidateQuestionsEvent, MultipleTextItemAddedEvent, MatrixColumnAddedEvent, GetQuestionDisplayValueEvent, PopupVisibleChangedEvent, ChoicesSearchEvent,
OpenFileChooserEvent, OpenDropdownMenuEvent, ResizeEvent
OpenFileChooserEvent, OpenDropdownMenuEvent, ResizeEvent,
GetTitleActionsEventMixin
} from "./survey-events-api";
import { QuestionMatrixDropdownModelBase } from "./question_matrixdropdownbase";
import { QuestionMatrixDynamicModel } from "./question_matrixdynamic";
Expand Down Expand Up @@ -442,7 +443,10 @@ 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>();
public get onProgressText(): EventBase<SurveyModel, GetProgressTextEvent> {
return this.onGetProgressText;
}
/**
* An event that is raised to convert Markdown content to HTML.
*
Expand Down Expand Up @@ -967,7 +971,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 @@ -4898,7 +4902,7 @@ export class SurveyModel extends SurveyElementCore
if (
onValueChanged &&
this.progressBarType == "pages" &&
this.onProgressText.isEmpty
this.onGetProgressText.isEmpty
)
return;
this.isCalculatingProgressText = true;
Expand All @@ -4908,7 +4912,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 @@ -4920,7 +4924,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 @@ -4931,7 +4935,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 @@ -5319,16 +5323,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 @@ -5337,21 +5349,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

0 comments on commit 35565bb

Please sign in to comment.