From 0cd120f492bd82fae666c88eb0b3154bf7c67cbb Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 30 Nov 2020 20:57:00 +0100 Subject: [PATCH] New template for index panel --- platypush/backend/http/app/routes/index.py | 64 +------- .../backend/http/webapp/src/assets/icons.json | 7 + .../http/webapp/src/components/Nav.vue | 155 ++++++++++++++++++ .../src/components/panels/Light/Index.vue | 78 +++++++++ .../src/components/panels/LightHue/Index.vue | 13 ++ .../webapp/src/components/panels/Panel.vue | 29 ++++ .../backend/http/webapp/src/router/index.js | 7 + .../http/webapp/src/style/themes/light.scss | 12 ++ .../backend/http/webapp/src/views/Panel.vue | 101 ++++++++++++ platypush/plugins/config.py | 19 +++ 10 files changed, 425 insertions(+), 60 deletions(-) create mode 100644 platypush/backend/http/webapp/src/assets/icons.json create mode 100644 platypush/backend/http/webapp/src/components/Nav.vue create mode 100644 platypush/backend/http/webapp/src/components/panels/Light/Index.vue create mode 100644 platypush/backend/http/webapp/src/components/panels/LightHue/Index.vue create mode 100644 platypush/backend/http/webapp/src/components/panels/Panel.vue create mode 100644 platypush/backend/http/webapp/src/views/Panel.vue diff --git a/platypush/backend/http/app/routes/index.py b/platypush/backend/http/app/routes/index.py index f9ee147d3f..9b9a25dd4d 100644 --- a/platypush/backend/http/app/routes/index.py +++ b/platypush/backend/http/app/routes/index.py @@ -1,14 +1,8 @@ -import json -import os - -from flask import Blueprint, render_template, request - -from platypush.backend.http.app import template_folder, static_folder -from platypush.backend.http.app.utils import authenticate, get_websocket_port +from flask import Blueprint, render_template +from platypush.backend.http.app import template_folder +from platypush.backend.http.app.utils import authenticate from platypush.backend.http.utils import HttpUtils -from platypush.config import Config -from platypush.message import Message index = Blueprint('index', __name__, template_folder=template_folder) @@ -22,57 +16,7 @@ __routes__ = [ @authenticate() def index(): """ Route to the main web panel """ - configured_plugins = Config.get_plugins() - enabled_templates = {} - enabled_scripts = {} - enabled_styles = {} - - enabled_plugins = set(request.args.get('enabled_plugins', '').split(',')) - for plugin in enabled_plugins: - if plugin not in configured_plugins: - configured_plugins[plugin] = {} - - configured_plugins['execute'] = {} - disabled_plugins = set(request.args.get('disabled_plugins', '').split(',')) - - js_folder = os.path.abspath( - os.path.join(template_folder, '..', 'static', 'js')) - style_folder = os.path.abspath( - os.path.join(template_folder, '..', 'static', 'css', 'dist')) - - for plugin, conf in configured_plugins.copy().items(): - if plugin in disabled_plugins: - if plugin == 'execute': - configured_plugins.pop('execute') - continue - - template_file = os.path.join( - template_folder, 'plugins', plugin, 'index.html') - - script_file = os.path.join(js_folder, 'plugins', plugin, 'index.js') - style_file = os.path.join(style_folder, 'webpanel', 'plugins', plugin+'.css') - - if os.path.isfile(template_file): - conf['_template_file'] = '/' + '/'.join(template_file.split(os.sep)[-3:]) - enabled_templates[plugin] = conf - - if os.path.isfile(script_file): - conf['_script_file'] = '/'.join(script_file.split(os.sep)[-4:]) - enabled_scripts[plugin] = conf - - if os.path.isfile(style_file): - conf['_style_file'] = 'css/dist/' + style_file[len(style_folder)+1:] - enabled_styles[plugin] = conf - - http_conf = Config.get('backend.http') - return render_template('index.html', templates=enabled_templates, - scripts=enabled_scripts, styles=enabled_styles, - utils=HttpUtils, token=Config.get('token'), - websocket_port=get_websocket_port(), - template_folder=template_folder, static_folder=static_folder, - plugins=Config.get_plugins(), backends=Config.get_backends(), - procedures=json.dumps(Config.get_procedures(), cls=Message.Encoder), - has_ssl=http_conf.get('ssl_cert') is not None) + return render_template('index.html', utils=HttpUtils) # vim:sw=4:ts=4:et: diff --git a/platypush/backend/http/webapp/src/assets/icons.json b/platypush/backend/http/webapp/src/assets/icons.json new file mode 100644 index 0000000000..91b2349118 --- /dev/null +++ b/platypush/backend/http/webapp/src/assets/icons.json @@ -0,0 +1,7 @@ +{ + "icons": { + "light.hue": { + "class": "fas fa-lightbulb" + } + } +} \ No newline at end of file diff --git a/platypush/backend/http/webapp/src/components/Nav.vue b/platypush/backend/http/webapp/src/components/Nav.vue new file mode 100644 index 0000000000..58ead89fa0 --- /dev/null +++ b/platypush/backend/http/webapp/src/components/Nav.vue @@ -0,0 +1,155 @@ + + + + + + diff --git a/platypush/backend/http/webapp/src/components/panels/Light/Index.vue b/platypush/backend/http/webapp/src/components/panels/Light/Index.vue new file mode 100644 index 0000000000..801fa2d570 --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Light/Index.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/platypush/backend/http/webapp/src/components/panels/LightHue/Index.vue b/platypush/backend/http/webapp/src/components/panels/LightHue/Index.vue new file mode 100644 index 0000000000..0d605dcca3 --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/LightHue/Index.vue @@ -0,0 +1,13 @@ + + + diff --git a/platypush/backend/http/webapp/src/components/panels/Panel.vue b/platypush/backend/http/webapp/src/components/panels/Panel.vue new file mode 100644 index 0000000000..8ff3b49a79 --- /dev/null +++ b/platypush/backend/http/webapp/src/components/panels/Panel.vue @@ -0,0 +1,29 @@ + diff --git a/platypush/backend/http/webapp/src/router/index.js b/platypush/backend/http/webapp/src/router/index.js index 8dcec38a53..129bde3e95 100644 --- a/platypush/backend/http/webapp/src/router/index.js +++ b/platypush/backend/http/webapp/src/router/index.js @@ -3,8 +3,15 @@ import Dashboard from "@/views/Dashboard.vue"; import NotFound from "@/views/NotFound"; import Login from "@/views/Login"; import Register from "@/views/Register"; +import Panel from "@/views/Panel"; const routes = [ + { + path: "/", + name: "Panel", + component: Panel, + }, + { path: "/dashboard/:name", name: "Dashboard", diff --git a/platypush/backend/http/webapp/src/style/themes/light.scss b/platypush/backend/http/webapp/src/style/themes/light.scss index 00262769e8..d58999735f 100644 --- a/platypush/backend/http/webapp/src/style/themes/light.scss +++ b/platypush/backend/http/webapp/src/style/themes/light.scss @@ -55,3 +55,15 @@ $active-glow-bg-2: #9cdfb0 !default; $default-hover-fg: #35b870 !default; $default-hover-fg-2: #38cf80 !default; $hover-bg: #def6ea !default; + +/// Navigator +$nav-bg: #002626 !default; +$nav-fg: #e8f8e8 !default; +$nav-entry-selected-bg: #205046 !default; +$nav-entry-hover-bg: #104036 !default; +$nav-entry-collapsed-selected-bg: rgba(160, 245, 178, 0.95) !default; +$nav-entry-collapsed-hover-bg: rgba(160, 245, 178, 0.60) !default; +$nav-box-shadow-main: 1px 0 2px #002626; +$nav-box-shadow-entry: 0 0 1px 1px #103824 !default; +$nav-box-shadow-collapsed: 1px 0 2px 1px #bbb !default; +$nav-collapsed-fg: #5e5e5e; diff --git a/platypush/backend/http/webapp/src/views/Panel.vue b/platypush/backend/http/webapp/src/views/Panel.vue new file mode 100644 index 0000000000..0dae45a6ee --- /dev/null +++ b/platypush/backend/http/webapp/src/views/Panel.vue @@ -0,0 +1,101 @@ + + + + + + + diff --git a/platypush/plugins/config.py b/platypush/plugins/config.py index 72eda41ba9..f8cf7558c6 100644 --- a/platypush/plugins/config.py +++ b/platypush/plugins/config.py @@ -1,4 +1,7 @@ +import json + from platypush import Config +from platypush.message import Message from platypush.plugins import Plugin, action @@ -7,6 +10,18 @@ class ConfigPlugin(Plugin): def get(self) -> dict: return Config.get() + @action + def get_plugins(self) -> dict: + return Config.get_plugins() + + @action + def get_backends(self) -> dict: + return Config.get_backends() + + @action + def get_procedures(self) -> dict: + return json.loads(json.dumps(Config.get_procedures(), cls=Message.Encoder)) + @action def dashboards(self) -> dict: return Config.get_dashboards() @@ -15,5 +30,9 @@ class ConfigPlugin(Plugin): def get_dashboard(self, name: str) -> str: return Config.get_dashboard(name) + @action + def get_device_id(self) -> str: + return Config.get('device_id') + # vim:sw=4:ts=4:et: