Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Introduced DataStreamer to prevent from UI-freezes during initializat…

…ion of big collections.
  • Loading branch information...
commit b25ac2fa8e1e0db89fcc900ec57b3b38065e22a8 1 parent f08177b
Michael Aufreiter authored
View
36 public/javascripts/helpers.js
@@ -6,6 +6,42 @@
* © 2010 Colin Snover <http://zetafleet.com>
* Released under MIT license.
*/
+
+var DataStreamer = {
+ stream: function(json, options) {
+ var collection,
+ nodes,
+ chunksTotal,
+ chunkCount = 0;
+
+ function nextChunk() {
+ chunkCount += 1;
+ var count = 0;
+ var nodeId = nodes.pop();
+
+ // Process chunk
+ while (nodeId && count < options.chunksize-1) {
+ collection.set(nodeId, json["items"][nodeId]);
+ nodeId = nodes.pop();
+ count += 1;
+ }
+
+ // Update progress
+ options.progress((chunkCount/chunksTotal));
+
+ setTimeout(function() {
+ nodes.length === 0 ? options.finished(collection)
+ : nextChunk();
+ }, 1);
+ }
+
+ nodes = _.keys(json.items);
+ chunksTotal = Math.ceil(nodes.length / options.chunksize);
+ collection = new Data.Collection({properties: json.properties, items: {}});
+ nextChunk(1);
+ }
+};
+
(function () {
_.date = function (date) {
var timestamp = Date.parse(date), minutesOffset = 0, struct;
View
30 public/javascripts/views/sheet.js
@@ -1,4 +1,4 @@
-// Visualization
+// Sheet
// --------------
// Map property keys to colors
@@ -68,6 +68,7 @@ var Sheet = Backbone.View.extend({
this.groupKey = [this.groupKeys()[0].key];
}
+ console.log(this.collection);
this.collection.properties().each(function(property, key) {
if (property.meta.facet) {
that.filters.set(key, {
@@ -143,14 +144,22 @@ var Sheet = Backbone.View.extend({
dataType: "json",
success: function(res) {
if (!res.status) {
- that.collection = new Data.Collection(res);
- that.filteredCollection = that.collection;
- that.initSheet();
- that.trigger('loaded');
- if (callback) callback();
- that.project = that.model;
- that.compute();
- that.render();
+ DataStreamer.stream(res, {
+ chunksize: 200,
+ finished: function(c) {
+ that.collection = c;
+ that.filteredCollection = that.collection;
+ that.initSheet();
+ that.trigger('loaded');
+ if (callback) callback();
+ that.project = that.model;
+ that.compute();
+ that.render();
+ },
+ progress: function(progress) {
+ $('#data_progress').html("Initializing... "+parseInt(progress*100)+"% complete");
+ }
+ });
} else {
$('#sheet').html("<h2>The sheet couldn't be loaded.</h2><p>You may not be permitted to access the datasource.<br/><br/></p>");
}
@@ -345,7 +354,6 @@ var Sheet = Backbone.View.extend({
this.facets = facets;
},
-
updateGroupKey: function() {
this.groupKey = [$('#group_key').val()];
this.compute();
@@ -432,8 +440,6 @@ var Sheet = Backbone.View.extend({
this.initEditors();
}
-
-
this.delegateEvents();
return this;
}
View
5 templates/app.html
@@ -462,7 +462,10 @@ <h2 id="project_title" title="Click to edit"><%= project.get('title') %></h2>
<div id="sheet">
<div id="sheet_header">
<h2>Loading sheet...</h2>
- <p>Depending on the amount of data this may take a while.<br/><br/></p>
+ <p>
+ Depending on the amount of data this may take a while.<br/><br/>
+ <div id="data_progress"></div><br/><br/>
+ </p>
</div>
</div>
</script>
Please sign in to comment.
Something went wrong with that request. Please try again.