Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Ranking: Cleaner JSON #7246

Merged
merged 5 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
18 changes: 13 additions & 5 deletions src/question_ranking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ export class QuestionRankingModel extends QuestionCheckboxModel {
public get rootClass(): string {
return new CssClassBuilder()
.append(this.cssClasses.root)
.append(this.cssClasses.rootMobileMod, IsMobile)
.append(this.cssClasses.rootMobileMod, this.isMobileMode())
.append(this.cssClasses.rootDisabled, this.isReadOnly)
.append(this.cssClasses.rootDesignMode, !!this.isDesignMode)
.append(this.cssClasses.itemOnError, this.hasCssError())
.append(this.cssClasses.rootDragHandleAreaIcon, settings.rankingDragHandleArea === "icon")
.append(this.cssClasses.rootSelectToRankMod, this.selectToRankEnabled)
.append(this.cssClasses.rootSelectToRankAlignHorizontal, this.selectToRankEnabled && this.selectToRankAreasLayout === "horizontal")
.append(this.cssClasses.rootSelectToRankAlignVertical, this.selectToRankEnabled && this.selectToRankAreasLayout === "vertical")
.append(this.cssClasses.rootSelectToRankAlignHorizontal, this.selectToRankEnabled && this.renderedSelectToRankAreasLayout === "horizontal")
.append(this.cssClasses.rootSelectToRankAlignVertical, this.selectToRankEnabled && this.renderedSelectToRankAreasLayout === "vertical")
.toString();
}

Expand Down Expand Up @@ -500,13 +500,21 @@ export class QuestionRankingModel extends QuestionCheckboxModel {
* @see selectToRankAreasLayout
*/
public get selectToRankAreasLayout(): string {
if (IsMobile) return "vertical";
return this.getPropertyValue("selectToRankAreasLayout", "horizontal");
return this.getPropertyValue("selectToRankAreasLayout");
}
public set selectToRankAreasLayout(val: string) {
this.setPropertyValue("selectToRankAreasLayout", val);
}

public get renderedSelectToRankAreasLayout(): string {
if (this.isMobileMode()) return "vertical";
return this.selectToRankAreasLayout;
}

public isMobileMode(): boolean {
return IsMobile;
}

@property({ localizable: { defaultStr: "selectToRankEmptyRankedAreaText" } }) selectToRankEmptyRankedAreaText: string;
@property({ localizable: { defaultStr: "selectToRankEmptyUnrankedAreaText" } }) selectToRankEmptyUnrankedAreaText: string;

Expand Down
13 changes: 13 additions & 0 deletions tests/question_ranking_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,17 @@ QUnit.test("selectToRankEnabled : checkMaxSelectedChoicesUnreached", function (a
questionModel.value = ["11", "22"];
assert.equal(questionModel.checkMaxSelectedChoicesUnreached(), false, "MaxSelectedChoices limit reached");
});

QUnit.test("Ranking: Mobile: renderedSelectToRankAreasLayout", function (assert) {
const selectToRankEnabled = true;
const withDefaultValue = false;
const questionModel = createRankingQuestionModel(selectToRankEnabled, withDefaultValue);

questionModel.isMobileMode = ()=>{ return true; }; // set mobile env

assert.equal(questionModel.renderedSelectToRankAreasLayout, "vertical", "'vertical' by default on mobile");

questionModel.selectToRankAreasLayout = "horizontal";
assert.equal(questionModel.renderedSelectToRankAreasLayout, "vertical", "'vertical' always on mobile");
});
// EO selectToRankEnabled
Loading