π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
β‘ Performance, functionality and robustness work for multi-config editing
Alicia Sykesce7662ea695e
diff --git a/src/App.vue b/src/App.vueindex 415d4577..7978499d 100644--- a/src/App.vue+++ b/src/App.vue@@ -60,6 +60,15 @@ export default {immediate: true,handler(t) { applyTheme(t, this.appConfig); },},+ /* Keep i18n in sync with the active page's language (incl. sub-page overrides) */+ 'appConfig.language': {+ immediate: true,+ handler(lang) {+ if (!lang) return;+ this.$i18n.locale = lang;+ document.documentElement.setAttribute('lang', lang);+ },+ },},computed: {/* If the user has specified custom text for footer - get it */diff --git a/src/components/Configuration/CloudBackupRestore.vue b/src/components/Configuration/CloudBackupRestore.vueindex 0f7dd4f3..41159b3d 100644--- a/src/components/Configuration/CloudBackupRestore.vue+++ b/src/components/Configuration/CloudBackupRestore.vue@@ -68,6 +68,7 @@ import Input from '@/components/FormElements/Input';import StoreKeys from '@/utils/StoreMutations';import { backup, update, restore } from '@/utils/CloudBackup';import { localStorageKeys } from '@/utils/config/defaults';+import { configScope, stripRootOwnedFields } from '@/utils/config/ConfigHelpers';import { InfoHandler, WarningInfoHandler, InfoKeys } from '@/utils/logging/ErrorHandler';// Import Iconsimport IconBackup from '@/assets/interface-icons/config-backup.svg';@@ -155,31 +156,22 @@ export default {this.showErrorMsg(this.$t('cloud-sync.backup-error-password'));}},- /* When restored data is revieved, then save to local storage, and apply it in state */+ /* When restored data is received, save to localStorage (scoped to active page) and apply it */applyRestoredData(config, backupId) {- const isSubPage = !!this.$store.state.currentConfigInfo.confId;- if (isSubPage) { // Apply to sub-page only- const subConfigId = this.$store.state.currentConfigInfo.confId;- const sectionStorageKey = `${localStorageKeys.CONF_SECTIONS}-${subConfigId}`;- const pageInfoStorageKey = `${localStorageKeys.PAGE_INFO}-${subConfigId}`;- const themeStoreKey = `${localStorageKeys.THEME}-${subConfigId}`;- localStorage.setItem(sectionStorageKey, JSON.stringify(config.sections));- localStorage.setItem(pageInfoStorageKey, JSON.stringify(config.pageInfo));- localStorage.setItem(themeStoreKey, config.appConfig.theme);- } else { // Apply to main config- localStorage.setItem(localStorageKeys.CONF_SECTIONS, JSON.stringify(config.sections));- localStorage.setItem(localStorageKeys.APP_CONFIG, JSON.stringify(config.appConfig));- localStorage.setItem(localStorageKeys.PAGE_INFO, JSON.stringify(config.pageInfo));+ const { confId } = this.$store.state.currentConfigInfo;+ const isSubPage = !!confId;+ const scope = configScope(confId);+ const clean = isSubPage ? stripRootOwnedFields(config) : config;+ const appConfig = clean.appConfig || {};+ localStorage.setItem(scope.APP_CONFIG, JSON.stringify(appConfig));+ localStorage.setItem(scope.PAGE_INFO, JSON.stringify(clean.pageInfo || {}));+ localStorage.setItem(scope.CONF_SECTIONS, JSON.stringify(clean.sections || []));+ if (appConfig.theme) localStorage.setItem(scope.THEME, appConfig.theme);+ if (!isSubPage) {localStorage.setItem(localStorageKeys.CONF_PAGES, JSON.stringify(config.pages || []));- if (config.appConfig.theme) {- localStorage.setItem(localStorageKeys.THEME, config.appConfig.theme);- }}- // Save hashed token in local storagethis.setBackupIdLocally(backupId, this.restorePassword);- // Update the current state- this.$store.commit(StoreKeys.SET_CONFIG, config);- // Show success message+ this.$store.dispatch(StoreKeys.APPLY_EDITED_CONFIG, clean);this.showSuccessMsg(this.$t('cloud-sync.restore-success-msg'));},/* After backup/ update is made, then replace 'Make Backup' with 'Update Backup' */diff --git a/src/components/Configuration/ConfigContainer.vue b/src/components/Configuration/ConfigContainer.vueindex 93d919f1..cd72c153 100644--- a/src/components/Configuration/ConfigContainer.vue+++ b/src/components/Configuration/ConfigContainer.vue@@ -83,7 +83,7 @@<script>import { localStorageKeys, modalNames } from '@/utils/config/defaults';-import { getUsersLanguage } from '@/utils/config/ConfigHelpers';+import { getUsersLanguage, clearScopedLocalConfig } from '@/utils/config/ConfigHelpers';import ErrorHandler from '@/utils/logging/ErrorHandler';import StoreKeys from '@/utils/StoreMutations';import { defineAsyncComponent, h } from 'vue';@@ -193,13 +193,14 @@ export default {openEditCssTab() {this.navigateToTab(3);},- /* Checks that the user is sure, then resets site-wide local storage, and reloads current page */+ /* Clears config-scoped localStorage entries for root + all sub-pages, then reloads config.+ * Preserves unrelated keys (auth tokens, backup hashes, mostUsed etc) */resetLocalSettings() {const msg = `${this.$t('config.reset-config-msg-l1')} `+ `${this.$t('config.reset-config-msg-l2')}\n\n${this.$t('config.reset-config-msg-l3')}`;const isTheUserSure = confirm(msg); // eslint-disable-line no-alert, no-restricted-globalsif (isTheUserSure) {- localStorage.clear();+ clearScopedLocalConfig(this.$store.getters.pages);this.$toast(this.$t('config.data-cleared-msg'));this.$store.dispatch(StoreKeys.INITIALIZE_CONFIG, this.$store.state.currentConfigInfo.confId);}diff --git a/src/components/Configuration/CustomCss.vue b/src/components/Configuration/CustomCss.vueindex f88cfc1a..69f6fb43 100644--- a/src/components/Configuration/CustomCss.vue+++ b/src/components/Configuration/CustomCss.vue@@ -28,7 +28,8 @@ import CustomThemeMaker from '@/components/Settings/CustomThemeMaker';import ThemeSelector from '@/components/Settings/ThemeSelector';import Button from '@/components/FormElements/Button';import StoreKeys from '@/utils/StoreMutations';-import { localStorageKeys, theme as defaultTheme } from '@/utils/config/defaults';+import { theme as defaultTheme } from '@/utils/config/defaults';+import { configScope } from '@/utils/config/ConfigHelpers';export default {name: 'StyleEditor',@@ -71,11 +72,12 @@ export default {style.textContent = cleanedCss;document.head.append(style);},- /* Saves custom CSS local storage */+ /* Saves custom CSS to localStorage, scoped to the active page */saveToBrowser(css) {- const localAppConfig = JSON.parse(localStorage.getItem(localStorageKeys.APP_CONFIG) || '{}');+ const key = configScope(this.$store.state.currentConfigInfo.confId).APP_CONFIG;+ const localAppConfig = JSON.parse(localStorage.getItem(key) || '{}');localAppConfig.customCss = css;- localStorage.setItem(localStorageKeys.APP_CONFIG, JSON.stringify(localAppConfig));+ localStorage.setItem(key, JSON.stringify(localAppConfig));},/* Reload the page (only called if removing styles) */reloadPage() {diff --git a/src/components/InteractiveEditor/EditItem.vue b/src/components/InteractiveEditor/EditItem.vueindex a187bf99..b88f5717 100644--- a/src/components/InteractiveEditor/EditItem.vue+++ b/src/components/InteractiveEditor/EditItem.vue@@ -246,7 +246,6 @@ export default {if (newItem.statusCheckAllowInsecure) {newItem.statusCheckAllowInsecure = strToBool(newItem.statusCheckAllowInsecure);}- // if (newItem.hotkey) newItem.hotkey = parseInt(newItem.hotkey, 10);return newItem;},/* Cleanup work for modal, triggered by save, cancel or click-outside */diff --git a/src/components/Settings/LocalConfigWarning.vue b/src/components/Settings/LocalConfigWarning.vueindex 436590d9..a1741348 100644--- a/src/components/Settings/LocalConfigWarning.vue+++ b/src/components/Settings/LocalConfigWarning.vue@@ -18,6 +18,7 @@<script>import { localStorageKeys, modalNames } from '@/utils/config/defaults';+import { clearScopedLocalConfig } from '@/utils/config/ConfigHelpers';import StoreKeys from '@/utils/StoreMutations';import configSavingMixin from '@/mixins/ConfigSaving';@@ -53,7 +54,7 @@ export default {+ `${this.$t('config.reset-config-msg-l2')}\n\n${this.$t('config.reset-config-msg-l3')}`;const isTheUserSure = confirm(msg); // eslint-disable-line no-alert, no-restricted-globalsif (isTheUserSure) {- localStorage.clear();+ clearScopedLocalConfig(this.$store.getters.pages);this.$toast(this.$t('config.data-cleared-msg'));this.$store.dispatch(StoreKeys.INITIALIZE_CONFIG);this.shouldHide = true;diff --git a/src/mixins/ConfigSaving.js b/src/mixins/ConfigSaving.jsindex 2a72605c..372361f1 100644--- a/src/mixins/ConfigSaving.js+++ b/src/mixins/ConfigSaving.js@@ -4,7 +4,9 @@ import request from '@/utils/request';import ErrorHandler, { InfoHandler } from '@/utils/logging/ErrorHandler';import { localStorageKeys, serviceEndpoints } from '@/utils/config/defaults';-import { makePageName, configScope, stripRootOwnedFields } from '@/utils/config/ConfigHelpers';+import {+ configScope, stripRootOwnedFields, clearScopedLocalConfig,+} from '@/utils/config/ConfigHelpers';import StoreKeys from '@/utils/StoreMutations';export default {@@ -97,13 +99,7 @@ export default {},/* After a successful disk write clear local overrides */carefullyClearLocalStorage() {- const clearScope = (confId) => {- const s = configScope(confId);- Object.values(s).forEach((key) => localStorage.removeItem(key));- };- clearScope(null); // root- localStorage.removeItem(localStorageKeys.CONF_PAGES);- (this.$store.getters.pages || []).forEach((page) => clearScope(makePageName(page.name)));+ clearScopedLocalConfig(this.$store.getters.pages);},},};diff --git a/src/router.js b/src/router.jsindex fffca35f..af156d9c 100644--- a/src/router.js+++ b/src/router.js@@ -150,6 +150,7 @@ router.beforeEach(async (to, from, next) => {if (to.name !== 'login' && !isAuthenticated()) next({ name: 'login' });else next();} catch (e) {+ ErrorHandler('Navigation guard failed', e);next();}});diff --git a/src/store.js b/src/store.jsindex b6972172..ad5fe2ac 100644--- a/src/store.js+++ b/src/store.js@@ -271,13 +271,13 @@ const store = createStore({},layout(state) {const scope = configScope(state.currentConfigInfo.confId);- const fromState = state.config.appConfig.layout || 'auto';+ const fromState = state.config?.appConfig?.layout || 'auto';if (state.editMode) return fromState;return localStorage.getItem(scope.LAYOUT) || fromState;},iconSize(state) {const scope = configScope(state.currentConfigInfo.confId);- const fromState = state.config.appConfig.iconSize || 'medium';+ const fromState = state.config?.appConfig?.iconSize || 'medium';if (state.editMode) return fromState;return localStorage.getItem(scope.ICON_SIZE) || fromState;},@@ -334,6 +334,7 @@ const store = createStore({// `pages` is always root-owned, regardless of the active page.const pages = Array.isArray(multiPages) ? multiPages : [];if (state.rootConfig) state.rootConfig = { ...state.rootConfig, pages };+ else ErrorHandler('SET_PAGES called before root config loaded; change may be lost');state.config = { ...state.config, pages };if (!state.currentConfigInfo.confId) {state.configSource = { ...state.configSource, pages };diff --git a/src/utils/config/ConfigAccumalator.js b/src/utils/config/ConfigAccumalator.jsindex 1e6e1426..96063972 100644--- a/src/utils/config/ConfigAccumalator.js+++ b/src/utils/config/ConfigAccumalator.js@@ -34,12 +34,12 @@ export default class ConfigAccumulator {appConfigFile = this.conf.appConfig;}// Fill in defaults if anything missing- let usersAppConfig = defaultAppConfig;+ let usersAppConfig = { ...defaultAppConfig };if (localStorage[localStorageKeys.APP_CONFIG]) {try { usersAppConfig = JSON.parse(localStorage[localStorageKeys.APP_CONFIG]); }catch (e) { ErrorHandler('Malformed app config in local storage'); }} else if (Object.keys(appConfigFile).length > 0) {- usersAppConfig = appConfigFile;+ usersAppConfig = { ...appConfigFile };}// Some settings have their own local storage keys, apply them hereusersAppConfig.layout = localStorage[localStorageKeys.LAYOUT_ORIENTATION]diff --git a/src/utils/config/ConfigHelpers.js b/src/utils/config/ConfigHelpers.jsindex a2378874..bcbf323e 100644--- a/src/utils/config/ConfigHelpers.js+++ b/src/utils/config/ConfigHelpers.js@@ -40,6 +40,18 @@ export const configScope = (confId) => {};};+/* Remove all local config settings from localStorage, leave unrelated stuff */+export const clearScopedLocalConfig = (pages) => {+ const clearScope = (confId) => {+ Object.values(configScope(confId)).forEach((key) => localStorage.removeItem(key));+ };+ clearScope(null);+ localStorage.removeItem(localStorageKeys.CONF_PAGES);+ (pages || []).forEach((page) => {+ if (page?.name) clearScope(makePageName(page.name));+ });+};+/* Metadata for each view in the canonical /<view>/:page?/:section? URL scheme */export const VIEW_META = {home: { supportsSection: true },diff --git a/src/utils/config/defaults.js b/src/utils/config/defaults.jsindex 59c51771..58473bd2 100644--- a/src/utils/config/defaults.js+++ b/src/utils/config/defaults.js@@ -137,7 +137,6 @@ const defaults = {CUSTOM_COLORS: 'customColors',CONF_SECTIONS: 'confSections',CONF_PAGES: 'confPages',- CONF_WIDGETS: 'confSections',PAGE_INFO: 'pageInfo',APP_CONFIG: 'appConfig',BACKUP_ID: 'backupId',