Skip to content

Commit

Permalink
Use Node-RED defined Default themes on error and loading pages
Browse files Browse the repository at this point in the history
Caches Node-RED Dashboard Default theme on config received. Theme will be retrieved from cache on subsequent app launches for use when loading or disconnected (to show error messages)
  • Loading branch information
cgjgh committed Nov 10, 2024
1 parent 7cd70e1 commit 5d3cb54
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
9 changes: 9 additions & 0 deletions ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ export default {
this.$store.commit('ui/groups', payload.groups)
this.$store.commit('ui/widgets', payload.widgets)
this.$store.commit('ui/themes', payload.themes)
for (const key in payload.themes) {
// check if "Default Theme" theme exists
if (payload.themes[key].name === 'Default Theme') {
// store the default theme in local storage for use when disconnected from Node-RED
localStorage.setItem('defaultNRDBTheme', JSON.stringify(payload.themes[key]))
break
}
}
})
},
methods: {
Expand Down
26 changes: 20 additions & 6 deletions ui/src/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,32 @@ import './stylesheets/common.css'
import store from './store/index.mjs'
import { useDataTracker } from './widgets/data-tracker.mjs' // eslint-disable-line import/order

// set a base theme on which we will add our custom NR-defined theme
// Retrieve the "Default" theme from cache
function retrieveDefaultThemeFromCache () {
const cachedTheme = localStorage.getItem('defaultNRDBTheme')
if (cachedTheme) {
console.log('Found cached theme in localStorage')
return JSON.parse(cachedTheme)
}
console.log('No cached theme found in localStorage')
return null
}

const defaultTheme = retrieveDefaultThemeFromCache()

// set a base theme on which we will add our custom NR-defined theme (initially set to the default theme if exists in cache)
const theme = {
dark: false,
colors: {
background: '#fff',
'navigation-background': '#ffffff',
'group-background': '#ffffff',
primary: '#0094CE',
background: defaultTheme ? defaultTheme.colors.bgPage : '#fff',
'navigation-background': defaultTheme ? defaultTheme.colors.surface : '#ffffff',
'group-background': defaultTheme ? defaultTheme.colors.groupBg : '#ffffff',
'group-outline': defaultTheme ? defaultTheme.colors.groupOutline : '#d1d1d1',
primary: defaultTheme ? defaultTheme.colors.primary : '#0094CE',
accent: '#ff6b99',
secondary: '#26ff8c',
success: '#a5d64c',
surface: '#ffffff',
surface: defaultTheme ? defaultTheme.colors.surface : '#ffffff',
info: '#ff53d0',
warning: '#ff8e00',
error: '#ff5252'
Expand Down
13 changes: 7 additions & 6 deletions ui/src/stylesheets/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ main {
display: flex;
align-items: center;
justify-content: center;
background-color: #eee;
background-color: rgb(var(--v-theme-background, 238, 238, 238)); /* Fallback to light gray (#eee) */
}

.nrdb-placeholder {
Expand All @@ -92,12 +92,13 @@ main {
flex-direction: column;
align-items: center;
justify-content: center;
color: #222;
text-align: center;
padding: 1.5rem 2rem;
border-radius: 6px;
border: 1px solid #d1d1d1;
background-color: #fff;
margin: 1rem;
border-radius: var(--group-border-radius, 6px);
border: 1px solid rgb(var(--v-theme-group-outline, 209, 209, 209)); /* Fallback to light gray (#d1d1d1) */
color: rgb(var(--v-theme-on-group-background, 34, 34, 34)); /* Fallback to dark gray (#222) */
background-color: rgb(var(--v-theme-group-background, 255, 255, 255)); /* Fallback to white (#fff) */
}

.nrdb-placeholder img {
Expand All @@ -119,7 +120,7 @@ main {

.nrdb-placeholder .status-duplicates {
font-weight: 400;
color: #222;
color: rgb(var(--v-theme-on-surface, 34, 34, 34)); /* Fallback to dark gray (#222) */
margin-top: 0.5rem;
}

Expand Down

0 comments on commit 5d3cb54

Please sign in to comment.