From 1e1d1061d680298f3e6a49486eef1f324b278b2b Mon Sep 17 00:00:00 2001 From: mikeTWC1984 Date: Sat, 30 Mar 2024 01:43:59 -0400 Subject: [PATCH] auto theme change --- htdocs/js/pages/Admin.class.js | 1 + htdocs/js/pages/Home.class.js | 9 ++++++++- htdocs/js/pages/admin/Secrets.js | 10 ++++++++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/htdocs/js/pages/Admin.class.js b/htdocs/js/pages/Admin.class.js index 12de02e..94f88b0 100644 --- a/htdocs/js/pages/Admin.class.js +++ b/htdocs/js/pages/Admin.class.js @@ -119,6 +119,7 @@ Class.subclass( Page.Base, "Page.Admin", { onDeactivate: function() { // called when page is deactivated // this.div.html( '' ); + if(this.observer) this.observer.disconnect() return true; } diff --git a/htdocs/js/pages/Home.class.js b/htdocs/js/pages/Home.class.js index be4146d..8f63825 100644 --- a/htdocs/js/pages/Home.class.js +++ b/htdocs/js/pages/Home.class.js @@ -135,6 +135,12 @@ Class.subclass( Page.Base, "Page.Home", { this.refresh_header_stats(); this.refresh_completed_job_chart(); this.refresh_event_queues(); + + const self = this; + self.observer = new MutationObserver((mutationList, observer)=> { + self.refresh_completed_job_chart(); + }); + self.observer.observe(document.querySelector('body'), {attributes: true}) return true; }, @@ -404,7 +410,7 @@ Class.subclass( Page.Base, "Page.Home", { let scaleType = $('#fe_cmp_job_chart_scale').val() || 'logarithmic'; // if chart is already generated only update data - if(app.jobHistoryChart) { + if(app.jobHistoryChart) { app.jobHistoryChart.data.datasets = datasets; app.jobHistoryChart.data.labels = labels; app.jobHistoryChart.options.scales.yAxes[0].type = scaleType; @@ -824,6 +830,7 @@ Class.subclass( Page.Base, "Page.Home", { onDeactivate: function() { // called when page is deactivated // this.div.html( '' ); + if(this.observer) this.observer.disconnect() return true; } diff --git a/htdocs/js/pages/admin/Secrets.js b/htdocs/js/pages/admin/Secrets.js index 19fd57e..f9404d9 100644 --- a/htdocs/js/pages/admin/Secrets.js +++ b/htdocs/js/pages/admin/Secrets.js @@ -9,8 +9,9 @@ Class.add( Page.Admin, { app.setWindowTitle("Secrets"); self.div.addClass('loading'); self.secret = {}; - self.secretId = args.id - + self.secretId = args.id + if(self.observer) self.observer.disconnect() // kill old observer if set by editor + app.api.post('/api/app/get_secret', { id: args.id || 'globalenv' }, self.receive_secrets.bind(self)); }, @@ -42,6 +43,11 @@ Class.add( Page.Admin, { editor.setValue(secret.data || ''); + self.observer = new MutationObserver((mutationList, observer)=> { + editor.setOption('theme', app.getPref('theme') == 'light' ? 'default' : 'solarized dark') + }); + self.observer.observe(document.querySelector('body'), {attributes: true}) + }, receive_secrets: function(resp) {