Skip to content

Commit

Permalink
New: Added progressive ItemsComponentModel bars (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored May 30, 2024
1 parent b167625 commit 3e193cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion js/PageLevelProgressIndicatorView.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Adapt from 'core/js/adapt';
import ItemsComponentModel from 'core/js/models/itemsComponentModel';

class PageLevelProgressIndicatorView extends Backbone.View {

Expand Down Expand Up @@ -41,7 +42,7 @@ class PageLevelProgressIndicatorView extends Backbone.View {
} else {
this.listenTo(Adapt, 'remove', this.remove);
}
this.listenTo(Adapt.course, 'bubble:change:_isComplete', this.refresh);
this.listenTo(Adapt.course, 'bubble:change:_isComplete bubble:change:_isVisited', this.refresh);
}

setPercentageComplete() {
Expand All @@ -51,6 +52,12 @@ class PageLevelProgressIndicatorView extends Backbone.View {
}

calculatePercentage() {
const isPresentationComponentWithItems = (!this.model.isTypeGroup('question') && this.model instanceof ItemsComponentModel);
if (isPresentationComponentWithItems) {
const children = this.model.getChildren();
const visited = children.filter(child => child.get('_isVisited'));
return Math.round(visited.length / children.length * 100);
}
return this.model.get('_isComplete') ? 100 : 0;
}

Expand Down
2 changes: 1 addition & 1 deletion js/adapt-contrib-pageLevelProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PageLevelProgress extends Backbone.Controller {
'router:contentObject': this.renderNavigationView
});

this.listenTo(Adapt.course, 'bubble:change:_isComplete', this.onCompletionChange);
this.listenTo(Adapt.course, 'bubble:change:_isComplete bubble:change:_isVisited', this.onCompletionChange);
}

onCompletionChange(event) {
Expand Down

0 comments on commit 3e193cc

Please sign in to comment.