diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-08-18 17:01:17 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-08-18 17:01:17 +0200 |
commit | 9a6ea22616cf3cc67e292c908521b79764400faf (patch) | |
tree | 1924843f28d992490d867d0557da90dfb1da6404 /pyload/web | |
parent | fixed login (diff) | |
download | pyload-9a6ea22616cf3cc67e292c908521b79764400faf.tar.xz |
new linkgrabber
Diffstat (limited to 'pyload/web')
19 files changed, 379 insertions, 110 deletions
diff --git a/pyload/web/app/scripts/collections/LinkList.js b/pyload/web/app/scripts/collections/LinkList.js new file mode 100644 index 000000000..170a2c039 --- /dev/null +++ b/pyload/web/app/scripts/collections/LinkList.js @@ -0,0 +1,14 @@ +define(['jquery', 'backbone', 'underscore', 'models/LinkStatus'], function($, Backbone, _, LinkStatus) { + 'use strict'; + + return Backbone.Collection.extend({ + + model: LinkStatus, + + comparator: function(link) { + return link.get('name'); + } + + }); + +});
\ No newline at end of file diff --git a/pyload/web/app/scripts/config.js b/pyload/web/app/scripts/config.js index ff4082ce4..51ea63285 100644 --- a/pyload/web/app/scripts/config.js +++ b/pyload/web/app/scripts/config.js @@ -59,8 +59,10 @@ require.config({ deps: ['underscore', 'jquery'], exports: 'Backbone' }, - - marionette: ['backbone'], + marionette: { + deps: ['backbone'], + exports: 'Backbone' + }, handlebars: { exports: 'Handlebars' }, diff --git a/pyload/web/app/scripts/helpers/linkStatus.js b/pyload/web/app/scripts/helpers/linkStatus.js new file mode 100644 index 000000000..2497785fb --- /dev/null +++ b/pyload/web/app/scripts/helpers/linkStatus.js @@ -0,0 +1,18 @@ +define('helpers/linkStatus', ['underscore', 'handlebars', 'utils/apitypes', 'utils/i18n'], + function(_, Handlebars, Api, i18n) { + 'use strict'; + function linkStatus(status) { + var s; + if (status === Api.DownloadStatus.Online) + s = '<span class="text-success">' + i18n.gettext('online') + '</span>'; + else if (status === Api.DownloadState.Offline) + s = '<span class="text-error">' + i18n.gettext('offline') + '</span>'; + else + s = '<span class="text-info">' + i18n.gettext('unknown') + '</span>'; + + return new Handlebars.SafeString(s); + } + + Handlebars.registerHelper('linkStatus', linkStatus); + return linkStatus; + }); diff --git a/pyload/web/app/scripts/models/CollectorPackage.js b/pyload/web/app/scripts/models/CollectorPackage.js new file mode 100644 index 000000000..293342440 --- /dev/null +++ b/pyload/web/app/scripts/models/CollectorPackage.js @@ -0,0 +1,77 @@ +define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'collections/LinkList'], + function($, Backbone, _, App, Api, LinkList) { + 'use strict'; + return Backbone.Model.extend({ + + idAttribute: 'name', + defaults: { + name: 'Unnamed package', + new_name: null, + links: null + }, + + initialize: function() { + this.set('links', new LinkList()); + }, + + destroy: function() { + // Copied from backbones destroy method + var model = this; + model.trigger('destroy', model, model.collection); + }, + + // get the actual name + getName: function() { + var new_name = this.get('new_name'); + if (new_name) + return new_name; + + return this.get('name'); + + }, + // Add the package to pyload + add: function() { + var self = this; + var links = this.get('links').pluck('url'); + + $.ajax(App.apiRequest('addPackage', + {name: this.getName(), + links: links}, + {success: function() { + self.destroy(); + App.vent.trigger('package:added'); + }})); + + }, + + updateLinks: function(links) { + this.get('links').set(links, {remove: false}); + this.trigger('change'); + }, + + toJSON: function() { + var data = { + name: this.getName(), + links: this.get('links').toJSON() + }; + var links = this.get('links'); + data.length = links.length; + data.online = 0; + data.offline = 0; + data.unknown = 0; + + // Summary + links.each(function(link) { + if (link.get('status') === Api.DownloadStatus.Online) + data.online++; + else if (link.get('status') === Api.DownloadStatus.Offline) + data.offline++; + else + data.unknown++; + }); + + return data; + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/models/LinkStatus.js b/pyload/web/app/scripts/models/LinkStatus.js new file mode 100644 index 000000000..2be1ce368 --- /dev/null +++ b/pyload/web/app/scripts/models/LinkStatus.js @@ -0,0 +1,22 @@ +define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], + function($, Backbone, _, App, Api) { + 'use strict'; + + return Backbone.Model.extend({ + + idAttribute: 'url', + + defaults: { + name: '', + plugin: '', + size: -1, + status: Api.DownloadStatus.Queued + }, + + destroy: function() { + var model = this; + model.trigger('destroy', model, model.collection); + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/abstract/modalView.js b/pyload/web/app/scripts/views/abstract/modalView.js index b6d9f0eab..61016a9fb 100644 --- a/pyload/web/app/scripts/views/abstract/modalView.js +++ b/pyload/web/app/scripts/views/abstract/modalView.js @@ -117,10 +117,14 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, }, destroy: function() { + this.onDestroy(); this.$el.remove(); this.dialog = null; this.remove(); - } + }, + onDestroy: function() { + + } }); });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/headerView.js b/pyload/web/app/scripts/views/headerView.js index 3fdfe32ba..60a47ad62 100644 --- a/pyload/web/app/scripts/views/headerView.js +++ b/pyload/web/app/scripts/views/headerView.js @@ -172,7 +172,7 @@ define(['jquery', 'underscore', 'backbone', 'app', 'models/ServerStatus', 'colle open_grabber: function() { var self = this; - _.requireOnce(['views/linkGrabberModal'], function(ModalView) { + _.requireOnce(['views/linkgrabber/modalView'], function(ModalView) { if (self.grabber === null) self.grabber = new ModalView(); diff --git a/pyload/web/app/scripts/views/linkGrabberModal.js b/pyload/web/app/scripts/views/linkGrabberModal.js deleted file mode 100644 index e6f59c134..000000000 --- a/pyload/web/app/scripts/views/linkGrabberModal.js +++ /dev/null @@ -1,49 +0,0 @@ -define(['jquery', 'underscore', 'app', 'views/abstract/modalView', 'hbs!tpl/dialogs/linkgrabber'], - function($, _, App, modalView, template) { - 'use strict'; - // Modal dialog for package adding - triggers package:added when package was added - return modalView.extend({ - - events: { - 'click .btn-success': 'addPackage', - 'keypress #inputPackageName': 'addOnEnter' - }, - - template: template, - - initialize: function() { - // Inherit parent events - this.events = _.extend({}, modalView.prototype.events, this.events); - }, - - addOnEnter: function(e) { - if (e.keyCode !== 13) return; - this.addPackage(e); - }, - - addPackage: function(e) { - var self = this; - var options = App.apiRequest('addPackage', - { - name: $('#inputPackageName').val(), - // TODO: better parsing / tokenization - links: $('#inputLinks').val().split('\n') - }, - { - success: function() { - App.vent.trigger('package:added'); - self.hide(); - } - }); - - $.ajax(options); - $('#inputPackageName').val(''); - $('#inputLinks').val(''); - }, - - onShow: function() { - this.$('#inputPackageName').focus(); - } - - }); - });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/linkgrabber/collectorView.js b/pyload/web/app/scripts/views/linkgrabber/collectorView.js new file mode 100644 index 000000000..d2b43f699 --- /dev/null +++ b/pyload/web/app/scripts/views/linkgrabber/collectorView.js @@ -0,0 +1,21 @@ +define(['jquery', 'underscore', 'backbone', 'app', './packageView'], + function($, _, Backbone, App, packageView) { + 'use strict'; + return Backbone.Marionette.CollectionView.extend({ + itemView: packageView, + updateData: function(result) { + var self = this; + _.each(result.data, function(links, name) { + var pack = self.collection.get(name); + if (!pack) { + pack = new self.collection.model({name: name}); + self.collection.add(pack); + } + + // TODO: remove links from all other packages than pack + pack.updateLinks(links); + }); + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/linkgrabber/modalView.js b/pyload/web/app/scripts/views/linkgrabber/modalView.js new file mode 100644 index 000000000..6e4781ac2 --- /dev/null +++ b/pyload/web/app/scripts/views/linkgrabber/modalView.js @@ -0,0 +1,61 @@ +define(['jquery', 'underscore', 'backbone', 'app', 'models/CollectorPackage', 'views/abstract/modalView', './collectorView', 'hbs!tpl/linkgrabber/modal'], + function($, _, Backbone, App, CollectorPackage, modalView, CollectorView, template) { + 'use strict'; + // Modal dialog for package adding - triggers package:added when package was added + return modalView.extend({ + + events: { + 'keypress #inputLinks': 'addOnEnter' + }, + + template: template, + + // Holds the view that display the packages + collectorView: null, + + initialize: function() { + // Inherit parent events + this.events = _.extend({}, modalView.prototype.events, this.events); + }, + + addOnEnter: function(e) { + if (e.keyCode !== 13) return; + this.addPackage(e); + }, + + addPackage: function(e) { + var self = this; + // split, trim and remove empty links + var links = _.filter(_.map(this.$('#inputLinks').val().split('\n'), function(link) { + return $.trim(link); + }), function(link) { + return link.length > 0; + }); + + var options = App.apiRequest('checkLinks', + {links: links}, + { + success: function(data) { + self.collectorView.updateData(data); + } + }); + + $.ajax(options); + this.$('#inputLinks').val(''); + }, + + onRender: function() { + // anonymous collection + this.collectorView = new CollectorView({collection: new (Backbone.Collection.extend({ + model: CollectorPackage + }))()}); + this.collectorView.setElement(this.$('.prepared-packages')); + }, + + onDestroy: function() { + if (this.collectorView) + this.collectorView.close(); + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/linkgrabber/packageView.js b/pyload/web/app/scripts/views/linkgrabber/packageView.js new file mode 100644 index 000000000..97d00f722 --- /dev/null +++ b/pyload/web/app/scripts/views/linkgrabber/packageView.js @@ -0,0 +1,58 @@ +define(['jquery', 'underscore', 'backbone', 'app', 'hbs!tpl/linkgrabber/package'], + function($, _, Backbone, App, template) { + 'use strict'; + return Backbone.Marionette.ItemView.extend({ + + tagName: 'div', + className: 'row-fluid package', + template: template, + + modelEvents: { + change: 'render' + }, + + ui: { + 'table': 'table' + }, + + events: { + 'click .btn-expand': 'expand', + 'click .btn-add': 'addPackage', + 'click .btn-delete': 'deletePackage', + 'click .btn-mini': 'deleteLink' + }, + + expanded: false, + + serializeData: function() { + var data = this.model.toJSON(); + data.expanded = this.expanded; + return data; + }, + + addPackage: function() { + this.model.add(); + }, + + deletePackage: function() { + this.model.destroy(); + }, + + deleteLink: function(e) { + var el = $(e.target); + var id = parseInt(el.data('index'), 10); + + var model = this.model.get('links').at(id); + if (model) + model.destroy(); + + this.render(); + }, + + expand: function() { + this.expanded ^= true; + this.ui.table.toggle(); + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/styles/default/linkgrabber.less b/pyload/web/app/styles/default/linkgrabber.less new file mode 100644 index 000000000..364c9c420 --- /dev/null +++ b/pyload/web/app/styles/default/linkgrabber.less @@ -0,0 +1,18 @@ +.prepared-packages { + hr { + margin: 0; + } + + .package > .btn { + margin-bottom: 3px; + } + + img { + height: 22px; + } + + .table { + margin-bottom: 0; + } + +}
\ No newline at end of file diff --git a/pyload/web/app/styles/default/main.less b/pyload/web/app/styles/default/main.less index 0bfa4fe2f..6bf21e80b 100644 --- a/pyload/web/app/styles/default/main.less +++ b/pyload/web/app/styles/default/main.less @@ -8,6 +8,7 @@ @import "pyload-common/styles/basic-layout"; @import "style"; +@import "linkgrabber"; @import "dashboard"; @import "settings"; @import "accounts"; diff --git a/pyload/web/app/templates/default/dialogs/linkgrabber.html b/pyload/web/app/templates/default/dialogs/linkgrabber.html deleted file mode 100755 index 8d90131ac..000000000 --- a/pyload/web/app/templates/default/dialogs/linkgrabber.html +++ /dev/null @@ -1,49 +0,0 @@ -<div class="modal-header"> - <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> - <h3> - AddPackage - <small>paste&add links to pyLoad</small> - </h3> -</div> - -<div class="modal-body"> - <div class="alert alert-error hidden"> - Upload files container failed. Please try again. - </div> - <form class="form-horizontal"> - <div class="control-group"> - <label class="control-label" for="inputPackageName">Package name</label> - - <div class="controls"> - <input type="text" class="span4" id="inputPackageName" placeholder="Name of your package"> - </div> - </div> - <div class="control-group"> - <label class="control-label" for="inputLinks">Links</label> - - <div class="controls"> - <textarea id="inputLinks" class="span4" rows="10" placeholder="Paste your links here..."></textarea> - </div> - </div> - <div class="control-group"> - <label class="control-label" for="inputPassword">Password</label> - - <div class="controls"> - <input type="text" id="inputPassword" class="span4" placeholder="Password for .rar files"> - </div> - </div> - <div class="control-group"> - <label class="control-label" for="inputContainer">Upload links container</label> - - <div class="controls controls-row"> - <input type="text" id="inputContainer" class="span3" placeholder="Path to your container"> - <button id="inputContainer-btn" class="btn span1" type="button">Browse…</button> - </div> - </div> - </form> -</div> - -<div class="modal-footer"> - <a class="btn btn-success"><i class="icon-plus icon-white"></i> {{_ "Add"}}</a> - <a class="btn btn-close">{{_ "Close"}}</a> -</div>
\ No newline at end of file diff --git a/pyload/web/app/templates/default/linkgrabber/modal.html b/pyload/web/app/templates/default/linkgrabber/modal.html new file mode 100755 index 000000000..67e2e4fe3 --- /dev/null +++ b/pyload/web/app/templates/default/linkgrabber/modal.html @@ -0,0 +1,41 @@ +<div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> + <h3> + {{_ "Add links" }} + <small>{{_ "paste & add links to pyLoad" }}</small> + </h3> +</div> + +<div class="modal-body"> + <div class="alert alert-error hidden"> + {{_ "Upload files container failed. Please try again." }} + </div> + <form class="form-horizontal"> + <div class="control-group"> + <label class="control-label" for="inputLinks">{{ _ "Links" }}</label> + + <div class="controls"> + <textarea id="inputLinks" class="span4" rows="2" placeholder="{{_ " Paste your links here..."}}"></textarea> + </div> + </div> + <div class="control-group"> + <label class="control-label" for="inputContainer">{{_ "Upload container file" }}</label> + <div class="controls controls-row"> + <input type="text" id="inputContainer" class="span3" readonly> + <button id="inputContainer-btn" class="btn span1" type="button">{{_ "Browse" }}…</button> + </div> + </div> + + <legend> + {{_ "Packages" }} + </legend> + <div class="container-fluid prepared-packages"> + + </div> + </form> +</div> + +<div class="modal-footer"> + <!--<a class="btn btn-success"><i class="icon-plus icon-white"></i> {{_ "Add"}}</a>--> + <a class="btn btn-close">{{_ "Close"}}</a> +</div>
\ No newline at end of file diff --git a/pyload/web/app/templates/default/linkgrabber/package.html b/pyload/web/app/templates/default/linkgrabber/package.html new file mode 100644 index 000000000..54f6f4ad1 --- /dev/null +++ b/pyload/web/app/templates/default/linkgrabber/package.html @@ -0,0 +1,30 @@ +<strong>{{ name }}</strong> - <button class="btn btn-small btn-blue btn-expand"><i class="icon-arrow-down"></i> </button> <button class="btn btn-small btn-success btn-add"><i class="icon-plus"></i> </button> <button class="btn btn-small btn-danger btn-delete"><i class="icon-trash"></i> </button> <br> +<table class="table table-condensed" {{#unless expanded}}style="display: none"{{/unless}}> + <tbody> + {{#each links}} + <tr> + <td>{{ name }}</td> + <td><img src="{{ pluginIcon plugin }}"> {{ plugin }}</td> + <td>{{ linkStatus status }}</td> + <td><button class="btn btn-danger btn-mini" data-index={{@index}}><i class="icon-trash"></i></button></td> + </tr> + {{/each}} + </tbody> +</table> +<hr> +{{ ngettext "%d link" "%d links" length }}: +{{#if online}} +<span class="text-success"> + {{ online }} {{_ "online" }} +</span> +{{/if}} +{{#if offline}} +<span class="text-error"> + {{ offline }} {{_ "offline" }} +</span> +{{/if}} +{{#if unknown}} +<span class="text-info"> + {{ unknown }} {{_ "unknown" }} +</span> +{{/if}} diff --git a/pyload/web/app/templates/default/settings/actionbar.html b/pyload/web/app/templates/default/settings/actionbar.html index 25b10d463..647d0af99 100644 --- a/pyload/web/app/templates/default/settings/actionbar.html +++ b/pyload/web/app/templates/default/settings/actionbar.html @@ -1,5 +1,5 @@ -<div class="span2 offset1"> -</div> -<span class="span9"> - <button class="btn btn-small btn-blue btn-add">Add Plugin</button> -</span>
\ No newline at end of file +<ul class="actionbar nav span8 offset3"> + <li> + <button class="btn btn-small btn-blue btn-add">Add Plugin</button> + </li> +</ul>
\ No newline at end of file diff --git a/pyload/web/app/templates/default/settings/layout.html b/pyload/web/app/templates/default/settings/layout.html index 39f1a2ec9..143d0caad 100644 --- a/pyload/web/app/templates/default/settings/layout.html +++ b/pyload/web/app/templates/default/settings/layout.html @@ -1,8 +1,8 @@ -<div class="span2"> +<div class="span3"> <ul class="nav nav-list well settings-menu"> </ul> </div> -<div class="span10"> +<div class="span9"> <div class="well setting-box"> <form class="form-horizontal" action="#"> <h1>Please choose a config section</h1> diff --git a/pyload/web/bower.json b/pyload/web/bower.json index 1d12378a0..b0176a891 100644 --- a/pyload/web/bower.json +++ b/pyload/web/bower.json @@ -13,7 +13,7 @@ "flot": "~0.8.1", "underscore": "~1.4.4", "backbone": "~1.0.0", - "backbone.marionette": "~1.0.3", + "backbone.marionette": "~1.1.0", "handlebars.js": "1.0.0-rc.3", "jed": "~0.5.4", "select2": "~3.4.0", |