Adds option to prevent saving changes locally (#485)

This commit is contained in:
Alicia Sykes 2022-02-11 10:20:45 +00:00
parent 76e5a1b77b
commit a65c3c569e
3 changed files with 27 additions and 8 deletions

View File

@ -8,11 +8,11 @@
:label="$t('config-editor.save-location-label')" :label="$t('config-editor.save-location-label')"
:options="saveOptions" :options="saveOptions"
:initialOption="initialSaveMode" :initialOption="initialSaveMode"
:disabled="!allowWriteToDisk" :disabled="!allowWriteToDisk || !allowSaveLocally"
/> />
<!-- Save Buttons --> <!-- Save Buttons -->
<div :class="`btn-container ${!isValid ? 'err' : ''}`"> <div :class="`btn-container ${!isValid ? 'err' : ''}`">
<Button :click="save"> <Button :click="save" :disallow="!allowWriteToDisk && !allowSaveLocally">
{{ $t('config-editor.save-button') }} {{ $t('config-editor.save-button') }}
</Button> </Button>
<Button :click="startPreview"> <Button :click="startPreview">
@ -101,8 +101,14 @@ export default {
const { appConfig } = this.config; const { appConfig } = this.config;
return !appConfig.preventWriteToDisk && appConfig.allowConfigEdit !== false && isUserAdmin(); return !appConfig.preventWriteToDisk && appConfig.allowConfigEdit !== false && isUserAdmin();
}, },
allowSaveLocally() {
if (this.config.appConfig.preventLocalSave) return false;
return true;
},
initialSaveMode() { initialSaveMode() {
return this.allowWriteToDisk ? 'file' : 'local'; if (this.allowWriteToDisk) return 'file';
if (this.allowSaveLocally) return 'local';
return '';
}, },
}, },
mounted() { mounted() {
@ -166,6 +172,10 @@ export default {
}, },
/* Saves config to local browser storage */ /* Saves config to local browser storage */
saveConfigLocally() { saveConfigLocally() {
if (!this.allowSaveLocally) {
ErrorHandler('Unable to save changes locally, this feature has been disabled');
return;
}
const data = this.jsonData; const data = this.jsonData;
if (data.sections) { if (data.sections) {
localStorage.setItem(localStorageKeys.CONF_SECTIONS, JSON.stringify(data.sections)); localStorage.setItem(localStorageKeys.CONF_SECTIONS, JSON.stringify(data.sections));
@ -180,7 +190,7 @@ export default {
if (data.appConfig.theme) { if (data.appConfig.theme) {
localStorage.setItem(localStorageKeys.THEME, data.appConfig.theme); localStorage.setItem(localStorageKeys.THEME, data.appConfig.theme);
} }
InfoHandler('Config has succesfully been saved in browser storage', InfoKeys.RAW_EDITOR); InfoHandler('Config has successfully been saved in browser storage', InfoKeys.RAW_EDITOR);
this.showToast(this.$t('config-editor.success-msg-local'), true); this.showToast(this.$t('config-editor.success-msg-local'), true);
}, },
/* Clears config from browser storage, only removing relevant items */ /* Clears config from browser storage, only removing relevant items */

View File

@ -3,7 +3,7 @@
@click="click ? click() : () => null" @click="click ? click() : () => null"
:class="disallow ? 'disallowed': ''" :class="disallow ? 'disallowed': ''"
:type="type || 'button'" :type="type || 'button'"
:disabled="disabled" :disabled="disabled || disallow"
v-tooltip="hoverText" v-tooltip="hoverText"
:title="tooltip" :title="tooltip"
> >
@ -68,7 +68,7 @@ button {
background: var(--background); background: var(--background);
border: 1px solid var(--primary); border: 1px solid var(--primary);
border-radius: var(--curve-factor); border-radius: var(--curve-factor);
&:hover:not(:disabled) { &:hover:not(:disabled):not(.disallowed) {
color: var(--background); color: var(--background);
background: var(--primary); background: var(--primary);
border-color: var(--background); border-color: var(--background);

View File

@ -17,6 +17,7 @@
</p> </p>
<Button <Button
:click="saveLocally" :click="saveLocally"
:disallow="!allowSaveLocally"
v-tooltip="tooltip($t('interactive-editor.menu.save-locally-tooltip'))" v-tooltip="tooltip($t('interactive-editor.menu.save-locally-tooltip'))"
> >
{{ $t('interactive-editor.menu.save-locally-btn') }} {{ $t('interactive-editor.menu.save-locally-btn') }}
@ -24,7 +25,7 @@
</Button> </Button>
<Button <Button
:click="writeToDisk" :click="writeToDisk"
:disabled="!allowWriteToDisk" :disallow="!allowWriteToDisk"
v-tooltip="tooltip($t('interactive-editor.menu.save-disk-tooltip'))" v-tooltip="tooltip($t('interactive-editor.menu.save-disk-tooltip'))"
> >
{{ $t('interactive-editor.menu.save-disk-btn') }} {{ $t('interactive-editor.menu.save-disk-btn') }}
@ -115,6 +116,10 @@ export default {
if (!isUserAdmin()) return false; // If auth configured, but user NOT admin if (!isUserAdmin()) return false; // If auth configured, but user NOT admin
return true; return true;
}, },
allowSaveLocally() {
if (this.config.appConfig.preventLocalSave) return false;
return true;
},
}, },
data() { data() {
return { return {
@ -152,6 +157,10 @@ export default {
localStorage.removeItem(localStorageKeys.CONF_SECTIONS); localStorage.removeItem(localStorageKeys.CONF_SECTIONS);
}, },
saveLocally() { saveLocally() {
if (!this.allowSaveLocally) {
ErrorHandler('Unable to save changes locally, this feature has been disabled');
return;
}
const data = this.config; const data = this.config;
localStorage.setItem(localStorageKeys.CONF_SECTIONS, JSON.stringify(data.sections)); localStorage.setItem(localStorageKeys.CONF_SECTIONS, JSON.stringify(data.sections));
localStorage.setItem(localStorageKeys.PAGE_INFO, JSON.stringify(data.pageInfo)); localStorage.setItem(localStorageKeys.PAGE_INFO, JSON.stringify(data.pageInfo));
@ -277,7 +286,7 @@ div.edit-mode-bottom-banner {
color: var(--interactive-editor-color); color: var(--interactive-editor-color);
border-color: var(--interactive-editor-color); border-color: var(--interactive-editor-color);
background: var(--interactive-editor-background); background: var(--interactive-editor-background);
&:hover { &:hover:not(.disallowed) {
color: var(--interactive-editor-background); color: var(--interactive-editor-background);
border-color: var(--interactive-editor-color); border-color: var(--interactive-editor-color);
background: var(--interactive-editor-color); background: var(--interactive-editor-color);