diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-08-11 20:36:10 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-08-11 20:36:10 +0200 |
commit | 080643e89af62013d70bb574cd54cf4876628515 (patch) | |
tree | e79e3bebe9175da613c4a339fc4ac3fa172ecced /pyload | |
parent | another try to fix broken accounts (diff) | |
download | pyload-080643e89af62013d70bb574cd54cf4876628515.tar.xz |
improved account list
Diffstat (limited to 'pyload')
20 files changed, 234 insertions, 39 deletions
diff --git a/pyload/api/AccountApi.py b/pyload/api/AccountApi.py index 144074d3c..d4b39c12b 100644 --- a/pyload/api/AccountApi.py +++ b/pyload/api/AccountApi.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from pyload.utils import to_bool from pyload.Api import Api, RequirePerm, Permission, Conflict from ApiComponent import ApiComponent @@ -49,13 +50,21 @@ class AccountApi(ApiComponent): :return: newly created or updated account info """ + # TODO: None pointer return self.core.accountManager.updateAccount(plugin, loginname, password, self.user).toInfoData() @RequirePerm(Permission.Accounts) def updateAccountInfo(self, account): """ Update account settings from :class:`AccountInfo` """ - #TODO + inst = self.core.accountManager.getAccount(account.plugin, account.loginname, self.user) + if not account: + return + + inst.activated = to_bool(account.activated) + inst.shared = to_bool(account.shared) + inst.updateConfig(account.config) + @RequirePerm(Permission.Accounts) def removeAccount(self, account): diff --git a/pyload/plugins/addons/MultiHoster.py b/pyload/plugins/addons/MultiHoster.py index 446dfe922..21529eb1a 100644 --- a/pyload/plugins/addons/MultiHoster.py +++ b/pyload/plugins/addons/MultiHoster.py @@ -81,9 +81,9 @@ class MultiHoster(Addon): self.addHoster(account) @AddEventListener("account:updated") - def refreshAccount(self, plugin, loginname): + def refreshAccount(self, acc): - account = self.core.accountManager.getAccount(plugin, loginname) + account = self.core.accountManager.getAccount(acc.plugin, acc.loginname) if isinstance(account, MultiHosterAccount) and account.isUsable(): self.addHoster(account) diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py index 5d59b9cbf..bc4e27df4 100644 --- a/pyload/utils/__init__.py +++ b/pyload/utils/__init__.py @@ -212,7 +212,7 @@ def to_string(value): return str(value) if not isinstance(value, basestring) else value def to_bool(value): - if not isinstance(value, basestring): return value + if not isinstance(value, basestring): return True if value else False return True if value.lower() in ("1", "true", "on", "an", "yes") else False def to_int(string, default=0): diff --git a/pyload/web/app/scripts/config.js b/pyload/web/app/scripts/config.js index 9d1d027d9..ff4082ce4 100644 --- a/pyload/web/app/scripts/config.js +++ b/pyload/web/app/scripts/config.js @@ -19,6 +19,7 @@ require.config({ marionette: '../components/backbone.marionette/lib/backbone.marionette', handlebars: '../components/handlebars.js/dist/handlebars', jed: '../components/jed/jed', + moment: '../components/momentjs/moment', // TODO: Two hbs dependencies could be replaced i18nprecompile: '../components/require-handlebars-plugin/hbs/i18nprecompile', diff --git a/pyload/web/app/scripts/helpers/fileHelper.js b/pyload/web/app/scripts/helpers/fileHelper.js index 044887eea..2e14f939f 100644 --- a/pyload/web/app/scripts/helpers/fileHelper.js +++ b/pyload/web/app/scripts/helpers/fileHelper.js @@ -1,5 +1,5 @@ // Helpers to render the file view -define('helpers/fileHelper', ['handlebars', 'utils/apitypes', 'helpers/formatTime'], +define('helpers/fileHelper', ['handlebars', 'utils/apitypes', 'helpers/formatTimeLeft'], function(Handlebars, Api, formatTime) { 'use strict'; diff --git a/pyload/web/app/scripts/helpers/formatSize.js b/pyload/web/app/scripts/helpers/formatSize.js index 926c4793d..f72d62158 100644 --- a/pyload/web/app/scripts/helpers/formatSize.js +++ b/pyload/web/app/scripts/helpers/formatSize.js @@ -1,14 +1,14 @@ // Format bytes in human readable format -define('helpers/formatSize', ['handlebars', './gettext'], function(Handlebars, gettext) { +define('helpers/formatSize', ['handlebars', 'utils/i18n'], function(Handlebars, i18n) { 'use strict'; var sizes = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB']; function formatSize(bytes, options) { if (!bytes || bytes === 0) return '0 B'; if (bytes === -1) - return gettext('not available'); + return i18n.gettext('not available'); if (bytes === -2) - return gettext('unlimited'); + return i18n.gettext('unlimited'); var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10); // round to two digits diff --git a/pyload/web/app/scripts/helpers/formatTime.js b/pyload/web/app/scripts/helpers/formatTime.js index 757ff73ad..0fb0f6058 100644 --- a/pyload/web/app/scripts/helpers/formatTime.js +++ b/pyload/web/app/scripts/helpers/formatTime.js @@ -1,15 +1,18 @@ -// Format bytes in human readable format -define('helpers/formatTime', ['handlebars', 'vendor/remaining'], function(Handlebars, Remaining) { +// Formats a timestamp +define('helpers/formatTime', ['underscore','handlebars', 'moment', 'utils/i18n'], + function(_, Handlebars, moment, i18n) { 'use strict'; - function formatTime(seconds, options) { - if (seconds === Infinity) - return '∞'; - else if (!seconds || seconds <= 0) - return '-'; + function formatTime(time, format) { + if (time === -1) + return i18n.gettext('unkown'); + else if (time === -2) + return i18n.gettext('unlimited'); - // TODO: digital or written string - return Remaining.getStringDigital(seconds, window.dates); + if (!_.isString(format)) + format = 'lll'; + + return moment(time).format(format); } Handlebars.registerHelper('formatTime', formatTime); diff --git a/pyload/web/app/scripts/helpers/formatTimeLeft.js b/pyload/web/app/scripts/helpers/formatTimeLeft.js new file mode 100644 index 000000000..dafeda3e2 --- /dev/null +++ b/pyload/web/app/scripts/helpers/formatTimeLeft.js @@ -0,0 +1,17 @@ +// Format seconds in human readable format +define('helpers/formatTimeLeft', ['handlebars', 'vendor/remaining'], function(Handlebars, Remaining) { + 'use strict'; + + function formatTimeLeft(seconds, options) { + if (seconds === Infinity) + return '∞'; + else if (!seconds || seconds <= 0) + return '-'; + + // TODO: digital or written string + return Remaining.getStringDigital(seconds, window.dates); + } + + Handlebars.registerHelper('formatTimeLeft', formatTimeLeft); + return formatTimeLeft; +});
\ No newline at end of file diff --git a/pyload/web/app/scripts/models/Account.js b/pyload/web/app/scripts/models/Account.js index 9cfc1c0c1..e2cc4f9ec 100644 --- a/pyload/web/app/scripts/models/Account.js +++ b/pyload/web/app/scripts/models/Account.js @@ -5,7 +5,7 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], function($ // TODO // generated, not submitted - idAttribute: 'user', + idAttribute: 'loginname', defaults: { plugin: null, @@ -30,8 +30,31 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], function($ }, - save: function(options) { - options = App.apiRequest('updateAccountInfo', {account: this.toJSON()}, options); + fetch: function(options) { + var refresh = _.has(options, 'refresh') && options.refresh; + options = App.apiRequest('getAccountInfo', + {plugin: this.get('plugin'), + loginname: this.get('loginname'), refresh: refresh}, options); + + return Backbone.Model.prototype.fetch.call(this, options); + }, + + setPassword: function(password, options) { + options = App.apiRequest('updateAccount', + {plugin: this.get('plugin'), loginname: this.get('loginname'), password: password}, options); + + return $.ajax(options); + }, + + save: function() { + // On success wait 1sec and trigger event to reload info + var options = App.apiRequest('updateAccountInfo', {account: this.toJSON()}, { + success: function() { + _.delay(function() { + App.vent.trigger('accounts:updated'); + }, 1000); + } + }); return $.ajax(options); }, diff --git a/pyload/web/app/scripts/views/abstract/modalView.js b/pyload/web/app/scripts/views/abstract/modalView.js index 65bc0a3c8..b6d9f0eab 100644 --- a/pyload/web/app/scripts/views/abstract/modalView.js +++ b/pyload/web/app/scripts/views/abstract/modalView.js @@ -83,6 +83,8 @@ define(['jquery', 'backbone', 'underscore', 'omniwindow'], function($, Backbone, }, renderContent: function() { + if (this.model) + return this.model.toJSON(); return {}; }, diff --git a/pyload/web/app/scripts/views/accounts/accountEdit.js b/pyload/web/app/scripts/views/accounts/accountEdit.js new file mode 100644 index 000000000..b9109390b --- /dev/null +++ b/pyload/web/app/scripts/views/accounts/accountEdit.js @@ -0,0 +1,37 @@ +define(['jquery', 'underscore', 'app', 'views/abstract/modalView', 'hbs!tpl/accounts/editAccount'], + function($, _, App, modalView, template) { + 'use strict'; + return modalView.extend({ + + events: { + 'click .btn-save': 'save', + 'submit form': 'save' + }, + + template: template, + + initialize: function() { + // Inherit parent events + this.events = _.extend({}, modalView.prototype.events, this.events); + }, + + onRender: function() { + }, + + save: function() { + var password = this.$('#password').val(); + if (password !== '') { + this.model.setPassword(password); + } + + this.hide(); + return false; + }, + + onShow: function() { + }, + + onHide: function() { + } + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/accounts/accountView.js b/pyload/web/app/scripts/views/accounts/accountView.js index 7d1f04315..123327a27 100644 --- a/pyload/web/app/scripts/views/accounts/accountView.js +++ b/pyload/web/app/scripts/views/accounts/accountView.js @@ -9,10 +9,39 @@ define(['jquery', 'underscore', 'backbone', 'app', 'hbs!tpl/accounts/account'], template: template, events: { - 'click .btn-danger': 'deleteAccount' + 'click .btn-success': 'toggle', + 'click .btn-blue': 'edit', + 'click .btn-yellow': 'refresh', + 'click .btn-danger': 'remove' }, - deleteAccount: function() { + modelEvents: { + 'change': 'render' + }, + + modal: null, + + toggle: function() { + this.model.set('activated', !this.model.get('activated')); + this.model.save(); + }, + + edit: function() { + // TODO: clean the modal on view close + var self = this; + _.requireOnce(['views/accounts/accountEdit'], function(Modal) { + if (self.modal === null) + self.modal = new Modal({model: self.model}); + + self.modal.show(); + }); + }, + + refresh: function() { + this.model.fetch({refresh: true}); + }, + + remove: function() { this.model.destroy(); } }); diff --git a/pyload/web/app/scripts/views/dashboard/fileView.js b/pyload/web/app/scripts/views/dashboard/fileView.js index ce91a5f38..ed2d2ea40 100644 --- a/pyload/web/app/scripts/views/dashboard/fileView.js +++ b/pyload/web/app/scripts/views/dashboard/fileView.js @@ -1,4 +1,4 @@ -define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'views/abstract/itemView', 'helpers/formatTime', 'hbs!tpl/dashboard/file'], +define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes', 'views/abstract/itemView', 'helpers/formatTimeLeft', 'hbs!tpl/dashboard/file'], function($, Backbone, _, App, Api, ItemView, formatTime, template) { 'use strict'; diff --git a/pyload/web/app/styles/default/accounts.less b/pyload/web/app/styles/default/accounts.less index e0c7342c1..3891d8e45 100644 --- a/pyload/web/app/styles/default/accounts.less +++ b/pyload/web/app/styles/default/accounts.less @@ -1,10 +1,19 @@ @import "common"; .account-list { - img { - width: 26px; - height: 26px; + + .account-type { + background-size: 32px 32px; + background-repeat: no-repeat; + background-position: left; + padding-left: 40px; + font-weight: bold; + } + + .account-name { + padding-top: 8px; } + } .logo-select { diff --git a/pyload/web/app/templates/default/accounts/account.html b/pyload/web/app/templates/default/accounts/account.html index 3b3875a3e..7039eae8c 100644 --- a/pyload/web/app/templates/default/accounts/account.html +++ b/pyload/web/app/templates/default/accounts/account.html @@ -1,15 +1,41 @@ -<div class="span3"> - <img src="{{ pluginIcon plugin }}"> {{ plugin }} +<div class="span3 account-type" style="background-image: url({{ pluginIcon plugin }})"> + {{ plugin }} <br> + {{#if valid }} + <span class="text-success"> + {{#if premium}} + {{_ "premium"}} + {{else}} + {{_ "valid" }} + {{/if}} + </span> + {{else}} + <span class="text-error"> + {{_ "invalid" }} + </span> + {{/if}} </div> -<div class="span3"> - {{ loginname }} +<div class="span2 account-name"> + {{ loginname }} + {{# if shared}} + TODO: shared + {{/if}} </div> -<div class="span3"> - {{ premium }} +<div class="span2 account-data"> + {{_ "Traffic left:"}}<br> {{ formatSize trafficleft }} - {{ shared }} - {{ activated }} +</div> +<div class="span2 account-data"> + {{_ "Valid until:"}}<br> + {{ formatTime validuntil }} </div> <div class="span3"> - <button type="button" class="btn btn-danger"><i class="icon-trash"></i></button> + {{#if activated }} + <button type="button" class="btn btn-success"><i class="icon-check"></i></button> + {{else}} + <button type="button" class="btn btn-success"><i class="icon-check-empty"></i></button> + {{/if}} + + <button type="button" class="btn btn-blue"><i class="icon-pencil"></i></button> + <button type="button" class="btn btn-yellow"><i class="icon-refresh"></i></button> + <button type="button" class="btn btn-danger"><i class="icon-trash"></i></button> </div>
\ No newline at end of file diff --git a/pyload/web/app/templates/default/accounts/editAccount.html b/pyload/web/app/templates/default/accounts/editAccount.html new file mode 100755 index 000000000..212f11e12 --- /dev/null +++ b/pyload/web/app/templates/default/accounts/editAccount.html @@ -0,0 +1,38 @@ +<div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> + <h3>{{_ "Edit account" }}</h3> +</div> +<div class="modal-body"> + <form class="form-horizontal" autocomplete="off"> + <div class="control-group"> + <label class="control-label" for="pluginSelect"> + Account + </label> + + <div class="controls"> + <img src="{{ pluginIcon plugin }}"> + {{ loginname }} + </div> + </div> + <div class="control-group"> + <label class="control-label" for="password"> + Password + </label> + + <div class="controls"> + <input type="password" id="password"> + </div> + </div> + {{#if options }} + <legend> + Options + </legend> + {{/if}} + <div class="account-options"> + </div> + </form> +</div> +<div class="modal-footer"> + <a class="btn btn-success btn-save">Save</a> + <a class="btn btn-close">Close</a> +</div>
\ No newline at end of file diff --git a/pyload/web/app/templates/default/accounts/layout.html b/pyload/web/app/templates/default/accounts/layout.html index bd8256659..6bb1a221f 100644 --- a/pyload/web/app/templates/default/accounts/layout.html +++ b/pyload/web/app/templates/default/accounts/layout.html @@ -3,7 +3,7 @@ {{ _ "Accounts" }} </h1> </div> -<div class="span9"> +<div class="span8"> <div class="container-fluid account-list"> </div> diff --git a/pyload/web/app/templates/default/header/progressStatus.html b/pyload/web/app/templates/default/header/progressStatus.html index 020ed2e96..2ee3719a5 100644 --- a/pyload/web/app/templates/default/header/progressStatus.html +++ b/pyload/web/app/templates/default/header/progressStatus.html @@ -4,5 +4,5 @@ {{ statusmsg }} {{/if}} <span class="pull-right"> - {{ formatTime eta }} + {{ formatTimeLeft eta }} </span>
\ No newline at end of file diff --git a/pyload/web/app/templates/default/header/progressSub.html b/pyload/web/app/templates/default/header/progressSub.html index 3400ee011..a3337e9bb 100644 --- a/pyload/web/app/templates/default/header/progressSub.html +++ b/pyload/web/app/templates/default/header/progressSub.html @@ -2,5 +2,5 @@ {{ linksqueue }} downloads left ({{ formatSize sizequeue }}) {{/if}} <span class="pull-right"> - {{ formatTime etaqueue }} + {{ formatTimeLeft etaqueue }} </span>
\ No newline at end of file diff --git a/pyload/web/bower.json b/pyload/web/bower.json index dfabc05d6..1d12378a0 100644 --- a/pyload/web/bower.json +++ b/pyload/web/bower.json @@ -16,7 +16,8 @@ "backbone.marionette": "~1.0.3", "handlebars.js": "1.0.0-rc.3", "jed": "~0.5.4", - "select2": "~3.4.0" + "select2": "~3.4.0", + "momentjs": "~2.1.0" }, "devDependencies": {} } |