gui/js: Now requesting all available content at once, disabling content verification to speed up the work

Change-Id: I787487505bb1d636e4a5a3200d84ff815395ec77
diff --git a/gui/html/chronoshare.js b/gui/html/chronoshare.js
index 91fe02e..2e4abd4 100644
--- a/gui/html/chronoshare.js
+++ b/gui/html/chronoshare.js
@@ -12,6 +12,7 @@
          this.restore = new Name ("/localhost").add (this.username).add ("chronoshare").add (foldername).add ("cmd").add ("restore").add ("file");
 
          this.ndn = new NDN ({host:"127.0.0.1"});
+	 this.ndn.verify = false; //disable content verification, works WAAAAY faster
      },
 
      run: function () {
@@ -81,7 +82,7 @@
 	this.callback = callback;
     },
     upcall: function(kind, upcallInfo) {
-        if (kind == Closure.UPCALL_CONTENT) {
+        if (kind == Closure.UPCALL_CONTENT || kind == Closure.UPCALL_CONTENT_UNVERIFIED) { //disable content verification
             convertedData = DataUtils.toString (upcallInfo.contentObject.content);
 	    this.callback (true, convertedData);
 	}
@@ -94,93 +95,136 @@
     }
 });
 
-$.Class ("FilesClosure", {}, {
-    init: function (chronoshare) {
-        this.chronoshare = chronoshare;
+$.Class ("RestPipelineClosure", {}, {
+    init: function (collectionName, moreName) {
+	this.collectionName = collectionName;
+	this.moreName = moreName;
+	$("#json").empty ();
+
+	this.collection = [];
     },
 
     upcall: function(kind, upcallInfo) {
-        $("#loader").fadeOut (500); // ("hidden");
-        if (kind == Closure.UPCALL_CONTENT) {
+        if (kind == Closure.UPCALL_CONTENT || kind == Closure.UPCALL_CONTENT_UNVERIFIED) { //disable content verification
+
             convertedData = DataUtils.toString (upcallInfo.contentObject.content);
 	    if (PARAMS.debug) {
-		$("#json").text (convertedData);
+		$("#json").append ($(document.createTextNode(convertedData)));
 		$("#json").removeClass ("hidden");
 	    }
             data = JSON.parse (convertedData);
 
-            tbody = $("<tbody />", { "id": "file-list-files" });
-
-            /// @todo Eventually set title for other pages
-            $("title").text ("ChronoShare - List of files" + (PARAMS.item?" - "+PARAMS.item:""));
-
-            // error handling?
-            newcontent = $("<div />", { "id": "content" }).append (
-		$("<h2 />").append ($(document.createTextNode("List of files ")), $("<green />").text (PARAMS.item)),
-                $("<table />", { "class": "item-list" })
-                    .append ($("<thead />")
-                             .append ($("<tr />")
-                                      .append ($("<th />", { "class": "filename border-left", "scope": "col" }).text ("Filename"))
-                                      .append ($("<th />", { "class": "version", "scope": "col" }).text ("Version"))
-                                      .append ($("<th />", { "class": "size", "scope": "col" }).text ("Size"))
-                                      .append ($("<th />", { "class": "modified", "scope": "col" }).text ("Modified"))
-                                      .append ($("<th />", { "class": "modified-by border-right", "scope": "col" }).text ("Modified By"))))
-                    .append (tbody)
-                    .append ($("<tfoot />")
-                             .append ($("<tr />")
-                                      .append ($("<td />", { "colspan": "5", "class": "border-right border-left" })))));
-            newcontent.hide ();
-
-            for (var i = 0; i < data.files.length; i++) {
-                file = data.files[i];
-
-		row = $("<tr />", { "class": "with-context-menu" } );
-		if (i%2) { row.addClass ("odd"); }
-
-                row.bind('mouseenter mouseleave', function() {
-                    $(this).toggleClass('highlighted');
-                });
-
-                row.attr ("filename", file.filename); //encodeURIComponent(encodeURIComponent(file.filename)));
-                row.bind('click', function (e) { openHistoryForItem ($(this).attr ("filename")) });
-
-		row.append ($("<td />", { "class": "filename border-left" })
-			    .text (file.filename)
-			    .prepend ($("<img />", { "src": fileExtension(file.filename) })));
-		row.append ($("<td />", { "class": "version" }).text (file.version));
-		row.append ($("<td />", { "class": "size" }).text (SegNumToFileSize (file.segNum)));
-		row.append ($("<td />", { "class": "modified" }).text (new Date (file.timestamp+"+00:00"))); // convert from UTC
-		row.append ($("<td />", { "class": "modified-by border-right"})
-			    .append ($("<userName />").text (file.owner.userName))
-			    .append ($("<seqNo> /").text (file.owner.seqNo)));
-
-		tbody = tbody.append (row);
-            }
-
-	    displayContent (newcontent, data.more, this.base_url ());
-
-	    $.contextMenu( 'destroy',  ".with-context-menu" ); // cleanup
-	    $.contextMenu({
-		selector: ".with-context-menu",
-		items: {
-		    "info": {name: "x", type: "html", html: "<b>File operations</b>"},
-		    "sep1": "---------",
-		    history: {name: "View file history",
-			      icon: "quit", // need a better icon
-			      callback: function(key, opt) {
-				  openHistoryForItem (opt.$trigger.attr ("filename"));
-			      }},
-		}
-	    });
-        }
+	    this.collection = this.collection.concat (data[this.collectionName]);
+	    if (data[this.moreName] !== undefined) {
+		nextSegment = upcallInfo.interest.name.cut (1).addSegment (data[this.moreName]);
+		console.log ("MORE: " +nextSegment.to_uri ());
+		CHRONOSHARE.ndn.expressInterest (nextSegment, this);
+	    }
+	    else {
+		$("#loader").fadeOut (500); // ("hidden");
+		this.onData (this.collection);
+	    }
+	}
         else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
-            $("#error").html ("Interest timed out");
-            $("#error").removeClass ("hidden");
+            $("#loader").fadeOut (500); // ("hidden");
+	    this.onTimeout (upcallInfo.interest);
         }
         else {
-            $("#error").html ("Unknown error happened");
-            $("#error").removeClass ("hidden");
+            $("#loader").fadeOut (500); // ("hidden");
+	    this.onUnknownError (upcallInfo.interest);
         }
+
+	return Closure.RESULT_OK; // make sure we never re-express the interest
+    },
+
+    onData: function(data) {
+    },
+
+    onTimeout: function () {
+        $("#error").html ("Interest timed out");
+        $("#error").removeClass ("hidden");
+    },
+
+    onUnknownError: function () {
+        $("#error").html ("Unknown error happened");
+        $("#error").removeClass ("hidden");
+    }
+});
+
+// $.Class ("FilesClosure", {}, {
+RestPipelineClosure ("FilesClosure", {}, {
+    init: function (chronoshare) {
+	this._super("files", "more");
+        this.chronoshare = chronoshare;
+    },
+
+    onData: function(data) {
+        tbody = $("<tbody />", { "id": "file-list-files" });
+
+        /// @todo Eventually set title for other pages
+        $("title").text ("ChronoShare - List of files" + (PARAMS.item?" - "+PARAMS.item:""));
+
+        // error handling?
+        newcontent = $("<div />", { "id": "content" }).append (
+	    $("<h2 />").append ($(document.createTextNode("List of files ")), $("<green />").text (PARAMS.item)),
+            $("<table />", { "class": "item-list" })
+                .append ($("<thead />")
+                         .append ($("<tr />")
+                                  .append ($("<th />", { "class": "filename border-left", "scope": "col" }).text ("Filename"))
+                                  .append ($("<th />", { "class": "version", "scope": "col" }).text ("Version"))
+                                  .append ($("<th />", { "class": "size", "scope": "col" }).text ("Size"))
+                                  .append ($("<th />", { "class": "modified", "scope": "col" }).text ("Modified"))
+                                  .append ($("<th />", { "class": "modified-by border-right", "scope": "col" }).text ("Modified By"))))
+                .append (tbody)
+                .append ($("<tfoot />")
+                         .append ($("<tr />")
+                                  .append ($("<td />", { "colspan": "5", "class": "border-right border-left" })))));
+        newcontent.hide ();
+
+        for (var i = 0; i < data.length; i++) {
+            file = data[i];
+
+	    row = $("<tr />", { "class": "with-context-menu" } );
+	    if (i%2) { row.addClass ("odd"); }
+
+            row.bind('mouseenter mouseleave', function() {
+                $(this).toggleClass('highlighted');
+            });
+
+            row.attr ("filename", file.filename); //encodeURIComponent(encodeURIComponent(file.filename)));
+            row.bind('click', function (e) { openHistoryForItem ($(this).attr ("filename")) });
+
+	    row.append ($("<td />", { "class": "filename border-left" })
+			.text (file.filename)
+			.prepend ($("<img />", { "src": fileExtension(file.filename) })));
+	    row.append ($("<td />", { "class": "version" }).text (file.version));
+	    row.append ($("<td />", { "class": "size" }).text (SegNumToFileSize (file.segNum)));
+	    row.append ($("<td />", { "class": "modified" }).text (new Date (file.timestamp+"+00:00"))); // convert from UTC
+	    row.append ($("<td />", { "class": "modified-by border-right"})
+			.append ($("<userName />").text (file.owner.userName))
+			.append ($("<seqNo> /").text (file.owner.seqNo)));
+
+	    tbody = tbody.append (row);
+        }
+
+	$("#content").fadeOut ("fast", function () {
+	    $(this).replaceWith (newcontent);
+	    $("#content").fadeIn ("fast");
+	});
+
+	$.contextMenu( 'destroy',  ".with-context-menu" ); // cleanup
+	$.contextMenu({
+	    selector: ".with-context-menu",
+	    items: {
+		"info": {name: "x", type: "html", html: "<b>File operations</b>"},
+		"sep1": "---------",
+		history: {name: "View file history",
+			  icon: "quit", // need a better icon
+			  callback: function(key, opt) {
+			      openHistoryForItem (opt.$trigger.attr ("filename"));
+			  }},
+	    }
+	});
     },
 
     base_url: function () {
@@ -195,137 +239,123 @@
 });
 
 
-$.Class ("HistoryClosure", {}, {
+RestPipelineClosure ("HistoryClosure", {}, {
     init: function (chronoshare) {
+	this._super("actions", "more");
         this.chronoshare = chronoshare;
     },
 
-    upcall: function(kind, upcallInfo) {
-        $("#loader").fadeOut (500); // ("hidden");
-        if (kind == Closure.UPCALL_CONTENT) {
-            convertedData = DataUtils.toString (upcallInfo.contentObject.content);
-	    if (PARAMS.debug) {
-		$("#json").text (convertedData);
-		$("#json").removeClass ("hidden");
+    onData: function(data) {
+        tbody = $("<tbody />", { "id": "history-list-actions" });
+
+        /// @todo Eventually set title for other pages
+        $("title").text ("ChronoShare - Recent actions" + (PARAMS.item?" - "+PARAMS.item:""));
+
+        newcontent = $("<div />", { "id": "content" }).append (
+	    $("<h2 />").append ($(document.createTextNode("Recent actions ")), $("<green />").text (PARAMS.item)),
+            $("<table />", { "class": "item-list" })
+                .append ($("<thead />")
+                         .append ($("<tr />")
+                                  .append ($("<th />", { "class": "filename border-left", "scope": "col" }).text ("Filename"))
+                                  .append ($("<th />", { "class": "version", "scope": "col" }).text ("Version"))
+                                  .append ($("<th />", { "class": "size", "scope": "col" }).text ("Size"))
+                                  .append ($("<th />", { "class": "modified", "scope": "col" }).text ("Modified"))
+                                  .append ($("<th />", { "class": "modified-by border-right", "scope": "col" }).text ("Modified By"))))
+                .append (tbody)
+                .append ($("<tfoot />")
+                         .append ($("<tr />")
+                                  .append ($("<td />", { "colspan": "5", "class": "border-right border-left" })))));
+
+        for (var i = 0; i < data.length; i++) {
+            action = data[i];
+
+	    row = $("<tr />");
+	    if (i%2) { row.addClass ("odd"); }
+            if (action.action=="DELETE") {
+		row.addClass ("delete");
 	    }
-            data = JSON.parse (convertedData);
+	    else {
+		row.addClass ("with-context-menu");
+                row.attr ("file_version", action.version);
+		row.attr ("file_hash", action.update.hash);
+		row.attr ("file_modified_by", action.id.userName);
+	    }
 
-            tbody = $("<tbody />", { "id": "history-list-actions" });
+            row.attr ("filename", action.filename);
+            row.bind('click', function (e) { openHistoryForItem ($(this).attr ("filename")) });
 
-            /// @todo Eventually set title for other pages
-            $("title").text ("ChronoShare - Recent actions" + (PARAMS.item?" - "+PARAMS.item:""));
+            row.bind('mouseenter mouseleave', function() {
+                $(this).toggleClass('highlighted');
+            });
 
-            newcontent = $("<div />", { "id": "content" }).append (
-		$("<h2 />").append ($(document.createTextNode("Recent actions ")), $("<green />").text (PARAMS.item)),
-                $("<table />", { "class": "item-list" })
-                    .append ($("<thead />")
-                             .append ($("<tr />")
-                                      .append ($("<th />", { "class": "filename border-left", "scope": "col" }).text ("Filename"))
-                                      .append ($("<th />", { "class": "version", "scope": "col" }).text ("Version"))
-                                      .append ($("<th />", { "class": "size", "scope": "col" }).text ("Size"))
-                                      .append ($("<th />", { "class": "modified", "scope": "col" }).text ("Modified"))
-                                      .append ($("<th />", { "class": "modified-by border-right", "scope": "col" }).text ("Modified By"))))
-                    .append (tbody)
-                    .append ($("<tfoot />")
-                             .append ($("<tr />")
-                                      .append ($("<td />", { "colspan": "5", "class": "border-right border-left" })))));
+	    row.append ($("<td />", { "class": "filename border-left" })
+			.text (action.filename)
+			.prepend ($("<img />", { "src": fileExtension(action.filename) })));
+	    row.append ($("<td />", { "class": "version" }).text (action.version));
+	    row.append ($("<td />", { "class": "size" }).text (action.update?SegNumToFileSize (action.update.segNum):""));
+	    row.append ($("<td />", { "class": "timestamp" }).text (new Date (action.timestamp+"+00:00"))); // conversion from UTC timezone (we store action time in UTC)
+	    row.append ($("<td />", { "class": "modified-by border-right" })
+	        	.append ($("<userName />").text (action.id.userName))
+	        	.append ($("<seqNo> /").text (action.id.seqNo)));
 
-            for (var i = 0; i < data.actions.length; i++) {
-                action = data.actions[i];
+	    tbody = tbody.append (row);
+        }
 
-		row = $("<tr />");
-	        if (i%2) { row.addClass ("odd"); }
-                if (action.action=="DELETE") {
-		    row.addClass ("delete");
-		}
-		else {
-		    row.addClass ("with-context-menu");
-                    row.attr ("file_version", action.version);
-		    row.attr ("file_hash", action.update.hash);
-		    row.attr ("file_modified_by", action.id.userName);
-		}
+	$("#content").fadeOut ("fast", function () {
+	    $(this).replaceWith (newcontent);
+	    $("#content").fadeIn ("fast");
+	});
 
-                row.attr ("filename", action.filename);
-                row.bind('click', function (e) { openHistoryForItem ($(this).attr ("filename")) });
+	$.contextMenu( 'destroy',  ".with-context-menu" ); // cleanup
+	$.contextMenu({
+	    selector: ".with-context-menu",
+	    items: {
+		"sep1": "---------",
+		restore: {name: "Restore this revision",
+			  icon: "cut", // need a better icon
+			  callback: function(key, opt) {
+			      filename = opt.$trigger.attr ("filename");
+			      version = opt.$trigger.attr ("file_version");
+			      hash = DataUtils.toNumbers (opt.$trigger.attr ("file_hash"));
+			      console.log (hash);
+			      modified_by = opt.$trigger.attr ("file_modified_by");
 
-                row.bind('mouseenter mouseleave', function() {
-                    $(this).toggleClass('highlighted');
-                });
+			      $("<div />", { "title": "Restore version " + version + "?" })
+				  .append ($("<p />")
+					   .append ($("<span />", { "class": "ui-icon ui-icon-alert",
+								    "style": "float: left; margin: 0 7px 50px 0;" }),
+						    $(document.createTextNode ("Are you sure you want restore version ")),
+						    $("<green/>").text (version),
+						    $(document.createTextNode (" by ")),
+						    $("<green/>").text (modified_by)))
+				  .dialog ({
+				      resizable: true,
+				      height:200,
+				      width:300,
+				      modal: true,
+				      buttons: {
+					  "Restore": function() {
+					      self = $(this);
+					      CHRONOSHARE.cmd_restore_file (filename, version, hash, function(didGetData, response) {
+						  if (!didGetData || response != "OK") {
+						      custom_alert (response);
+						  }
+						  console.log (response);
+						  self.dialog ("close");
 
-		row.append ($("<td />", { "class": "filename border-left" })
-			    .text (action.filename)
-			    .prepend ($("<img />", { "src": fileExtension(action.filename) })));
-	        row.append ($("<td />", { "class": "version" }).text (action.version));
-		row.append ($("<td />", { "class": "size" }).text (action.update?SegNumToFileSize (action.update.segNum):""));
-	        row.append ($("<td />", { "class": "timestamp" }).text (new Date (action.timestamp+"+00:00"))); // conversion from UTC timezone (we store action time in UTC)
-	        row.append ($("<td />", { "class": "modified-by border-right" })
-	        	    .append ($("<userName />").text (action.id.userName))
-	        	    .append ($("<seqNo> /").text (action.id.seqNo)));
-
-	        tbody = tbody.append (row);
-            }
-
-	    displayContent (newcontent, data.more, this.base_url (PAGE));
-
-	    $.contextMenu( 'destroy',  ".with-context-menu" ); // cleanup
-	    $.contextMenu({
-		selector: ".with-context-menu",
-		items: {
-		    "sep1": "---------",
-		    restore: {name: "Restore this revision",
-			      icon: "cut", // need a better icon
-			      callback: function(key, opt) {
-				  filename = opt.$trigger.attr ("filename");
-				  version = opt.$trigger.attr ("file_version");
-				  hash = DataUtils.toNumbers (opt.$trigger.attr ("file_hash"));
-				  console.log (hash);
-				  modified_by = opt.$trigger.attr ("file_modified_by");
-
-				  $("<div />", { "title": "Restore version " + version + "?" })
-				      .append ($("<p />")
-					       .append ($("<span />", { "class": "ui-icon ui-icon-alert",
-								        "style": "float: left; margin: 0 7px 50px 0;" }),
-							$(document.createTextNode ("Are you sure you want restore version ")),
-							$("<green/>").text (version),
-							$(document.createTextNode (" by ")),
-							$("<green/>").text (modified_by)))
-				      .dialog ({
-					  resizable: true,
-					  height:200,
-					  width:300,
-					  modal: true,
-					  buttons: {
-					      "Restore": function() {
-						  self = $(this);
-						  CHRONOSHARE.cmd_restore_file (filename, version, hash, function(didGetData, response) {
-						      if (!didGetData || response != "OK") {
-							  custom_alert (response);
-						      }
-						      console.log (response);
-						      self.dialog ("close");
-
-						      $.timer (function() {CHRONOSHARE.run ();}).once (1000);
-						  });
-					      },
-					      Cancel: function() {
-						  $(this).dialog ("close");
-					      }
+						  $.timer (function() {CHRONOSHARE.run ();}).once (1000);
+					      });
+					  },
+					  Cancel: function() {
+					      $(this).dialog ("close");
 					  }
-				      });
-				  // openHistoryForItem (opt.$trigger.attr ("filename"));
-			      }},
-		    "sep2": "---------",
-		}
-	    });
-        }
-        else if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
-            $("#error").html ("Interest timed out");
-            $("#error").removeClass ("hidden");
-        }
-        else {
-            $("#error").html ("Unknown error happened");
-            $("#error").removeClass ("hidden");
-        }
+				      }
+				  });
+			      // openHistoryForItem (opt.$trigger.attr ("filename"));
+			  }},
+		"sep2": "---------",
+	    }
+	});
     },
 
     base_url: function (page) {