Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-kurmanov committed Oct 11, 2023
1 parent 61d48ce commit a996376
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/dragdrop/ranking-select-to-rank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,22 @@ export class DragDropRankingSelectToRank extends DragDropRankingChoices {
): void {
const questionModel: any = this.parentElement;

let { fromIndex, toIndex } = this.getIndixies(questionModel, fromChoicesArray, toChoicesArray);

rankFunction(questionModel, fromIndex, toIndex);
this.doUIEffects(dropTargetNode, fromIndex, toIndex);
}

public getIndixies(model: any, fromChoicesArray: Array<ItemValue>, toChoicesArray: Array<ItemValue>) {
let fromIndex = fromChoicesArray.indexOf(this.draggedElement);
let toIndex = toChoicesArray.indexOf(this.dropTarget);

if (toIndex === -1) toIndex = questionModel.value.length;
if (toIndex === -1) toIndex = model.value.length;

rankFunction(questionModel, fromIndex, toIndex);
this.doUIEffects(dropTargetNode, fromIndex, toIndex);
return { fromIndex, toIndex };
}

private doUIEffects(dropTargetNode: HTMLElement, fromIndex: number, toIndex:number) {
private doUIEffects(dropTargetNode: HTMLElement, fromIndex: number, toIndex: number) {
const questionModel: any = this.parentElement;
const isDropToEmptyRankedContainer = this.dropTarget === "to-container" && questionModel.isEmpty();
const isNeedToShowIndexAtShortcut = !this.isDropTargetUnranked || isDropToEmptyRankedContainer;
Expand Down
9 changes: 9 additions & 0 deletions tests/dragdrophelpertests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ QUnit.test("DragDropRankingSelectToRank reorderRankedItem", function (assert) {
assert.equal(questionModel.rankingChoices[1].value, "33", "item 2 is correct");
assert.equal(questionModel.rankingChoices.length, 2, "rankingChoices count");
});

QUnit.test("DragDropRankingSelectToRank getIndixies", function (assert) {
const withDefaultValue = true;
const dndModel = new DragDropRankingSelectToRank();
const questionModel = createRankingQuestionModel(withDefaultValue);

let { toIndex } = dndModel.getIndixies(questionModel, questionModel.rankingChoices, questionModel.unRankingChoices);
assert.equal(toIndex, 2);
});
// EO selectToRankEnabled

QUnit.test("rows: check matrixdynamic d&d", function (assert) {
Expand Down

0 comments on commit a996376

Please sign in to comment.