Skip to content

Commit

Permalink
PR: Ranking: Cleaner JSON (#7246)
Browse files Browse the repository at this point in the history
* work for cleaner ranking json

* work for cleaner ranking json (u test)

* work for cleaner ranking json (lint)

* work for cleaner ranking json (u test 2)
  • Loading branch information
dmitry-kurmanov committed Oct 30, 2023
1 parent 283fe5e commit c48ea82
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
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
22 changes: 22 additions & 0 deletions tests/question_ranking_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,26 @@ QUnit.test("selectToRankEnabled : checkMaxSelectedChoicesUnreached", function (a
questionModel.value = ["11", "22"];
assert.equal(questionModel.checkMaxSelectedChoicesUnreached(), false, "MaxSelectedChoices limit reached");
});

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

assert.equal(questionModel.selectToRankAreasLayout, "horizontal", "default");
assert.equal(questionModel.renderedSelectToRankAreasLayout, "horizontal", "default");

questionModel.selectToRankAreasLayout = "vertical";
assert.equal(questionModel.selectToRankAreasLayout, "vertical", "set vertical");
assert.equal(questionModel.renderedSelectToRankAreasLayout, "vertical", "set vertical");

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

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

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

0 comments on commit c48ea82

Please sign in to comment.