From 8a91e23043147543b528c41817caea1f500a8036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Garc=C3=ADa=20Amor?= Date: Sun, 9 Jul 2017 21:45:59 +0200 Subject: [PATCH] WIP: Add some style to web frontend --- supysonic/frontend/__init__.py | 2 +- supysonic/frontend/folder.py | 8 +- supysonic/frontend/user.py | 16 ++-- supysonic/static/css/supysonic.css | 8 ++ supysonic/templates/addfolder.html | 26 +++++- supysonic/templates/adduser.html | 49 ++++++++-- supysonic/templates/change_mail.html | 19 +++- supysonic/templates/change_pass.html | 35 ++++++- supysonic/templates/folders.html | 41 ++++++--- supysonic/templates/home.html | 27 +----- supysonic/templates/importusers.html | 20 +++- supysonic/templates/layout.html | 37 +++++++- supysonic/templates/profile.html | 131 ++++++++++++++++++--------- supysonic/templates/users.html | 37 ++++++-- 14 files changed, 329 insertions(+), 127 deletions(-) diff --git a/supysonic/frontend/__init__.py b/supysonic/frontend/__init__.py index 1889d97..d5e5778 100644 --- a/supysonic/frontend/__init__.py +++ b/supysonic/frontend/__init__.py @@ -31,7 +31,7 @@ def login_check(): return if request.path.startswith('/static/'): - return + return if request.endpoint != 'login': should_login = False diff --git a/supysonic/frontend/folder.py b/supysonic/frontend/folder.py index 5a40ed1..83983b5 100644 --- a/supysonic/frontend/folder.py +++ b/supysonic/frontend/folder.py @@ -38,12 +38,12 @@ def check_admin(): @app.route('/folder') def folder_index(): - return render_template('folders.html', folders = store.find(Folder, Folder.root == True)) + return render_template('folders.html', folders = store.find(Folder, Folder.root == True), admin = UserManager.get(store, session.get('userid'))[1].admin) @app.route('/folder/add', methods = [ 'GET', 'POST' ]) def add_folder(): if request.method == 'GET': - return render_template('addfolder.html') + return render_template('addfolder.html', admin = UserManager.get(store, session.get('userid'))[1].admin) error = False (name, path) = map(request.form.get, [ 'name', 'path' ]) @@ -54,12 +54,12 @@ def add_folder(): flash('The path is required.') error = True if error: - return render_template('addfolder.html') + return render_template('addfolder.html', admin = UserManager.get(store, session.get('userid'))[1].admin) ret = FolderManager.add(store, name, path) if ret != FolderManager.SUCCESS: flash(FolderManager.error_str(ret)) - return render_template('addfolder.html') + return render_template('addfolder.html', admin = UserManager.get(store, session.get('userid'))[1].admin) flash("Folder '%s' created. You should now run a scan" % name) diff --git a/supysonic/frontend/user.py b/supysonic/frontend/user.py index dfb2213..6c112b6 100644 --- a/supysonic/frontend/user.py +++ b/supysonic/frontend/user.py @@ -37,12 +37,12 @@ def check_admin(): @app.route('/user') def user_index(): - return render_template('users.html', users = store.find(User)) + return render_template('users.html', users = store.find(User), admin = UserManager.get(store, session.get('userid'))[1].admin) @app.route('/user/me') def user_profile(): prefs = store.find(ClientPrefs, ClientPrefs.user_id == uuid.UUID(session.get('userid'))) - return render_template('profile.html', user = UserManager.get(store, session.get('userid'))[1], api_key = config.get('lastfm', 'api_key'), clients = prefs) + return render_template('profile.html', user = UserManager.get(store, session.get('userid'))[1], api_key = config.get('lastfm', 'api_key'), clients = prefs, admin = UserManager.get(store, session.get('userid'))[1].admin) @app.route('/user/me', methods = [ 'POST' ]) def update_clients(): @@ -74,7 +74,7 @@ def change_mail(): store.commit() return redirect(url_for('user_profile')) - return render_template('change_mail.html', user = user) + return render_template('change_mail.html', user = user, admin = UserManager.get(store, session.get('userid'))[1].admin) @app.route('/user/changepass', methods = [ 'GET', 'POST' ]) def change_password(): @@ -99,15 +99,15 @@ def change_password(): flash('Password changed') return redirect(url_for('user_profile')) - return render_template('change_pass.html', user = UserManager.get(store, session.get('userid'))[1].name) + return render_template('change_pass.html', user = UserManager.get(store, session.get('userid'))[1].name, admin = UserManager.get(store, session.get('userid'))[1].admin) @app.route('/user/add', methods = [ 'GET', 'POST' ]) def add_user(): if request.method == 'GET': - return render_template('adduser.html') + return render_template('adduser.html', admin = UserManager.get(store, session.get('userid'))[1].admin) error = False - (name, passwd, passwd_confirm, mail, admin) = map(request.form.get, [ 'name', 'passwd', 'passwd_confirm', 'mail', 'admin' ]) + (name, passwd, passwd_confirm, mail, admin) = map(request.form.get, [ 'user', 'passwd', 'passwd_confirm', 'mail', 'admin' ]) if name in (None, ''): flash('The name is required.') error = True @@ -154,12 +154,12 @@ def export_users(): @app.route('/user/import') def import_users(): - return render_template('importusers.html') + return render_template('importusers.html', admin = UserManager.get(store, session.get('userid'))[1].admin) @app.route('/user/import', methods = [ 'POST' ]) def do_user_import(): if not request.files['file']: - return render_template('importusers.html') + return render_template('importusers.html', admin = UserManager.get(store, session.get('userid'))[1].admin) users = [] reader = csv.reader(request.files['file']) diff --git a/supysonic/static/css/supysonic.css b/supysonic/static/css/supysonic.css index c7a6613..27c5101 100644 --- a/supysonic/static/css/supysonic.css +++ b/supysonic/static/css/supysonic.css @@ -26,6 +26,14 @@ body { margin-bottom: 0px; } +#adduserform label { + margin-bottom: 0; +} + +#clients td { + vertical-align: middle; +} + .page-header { margin-top: 20px; } diff --git a/supysonic/templates/addfolder.html b/supysonic/templates/addfolder.html index e958792..b251670 100644 --- a/supysonic/templates/addfolder.html +++ b/supysonic/templates/addfolder.html @@ -18,10 +18,30 @@ along with this program. If not, see . -#} {% extends "layout.html" %} +{% block navbar_folders %} +
  • Folders (current)
  • +{% endblock %} + {% block body %} +
    -
    -
    - +
    + +
    + + +
    +
    +
    + +
    + + +
    +
    +
    {% endblock %} diff --git a/supysonic/templates/adduser.html b/supysonic/templates/adduser.html index 4cb4e59..e2344de 100644 --- a/supysonic/templates/adduser.html +++ b/supysonic/templates/adduser.html @@ -18,13 +18,48 @@ along with this program. If not, see . -#} {% extends "layout.html" %} +{% block navbar_users %} +
  • Users (current)
  • +{% endblock %} + {% block body %} -
    -
    -
    -
    -
    -
    - + + +
    + +
    + + + + + + +
    +
    +
    + +
    + + +
    +
    +
    + +
    + + +
    +
    +
    + +
    + + +
    +
    +
    {% endblock %} diff --git a/supysonic/templates/change_mail.html b/supysonic/templates/change_mail.html index 63257ed..2bd921c 100644 --- a/supysonic/templates/change_mail.html +++ b/supysonic/templates/change_mail.html @@ -18,11 +18,24 @@ along with this program. If not, see . -#} {% extends "layout.html" %} +{% block navbar_profile %} +
  • {{ session.username }} (current)
  • +{% endblock %} + {% block body %} -

    {{ user.name }}

    + +
    -
    - +
    + +
    + + +
    +
    +
    {% endblock %} diff --git a/supysonic/templates/change_pass.html b/supysonic/templates/change_pass.html index 4951966..4f98988 100644 --- a/supysonic/templates/change_pass.html +++ b/supysonic/templates/change_pass.html @@ -18,13 +18,38 @@ along with this program. If not, see . -#} {% extends "layout.html" %} +{% block navbar_profile %} +
  • {{ session.username }} (current)
  • +{% endblock %} + {% block body %} -

    {{ user }}

    + +
    -
    -
    -
    - +
    + +
    +
    + +
    +
    +
    + +
    +
    + +
    +
    +
    + +
    +
    + +
    +
    +
    {% endblock %} diff --git a/supysonic/templates/folders.html b/supysonic/templates/folders.html index 5fb1c44..a0d60ca 100644 --- a/supysonic/templates/folders.html +++ b/supysonic/templates/folders.html @@ -18,16 +18,33 @@ along with this program. If not, see . -#} {% extends "layout.html" %} -{% block body %} -

    Music folders

    - - - {% for folder in folders %} - - - - - {% endfor %} -
    NamePath
    {{ folder.name }}{{ folder.path }}XScan
    -Add Scan all +{% block navbar_folders %} +
  • Folders (current)
  • +{% endblock %} + +{% block body %} + + + + + + + {% for folder in folders %} + + + + + {% endfor %} + +
    NamePath
    {{ folder.name }}{{ folder.path }} + + +
    + {% endblock %} diff --git a/supysonic/templates/home.html b/supysonic/templates/home.html index cff81d9..5345ab1 100644 --- a/supysonic/templates/home.html +++ b/supysonic/templates/home.html @@ -18,30 +18,9 @@ along with this program. If not, see . -#} {% extends "layout.html" %} -{% block navbar %} - - +{% block navbar_index %} +
  • Home (current)
  • {% endblock %} {% block body %} diff --git a/supysonic/templates/importusers.html b/supysonic/templates/importusers.html index 31a5896..a1fb05a 100644 --- a/supysonic/templates/importusers.html +++ b/supysonic/templates/importusers.html @@ -18,11 +18,23 @@ along with this program. If not, see . -#} {% extends "layout.html" %} +{% block navbar_users %} +
  • Users (current)
  • +{% endblock %} {% block body %} -

    Import users

    -

    Warning: this will overwrite any existing users, even you!

    + +
    - - +
    + + +
    +
    {% endblock %} diff --git a/supysonic/templates/layout.html b/supysonic/templates/layout.html index dae94f4..cc2b428 100644 --- a/supysonic/templates/layout.html +++ b/supysonic/templates/layout.html @@ -55,8 +55,35 @@ {% endif %} Supysonic - {% block navbar %}{% endblock %} - + {% if session.userid %} + + + {% endif %} +
    @@ -86,5 +113,11 @@ + + diff --git a/supysonic/templates/profile.html b/supysonic/templates/profile.html index 0df398a..a1fa35c 100644 --- a/supysonic/templates/profile.html +++ b/supysonic/templates/profile.html @@ -18,53 +18,96 @@ along with this program. If not, see . -#} {% extends "layout.html" %} +{% block navbar_profile %} +
  • {{ session.username }} (current)
  • +{% endblock %} + {% block body %} -

    {{ user.name }}

    -
      - {% if user.admin %}
    • You're an admin!
    • {% endif %} -
    • Email: {{ user.mail }} - Change
    • -
    • - LastFM status: - {% if api_key %} - {% if user.lastfm_session %} - {% if user.lastfm_status %}Linked{% else %}Invalid session{% endif %} - Unlink - {% else %} - Unlinked - Link - {% endif %} - {% else %} - Unavailable - {% endif %} -
    • -
    • Change password
    • -
    + + +
    +
    +
    +
    + +
    +
    User eMail
    + + +
    +
    +
    +
    +
    +
    +
    + +
    +
    LastFM status
    + {% if api_key %} + {% if user.lastfm_session %} + +
    + Unlink +
    + {% else %} + +
    + Link +
    + {% endif %} + {% else %} + + {% endif %} +
    +
    +
    +
    +
    + +Change password {% if clients.count() %} -

    Clients

    -

    Here's a list of clients you used to stream music. If you want to use transcoding or downsampling with one of them (for instance using a low bitrate on - mobile connections to reduce used bandwidth), but the client doesn't provide options to do so, you can set default values here. They'll only be used if no - transcoding/downsampling is requested by the client.

    -
    - - - {% for client in clients %} - - - - - - - {% endfor %} -
    ClientFormatMax bitrateForget
    {{ client.client_name }}
    - -
    + +

    Here's a list of clients you used to stream music. If you want to use +transcoding or downsampling with one of them (for instance using a low +bitrate on mobile connections to reduce used bandwidth), but the client +doesn't provide options to do so, you can set default values here. They'll +only be used if no transcoding/downsampling is requested by the client.

    + +
    + + + + + + {% for client in clients %} + + + + + + + {% endfor %} + +
    ClientFormatMax bitrateForget
    + +
    {% endif %} {% endblock %} diff --git a/supysonic/templates/users.html b/supysonic/templates/users.html index 054e343..6d1fe7a 100644 --- a/supysonic/templates/users.html +++ b/supysonic/templates/users.html @@ -18,14 +18,31 @@ along with this program. If not, see . -#} {% extends "layout.html" %} -{% block body %} -

    Users

    - - - {% for user in users %} - - {% endfor %} -
    NameEMailAdminLast play date
    {{ user.name }}{{ user.mail }}{{ user.admin }}{{ user.last_play_date }}X
    -Add - Export - Import - +{% block navbar_users %} +
  • Users (current)
  • +{% endblock %} + +{% block body %} + + + + + + + {% for user in users %} + + {% endfor %} + +
    NameEMailAdminLast play date
    {{ user.name }}{{ user.mail }}{{ user.admin }}{{ user.last_play_date }} + +
    + + {% endblock %}