summaryrefslogtreecommitdiffstats
path: root/lib/parse/progress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/parse/progress.js')
-rw-r--r--lib/parse/progress.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/parse/progress.js b/lib/parse/progress.js
new file mode 100644
index 0000000..8088aa8
--- /dev/null
+++ b/lib/parse/progress.js
@@ -0,0 +1,38 @@
+var _ = require("lodash");
+
+var calculProgress = function(navigation, current) {
+ var n = _.size(navigation);
+ var percent = 0;
+ var done = true;
+
+ var chapters = _.chain(navigation)
+ .map(function(nav, path) {
+ nav.path = path;
+ return nav;
+ })
+ .sortBy(function(nav) {
+ return nav.level;
+ })
+ .map(function(nav, i) {
+ // Calcul percent
+ nav.percent = (i * 100) / Math.max((n - 1), 1);
+
+ // Is it done
+ nav.done = done;
+ if (nav.path == current) {
+ percent = nav.percent;
+ done = false;
+ }
+
+ return nav;
+ })
+ .value();
+
+
+ return {
+ percent: percent,
+ chapters: chapters
+ };
+}
+
+module.exports = calculProgress; \ No newline at end of file