diff options
| author | Henry Jameson <me@hjkos.com> | 2023-03-21 22:46:40 +0200 |
|---|---|---|
| committer | Henry Jameson <me@hjkos.com> | 2023-03-21 22:46:40 +0200 |
| commit | 2bf224e214d9b42333a2139a89c089ca9a544149 (patch) | |
| tree | 0d2fce61635c269b8f970c0d25f923307bd65400 /src/components/settings_modal/helpers | |
| parent | 6b40fc989575fd52b3b9bf3e8d78d7fb4a6c7696 (diff) | |
made draft-mode and source inject-able
Diffstat (limited to 'src/components/settings_modal/helpers')
5 files changed, 32 insertions, 18 deletions
diff --git a/src/components/settings_modal/helpers/choice_setting.js b/src/components/settings_modal/helpers/choice_setting.js index 3ff81bc9..bdeece76 100644 --- a/src/components/settings_modal/helpers/choice_setting.js +++ b/src/components/settings_modal/helpers/choice_setting.js @@ -22,8 +22,7 @@ export default { computed: { ...Setting.computed, realOptions () { - if (this.source === 'admin') { - console.log(this.backendDescriptionSuggestions) + if (this.realSource === 'admin') { return this.backendDescriptionSuggestions.map(x => ({ key: x, value: x, diff --git a/src/components/settings_modal/helpers/choice_setting.vue b/src/components/settings_modal/helpers/choice_setting.vue index 55f9a62c..8713acf5 100644 --- a/src/components/settings_modal/helpers/choice_setting.vue +++ b/src/components/settings_modal/helpers/choice_setting.vue @@ -11,7 +11,7 @@ </template> {{ ' ' }} <Select - :model-value="draftMode ? draft :state" + :model-value="realDraftMode ? draft :state" :disabled="disabled" @update:modelValue="update" > diff --git a/src/components/settings_modal/helpers/number_setting.vue b/src/components/settings_modal/helpers/number_setting.vue index 93a7a79a..f97d5cf2 100644 --- a/src/components/settings_modal/helpers/number_setting.vue +++ b/src/components/settings_modal/helpers/number_setting.vue @@ -18,7 +18,7 @@ :step="step || 1" :disabled="disabled" :min="min || 0" - :value="draftMode ? draft :state" + :value="realDraftMode ? draft :state" @change="update" > {{ ' ' }} diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js index fd730db9..7cad27b7 100644 --- a/src/components/settings_modal/helpers/setting.js +++ b/src/components/settings_modal/helpers/setting.js @@ -31,10 +31,18 @@ export default { }, source: { type: String, - default: 'default' + default: undefined }, draftMode: { type: Boolean, + default: undefined + } + }, + inject: { + defaultSource: { + default: 'default' + }, + defaultDraftMode: { default: false } }, @@ -44,7 +52,7 @@ export default { } }, created () { - if (this.draftMode) { + if (this.realDraftMode) { this.draft = this.state } }, @@ -57,6 +65,12 @@ export default { return value } }, + realSource () { + return this.source || this.defaultSource + }, + realDraftMode () { + return typeof this.draftMode === 'undefined' ? this.defaultDraftMode : this.draftMode + }, backendDescription () { return get(this.$store.state.adminSettings.descriptions, this.path) }, @@ -74,7 +88,8 @@ export default { return this.disabled || (parentValue !== null ? (this.parentInvert ? parentValue : !parentValue) : false) }, configSource () { - switch (this.source) { + console.log('SRC', this.realSource) + switch (this.realSource) { case 'profile': return this.$store.state.profileConfig case 'admin': @@ -84,7 +99,7 @@ export default { } }, configSink () { - switch (this.source) { + switch (this.realSource) { case 'profile': return (k, v) => this.$store.dispatch('setProfileOption', { name: k, value: v }) case 'admin': @@ -94,7 +109,7 @@ export default { } }, defaultState () { - switch (this.source) { + switch (this.realSource) { case 'profile': return {} default: @@ -102,10 +117,10 @@ export default { } }, isProfileSetting () { - return this.source === 'profile' + return this.realSource === 'profile' }, isChanged () { - switch (this.source) { + switch (this.realSource) { case 'profile': case 'admin': return false @@ -114,10 +129,10 @@ export default { } }, isDirty () { - return this.draftMode && this.draft !== this.state + return this.realDraftMode && this.draft !== this.state }, canHardReset () { - return this.source === 'admin' && this.$store.state.adminSettings.modifiedPaths.has(this.path) + return this.realSource === 'admin' && this.$store.state.adminSettings.modifiedPaths.has(this.path) }, matchesExpertLevel () { return (this.expert || 0) <= this.$store.state.config.expertLevel > 0 @@ -128,20 +143,20 @@ export default { return e.target.value }, update (e) { - if (this.draftMode) { + if (this.realDraftMode) { this.draft = this.getValue(e) } else { this.configSink(this.path, this.getValue(e)) } }, commitDraft () { - if (this.draftMode) { + if (this.realDraftMode) { this.configSink(this.path, this.draft) } }, reset () { console.log('reset') - if (this.draftMode) { + if (this.realDraftMode) { console.log(this.draft) console.log(this.state) this.draft = this.state @@ -150,7 +165,7 @@ export default { } }, hardReset () { - switch (this.source) { + switch (this.realSource) { case 'admin': return this.$store.dispatch('resetAdminSetting', { path: this.path }) .then(() => { this.draft = this.state }) diff --git a/src/components/settings_modal/helpers/string_setting.vue b/src/components/settings_modal/helpers/string_setting.vue index 91a4afa4..fb91b5d9 100644 --- a/src/components/settings_modal/helpers/string_setting.vue +++ b/src/components/settings_modal/helpers/string_setting.vue @@ -16,7 +16,7 @@ class="string-input" step="1" :disabled="disabled" - :value="draftMode ? draft :state" + :value="realDraftMode ? draft : state" @change="update" > {{ ' ' }} |
