From 131a49030e2e0758df3dbc94096bad41d1e4243d Mon Sep 17 00:00:00 2001 From: Ross Mountjoy Date: Wed, 12 Feb 2020 18:17:23 -0500 Subject: [PATCH] added list view, and possibly some bugs ;) --- dashmachine/main/read_config.py | 33 +++---- dashmachine/main/routes.py | 19 +++- dashmachine/main/utils.py | 8 -- dashmachine/settings_system/models.py | 1 + dashmachine/static/css/global/dashmachine.css | 2 +- dashmachine/static/css/main/home.css | 34 +++++++ .../static/css/settings_system/settings.css | 4 +- dashmachine/static/js/main/home.js | 1 + dashmachine/templates/main/home.html | 67 ++++---------- dashmachine/templates/main/layout.html | 9 +- dashmachine/templates/main/macros.html | 92 +++++++++++++++++++ .../templates/settings_system/settings.html | 34 +++---- dashmachine/version.py | 2 +- migrations/versions/ff5eb645bfe4_.py | 28 ++++++ run.py | 9 ++ 15 files changed, 237 insertions(+), 106 deletions(-) create mode 100644 dashmachine/templates/main/macros.html create mode 100644 migrations/versions/ff5eb645bfe4_.py diff --git a/dashmachine/main/read_config.py b/dashmachine/main/read_config.py index 6d9c4dd..84296f3 100644 --- a/dashmachine/main/read_config.py +++ b/dashmachine/main/read_config.py @@ -36,20 +36,12 @@ def read_config(): # Settings creation if section == "Settings": settings = Settings() - if "theme" in config["Settings"]: - settings.theme = config["Settings"]["theme"] - else: - settings.theme = "light" - if "accent" in config["Settings"]: - settings.accent = config["Settings"]["accent"] - else: - settings.accent = "orange" + settings.theme = config["Settings"].get("theme", "light") - if "background" in config["Settings"]: - settings.background = config["Settings"]["background"] - else: - settings.background = "None" + settings.accent = config["Settings"].get("accent", "orange") + + settings.background = config["Settings"].get("background", "None") if "roles" in config["Settings"]: settings.roles = config["Settings"]["roles"] @@ -62,17 +54,14 @@ def read_config(): else: settings.roles = "admin,user,public_user" - if "home_access_groups" in config["Settings"]: - settings.home_access_groups = config["Settings"]["home_access_groups"] - else: - settings.home_access_groups = "admin_only" + settings.home_access_groups = config["Settings"].get( + "home_access_groups", "admin_only" + ) - if "settings_access_groups" in config["Settings"]: - settings.settings_access_groups = config["Settings"][ - "settings_access_groups" - ] - else: - settings.settings_access_groups = "admin_only" + settings.settings_access_groups = config["Settings"].get( + "settings_access_groups", "admin_only" + ) + settings.home_view_mode = config["Settings"].get("home_view_mode", "grid") db.session.add(settings) db.session.commit() diff --git a/dashmachine/main/routes.py b/dashmachine/main/routes.py index dc12a50..16c5939 100755 --- a/dashmachine/main/routes.py +++ b/dashmachine/main/routes.py @@ -2,6 +2,7 @@ import os import glob from secrets import token_hex from htmlmin.main import minify +from configparser import ConfigParser from flask import render_template, url_for, redirect, request, Blueprint, jsonify from flask_login import current_user from dashmachine.main.models import Files, Apps, DataSources, Tags @@ -12,7 +13,7 @@ from dashmachine.main.utils import ( get_data_source, ) from dashmachine.settings_system.models import Settings -from dashmachine.paths import cache_folder +from dashmachine.paths import cache_folder, user_data_folder from dashmachine import app, db @@ -57,7 +58,7 @@ def check_valid_login(): # ------------------------------------------------------------------------------ @public_route @main.route("/") -@main.route("/home", methods=["GET", "POST"]) +@main.route("/home", methods=["GET"]) def home(): tags_form = TagsForm() tags_form.tags.choices += [ @@ -88,6 +89,20 @@ def load_data_source(): return data +@public_route +@main.route("/change_home_view_mode?", methods=["GET"]) +def change_home_view_mode(mode): + config = ConfigParser() + config.read(os.path.join(user_data_folder, "config.ini")) + config.set("Settings", "home_view_mode", mode) + config.write(open(os.path.join(user_data_folder, "config.ini"), "w")) + settings = Settings.query.first() + settings.home_view_mode = mode + db.session.merge(settings) + db.session.commit() + return redirect(url_for("main.home")) + + # ------------------------------------------------------------------------------ # TCDROP routes # ------------------------------------------------------------------------------ diff --git a/dashmachine/main/utils.py b/dashmachine/main/utils.py index b4d23ba..29ec71c 100755 --- a/dashmachine/main/utils.py +++ b/dashmachine/main/utils.py @@ -56,14 +56,6 @@ def public_route(decorated_function): def dashmachine_init(): db.create_all() db.session.commit() - migrate_cmd = "python " + os.path.join(root_folder, "manage_db.py db stamp head") - subprocess.run(migrate_cmd, stderr=subprocess.PIPE, shell=True, encoding="utf-8") - - migrate_cmd = "python " + os.path.join(root_folder, "manage_db.py db migrate") - subprocess.run(migrate_cmd, stderr=subprocess.PIPE, shell=True, encoding="utf-8") - - upgrade_cmd = "python " + os.path.join(root_folder, "manage_db.py db upgrade") - subprocess.run(upgrade_cmd, stderr=subprocess.PIPE, shell=True, encoding="utf-8") read_template_apps() user_data_folder = os.path.join(dashmachine_folder, "user_data") diff --git a/dashmachine/settings_system/models.py b/dashmachine/settings_system/models.py index bc2c7e7..b686a3d 100644 --- a/dashmachine/settings_system/models.py +++ b/dashmachine/settings_system/models.py @@ -9,3 +9,4 @@ class Settings(db.Model): roles = db.Column(db.String()) home_access_groups = db.Column(db.String()) settings_access_groups = db.Column(db.String()) + home_view_mode = db.Column(db.String()) diff --git a/dashmachine/static/css/global/dashmachine.css b/dashmachine/static/css/global/dashmachine.css index 8112c42..7eb485b 100644 --- a/dashmachine/static/css/global/dashmachine.css +++ b/dashmachine/static/css/global/dashmachine.css @@ -620,7 +620,7 @@ input:disabled { .sidenav { background-color: var(--theme-surface); top: unset; - overflow: scroll; + overflow-y: scroll; scrollbar-width: none; } diff --git a/dashmachine/static/css/main/home.css b/dashmachine/static/css/main/home.css index 65d2e61..97ad099 100644 --- a/dashmachine/static/css/main/home.css +++ b/dashmachine/static/css/main/home.css @@ -20,4 +20,38 @@ width: calc(100vw - 45px) !important; margin-left: 15px !important; } +} + +#list-view-collection .app-a { + background: rgba(var(--theme-surface-rgb), 0.8); +} +#list-view-collection .app-a:hover { + background: var(--theme-surface-1); +} +#list-view-collection .app-name { + font-size: 1.3rem; + position: relative; + margin-left: 1rem; + bottom: 2px; +} +#list-view-collection .app-description { + margin-left: .4rem; +} +#list-view-collection .app-icon { + height: 24px; + position: relative; + top: 4px; +} +#list-view-collection { + border: 0; +} +#list-view-collection .data-source-container { + position: relative; + top: 6px; +} +#list-view-collection .material-icons-outlined { + font-size: 1.2rem; + position: relative; + margin-left: .5rem; + top: 1px; } \ No newline at end of file diff --git a/dashmachine/static/css/settings_system/settings.css b/dashmachine/static/css/settings_system/settings.css index c2451c3..eb92ad7 100644 --- a/dashmachine/static/css/settings_system/settings.css +++ b/dashmachine/static/css/settings_system/settings.css @@ -18,8 +18,8 @@ min-height: calc(100vh - 142px) !important; } .settings-page-card-left { - max-height: calc(100vh - 30px); - min-height: calc(100vh - 30px); + max-height: calc(100vh - 130px) !important; + min-height: calc(100vh - 130px) !important; } #apps .dropdown-content { diff --git a/dashmachine/static/js/main/home.js b/dashmachine/static/js/main/home.js index 664916b..22d1c5a 100644 --- a/dashmachine/static/js/main/home.js +++ b/dashmachine/static/js/main/home.js @@ -3,6 +3,7 @@ d.className += " active theme-primary"; $( document ).ready(function() { + $(".tooltipped").tooltip(); $("#apps-filter").on('keyup', function(e) { var value = $(this).val().toLowerCase(); $(".app-a").each(function(i, e) { diff --git a/dashmachine/templates/main/home.html b/dashmachine/templates/main/home.html index 0b4595a..4d82aea 100644 --- a/dashmachine/templates/main/home.html +++ b/dashmachine/templates/main/home.html @@ -1,5 +1,6 @@ {% extends "main/layout.html" %} {% from 'global_macros.html' import data, preload_circle, select %} +{% from 'main/macros.html' import GridViewApp, ListViewApp %} {% block page_vendor_css %} {% endblock page_vendor_css %} @@ -26,6 +27,18 @@ search + + {% if current_user.role == "admin" %} + {% if settings.home_view_mode == "list" %} + + apps + + {% else %} + + list + + {% endif %} + {% endif %} {% if tags_form.tags.choices|count > 1 %} @@ -37,54 +50,14 @@
{% if apps %} - {% for app in apps %} - {% if app.open_in == 'iframe' %} - - {% elif app.open_in == 'this_tab' %} - - {% elif app.open_in == "new_tab" %} - - {% endif %} -
-
-
- {% if app.data_sources.count() > 0 %} -
-
- -
+ {% if settings.home_view_mode == "list" %} + {{ ListViewApp(apps) }} + {% else %} + {% for app in apps %} + {{ GridViewApp(app) }} + {% endfor %} + {% endif %} -
- {{ preload_circle() }} - {% for data_source in app.data_sources %} -

-

- {% endfor %} -
-
- {% else %} - - {% endif %} -
-
-
{{ app.name }} -
- {% if app.description %} - {{ app.description }} - {% else %} - - {% endif %} -
-
-
-
- {% endfor %} {% else %}
diff --git a/dashmachine/templates/main/layout.html b/dashmachine/templates/main/layout.html index 82f187e..b8f7656 100644 --- a/dashmachine/templates/main/layout.html +++ b/dashmachine/templates/main/layout.html @@ -1,4 +1,5 @@ {% extends "main/base.html" %} +{% from 'main/macros.html' import AppAnchor %} {% block header %} @@ -43,13 +44,7 @@ {% for app in apps %}
  • - {% if app.open_in == 'iframe' %} - - {% elif app.open_in == "this_tab" %} - - {% elif app.open_in == "new_tab" %} - - {% endif %} + {{ AppAnchor(app) }} {{ app.name }}
  • diff --git a/dashmachine/templates/main/macros.html b/dashmachine/templates/main/macros.html new file mode 100644 index 0000000..bb8f615 --- /dev/null +++ b/dashmachine/templates/main/macros.html @@ -0,0 +1,92 @@ +{% from 'global_macros.html' import preload_circle %} + +{% macro AppAnchor(app, classes=None) %} + {% if app.open_in == 'iframe' %} + + {% elif app.open_in == 'this_tab' %} + + {% elif app.open_in == "new_tab" %} + + {% endif %} +{% endmacro %} + +{% macro GridViewApp(app) %} + {{ AppAnchor(app) }} +
    +
    +
    + {% if app.data_sources.count() > 0 %} +
    +
    + +
    + +
    + {{ preload_circle() }} + {% for data_source in app.data_sources %} +

    +

    + {% endfor %} +
    +
    + {% else %} + + {% endif %} +
    +
    +
    {{ app.name }} +
    + {% if app.description %} + {{ app.description }} + {% else %} + + {% endif %} +
    +
    +
    +
    + {# This closes AppAnchor() #} +{% endmacro %} + +{% macro ListViewApp(apps) %} +
    +
    + {% for app in apps %} + {{ AppAnchor(app, classes="collection-item") }} +
    +
    + + {{ app.name }} + {% if app.description %} + info + {% endif %} +
    +
    + {% if app.data_sources.count() > 0 %} + {{ preload_circle() }} + {% for data_source in app.data_sources %} + + + {% endfor %} + {% endif %} +
    +
    + + {# This closes AppAnchor() #} + {% endfor %} +
    +
    +{% endmacro %} \ No newline at end of file diff --git a/dashmachine/templates/settings_system/settings.html b/dashmachine/templates/settings_system/settings.html index e1b0139..f7fdbc7 100644 --- a/dashmachine/templates/settings_system/settings.html +++ b/dashmachine/templates/settings_system/settings.html @@ -26,31 +26,33 @@
    -
    +
    -
    -
    -
    Config.ini
    +
    +
    + + Config.ini {{ button( icon="save", id="save-config-btn", - float="left", + float="right", class="ml-0 mt-1 mb-1", data={'url': url_for('settings_system.save_config')}, text="save" ) }} -
    - -
    -
    - {{ input( - size="s12", - class="materialize-textarea code", - form_obj=config_form.config, - id="config-textarea" - ) }} -
    +
    +
    +
    +
    +
    + {{ input( + size="s12", + class="materialize-textarea code", + form_obj=config_form.config, + id="config-textarea" + ) }} +
    diff --git a/dashmachine/version.py b/dashmachine/version.py index 280f0eb..c02c186 100755 --- a/dashmachine/version.py +++ b/dashmachine/version.py @@ -1 +1 @@ -version = "v0.32" +version = "v0.33" diff --git a/migrations/versions/ff5eb645bfe4_.py b/migrations/versions/ff5eb645bfe4_.py new file mode 100644 index 0000000..631360c --- /dev/null +++ b/migrations/versions/ff5eb645bfe4_.py @@ -0,0 +1,28 @@ +"""empty message + +Revision ID: ff5eb645bfe4 +Revises: 885c5f9b33d5 +Create Date: 2020-02-12 16:09:39.133644 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "ff5eb645bfe4" +down_revision = "885c5f9b33d5" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column("settings", sa.Column("home_view_mode", sa.String(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("settings", "home_view_mode") + # ### end Alembic commands ### diff --git a/run.py b/run.py index ae40883..3e03f26 100755 --- a/run.py +++ b/run.py @@ -1,5 +1,14 @@ #!/usr/bin/env python3 +import os +from dashmachine.paths import root_folder + +os.system("python " + os.path.join(root_folder, "manage_db.py db stamp head")) + +os.system("python " + os.path.join(root_folder, "manage_db.py db migrate")) + +os.system("python " + os.path.join(root_folder, "manage_db.py db upgrade")) + from dashmachine import app from dashmachine.main.utils import dashmachine_init