Skip to content

Commit 3719926

Browse files
committed
Initial commit
0 parents  commit 3719926

9 files changed

Lines changed: 225 additions & 0 deletions

File tree

.bowerrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"directory": "src/plugins",
3+
"registry": "http://adapt-bower-repository.herokuapp.com/"
4+
}

LICENSE

Whitespace-only changes.

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Adapt Course Progress
2+
=================
3+
**Course Progress** adds a progress bar to the bottom of each page indicating the overall course completion.
4+
5+
![Preview](https://cloud.githubusercontent.com/assets/480718/24266680/af45315c-0fd5-11e7-9421-ff0599524fc1.gif)
6+
7+
8+
Settings
9+
--------
10+
None.
11+
12+
Limitations
13+
-----------
14+
No known limitations.
15+
16+
-----------
17+
**Course Progress** is a plugin for the Adapt Framework. [Adapt](https://www.adaptlearning.org) is a free and easy to use e-learning authoring tool that creates fully responsive, multi-device, HTML5 e-learning content using the award-winning Adapt developer framework.

bower.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "adapt-course-progress",
3+
"repository": "git://github.com/gowithfloat/adapt-course-progress.git",
4+
"homepage": "https://github.com/gowithfloat/adapt-course-progress",
5+
"issues": "https://github.com/gowithfloat/adapt-course-progress/issues",
6+
"version": "1.0.0",
7+
"framework": "^2.0.0",
8+
"authors": [
9+
"Daniel Pfeiffer <dpfeiffer@gowithfloat.com>"
10+
],
11+
"main": "/js/adapt-course-progress.js",
12+
"extension": "adapt-course-progress",
13+
"displayName": "Course Progress",
14+
"description": "Adds a progress bar to the bottom of each page indicating the overall course completion",
15+
"keywords": [
16+
"adapt-plugin",
17+
"adapt-extension"
18+
],
19+
"license": "MIT",
20+
"homepage": "",
21+
"ignore": [
22+
"**/.*",
23+
"node_modules",
24+
"bower_components",
25+
"test",
26+
"tests"
27+
]
28+
}

js/ProgressView.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
define(function(require) {
2+
3+
var ProgressView = Backbone.View.extend({
4+
initialize: function () {
5+
this.model.on("change", this.render, this);
6+
this.render();
7+
},
8+
9+
render: function() {
10+
var data = this.model.toJSON();
11+
var template = Handlebars.templates["course-progress"];
12+
this.$el.html(template(data));
13+
return this;
14+
}
15+
});
16+
17+
return ProgressView;
18+
});

js/adapt-course-progress.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
define(["coreJS/adapt", "./ProgressView"], function(Adapt, ProgressView) {
2+
var progressReporter = new Progress();
3+
var progressView = new ProgressView({model: progressReporter});
4+
5+
Adapt.on('app:dataLoaded', function() {
6+
calculateCompletion(Adapt, progressReporter);
7+
8+
Adapt.articles.on("change:_isComplete", function() {
9+
calculateCompletion(Adapt, progressReporter);
10+
});
11+
12+
Adapt.on("pageView:postRender", function(view) {
13+
view.$el.addClass("shows-progress");
14+
view.$el.append(progressView.$el);
15+
});
16+
});
17+
});
18+
19+
var Progress = Backbone.Model.extend({
20+
defaults: {
21+
/**
22+
* The number of units that are completed.
23+
*
24+
* @type {Number}
25+
*/
26+
completeUnitCount: 0,
27+
/**
28+
* The total number of units.
29+
* "Units" is a generic term of an item being used to track completion (e.g Adapt Pages or Articles).
30+
*
31+
* @type {Number}
32+
*/
33+
totalUnitCount: 0,
34+
/**
35+
* The number of units left to complete.
36+
*
37+
* @type {Number}
38+
*/
39+
remainingUnitCount: 0,
40+
/**
41+
* The percent completion on a scale of 0 to 1.
42+
*
43+
* @type {Number}
44+
*/
45+
percentComplete: 0,
46+
/**
47+
* The percent completion on a scale of 0 to 100 (whole numbers).
48+
*
49+
* @type {Number}
50+
*/
51+
displayPercentComplete: 0
52+
},
53+
54+
/**
55+
* Updates the progress represented by this progress model.
56+
*
57+
* @param {Number} completeUnitCount The number of units completed.
58+
* @param {Number} totalUnitCount The total number of units.
59+
*/
60+
updateProgress: function(completeUnitCount, totalUnitCount) {
61+
this.set({
62+
completeUnitCount: completeUnitCount,
63+
remainingUnitCount: totalUnitCount - completeUnitCount,
64+
totalUnitCount: totalUnitCount,
65+
percentComplete: completeUnitCount / totalUnitCount,
66+
displayPercentComplete: Math.round(completeUnitCount / totalUnitCount * 100)
67+
})
68+
}
69+
});
70+
71+
/**
72+
* Calculates the completion of the provided Adapt course.
73+
*
74+
* @param {AdaptModel} Adapt The Adapt course to report completion on.
75+
* @param {Progress} progressReporter The progress reporter receiving the updated progress information.
76+
*/
77+
function calculateCompletion(Adapt, progressReporter) {
78+
var availableContentObjects = new Backbone.Collection(Adapt.articles.where({_isAvailable: true, _isOptional: false}));
79+
80+
var requireCompletionOf = Adapt.course.get("_requireCompletionOf");
81+
var total = requireCompletionOf === -1 ? availableContentObjects.length : requireCompletionOf;
82+
83+
var complete = availableContentObjects.where({_isComplete: true}).length;
84+
85+
progressReporter.updateProgress(complete, total);
86+
}

less/course-progress.less

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.page.shows-progress {
2+
padding-bottom: @item-padding * 2;
3+
}
4+
5+
#course-progress {
6+
background-color: @background-color-inverted;
7+
bottom: 0;
8+
position: fixed;
9+
width: 100%;
10+
z-index: 99;
11+
12+
.block-inner {
13+
padding: @item-padding 0;
14+
}
15+
16+
.progress-bar {
17+
background-color: darken(@background-color-inverted, 20%);;
18+
height: 10px;
19+
20+
&.complete {
21+
background-color: @primary-color;
22+
}
23+
}
24+
25+
.progress-percent-complete {
26+
color: @foreground-color-inverted;
27+
font-size: 0.9em;
28+
font-weight: bold;
29+
margin: @item-margin 0;
30+
text-align: right;
31+
}
32+
}

properties.schema

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"type": "object",
3+
"$schema": "http://json-schema.org/draft-04/schema",
4+
"id": "http://jsonschema.net",
5+
"required":false,
6+
"properties":{
7+
"pluginLocations": {
8+
"type": "object",
9+
"required":true,
10+
"properties":{
11+
"config": {
12+
"type": "object"
13+
},
14+
"course": {
15+
"type": "object"
16+
},
17+
"contentobject": {
18+
"type": "object"
19+
},
20+
"article": {
21+
"type": "object"
22+
},
23+
"block": {
24+
"type": "object"
25+
},
26+
"component": {
27+
"type": "object"
28+
}
29+
}
30+
}
31+
}
32+
}

templates/course-progress.hbs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div id="course-progress" class="block">
2+
<div class="block-inner">
3+
<div class="progress-bar">
4+
<div class="complete progress-bar" style="width:{{displayPercentComplete}}%">&nbsp;</div>
5+
</div>
6+
<p class="progress-percent-complete">{{displayPercentComplete}}% complete</p>
7+
</div>
8+
</div>

0 commit comments

Comments
 (0)