-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix: Keep active item position on save/restore (fixes #295) * Fix: storeUserAnswer on setActiveItem Moved from adaptlearning/adapt-contrib-core#494 * Revert * FW bump for core dependency --------- Co-authored-by: joe-allen-89 <[email protected]>
- Loading branch information
1 parent
5f0df20
commit 1c0e9d7
Showing
3 changed files
with
24 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
import ItemsComponentModel from 'core/js/models/itemsComponentModel'; | ||
|
||
export default class NarrativeModel extends ItemsComponentModel {} | ||
export default class NarrativeModel extends ItemsComponentModel { | ||
restoreUserAnswers() { | ||
const numberArray = this.get('_userAnswer'); | ||
if (!numberArray) return; | ||
const children = this.getChildren(); | ||
const shouldRestoreActiveItem = (numberArray.length > children.length); | ||
if (shouldRestoreActiveItem) { | ||
const activeItemIndex = numberArray.pop(); | ||
this.setActiveItem(activeItemIndex); | ||
} | ||
children.forEach(child => child.set('_isVisited', Boolean(numberArray[child.get('_index')]))); | ||
} | ||
|
||
storeUserAnswer() { | ||
const items = this.getChildren().slice(0); | ||
items.sort((a, b) => a.get('_index') - b.get('_index')); | ||
const numberArray = items.map(child => child.get('_isVisited') ? 1 : 0); | ||
const activeItem = this.getActiveItem(); | ||
if (activeItem) numberArray.push(activeItem.get('_index')); | ||
this.set('_userAnswer', numberArray); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters