From c47482be94ad6a93613475748e01f93dee0a36d5 Mon Sep 17 00:00:00 2001 From: hsyoun Date: Thu, 2 May 2024 09:50:49 +0900 Subject: [PATCH 01/14] ADD prototype version dark mode for Airflow UI --- airflow/www/static/css/bootstrap-theme.css | 6 ++++ airflow/www/templates/appbuilder/navbar.html | 29 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/airflow/www/static/css/bootstrap-theme.css b/airflow/www/static/css/bootstrap-theme.css index 371762d55857e..e9e052aebed35 100644 --- a/airflow/www/static/css/bootstrap-theme.css +++ b/airflow/www/static/css/bootstrap-theme.css @@ -36,6 +36,9 @@ html { -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; } +html.dark-mode{ + filter: invert(100%)hue-rotate(180deg); +} body { margin: 0; } @@ -298,6 +301,9 @@ html { font-size: 12px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } +html.dark-mode{ + filter: invert(100%)hue-rotate(180deg); +} body { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; diff --git a/airflow/www/templates/appbuilder/navbar.html b/airflow/www/templates/appbuilder/navbar.html index f3320c3c0004d..065c9f3c50068 100644 --- a/airflow/www/templates/appbuilder/navbar.html +++ b/airflow/www/templates/appbuilder/navbar.html @@ -50,8 +50,37 @@ {% include 'appbuilder/navbar_menu.html' %} + + From eadcd23b8a2e66cf2b4c8e0da06f6df6a1c04913 Mon Sep 17 00:00:00 2001 From: hsyoun Date: Thu, 9 May 2024 15:56:49 +0900 Subject: [PATCH 02/14] fix flickering when refresh page --- airflow/www/static/css/bootstrap-theme.css | 10 +++--- airflow/www/static/js/toggle_theme.js | 33 ++++++++++++++++++++ airflow/www/templates/appbuilder/navbar.html | 26 ++------------- airflow/www/views.py | 11 ++++++- 4 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 airflow/www/static/js/toggle_theme.js diff --git a/airflow/www/static/css/bootstrap-theme.css b/airflow/www/static/css/bootstrap-theme.css index e9e052aebed35..51ae17b9ab559 100644 --- a/airflow/www/static/css/bootstrap-theme.css +++ b/airflow/www/static/css/bootstrap-theme.css @@ -36,8 +36,11 @@ html { -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; } -html.dark-mode{ - filter: invert(100%)hue-rotate(180deg); +html[data-color-scheme='dark'] { + filter:invert(100%)hue-rotate(180deg); +} +html[data-color-scheme='light'] { + } body { margin: 0; @@ -301,9 +304,6 @@ html { font-size: 12px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } -html.dark-mode{ - filter: invert(100%)hue-rotate(180deg); -} body { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; diff --git a/airflow/www/static/js/toggle_theme.js b/airflow/www/static/js/toggle_theme.js new file mode 100644 index 0000000000000..150b8d25beca8 --- /dev/null +++ b/airflow/www/static/js/toggle_theme.js @@ -0,0 +1,33 @@ +const STORAGE_THEME_KEY = 'darkTheme'; +const HTML_THEME_DATASET_KEY = 'data-color-scheme'; +const HTML = document.documentElement; +const TOGGLE_BUTTON_ID = 'themeToggleButton'; + +const getJsonFromStorage = (key)=>JSON.parse(localStorage.getItem(key)); +const updateTheme = (isDark)=>{ + localStorage.setItem(STORAGE_THEME_KEY, isDark); + HTML.setAttribute(HTML_THEME_DATASET_KEY, isDark ? 'dark' : 'light'); +} +; +const initTheme = ()=>{ + const isDark = getJsonFromStorage(STORAGE_THEME_KEY) ?? window.matchMedia('(prefers-color-scheme: dark)').matches; + updateTheme(isDark); +} +; +const toggleTheme = ()=>{ + const isDark = getJsonFromStorage(STORAGE_THEME_KEY); + updateTheme(!isDark); +} +; +window.addEventListener('click', (e)=>{ + if (e.target.id !== TOGGLE_BUTTON_ID) + return; + toggleTheme(); +} +); +window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e)=>{ + const isDark = e.matches; + updateTheme(isDark); +} +); +initTheme(); diff --git a/airflow/www/templates/appbuilder/navbar.html b/airflow/www/templates/appbuilder/navbar.html index 065c9f3c50068..d749643041283 100644 --- a/airflow/www/templates/appbuilder/navbar.html +++ b/airflow/www/templates/appbuilder/navbar.html @@ -51,8 +51,8 @@ - - diff --git a/airflow/www/views.py b/airflow/www/views.py index 306926c163ae0..b7c5cdf4e06c5 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -719,8 +719,17 @@ def render_template(self, *args, **kwargs): **kwargs, ) +class CustomAirflow(AirflowBaseView): + def render_template(self, *args, **kwargs): + rendered_template = super().render_template(*args, **kwargs) + + script_tag = '' + + return rendered_template.replace("", f"{script_tag}") + -class Airflow(AirflowBaseView): +#class Airflow(AirflowBaseView): +claass Airflow(CustomAirflow): """Main Airflow application.""" @expose("/health") From 43a2d962189db3c672cc5079e59bcbe5fb901160 Mon Sep 17 00:00:00 2001 From: hightophades Date: Sat, 11 May 2024 16:37:04 +0900 Subject: [PATCH 03/14] clean up commented code --- airflow/www/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/airflow/www/views.py b/airflow/www/views.py index f104a6e35e3ee..c4e2ffb5b244a 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -728,8 +728,7 @@ def render_template(self, *args, **kwargs): return rendered_template.replace("", f"{script_tag}") -#class Airflow(AirflowBaseView): -claass Airflow(CustomAirflow): +class Airflow(CustomAirflow): """Main Airflow application.""" @expose("/health") From 58767aebac495d4df5989feb98ce0bb3b3f07715 Mon Sep 17 00:00:00 2001 From: hightophades Date: Sat, 11 May 2024 16:40:39 +0900 Subject: [PATCH 04/14] indent fix tab to 2 indent --- airflow/www/templates/appbuilder/navbar.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airflow/www/templates/appbuilder/navbar.html b/airflow/www/templates/appbuilder/navbar.html index d749643041283..ec7d08cece318 100644 --- a/airflow/www/templates/appbuilder/navbar.html +++ b/airflow/www/templates/appbuilder/navbar.html @@ -50,7 +50,7 @@ {% include 'appbuilder/navbar_menu.html' %}