Template Progress widget.
authorJason Skomorowski <jason@indexdata.com>
Fri, 8 Aug 2014 18:53:58 +0000 (14:53 -0400)
committerJason Skomorowski <jason@indexdata.com>
Mon, 11 Aug 2014 13:37:49 +0000 (09:37 -0400)
src/mkws-handlebars.js
src/mkws-widget-main.js
src/mkws-widget-main.templates/Progress.handlebars [new file with mode: 0644]

index 866dc8a..bd9af8d 100644 (file)
@@ -96,3 +96,11 @@ Handlebars.registerHelper('mkws-commaList', function(items, options) {
 Handlebars.registerHelper('mkws-index1', function(obj) {
   return obj.data.index + 1;
 });
+
+Handlebars.registerHelper('mkws-repeat', function(count, options) {
+  var out = "";
+  for (var i = 0; i < count; i++) {
+    out += options.fn(this);
+  }
+  return out;
+});
index f76edbc..ffe00d6 100644 (file)
@@ -342,19 +342,13 @@ mkws.registerWidgetType('Config', function() {
 
 mkws.registerWidgetType('Progress', function() {
   var that = this;
-
   this.node.hide();
   this.team.queue("stat").subscribe(function(data) {
-    var s = '<span class="mkwsDone">';
-    for (var i = 0; i < data.clients; i++) {
-      if (i == data.clients - data.activeclients) {
-        s += '</span>';
-        s += '<span class="mkwsWaiting">';
-      }
-      s += '&#x2588;';
-    }
-    s += '</span>';
-    that.node.html(s);
+    var template = this.team.loadTemplate(this.config.template || "Progress");
+    this.node.html(template({
+      done: data.clients - data.activeclients,
+      waiting: data.activeclients
+    }));
     that.node.show();
   });
 });
diff --git a/src/mkws-widget-main.templates/Progress.handlebars b/src/mkws-widget-main.templates/Progress.handlebars
new file mode 100644 (file)
index 0000000..1b08a2c
--- /dev/null
@@ -0,0 +1,11 @@
+{{!
+Progress
+
+done - number of targets complete
+waiting - number of targets waiting
+}}
+<span class="mkwsDone">{{#mkws-repeat done}}&#x2588;{{/mkws-repeat}}</span>
+{{~#if waiting~}}
+<span class="mkwsWaiting">{{#mkws-repeat waiting}}&#x2588;{{/mkws-repeat}}</span>
+{{~/if~}}
+