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

View File

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

View File

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