aboutsummaryrefslogtreecommitdiff
path: root/src/components/settings_modal/helpers/setting.js
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2023-03-12 14:32:13 +0200
committerHenry Jameson <me@hjkos.com>2023-03-12 14:36:49 +0200
commitaf0cd5422304d7b2111739d85c279b3fa175a853 (patch)
treec082ac704adc18e0d187166a8acb817d59969e29 /src/components/settings_modal/helpers/setting.js
parent8abaf8fa375d8453b2284fbf529cd03ff565bcd4 (diff)
serverSideConfig renamed into profileSettingConfig to avoid confusion
with serverSideStorage, reduced overall need for SharedComputedObject in settings tabs, moved copypaste code of "setting" type of helpers into a separate file.
Diffstat (limited to 'src/components/settings_modal/helpers/setting.js')
-rw-r--r--src/components/settings_modal/helpers/setting.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js
new file mode 100644
index 00000000..dc37675c
--- /dev/null
+++ b/src/components/settings_modal/helpers/setting.js
@@ -0,0 +1,84 @@
+import { get, set } from 'lodash'
+export default {
+ props: {
+ path: {
+ type: String,
+ required: true
+ },
+ disabled: {
+ type: Boolean,
+ default: false
+ },
+ parentPath: {
+ type: String
+ },
+ parentInvert: {
+ type: Boolean,
+ default: false
+ },
+ expert: {
+ type: [Number, String],
+ default: 0
+ },
+ source: {
+ type: String,
+ default: 'default'
+ }
+ },
+ computed: {
+ state () {
+ const value = get(this.configSource, this.path)
+ if (value === undefined) {
+ return this.defaultState
+ } else {
+ return value
+ }
+ },
+ shouldBeDisabled () {
+ const parentValue = this.parentPath !== undefined ? get(this.configSource, this.parentPath) : null
+ return this.disabled || (parentValue !== null ? (this.parentInvert ? parentValue : !parentValue) : false)
+ },
+ configSource () {
+ switch (this.source) {
+ case 'profile':
+ return this.$store.state.profileConfig
+ default:
+ return this.$store.getters.mergedConfig
+ }
+ },
+ configSink () {
+ switch (this.source) {
+ case 'profile':
+ return (k, v) => this.$store.dispatch('setProfileOption', { name: k, value: v })
+ default:
+ return (k, v) => this.$store.dispatch('setOption', { name: k, value: v })
+ }
+ },
+ defaultState () {
+ switch (this.source) {
+ case 'profile':
+ return {}
+ default:
+ return get(this.$store.getters.defaultConfig, this.path)
+ }
+ },
+ isProfileTied () {
+ return this.source === 'profile'
+ },
+ isChanged () {
+ return !this.source === 'default' && this.state !== this.defaultState
+ },
+ matchesExpertLevel () {
+ return (this.expert || 0) <= this.$store.state.config.expertLevel > 0
+ }
+ },
+ methods: {
+ update (e) {
+ console.log('U', this.path, e)
+ this.configSink(this.path, e)
+ },
+ reset () {
+ set(this.$store.getters.mergedConfig, this.path, this.defaultState)
+ }
+ }
+}