From 13ae9090e023f1a372cbb0b3b54fcb72a2e4d844 Mon Sep 17 00:00:00 2001 From: --global Date: Wed, 14 Aug 2019 10:47:29 +0300 Subject: [PATCH 01/26] Add a dark theme for the browser UI. --- swift_browser_ui/front.py | 17 +++++ swift_browser_ui/server.py | 7 +- swift_browser_ui_frontend/401.html | 1 + swift_browser_ui_frontend/403.html | 1 + swift_browser_ui_frontend/404.html | 1 + swift_browser_ui_frontend/browse.html | 19 ++--- swift_browser_ui_frontend/css/browse.css | 5 -- .../css/css_dark/Makefile | 13 ++++ .../css/css_dark/sass/darktheme.scss | 74 +++++++++++++++++++ swift_browser_ui_frontend/index.html | 1 + swift_browser_ui_frontend/js/btablecomp.js | 2 +- swift_browser_ui_frontend/js/containers.js | 4 +- 12 files changed, 127 insertions(+), 18 deletions(-) create mode 100644 swift_browser_ui_frontend/css/css_dark/Makefile create mode 100644 swift_browser_ui_frontend/css/css_dark/sass/darktheme.scss diff --git a/swift_browser_ui/front.py b/swift_browser_ui/front.py index 5173523fa..7b1060dab 100644 --- a/swift_browser_ui/front.py +++ b/swift_browser_ui/front.py @@ -1,5 +1,7 @@ """Web frontend functions for stand-alone running.""" +import os + import aiohttp.web from .settings import setd @@ -25,3 +27,18 @@ async def index(_): return aiohttp.web.FileResponse( setd['static_directory'] + '/index.html' ) + + +async def darktheme(req): + """Serve with dark theme if cookie matches.""" + if ( + "ENA_DARK" in req.cookies and + os.path.exists(setd['static_directory'] + "/css/bulma-custom.css") + ): + resp = aiohttp.web.FileResponse( + setd['static_directory'] + "/css/bulma-custom.css" + ) + return resp + return aiohttp.web.Response( + status=204, + ) diff --git a/swift_browser_ui/server.py b/swift_browser_ui/server.py index 2ddb9a218..d496f7199 100644 --- a/swift_browser_ui/server.py +++ b/swift_browser_ui/server.py @@ -13,7 +13,7 @@ import cryptography.fernet import aiohttp.web -from .front import index, browse +from .front import index, browse, darktheme from .login import handle_login, sso_query_begin, handle_logout from .login import sso_query_end from .login import token_rescope @@ -118,6 +118,11 @@ async def servinit(): aiohttp.web.get('/api/get-project-meta', get_project_metadata), ]) + # Add miscellaneous routes + app.add_routes([ + aiohttp.web.get('/css-conditional/bulma-custom.css', darktheme) + ]) + # Add graceful shutdown handler app.on_shutdown.append(kill_sess_on_shutdown) diff --git a/swift_browser_ui_frontend/401.html b/swift_browser_ui_frontend/401.html index 2c8c97745..82ddca951 100644 --- a/swift_browser_ui_frontend/401.html +++ b/swift_browser_ui_frontend/401.html @@ -10,6 +10,7 @@ + Unauthorized diff --git a/swift_browser_ui_frontend/403.html b/swift_browser_ui_frontend/403.html index 02c7afe86..0dca3e94a 100644 --- a/swift_browser_ui_frontend/403.html +++ b/swift_browser_ui_frontend/403.html @@ -10,6 +10,7 @@ + Forbidden diff --git a/swift_browser_ui_frontend/404.html b/swift_browser_ui_frontend/404.html index 322cd5af1..8a5e5ce7b 100644 --- a/swift_browser_ui_frontend/404.html +++ b/swift_browser_ui_frontend/404.html @@ -10,6 +10,7 @@ + Not found diff --git a/swift_browser_ui_frontend/browse.html b/swift_browser_ui_frontend/browse.html index 799984ad7..cdbf4e8a4 100644 --- a/swift_browser_ui_frontend/browse.html +++ b/swift_browser_ui_frontend/browse.html @@ -14,6 +14,7 @@ + @@ -23,17 +24,17 @@
-