diff --git a/js/PageLevelProgressIndicatorView.js b/js/PageLevelProgressIndicatorView.js index 571f387..20f7627 100644 --- a/js/PageLevelProgressIndicatorView.js +++ b/js/PageLevelProgressIndicatorView.js @@ -1,4 +1,5 @@ import Adapt from 'core/js/adapt'; +import ItemsComponentModel from 'core/js/models/itemsComponentModel'; class PageLevelProgressIndicatorView extends Backbone.View { @@ -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() { @@ -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; } diff --git a/js/adapt-contrib-pageLevelProgress.js b/js/adapt-contrib-pageLevelProgress.js index 62a6a7d..73bddd0 100644 --- a/js/adapt-contrib-pageLevelProgress.js +++ b/js/adapt-contrib-pageLevelProgress.js @@ -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) {