diff options
Diffstat (limited to 'module/web/static/js')
-rw-r--r-- | module/web/static/js/models/File.js | 7 | ||||
-rw-r--r-- | module/web/static/js/models/ServerStatus.js | 81 | ||||
-rw-r--r-- | module/web/static/js/views/dashboardView.js | 19 | ||||
-rw-r--r-- | module/web/static/js/views/headerView.js | 19 | ||||
-rw-r--r-- | module/web/static/js/views/linkGrabberModal.js | 3 |
5 files changed, 79 insertions, 50 deletions
diff --git a/module/web/static/js/models/File.js b/module/web/static/js/models/File.js index fa0945713..2ac6c05f5 100644 --- a/module/web/static/js/models/File.js +++ b/module/web/static/js/models/File.js @@ -31,6 +31,13 @@ define(['jquery', 'backbone', 'underscore', 'utils/apitypes'], function($, Backb }, + fetch: function(options){ + options || (options = {}); + options.url = 'api/getFileInfo/' + this.get('fid'); + + return Backbone.Model.prototype.fetch.call(this, options); + }, + destroy: function(options) { options || (options = {}); // TODO: as post data diff --git a/module/web/static/js/models/ServerStatus.js b/module/web/static/js/models/ServerStatus.js index 2430a9ffd..9242bdf95 100644 --- a/module/web/static/js/models/ServerStatus.js +++ b/module/web/static/js/models/ServerStatus.js @@ -1,47 +1,46 @@ define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) { - return Backbone.Model.extend({ + return Backbone.Model.extend({ + + defaults: { + speed: 0, + linkstotal: 0, + linksqueue: 0, + sizetotal: 0, + sizequeue: 0, + notifications: -1, + paused: false, + download: false, + reconnect: false + }, + + // Model Constructor + initialize: function() { + + }, + + fetch: function() { + options || (options = {}); + options.url = 'api/getServerStatus'; + + return Backbone.Model.prototype.fetch.call(this, options); + }, + + toJSON: function(options) { + var obj = Backbone.Model.prototype.toJSON.call(this, options); + + obj.linksdone = obj.linkstotal - obj.linksqueue; + obj.sizedone = obj.sizetotal - obj.sizequeue; + if (obj.speed && obj.speed > 0) + obj.eta = Math.round(obj.sizequeue / obj.speed); + else if (obj.sizequeue > 0) + obj.eta = Infinity; + else + obj.eta = 0; - defaults: { - speed: 0, - files: null, - notifications: -1, - paused: false, - download: false, - reconnect: false - }, - - // Model Constructor - initialize: function() { - - }, - - fetch: function() { - options || (options = {}); - options.url = 'api/getServerStatus'; - - return Backbone.Model.prototype.fetch.call(this, options); - }, - - toJSON: function(options) { - var obj = Backbone.Model.prototype.toJSON.call(this, options); - - // stats are not available - if (obj.files === null) return obj; + } - obj.files.linksleft = obj.files.linkstotal - obj.files.linksdone; - obj.files.sizeleft = obj.files.sizetotal - obj.files.sizedone; - if (obj.speed && obj.speed > 0) - obj.files.eta = Math.round(obj.files.sizeleft / obj.speed); - else if (obj.files.sizeleft > 0) - obj.files.eta = Infinity; - else - obj.files.eta = 0; - - return obj; - } - - }); -});
\ No newline at end of file + }); + });
\ No newline at end of file diff --git a/module/web/static/js/views/dashboardView.js b/module/web/static/js/views/dashboardView.js index d9ff1c5fc..58a50777c 100644 --- a/module/web/static/js/views/dashboardView.js +++ b/module/web/static/js/views/dashboardView.js @@ -35,7 +35,11 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', self.tree.fetch(); }); - // TODO file:added + App.vent.on('file:updated', _.bind(this.fileUpdated, this)); + + // TODO: file:added + // TODO: package:deleted + // TODO: package:updated }, init: function() { @@ -48,7 +52,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', self.tree.get('packages').on('add', function(pack) { console.log('Package ' + pack.get('pid') + ' added to tree'); self.appendPackage(pack, 0, true); - + self.openPackage(pack); }); }}); @@ -144,6 +148,17 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection', //TODO: show placeholder when nothing is displayed (filtered content empty) this.fileUL.fadeIn(); App.vent.trigger('dashboard:updated'); + }, + + // Refresh the file if it is currently shown + fileUpdated: function(data) { + // this works with ids and object + var file = this.files.get(data); + if (file) + if (_.isObject(data)) // update directly + file.set(data); + else // fetch from server + file.fetch(); } }); });
\ No newline at end of file diff --git a/module/web/static/js/views/headerView.js b/module/web/static/js/views/headerView.js index c22f173c4..35df06003 100644 --- a/module/web/static/js/views/headerView.js +++ b/module/web/static/js/views/headerView.js @@ -12,6 +12,7 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ServerStatus', 'flot' }, templateStatus: _.compile($('#template-header-status').html()), + templateProgress: _.compile($('#template-header-progress').html()), // Will hold the link grabber grabber: null, @@ -100,11 +101,15 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ServerStatus', 'flot' }, render: function() { -// console.log('Render header'); + // TODO: what should be displayed in the header + // queue/processing size? this.$('.status-block').html( this.templateStatus(this.status.toJSON()) ); + + // TODO: render progress + this.$('.progress-list'); }, toggle_taskList: function() { @@ -132,10 +137,10 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ServerStatus', 'flot' if (data['@class'] === "ServerStatus") { this.status.set(data); } - else if (data['@class'] === 'progress') + else if (_.isArray(data)) this.onProgressUpdate(data); - else if (data['@class'] === 'event') - this.onEvent(data); + else if (data['@class'] === 'EventInfo') + this.onEvent(data.eventname, data.event_args); else console.log('Unknown Async input'); @@ -145,8 +150,10 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ServerStatus', 'flot' }, - onEvent: function(event) { - + onEvent: function(event, args) { + args.unshift(event); + console.log('Core send event', args); + App.vent.trigger.apply(App.vent, args); } }); diff --git a/module/web/static/js/views/linkGrabberModal.js b/module/web/static/js/views/linkGrabberModal.js index ea11aa339..9f7a5882d 100644 --- a/module/web/static/js/views/linkGrabberModal.js +++ b/module/web/static/js/views/linkGrabberModal.js @@ -30,7 +30,8 @@ define(['jquery', 'underscore', 'app', 'views/abstract/modalView', 'text!tpl/def type: 'POST', data: { name: JSON.stringify($('#inputPackageName').val()), - links: JSON.stringify(['http://download.pyload.org/random.bin', 'invalid link', 'invalid link 2', 'invalid link 3', 'inavlid link 4', + links: JSON.stringify(['http://download.pyload.org/random.bin', 'http://download.pyload.org/random100.bin', + 'invalid link', 'invalid link 2', 'invalid link 3', 'inavlid link 4', 'http://download.pyload.org/random.bin', 'http://download.pyload.org/random.bin', 'http://download.pyload.org/random.bin', 'A really really long invalid url that should exceed length of most of the urls by far and split into two lines']) }, |