diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-10-03 19:21:05 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-10-03 19:21:05 +0200 |
commit | a8d3e8341eee6af4c778f512d7f8584c476d49fe (patch) | |
tree | 777681f695f64488c4aa5e869cf937112077befc /pyload/web | |
parent | small bug fixes (diff) | |
download | pyload-a8d3e8341eee6af4c778f512d7f8584c476d49fe.tar.xz |
basically working web setup
Diffstat (limited to 'pyload/web')
-rw-r--r-- | pyload/web/app/scripts/models/Setup.js | 20 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/setup/finishedView.js | 25 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/setup/setupView.js | 52 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/setup/systemView.js | 5 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/setup/userView.js | 39 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/setup/welcomeView.js | 5 | ||||
-rw-r--r-- | pyload/web/app/styles/default/main.less | 1 | ||||
-rw-r--r-- | pyload/web/app/styles/default/setup.less | 0 | ||||
-rw-r--r-- | pyload/web/app/templates/default/setup/error.html | 14 | ||||
-rw-r--r-- | pyload/web/app/templates/default/setup/finished.html | 23 | ||||
-rw-r--r-- | pyload/web/app/templates/default/setup/layout.html | 5 | ||||
-rw-r--r-- | pyload/web/app/templates/default/setup/system.html | 57 | ||||
-rw-r--r-- | pyload/web/app/templates/default/setup/user.html | 34 | ||||
-rw-r--r-- | pyload/web/app/templates/default/setup/welcome.html | 24 | ||||
-rw-r--r-- | pyload/web/pyload_app.py | 6 | ||||
-rw-r--r-- | pyload/web/setup_app.py | 47 |
16 files changed, 327 insertions, 30 deletions
diff --git a/pyload/web/app/scripts/models/Setup.js b/pyload/web/app/scripts/models/Setup.js index 82a2978db..424edf452 100644 --- a/pyload/web/app/scripts/models/Setup.js +++ b/pyload/web/app/scripts/models/Setup.js @@ -4,10 +4,30 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'], return Backbone.Model.extend({ + url: App.apiUrl('setup'), defaults: { lang: 'en', + system: null, + deps: null, user: null, password: null + }, + + fetch: function(options) { + options || (options = {}); + options.url = App.apiUrl('setup'); + return Backbone.Model.prototype.fetch.call(this, options); + }, + + // will get a 409 on success + submit: function(options) { + options || (options = {}); + options.url = App.apiUrl('setup_done'); + options.data = { + user: this.get('user'), + password: this.get('password') + }; + return Backbone.Model.prototype.fetch.call(this, options); } }); diff --git a/pyload/web/app/scripts/views/setup/finishedView.js b/pyload/web/app/scripts/views/setup/finishedView.js new file mode 100644 index 000000000..9f0f8db19 --- /dev/null +++ b/pyload/web/app/scripts/views/setup/finishedView.js @@ -0,0 +1,25 @@ +define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/setup/finished'], + function($, Backbone, _, App, template) { + 'use strict'; + + return Backbone.Marionette.ItemView.extend({ + + name: 'Finished', + template: template, + + events: { + 'click .btn-blue': 'confirm' + }, + + ui: { + }, + + onRender: function() { + }, + + confirm: function() { + this.model.submit(); + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/setup/setupView.js b/pyload/web/app/scripts/views/setup/setupView.js index 7636a0bc2..8ab6fba51 100644 --- a/pyload/web/app/scripts/views/setup/setupView.js +++ b/pyload/web/app/scripts/views/setup/setupView.js @@ -1,6 +1,6 @@ -define(['jquery', 'backbone', 'underscore', 'app', 'models/Setup', 'hbs!tpl/setup/layout', 'hbs!tpl/setup/actionbar', - './welcomeView', './systemView'], - function($, Backbone, _, App, Setup, template, templateBar, welcomeView, systemView) { +define(['jquery', 'backbone', 'underscore', 'app', 'models/Setup', 'hbs!tpl/setup/layout', 'hbs!tpl/setup/actionbar', 'hbs!tpl/setup/error', + './welcomeView', './systemView', './userView', './finishedView'], + function($, Backbone, _, App, Setup, template, templateBar, templateError, welcomeView, systemView, userView, finishedView) { 'use strict'; return Backbone.Marionette.ItemView.extend({ @@ -15,11 +15,14 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/Setup', 'hbs!tpl/setu pages: [ welcomeView, - systemView + systemView, + userView, + finishedView ], page: 0, view: null, + error: null, initialize: function() { var self = this; @@ -52,37 +55,66 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/Setup', 'hbs!tpl/setu }); this.listenTo(this.model, 'page:next', function() { - self.openPage(self.page++); + self.openPage(self.page + 1); }); this.listenTo(this.model, 'page:prev', function() { - self.openPage(self.page--); + self.openPage(self.page - 1); }); + + this.listenTo(this.model, 'error', this.onError); + this.model.fetch(); }, openPage: function(page) { console.log('Change page', page); // check if number is reasonable - if (!_.isNumber(page) || !_.isFinite(page)) + if (!_.isNumber(page) || !_.isFinite(page) || page < 0 || page >= this.pages.length) return; if (page === this.page) return; + // Render error directly + if (this.error) { + this.onRender(); + return; + } + this.page = page; - this.onRender(); + + var self = this; + this.ui.page.fadeOut({complete: function() { + self.onRender(); + }}); this.model.trigger('page:changed', page); }, + onError: function(model, xhr) { + console.log('Setup error', xhr); + this.error = xhr; + this.onRender(); + }, + onRender: function() { + // close old opened view if (this.view) this.view.close(); - // TODO: animation + // Render error if occurred + if (this.error) { + this.ui.page.html(templateError(this.error)); + return; + } + this.view = new this.pages[this.page]({model: this.model}); this.ui.page.empty(); - this.ui.page.append(this.view.render().$el); + + var el = this.view.render().el; + this.ui.page.append(el); + + this.ui.page.fadeIn(); } }); diff --git a/pyload/web/app/scripts/views/setup/systemView.js b/pyload/web/app/scripts/views/setup/systemView.js index 11e50213d..b4c0f7e12 100644 --- a/pyload/web/app/scripts/views/setup/systemView.js +++ b/pyload/web/app/scripts/views/setup/systemView.js @@ -8,12 +8,17 @@ define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/setup/system'], template: template, events: { + 'click .btn-blue': 'nextPage' }, ui: { }, onRender: function() { + }, + + nextPage: function() { + this.model.trigger('page:next'); } }); diff --git a/pyload/web/app/scripts/views/setup/userView.js b/pyload/web/app/scripts/views/setup/userView.js new file mode 100644 index 000000000..95eaa0dc2 --- /dev/null +++ b/pyload/web/app/scripts/views/setup/userView.js @@ -0,0 +1,39 @@ +define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/setup/user'], + function($, Backbone, _, App, template) { + 'use strict'; + + return Backbone.Marionette.ItemView.extend({ + + name: 'User', + template: template, + + events: { + 'click .btn-blue': 'submit' + }, + + ui: { + username: '#username', + password: '#password', + password2: '#password2' + }, + + onRender: function() { + }, + + submit: function() { + var pw = this.ui.password.val(); + var pw2 = this.ui.password2.val(); + + // TODO more checks and error messages + if (pw !== pw2) { + return; + } + + this.model.set('user', this.ui.username.val()); + this.model.set('password', pw); + + this.model.trigger('page:next'); + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/setup/welcomeView.js b/pyload/web/app/scripts/views/setup/welcomeView.js index 4affc9075..a964e0d42 100644 --- a/pyload/web/app/scripts/views/setup/welcomeView.js +++ b/pyload/web/app/scripts/views/setup/welcomeView.js @@ -8,12 +8,17 @@ define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/setup/welcome'], template: template, events: { + 'click .btn-blue': 'nextPage' }, ui: { }, onRender: function() { + }, + + nextPage: function() { + this.model.trigger('page:next'); } }); diff --git a/pyload/web/app/styles/default/main.less b/pyload/web/app/styles/default/main.less index 6bf21e80b..c978a3b90 100644 --- a/pyload/web/app/styles/default/main.less +++ b/pyload/web/app/styles/default/main.less @@ -13,6 +13,7 @@ @import "settings"; @import "accounts"; @import "admin"; +@import "setup"; @ResourcePath: "../.."; @DefaultFont: 'Abel', sans-serif; diff --git a/pyload/web/app/styles/default/setup.less b/pyload/web/app/styles/default/setup.less new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/pyload/web/app/styles/default/setup.less diff --git a/pyload/web/app/templates/default/setup/error.html b/pyload/web/app/templates/default/setup/error.html new file mode 100644 index 000000000..37ce51283 --- /dev/null +++ b/pyload/web/app/templates/default/setup/error.html @@ -0,0 +1,14 @@ +{{#ifEq status 410}} + <h2 class="text-warning">{{ _ "Setup timed out" }}</h2> + <p>{{ _ "Setup was closed due to inactivity. Please restart it to continue configuration." }}</p> +{{else}} +{{#ifEq status 409}} + <h2 class="text-success">{{ _ "Setup finished" }}</h2> + <p>{{ _ "Setup was successful. You can restart pyLoad now." }}</p> +{{else}} + <h2 class="text-error"> + {{ _ "Setup failed" }} + </h2> + <p>{{ _ "Try to restart it or open a bug report." }}</p> +{{/ifEq}} +{{/ifEq}}
\ No newline at end of file diff --git a/pyload/web/app/templates/default/setup/finished.html b/pyload/web/app/templates/default/setup/finished.html new file mode 100644 index 000000000..abe93b352 --- /dev/null +++ b/pyload/web/app/templates/default/setup/finished.html @@ -0,0 +1,23 @@ +{{#if user}} + +<h2> + {{ _ "Nearly Done" }} +</h2> + +<p> + {{ _ "Please check your settings." }} +</p> + +<p> + <strong>Username:</strong> {{user}} +</p> + +<button class="btn btn-large btn-blue"> + {{ _ "Confirm" }} +</button> + +{{else}} + +<h2>{{ _ "Pleae add a user first." }}</h2> + +{{/if}}
\ No newline at end of file diff --git a/pyload/web/app/templates/default/setup/layout.html b/pyload/web/app/templates/default/setup/layout.html index 7b75e53b1..2e986173a 100644 --- a/pyload/web/app/templates/default/setup/layout.html +++ b/pyload/web/app/templates/default/setup/layout.html @@ -3,5 +3,8 @@ {{ _ "Setup" }} </h1> </div> -<div class="span8 setup-page"> +<div class="span8"> + <div class="hero-unit setup-page"> + + </div> </div>
\ No newline at end of file diff --git a/pyload/web/app/templates/default/setup/system.html b/pyload/web/app/templates/default/setup/system.html index 84a217b19..0c5023669 100644 --- a/pyload/web/app/templates/default/setup/system.html +++ b/pyload/web/app/templates/default/setup/system.html @@ -1,5 +1,56 @@ -<h1>{{ _ "System" }} </h1> +<h3>{{ _ "System" }} </h3> -<h2>{{_ "Dependencies" }}</h2> +<dl class="dl-horizontal"> + {{#each system}} + <dt>{{ @key }}</dt> + <dd>{{ this }}</dd> + {{/each}} +</dl> -<h2>{{ _ "Optional" }}</h2>
\ No newline at end of file +<h3>{{_ "Dependencies" }}</h3> +<dl class="dl-horizontal"> + {{#each deps.core}} + <dt>{{ name }}</dt> + <dd> + {{#if avail}} + <span class="text-success"> + <i class="icon-ok"></i> + {{#if v}} + ({{v}}) + {{/if}} + </span> + {{else}} + <span class="text-error"> + <i class="icon-remove"></i> + </span> + {{/if}} + </dd> + {{/each}} +</dl> + + +<h4>{{ _ "Optional" }}</h4> +<dl class="dl-horizontal"> + {{#each deps.opt}} + <dt>{{ name }}</dt> + <dd> + {{#if avail}} + <span class="text-success"> + {{ _ "available" }} + {{#if v}} + ({{v}}) + {{/if}} + </span> + {{else}} + <span class="text-error"> + {{ _ "not available" }} + </span> + {{/if}} + </dd> + {{/each}} +</dl> + + +<button class="btn btn-blue"> + {{ _ "Next" }} +</button>
\ No newline at end of file diff --git a/pyload/web/app/templates/default/setup/user.html b/pyload/web/app/templates/default/setup/user.html new file mode 100644 index 000000000..fe3f2de71 --- /dev/null +++ b/pyload/web/app/templates/default/setup/user.html @@ -0,0 +1,34 @@ +<form class="form-horizontal"> + <div class="control-group"> + <label class="control-label"> + Username + </label> + + <div class="controls"> + <input type="text" id="username" placeholder="User"> + </div> + </div> + <div class="control-group"> + <label class="control-label"> + Password + </label> + + <div class="controls"> + <input type="password" id="password"> + </div> + </div> + <div class="control-group"> + <label class="control-label"> + Password (again) + </label> + + <div class="controls"> + <input type="password" id="password2"> + </div> + </div> + <div class="control-group"> + <div class="controls"> + <a class="btn btn-blue">Submit</a> + </div> + </div> +</form>
\ No newline at end of file diff --git a/pyload/web/app/templates/default/setup/welcome.html b/pyload/web/app/templates/default/setup/welcome.html index f5c5af4d7..5a4f74d9f 100644 --- a/pyload/web/app/templates/default/setup/welcome.html +++ b/pyload/web/app/templates/default/setup/welcome.html @@ -1,16 +1,14 @@ -<div class="hero-unit"> - <h1>{{ _ "Welcome!" }}</h1> +<h1>{{ _ "Welcome!" }}</h1> - <p>{{ _ "pyLoad is running and ready for configuration." }}</p> +<p>{{ _ "pyLoad is running and ready for configuration." }}</p> - <p> - {{ _ "Select your language:" }} - <select> - <option>en</option> - </select> - </p> +<p> + {{ _ "Select your language:" }} + <select> + <option>en</option> + </select> +</p> - <button class="btn btn-large btn-blue"> - {{ _ "Start configuration" }} - </button> -</div>
\ No newline at end of file +<button class="btn btn-large btn-blue"> + {{ _ "Start configuration" }} +</button>
\ No newline at end of file diff --git a/pyload/web/pyload_app.py b/pyload/web/pyload_app.py index 1ec7cf4c9..1c89e2ada 100644 --- a/pyload/web/pyload_app.py +++ b/pyload/web/pyload_app.py @@ -70,7 +70,11 @@ def index(): # set variable depending on setup mode setup = 'false' if SETUP is None else 'true' ws = PYLOAD.getWSAddress() if PYLOAD else False - web = PYLOAD.getConfigValue('webinterface', 'port') if PYLOAD else False + web = None + if PYLOAD: + web = PYLOAD.getConfigValue('webinterface', 'port') + elif SETUP: + web = SETUP.config['webinterface']['port'] # Render variables into the html page if resp.status_code == 200: diff --git a/pyload/web/setup_app.py b/pyload/web/setup_app.py index 5163f9cc6..680c5ae89 100644 --- a/pyload/web/setup_app.py +++ b/pyload/web/setup_app.py @@ -3,26 +3,69 @@ from time import time +from pyload.utils import json_dumps + from bottle import route, request, response, HTTPError, redirect from webinterface import PROJECT_DIR, SETUP from utils import add_json_header +# returns http error +def error(code, msg): + return HTTPError(code, json_dumps(msg), **dict(response.headers)) + + def setup_required(func): def _view(*args, **kwargs): + global timestamp + # setup needs to be running if SETUP is None: - redirect("/nopermission") + return error(404, "Not Found") + + # setup finished + if timestamp == 0: + return error(409, "Done") + + # setup timed out due to inactivity + if timestamp + TIMEOUT * 60 < time(): + return error(410, "Timeout") + + timestamp = time() return func(*args, **kwargs) + return _view # setup will close after inactivity TIMEOUT = 15 timestamp = time() + @route("/setup") @setup_required def setup(): - pass # TODO + add_json_header(response) + + return json_dumps({ + "system": SETUP.check_system(), + "deps": SETUP.check_deps() + }) + + +@route("/setup_done") +@setup_required +def setup_done(): + global timestamp + add_json_header(response) + + SETUP.addUser( + request.params['user'], + request.params['password'] + ) + + # mark setup as finished + timestamp = 0 + + return error(409, "Done") |