Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 786f73c

Browse files
author
Brad Miller
committed
V1 display page progress bar
1 parent b0e7ad3 commit 786f73c

4 files changed

Lines changed: 51 additions & 1 deletion

File tree

runestone/common/css/runestone-custom-sphinx-bootstrap.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,3 +856,14 @@ textarea#lp-result {
856856
padding-left: 2em;
857857
padding-right: 2em;
858858
}
859+
860+
861+
#scprogresscontainer {
862+
width: 50%;
863+
margin-left: auto;
864+
margin-right: auto;
865+
}
866+
867+
#subchapterprogress > div {
868+
background: green;
869+
}

runestone/common/js/bookfuncs.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,38 @@ function timedRefresh() {
104104
$.idleTimer(timeoutPeriod);
105105
}
106106

107+
function calculateProgress() {
108+
let possible = 0;
109+
let total = 1;
110+
for (let k in eBookConfig.activities) {
111+
if (k !== undefined) {
112+
possible++;
113+
if (eBookConfig.activities[k] > 0) {
114+
total++;
115+
}
116+
}
117+
}
118+
return {possible: possible, total: total}
119+
}
120+
121+
122+
function addProgress() {
123+
let {possible, total} = calculateProgress()
124+
$("#scprogresstotal").text(total);
125+
$("#scprogressposs").text(possible);
126+
$( "#subchapterprogress" ).progressbar({
127+
value: 100 * total/possible
128+
});
129+
}
130+
131+
function updateProgress(div_id) {
132+
eBookConfig.activities[div_id]++;
133+
let {possible, total} = calculateProgress();
134+
let val = 100 * total / possible;
135+
$("#scprogresstotal").text(total);
136+
$("#scprogressposs").text(possible);
137+
$("#subchapterprogress").progressbar("option","value", val)
138+
}
107139

108140
function handlePageSetup() {
109141

@@ -124,6 +156,7 @@ function handlePageSetup() {
124156
}
125157
$(".loggedinuser").html(mess);
126158

159+
addProgress();
127160
notifyRunestoneComponents();
128161
}
129162

runestone/common/js/runestonebase.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ RunestoneBase.prototype.logBookEvent = function (eventInfo) {
3838
null, 'json');
3939
}
4040
console.log("logging event " + JSON.stringify(eventInfo));
41+
updateProgress(eventInfo.div_id);
4142
return post_return;
4243
};
4344

runestone/common/project_template/_templates/plugin_layouts/sphinx_bootstrap/layout.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
eBookConfig.isInstructor = {{= is_instructor }};
243243
eBookConfig.username = '{{= user_id}}';
244244
eBookConfig.readings = {{= readings}};
245+
eBookConfig.activities = {{= XML(activity_info) }}
245246
{% endraw %}
246247
{% else %}
247248
eBookConfig.useRunestoneServices = {% if use_services == 'True' -%}true{%- else -%}false{%- endif -%};
@@ -294,7 +295,11 @@
294295
<div class="container" id="continue-reading"></div>
295296

296297
<div class="container" id="main-content">
297-
{% block body %}{% endblock %}
298+
{% block body %}
299+
{% endblock %}
300+
<div id=scprogresscontainer>
301+
You have attempted <span id=scprogresstotal></span> of <span id=scprogressposs></span> activities on this page <div id="subchapterprogress"></div>
302+
</div>
298303
{% block nextprevious %}
299304
{% include "subchapter.html" %}
300305
{% endblock %}

0 commit comments

Comments
 (0)