From 1bf869f508331b5d80dd3b59c4403d1ce9edaf59 Mon Sep 17 00:00:00 2001 From: Felix Kaechele Date: Sun, 10 Jun 2018 15:16:28 +0200 Subject: [PATCH] Add webassets support Also updates AdminLTE to latest stable version. Signed-off-by: Felix Kaechele --- .gitignore | 3 ++ app/__init__.py | 4 ++ app/assets.py | 67 +++++++++++++++++++++++++++++ app/templates/base.html | 65 +++++----------------------- app/templates/login.html | 22 +++------- app/templates/register.html | 22 +++------- app/views.py | 8 ++-- docker/PowerDNS-Admin/Dockerfile | 1 - docker/PowerDNS-Admin/entrypoint.sh | 10 ++++- requirements.txt | 3 ++ 10 files changed, 112 insertions(+), 93 deletions(-) create mode 100644 app/assets.py diff --git a/.gitignore b/.gitignore index 8901431..d87797c 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,6 @@ tmp/* pdns.db node_modules + +.webassets-cache +app/static/generated diff --git a/app/__init__.py b/app/__init__.py index c309b78..971b424 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -3,10 +3,14 @@ from flask import Flask, request, session, redirect, url_for from flask_login import LoginManager from flask_sqlalchemy import SQLAlchemy +from app.assets import assets + app = Flask(__name__) app.config.from_object('config') app.wsgi_app = ProxyFix(app.wsgi_app) +assets.init_app(app) + #### CONFIGURE LOGGER #### from app.lib.log import logger logging = logger('powerdns-admin', app.config['LOG_LEVEL'], app.config['LOG_FILE']).config() diff --git a/app/assets.py b/app/assets.py new file mode 100644 index 0000000..e6f93b4 --- /dev/null +++ b/app/assets.py @@ -0,0 +1,67 @@ +from flask_assets import Bundle, Environment, Filter + +class ConcatFilter(Filter): + """ + Filter that merges files, placing a semicolon between them. + + Fixes issues caused by missing semicolons at end of JS assets, for example + with last statement of jquery.pjax.js. + """ + def concat(self, out, hunks, **kw): + out.write(';'.join([h.data() for h, info in hunks])) + +css_login = Bundle( + 'node_modules/bootstrap/dist/css/bootstrap.css', + 'node_modules/font-awesome/css/font-awesome.css', + 'node_modules/ionicons/dist/css/ionicons.css', + 'node_modules/icheck/skins/square/blue.css', + 'node_modules/admin-lte/dist/css/AdminLTE.css', + filters=('cssmin','cssrewrite'), + output='generated/login.css' +) + +js_login = Bundle( + 'node_modules/jquery/dist/jquery.js', + 'node_modules/bootstrap/dist/js/bootstrap.js', + 'node_modules/icheck/icheck.js', + filters=(ConcatFilter, 'jsmin'), + output='generated/login.js' +) + +css_main = Bundle( + 'node_modules/bootstrap/dist/css/bootstrap.css', + 'node_modules/font-awesome/css/font-awesome.css', + 'node_modules/ionicons/dist/css/ionicons.css', + 'node_modules/datatables.net-bs/css/dataTables.bootstrap.css', + 'node_modules/icheck/skins/square/blue.css', + 'node_modules/multiselect/css/multi-select.css', + 'node_modules/admin-lte/dist/css/AdminLTE.css', + 'node_modules/admin-lte/dist/css/skins/_all-skins.css', + 'custom/css/custom.css', + filters=('cssmin','cssrewrite'), + output='generated/main.css' +) + +js_main = Bundle( + 'node_modules/jquery/dist/jquery.js', + 'node_modules/jquery-ui-dist/jquery-ui.js', + 'node_modules/bootstrap/dist/js/bootstrap.js', + 'node_modules/datatables.net/js/jquery.dataTables.js', + 'node_modules/datatables.net-bs/js/dataTables.bootstrap.js', + 'node_modules/jquery-sparkline/jquery.sparkline.js', + 'node_modules/jquery-slimscroll/jquery.slimscroll.js', + 'node_modules/icheck/icheck.js', + 'node_modules/fastclick/lib/fastclick.js', + 'node_modules/moment/moment.js', + 'node_modules/admin-lte/dist/js/adminlte.js', + 'node_modules/multiselect/js/jquery.multi-select.js', + 'custom/js/custom.js', + filters=(ConcatFilter, 'jsmin'), + output='generated/main.js' +) + +assets = Environment() +assets.register('js_login', js_login) +assets.register('css_login', css_login) +assets.register('js_main', js_main) +assets.register('css_main', css_main) diff --git a/app/templates/base.html b/app/templates/base.html index 1ba7b56..937666b 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -6,30 +6,13 @@ {% block title %}DNS Control Panel{% endblock %} - - + + - - - - - - - - - - - - - - - - - - - + {% assets "css_main" -%} + + {%- endassets %}