Less confusing handling of local config

This commit is contained in:
Alicia Sykes 2024-04-16 16:50:06 +01:00
parent c456bd6bd6
commit 3c9e5bd369
8 changed files with 116 additions and 20 deletions

View File

@ -171,9 +171,9 @@
"status-fail-msg": "Task Failed", "status-fail-msg": "Task Failed",
"success-msg-disk": "Config file written to disk successfully", "success-msg-disk": "Config file written to disk successfully",
"success-msg-local": "Local changes saved successfully", "success-msg-local": "Local changes saved successfully",
"success-note-l1": "The app should rebuild automatically.", "success-note-l1": "You will need to refresh the page for changes to take effect.",
"success-note-l2": "This may take up to a minute.", "success-note-l2": "",
"success-note-l3": "You will need to refresh the page for changes to take effect.", "success-note-l3": "",
"error-msg-save-mode": "Please select a Save Mode: Local or File", "error-msg-save-mode": "Please select a Save Mode: Local or File",
"error-msg-cannot-save": "An error occurred saving config", "error-msg-cannot-save": "An error occurred saving config",
"error-msg-bad-json": "Error in JSON, possibly malformed", "error-msg-bad-json": "Error in JSON, possibly malformed",

View File

@ -47,16 +47,17 @@
</Button> </Button>
<!-- Display app version and language --> <!-- Display app version and language -->
<p class="language">{{ getLanguage() }}</p> <p class="language">{{ getLanguage() }}</p>
<p v-if="$store.state.currentConfigInfo" class="config-location"> <!-- Display location of config file -->
Using Config From<br> <p class="config-location">
{{ $store.state.currentConfigInfo.confPath }} Using config from
<a :href="configPath">{{ configPath }}</a>
</p> </p>
<AppVersion /> <AppVersion />
</div> </div>
<!-- Display note if Config disabled, or if on mobile --> <!-- Display note if Config disabled, or if on mobile -->
<p v-if="!enableConfig" class="config-disabled-note">{{ $t('config.disabled-note') }}</p> <p v-if="!enableConfig" class="config-disabled-note">{{ $t('config.disabled-note') }}</p>
<p class="small-screen-note" style="display: none;">{{ $t('config.small-screen-note') }}</p> <p class="small-screen-note" style="display: none;">{{ $t('config.small-screen-note') }}</p>
<div class="config-note"> <div class="config-note" @click="openExportConfigModal">
<span>{{ $t('config.backup-note') }}</span> <span>{{ $t('config.backup-note') }}</span>
</div> </div>
</div> </div>
@ -116,6 +117,11 @@ export default {
enableConfig() { enableConfig() {
return this.$store.getters.permissions.allowViewConfig; return this.$store.getters.permissions.allowViewConfig;
}, },
configPath() {
return this.$store.state.currentConfigInfo?.confPath
|| process.env.VUE_APP_CONFIG_PATH
|| '/conf.yml';
},
}, },
components: { components: {
Button, Button,
@ -248,8 +254,12 @@ a.hyperlink-wrapper {
p.app-version, p.language, p.config-location { p.app-version, p.language, p.config-location {
margin: 0.5rem auto; margin: 0.5rem auto;
font-size: 1rem; font-size: 1rem;
color: var(--transparent-white-50); color: var(--config-settings-color);
cursor: default; cursor: default;
opacity: var(--dimming-factor);
a {
color: var(--config-settings-color);
}
} }
div.code-container { div.code-container {

View File

@ -22,6 +22,14 @@
<DownloadConfigIcon /> <DownloadConfigIcon />
</Button> </Button>
</div> </div>
<!-- Show path to which config file is being used -->
<div class="config-path-info">
<h3>Config Location</h3>
<p>
The base config file you are currently using is
<a :href="configPath">{{ configPath }}</a>
</p>
</div>
<!-- View Config in Tree Mode Section --> <!-- View Config in Tree Mode Section -->
<h3>{{ $t('interactive-editor.export.view-title') }}</h3> <h3>{{ $t('interactive-editor.export.view-title') }}</h3>
<tree-view :data="config" class="config-tree-view" /> <tree-view :data="config" class="config-tree-view" />
@ -61,6 +69,11 @@ export default {
allowViewConfig() { allowViewConfig() {
return this.$store.getters.permissions.allowViewConfig; return this.$store.getters.permissions.allowViewConfig;
}, },
configPath() {
return this.$store.state.currentConfigInfo?.confPath
|| process.env.VUE_APP_CONFIG_PATH
|| '/conf.yml';
},
}, },
methods: { methods: {
convertJsonToYaml() { convertJsonToYaml() {
@ -121,6 +134,13 @@ export default {
border-bottom: 1px dashed var(--interactive-editor-color); border-bottom: 1px dashed var(--interactive-editor-color);
button { margin: 0 1rem; } button { margin: 0 1rem; }
} }
.config-path-info {
p, a {
color: var(--interactive-editor-color);
font-size: 1.2rem;
}
border-bottom: 1px dashed var(--interactive-editor-color);
}
.config-tree-view { .config-tree-view {
padding: 0.5rem; padding: 0.5rem;
font-family: var(--font-monospace); font-family: var(--font-monospace);

View File

@ -1,36 +1,70 @@
<template> <template>
<transition name="slide-fade"> <transition name="slide-fade">
<div class="kb-sc-info" v-if="!shouldHide"> <div class="kb-sc-info" v-if="!shouldHide">
<h5>There are keyboard shortcuts! 🙌</h5> <h5>{{ popupContent.title }}</h5>
<div class="close" title="Hide forever [Esc]" @click="hideWelcomeHelper()">x</div> <div class="close" title="Hide forever [Esc]" @click="hideWelcomeHelper()">x</div>
<p title="Press [Esc] to hide this tip forever. See there's even a shortcut for that! 🚀"> <p :title="popupContent.hoverText">{{ popupContent.message }}</p>
Just start typing to filter. Then use the tab key to cycle through results, <p :title="popupContent.hoverText">{{ popupContent.messageContinued }}</p>
and press enter to launch the selected item, or alt + enter to open in a modal. <div class="action-buttons">
You can hit Esc at anytime to clear the search. Easy 🥳 <button @click="exportConfig">Export Local Config</button>
</p> <button @click="saveConfig">Save Changes to Disk</button>
<button @click="resetLocalConfig">Reset Local Changes</button>
<button @click="hideWelcomeHelper">Dismiss this Notification</button>
</div>
</div> </div>
</transition> </transition>
</template> </template>
<script> <script>
import { localStorageKeys } from '@/utils/defaults'; import { localStorageKeys, modalNames } from '@/utils/defaults';
import StoreKeys from '@/utils/StoreMutations';
import configSavingMixin from '@/mixins/ConfigSaving';
export default { export default {
name: 'KeyboardShortcutInfo', name: 'KeyboardShortcutInfo',
mixins: [configSavingMixin],
data() { data() {
return { return {
shouldHide: true, // False = show/ true = hide. Intuitive, eh? shouldHide: true, // False = show/ true = hide. Intuitive, eh?
timeDelay: 3000, // Short delay in ms before popup appears timeDelay: 2000, // Short delay in ms before popup appears
popupContent: {
title: '⚠️ You\'re using a local config',
message: `This means that your settings are saved in this browser only,
and won't persist across devices.`,
messageContinued: `To ensure you don't loose your changes,
it's recommended to download a copy of your config, so you can restore it later.`,
hoverText: 'Press [Esc] to hide this warning',
},
}; };
}, },
methods: { methods: {
exportConfig() {
this.$modal.show(modalNames.EXPORT_CONFIG_MENU);
this.shouldHide = true;
},
saveConfig() {
const localConfig = this.$store.state.config;
this.writeConfigToDisk(localConfig);
this.shouldHide = true;
},
resetLocalConfig() {
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-globals
if (isTheUserSure) {
localStorage.clear();
this.$toasted.show(this.$t('config.data-cleared-msg'));
this.$store.dispatch(StoreKeys.INITIALIZE_CONFIG);
this.shouldHide = true;
}
},
/** /**
* Returns true if the key exists in session storage, otherwise false * Returns true if the key exists in session storage, otherwise false
* And the !! just converts 'false' to false, as strings resolve to true * And the !! just converts 'false' to false, as strings resolve to true
*/ */
shouldHideWelcomeMessage() { shouldHideWelcomeMessage() {
return !!localStorage[localStorageKeys.HIDE_WELCOME_BANNER]; return !!localStorage[localStorageKeys.HIDE_INFO_NOTIFICATION];
}, },
/** /**
* Update session storage, so that it won't be shown again * Update session storage, so that it won't be shown again
@ -38,7 +72,7 @@ export default {
*/ */
hideWelcomeHelper() { hideWelcomeHelper() {
this.shouldHide = true; this.shouldHide = true;
localStorage.setItem(localStorageKeys.HIDE_WELCOME_BANNER, true); localStorage.setItem(localStorageKeys.HIDE_INFO_NOTIFICATION, true);
window.removeEventListener('keyup', this.keyPressEvent); window.removeEventListener('keyup', this.keyPressEvent);
}, },
/* Passed to window function, to add/ remove event listener */ /* Passed to window function, to add/ remove event listener */
@ -114,6 +148,23 @@ export default {
} }
} }
} }
.action-buttons {
display: flex;
justify-content: space-around;
margin-top: 1em;
button {
padding: 0.2rem;
background: var(--welcome-popup-background);
color: var(--welcome-popup-text-color);
border: 1px solid var(--welcome-popup-text-color);
border-radius: var(--curve-factor);
transition: all 0.2s ease-in-out;
&:hover {
background: var(--welcome-popup-text-color);
color: var(--welcome-popup-background);
}
}
}
/* Animations, animations everywhere */ /* Animations, animations everywhere */
.slide-fade-enter-active { .slide-fade-enter-active {
transition: all 1s ease; transition: all 1s ease;

View File

@ -19,6 +19,7 @@ const {
SET_CONFIG, SET_CONFIG,
SET_ROOT_CONFIG, SET_ROOT_CONFIG,
SET_CURRENT_CONFIG_INFO, SET_CURRENT_CONFIG_INFO,
SET_IS_USING_LOCAL_CONFIG,
SET_MODAL_OPEN, SET_MODAL_OPEN,
SET_LANGUAGE, SET_LANGUAGE,
SET_ITEM_LAYOUT, SET_ITEM_LAYOUT,
@ -49,6 +50,7 @@ const store = new Vuex.Store({
editMode: false, // While true, the user can drag and edit items + sections editMode: false, // While true, the user can drag and edit items + sections
modalOpen: false, // KB shortcut functionality will be disabled when modal is open modalOpen: false, // KB shortcut functionality will be disabled when modal is open
currentConfigInfo: {}, // For multi-page support, will store info about config file currentConfigInfo: {}, // For multi-page support, will store info about config file
isUsingLocalConfig: false, // If true, will use local config instead of fetched
navigateConfToTab: undefined, // Used to switch active tab in config modal navigateConfToTab: undefined, // Used to switch active tab in config modal
}, },
getters: { getters: {
@ -155,6 +157,9 @@ const store = new Vuex.Store({
[SET_CURRENT_CONFIG_INFO](state, subConfigInfo) { [SET_CURRENT_CONFIG_INFO](state, subConfigInfo) {
state.currentConfigInfo = subConfigInfo; state.currentConfigInfo = subConfigInfo;
}, },
[SET_IS_USING_LOCAL_CONFIG](state, isUsingLocalConfig) {
state.isUsingLocalConfig = isUsingLocalConfig;
},
[SET_LANGUAGE](state, lang) { [SET_LANGUAGE](state, lang) {
const newConfig = state.config; const newConfig = state.config;
newConfig.appConfig.language = lang; newConfig.appConfig.language = lang;
@ -334,6 +339,7 @@ const store = new Vuex.Store({
*/ */
async [INITIALIZE_CONFIG]({ commit, state }, subConfigId) { async [INITIALIZE_CONFIG]({ commit, state }, subConfigId) {
const rootConfig = state.rootConfig || await this.dispatch(Keys.INITIALIZE_ROOT_CONFIG); const rootConfig = state.rootConfig || await this.dispatch(Keys.INITIALIZE_ROOT_CONFIG);
commit(SET_IS_USING_LOCAL_CONFIG, false);
if (!subConfigId) { // Use root config as config if (!subConfigId) { // Use root config as config
commit(SET_CONFIG, rootConfig); commit(SET_CONFIG, rootConfig);
commit(SET_CURRENT_CONFIG_INFO, {}); commit(SET_CURRENT_CONFIG_INFO, {});
@ -350,6 +356,7 @@ const store = new Vuex.Store({
} }
if (localSections.length > 0) { if (localSections.length > 0) {
rootConfig.sections = localSections; rootConfig.sections = localSections;
commit(SET_IS_USING_LOCAL_CONFIG, true);
} }
return rootConfig; return rootConfig;
} else { } else {
@ -377,7 +384,10 @@ const store = new Vuex.Store({
if (localSectionsRaw) { if (localSectionsRaw) {
try { try {
const json = JSON.parse(localSectionsRaw); const json = JSON.parse(localSectionsRaw);
if (json.length >= 1) configContent.sections = json; if (json.length >= 1) {
configContent.sections = json;
commit(SET_IS_USING_LOCAL_CONFIG, true);
}
} catch (e) { } catch (e) {
ErrorHandler('Malformed section data in local storage for sub-config'); ErrorHandler('Malformed section data in local storage for sub-config');
} }

View File

@ -6,6 +6,7 @@ const KEY_NAMES = [
'SET_CONFIG', 'SET_CONFIG',
'SET_ROOT_CONFIG', 'SET_ROOT_CONFIG',
'SET_CURRENT_CONFIG_INFO', 'SET_CURRENT_CONFIG_INFO',
'SET_IS_USING_LOCAL_CONFIG',
'SET_CURRENT_SUB_PAGE', 'SET_CURRENT_SUB_PAGE',
'SET_MODAL_OPEN', 'SET_MODAL_OPEN',
'SET_LANGUAGE', 'SET_LANGUAGE',

View File

@ -116,7 +116,7 @@ module.exports = {
/* Key names for local storage identifiers */ /* Key names for local storage identifiers */
localStorageKeys: { localStorageKeys: {
LANGUAGE: 'language', LANGUAGE: 'language',
HIDE_WELCOME_BANNER: 'hideWelcomeHelpers', HIDE_INFO_NOTIFICATION: 'hideWelcomeHelpers',
LAYOUT_ORIENTATION: 'layoutOrientation', LAYOUT_ORIENTATION: 'layoutOrientation',
COLLAPSE_STATE: 'collapseState', COLLAPSE_STATE: 'collapseState',
ICON_SIZE: 'iconSize', ICON_SIZE: 'iconSize',

View File

@ -56,6 +56,8 @@
<EditModeSaveMenu v-if="isEditMode" /> <EditModeSaveMenu v-if="isEditMode" />
<!-- Modal for viewing and exporting configuration file --> <!-- Modal for viewing and exporting configuration file -->
<ExportConfigMenu /> <ExportConfigMenu />
<!-- Shows pertinent info -->
<NotificationThing v-if="$store.state.isUsingLocalConfig"/>
</div> </div>
</template> </template>
@ -66,6 +68,7 @@ import Section from '@/components/LinkItems/Section.vue';
import EditModeSaveMenu from '@/components/InteractiveEditor/EditModeSaveMenu.vue'; import EditModeSaveMenu from '@/components/InteractiveEditor/EditModeSaveMenu.vue';
import ExportConfigMenu from '@/components/InteractiveEditor/ExportConfigMenu.vue'; import ExportConfigMenu from '@/components/InteractiveEditor/ExportConfigMenu.vue';
import AddNewSection from '@/components/InteractiveEditor/AddNewSectionLauncher.vue'; import AddNewSection from '@/components/InteractiveEditor/AddNewSectionLauncher.vue';
import NotificationThing from '@/components/Settings/LocalConfigWarning.vue';
import StoreKeys from '@/utils/StoreMutations'; import StoreKeys from '@/utils/StoreMutations';
import { localStorageKeys, modalNames } from '@/utils/defaults'; import { localStorageKeys, modalNames } from '@/utils/defaults';
import ErrorHandler from '@/utils/ErrorHandler'; import ErrorHandler from '@/utils/ErrorHandler';
@ -79,6 +82,7 @@ export default {
EditModeSaveMenu, EditModeSaveMenu,
ExportConfigMenu, ExportConfigMenu,
AddNewSection, AddNewSection,
NotificationThing,
Section, Section,
BackIcon, BackIcon,
}, },