Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Aug 29, 2023
2 parents c9bb0de + cd9747e commit 26174e3
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 116 deletions.
8 changes: 8 additions & 0 deletions src/base-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,11 @@ export interface ISurveyLayoutElement {
template?: string;
data?: any;
}
export interface IPlainDataOptions {
includeEmpty?: boolean;
includeQuestionTypes?: boolean;
includeValues?: boolean;
calculations?: Array<{
propertyName: string,
}>;
}
21 changes: 16 additions & 5 deletions src/common-styles/sv-ranking.scss
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@
.sv-ranking__container--empty {
padding-top: calcSize(1);
padding-bottom: calcSize(1);
display: flex;
justify-content: center;
align-items: center;
}
}

Expand All @@ -243,15 +246,23 @@

.sv-ranking__container--empty {
&.sv-ranking__container--to {
padding-right: calcSize(3);
//padding-right: calcSize(3);

.sv-ranking-item {
left: initial;
}

.sv-ranking__container-placeholder {
padding-left: calcSize(5);
}
}

&.sv-ranking__container--from {
padding-left: calcSize(3);
//padding-left: calcSize(3);

.sv-ranking__container-placeholder {
padding-right: calcSize(5);
}
}
}
}
Expand All @@ -263,17 +274,17 @@
display: flex;
justify-content: center;
align-items: center;
width: 100%;
//width: 100%;
height: 100%;
}

.sv-ranking__container {
flex: 1;
max-width: 100%;
//max-width: 100%;
}

.sv-ranking__container--empty {
padding: calcSize(8);
//padding: calcSize(8);
box-sizing: border-box;
text-align: center;
}
Expand Down
32 changes: 32 additions & 0 deletions src/defaultV2-theme/blocks/sd-ranking.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,36 @@

.sv-ranking-item__content.sd-ranking-item__content {
line-height: calcLineHeight(1.5);
}

.sv-dragdrop-movedown {
transform: translate(0, 0);
animation: svdragdropmovedown 0.1s;
animation-timing-function: ease-in-out;
}

@keyframes svdragdropmovedown {
0% {
transform: translate(0, -50px);
}

100% {
transform: translate(0, 0);
}
}

.sv-dragdrop-moveup {
transform: translate(0, 0);
animation: svdragdropmoveup 0.1s;
animation-timing-function: ease-in-out;
}

@keyframes svdragdropmoveup {
0% {
transform: translate(0, 50px);
}

100% {
transform: translate(0, 0);
}
}
8 changes: 7 additions & 1 deletion src/dragdrop/choices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,13 @@ export class DragDropChoices extends DragDropCore<QuestionSelectBase> {

private getVisibleChoices() {
const parent = this.parentElement;
if (parent.getType() === "ranking") return <QuestionRankingModel>parent.rankingChoices;
if (parent.getType() === "ranking") {
if (parent.selectToRankEnabled) {
return parent.visibleChoices;
} else {
return <QuestionRankingModel>parent.rankingChoices;
}
}
return parent.visibleChoices;
}

Expand Down
6 changes: 3 additions & 3 deletions src/dragdrop/dom-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class DragDropDOMAdapter implements IDragDropDOMAdapter {
private savedTargetNode: any;
private scrollIntervalId: number = null;

constructor(private dd: IDragDropEngine, private longTap?: boolean) {
}
constructor(private dd: IDragDropEngine, private longTap: boolean = true) {}

private get rootElement() {
if(isShadowDOM(settings.environment.root)) {
return settings.environment.root.host;
Expand Down Expand Up @@ -105,7 +105,7 @@ export class DragDropDOMAdapter implements IDragDropDOMAdapter {
}

this.stopLongTap();
}, this.longTap? 500: 0);
}, this.longTap ? 500: 0);

document.addEventListener("pointerup", this.stopLongTap);
document.addEventListener("pointermove", this.stopLongTapIfMoveEnough);
Expand Down
1 change: 1 addition & 0 deletions src/entries/chunks/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export {
ISurveyData,
ITitleOwner,
ISurveyLayoutElement,
IPlainDataOptions as IPlainData,
IShortcutText
} from "../../base-interfaces";
export { SurveyError } from "../../survey-error";
Expand Down
19 changes: 6 additions & 13 deletions src/question.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HashTable, Helpers } from "./helpers";
import { JsonObject, Serializer, property } from "./jsonobject";
import { Base, EventBase } from "./base";
import { IElement, IQuestion, IPanel, IConditionRunner, ISurveyImpl, IPage, ITitleOwner, IProgressInfo, ISurvey } from "./base-interfaces";
import { IElement, IQuestion, IPanel, IConditionRunner, ISurveyImpl, IPage, ITitleOwner, IProgressInfo, ISurvey, IPlainDataOptions } from "./base-interfaces";
import { SurveyElement } from "./survey-element";
import { surveyLocalization } from "./surveyStrings";
import { AnswerRequiredError, CustomError } from "./error";
Expand Down Expand Up @@ -1528,15 +1528,7 @@ export class Question extends SurveyElement<Question>
*
* Pass an object with the `includeEmpty` property set to `false` if you want to skip empty answers.
*/
public getPlainData(
options?: {
includeEmpty?: boolean,
includeQuestionTypes?: boolean,
calculations?: Array<{
propertyName: string,
}>,
}
): IQuestionPlainData {
public getPlainData(options?: IPlainDataOptions): IQuestionPlainData {
if (!options) {
options = { includeEmpty: true, includeQuestionTypes: false };
}
Expand All @@ -1554,9 +1546,7 @@ export class Question extends SurveyElement<Question>
questionPlainData.questionType = this.getType();
}
(options.calculations || []).forEach((calculation) => {
questionPlainData[calculation.propertyName] = this[
calculation.propertyName
];
questionPlainData[calculation.propertyName] = this.getPlainDataCalculatedValue(calculation.propertyName);
});
if (this.hasComment) {
questionPlainData.isNode = true;
Expand All @@ -1577,6 +1567,9 @@ export class Question extends SurveyElement<Question>
}
return undefined;
}
protected getPlainDataCalculatedValue(propName: string): any {
return this[propName];
}
/**
* A correct answer to this question. Specify this property if you want to [create a quiz](https://surveyjs.io/form-library/documentation/design-survey-create-a-quiz).
* @see SurveyModel.getCorrectAnswerCount
Expand Down
16 changes: 5 additions & 11 deletions src/question_baseselect.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { property, Serializer } from "./jsonobject";
import { SurveyError } from "./survey-error";
import { ISurveyImpl, ISurvey, ISurveyData } from "./base-interfaces";
import { ISurveyImpl, ISurvey, ISurveyData, IPlainDataOptions } from "./base-interfaces";
import { SurveyModel } from "./survey";
import { Question } from "./question";
import { IQuestionPlainData, Question } from "./question";
import { ItemValue } from "./itemvalue";
import { surveyLocalization } from "./surveyStrings";
import { OtherEmptyError } from "./error";
Expand Down Expand Up @@ -938,17 +938,11 @@ export class QuestionSelectBase extends Question {
this.isDesignMode && !this.customWidget && !this.isContentElement;
}
public getPlainData(
options: {
includeEmpty?: boolean,
includeQuestionTypes?: boolean,
calculations?: Array<{
propertyName: string,
}>,
} = {
options: IPlainDataOptions = {
includeEmpty: true,
includeQuestionTypes: false,
}
) {
): IQuestionPlainData {
var questionPlainData = super.getPlainData(options);
if (!!questionPlainData) {
var values = Array.isArray(this.value) ? this.value : [this.value];
Expand Down Expand Up @@ -990,7 +984,7 @@ export class QuestionSelectBase extends Question {
protected getDisplayValueEmpty(): string {
return ItemValue.getTextOrHtmlByValue(this.visibleChoices, undefined);
}
protected getChoicesDisplayValue(items: ItemValue[], val: any): any {
private getChoicesDisplayValue(items: ItemValue[], val: any): any {
if (val == this.otherItemValue.value)
return this.otherValue ? this.otherValue : this.locOtherText.textOrHtml;
const selItem = this.getSingleSelectedItem();
Expand Down
12 changes: 4 additions & 8 deletions src/question_file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Question } from "./question";
import { IPlainDataOptions } from "./base-interfaces";
import { IQuestionPlainData, Question } from "./question";
import { property, propertyArray, Serializer } from "./jsonobject";
import { QuestionFactory } from "./questionfactory";
import { EventBase, ComputedUpdater } from "./base";
Expand Down Expand Up @@ -464,15 +465,10 @@ export class QuestionFileModel extends Question {
return result;
}
public getPlainData(
options: {
includeEmpty?: boolean,
calculations?: Array<{
propertyName: string,
}>,
} = {
options: IPlainDataOptions = {
includeEmpty: true,
}
) {
): IQuestionPlainData {
var questionPlainData = super.getPlainData(options);
if (!!questionPlainData && !this.isEmpty()) {
questionPlainData.isNode = false;
Expand Down
12 changes: 4 additions & 8 deletions src/question_matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import { RequiredInAllRowsError } from "./error";
import { QuestionFactory } from "./questionfactory";
import { LocalizableString, ILocalizableOwner } from "./localizablestring";
import { QuestionDropdownModel } from "./question_dropdown";
import { IConditionObject } from "./question";
import { IConditionObject, IQuestionPlainData } from "./question";
import { settings } from "./settings";
import { SurveyModel } from "./survey";
import { CssClassBuilder } from "./utils/cssClassBuilder";
import { IPlainDataOptions } from "./base-interfaces";

export interface IMatrixData {
onMatrixRowChanged(row: MatrixRowModel): void;
Expand Down Expand Up @@ -484,15 +485,10 @@ export class QuestionMatrixModel
return res;
}
public getPlainData(
options: {
includeEmpty?: boolean,
calculations?: Array<{
propertyName: string,
}>,
} = {
options: IPlainDataOptions = {
includeEmpty: true,
}
) {
): IQuestionPlainData {
var questionPlainData = super.getPlainData(options);
if (!!questionPlainData) {
var values = this.createValueCopy();
Expand Down
15 changes: 3 additions & 12 deletions src/question_matrixdropdownbase.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { JsonObject, CustomPropertiesCollection, Serializer, property } from "./jsonobject";
import { QuestionMatrixBaseModel } from "./martixBase";
import { Question, IConditionObject } from "./question";
import { Question, IConditionObject, IQuestionPlainData } from "./question";
import { HashTable, Helpers } from "./helpers";
import { Base } from "./base";
import { IElement, IQuestion, ISurveyData, ISurvey, ISurveyImpl, ITextProcessor, IProgressInfo, IPanel } from "./base-interfaces";
import { IElement, IQuestion, ISurveyData, ISurvey, ISurveyImpl, ITextProcessor, IProgressInfo, IPanel, IPlainDataOptions } from "./base-interfaces";
import { SurveyElement } from "./survey-element";
import { TextPreProcessorValue, QuestionTextProcessor } from "./textPreProcessor";
import { ItemValue } from "./itemvalue";
Expand Down Expand Up @@ -1732,16 +1732,7 @@ export class QuestionMatrixDropdownModelBase extends QuestionMatrixBaseModel<Mat
}
return rowValue;
}
public getPlainData(
options: {
includeEmpty?: boolean,
calculations?: Array<{
propertyName: string,
}>,
} = {
includeEmpty: true,
}
) {
public getPlainData(options: IPlainDataOptions = { includeEmpty: true }): IQuestionPlainData {
var questionPlainData = super.getPlainData(options);
if (!!questionPlainData) {
questionPlainData.isNode = true;
Expand Down
14 changes: 3 additions & 11 deletions src/question_paneldynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import {
ISurveyImpl,
ITextProcessor,
IProgressInfo,
IPlainDataOptions,
} from "./base-interfaces";
import { SurveyElement } from "./survey-element";
import { LocalizableString } from "./localizablestring";
import {
TextPreProcessorValue,
QuestionTextProcessor,
} from "./textPreProcessor";
import { Question, IConditionObject } from "./question";
import { Question, IConditionObject, IQuestionPlainData } from "./question";
import { PanelModel } from "./panel";
import { JsonObject, property, Serializer } from "./jsonobject";
import { QuestionFactory } from "./questionfactory";
Expand Down Expand Up @@ -1956,16 +1957,7 @@ export class QuestionPanelDynamicModel extends Question
getRootData(): ISurveyData {
return this.data;
}
public getPlainData(
options: {
includeEmpty?: boolean,
calculations?: Array<{
propertyName: string,
}>,
} = {
includeEmpty: true,
}
) {
public getPlainData(options: IPlainDataOptions = { includeEmpty: true }): IQuestionPlainData {
var questionPlainData = super.getPlainData(options);
if (!!questionPlainData) {
questionPlainData.isNode = true;
Expand Down
8 changes: 7 additions & 1 deletion src/question_rating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { settings } from "./settings";
import { surveyLocalization } from "./surveyStrings";
import { CssClassBuilder } from "./utils/cssClassBuilder";
import { Base } from "./base";
import { HtmlConditionItem } from "./expressionItems";
import { mergeValues } from "./utils/utils";
import { DropdownListModel } from "./dropdownListModel";
import { SurveyModel } from "./survey";
Expand Down Expand Up @@ -313,6 +312,7 @@ export class QuestionRatingModel extends Question {
}

protected getDisplayValueCore(keysAsText: boolean, value: any): any {
if(!this.useRateValues) return super.getDisplayValueCore(keysAsText, value);
var res = ItemValue.getTextOrHtmlByValue(this.visibleRateValues, value);
return !!res ? res : value;
}
Expand Down Expand Up @@ -390,6 +390,12 @@ export class QuestionRatingModel extends Question {
public supportOther(): boolean {
return false;
}
protected getPlainDataCalculatedValue(propName: string): any {
const res = super.getPlainDataCalculatedValue(propName);
if(res !== undefined || !this.useRateValues || this.isEmpty()) return res;
const item = <any>ItemValue.getItemByValue(this.visibleRateValues, this.value);
return item ? item[propName] : undefined;
}
/**
* Specifies a description for the minimum (first) rate value.
* @see rateValues
Expand Down
Loading

0 comments on commit 26174e3

Please sign in to comment.