Added /plugin/<plugin_name> route for single plugin view (see #83)

This commit is contained in:
Fabio Manganiello 2020-01-23 00:27:36 +01:00
parent 8255f9af28
commit eff21c0720
2 changed files with 117 additions and 0 deletions

View file

@ -0,0 +1,54 @@
import os
from flask import Blueprint, render_template
from platypush.backend.http.app import template_folder, static_folder
from platypush.backend.http.app.utils import authenticate, get_websocket_port
from platypush.backend.http.utils import HttpUtils
from platypush.config import Config
panel = Blueprint('plugin', __name__, template_folder=template_folder)
# Declare routes list
__routes__ = [
panel,
]
@panel.route('/plugin/<plugin>', methods=['GET'])
@authenticate()
def plugin_route(plugin):
""" Route to the plugin pane template """
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'))
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')
conf = Config.get(plugin) or {}
if os.path.isfile(template_file):
conf['_template_file'] = '/' + '/'.join(template_file.split(os.sep)[-3:])
if os.path.isfile(script_file):
conf['_script_file'] = '/'.join(script_file.split(os.sep)[-4:])
if os.path.isfile(style_file):
conf['_style_file'] = 'css/dist/' + style_file[len(style_folder)+1:]
http_conf = Config.get('backend.http')
return render_template('plugin.html',
plugin=plugin,
conf=conf,
template=conf.get('_template_file', {}),
script=conf.get('_script_file', {}),
style=conf.get('_style_file', {}),
utils=HttpUtils,
token=Config.get('token'),
websocket_port=get_websocket_port(),
template_folder=template_folder,
static_folder=static_folder,
has_ssl=http_conf.get('ssl_cert') is not None)
# vim:sw=4:ts=4:et:

View file

@ -0,0 +1,63 @@
<!doctype html>
<head>
<title>{{ plugin }}</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
{% include 'css-common.html' %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/dist/webpanel.css') }}">
<script type="text/javascript">
if (!window.config) {
window.config = {};
}
window.config = { ...window.config,
websocket_port: {{ websocket_port }},
has_ssl: {{ 'true' if has_ssl else 'false' }},
};
{% if token %}
window.config.token = '{{ token }}';
{% else %}
window.config.token = undefined;
{% endif %}
</script>
{% include 'js-common.html' %}
<script type="text/javascript" src="{{ url_for('static', filename='js/autocomplete.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename=style) }}">
<style>
#app main {
height: 100vh;
}
</style>
{% include 'elements.html' %}
{% with configuration=conf %}
{% include template %}
{% endwith %}
<script type="text/javascript" src="{{ url_for('static', filename=script) }}"></script>
</head>
<body>
<div id="app">
<main>
<div class="plugins-container">
<plugin :tag="'{{ plugin }}'.replace(/\./g, '-')"
:config='{{ utils.to_json(conf) }}'>
</plugin>
</div>
</main>
{% include 'notifications.html' %}
</div>
{% include 'plugins/template.html' %}
<script type="text/javascript" src="{{ url_for('static', filename='js/application.js') }}"></script>
</body>