fixes for diabled state, tri-state boolean and access control

This commit is contained in:
Henry Jameson 2023-03-22 00:00:52 +02:00
commit 6992439c92
7 changed files with 115 additions and 8 deletions

View file

@ -3,13 +3,28 @@ import Setting from './setting.js'
export default {
...Setting,
props: {
...Setting.props,
indeterminateState: [String, Object]
},
components: {
...Setting.components,
Checkbox
},
computed: {
...Setting.computed,
isIndeterminate () {
return this.visibleState === this.indeterminateState
}
},
methods: {
...Setting.methods,
getValue (e) {
// Basic tri-state toggle implementation
if (!!this.indeterminateState && !e && this.visibleState === true) {
// If we have indeterminate state, switching from true to false first goes through indeterminate
return this.indeterminateState
}
return e
}
}

View file

@ -4,13 +4,15 @@
class="BooleanSetting"
>
<Checkbox
:model-value="draftMode ? draft :state"
:model-value="visibleState"
:disabled="shouldBeDisabled"
:indeterminate="isIndeterminate"
@update:modelValue="update"
>
<span
v-if="!!$slots.default"
class="label"
:class="{ 'faint': shouldBeDisabled }"
>
<template v-if="backendDescription">
{{ backendDescriptionLabel }}
@ -29,6 +31,7 @@
<p
v-if="backendDescriptionDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ backendDescriptionDescription + ' ' }}
</p>

View file

@ -49,13 +49,13 @@
</template>
</Popover>
<Popover
v-if="$parent.canHardReset"
trigger="hover"
:trigger-attrs="{ 'aria-label': $t('settings.hard_reset_value_tooltip') }"
>
<template #trigger>
&nbsp;
<button
v-if="$parent.canHardReset"
class="button button-default btn"
type="button"
:title="$t('settings.hard_reset_value')"

View file

@ -3,7 +3,7 @@
v-if="matchesExpertLevel"
class="NumberSetting"
>
<label :for="path">
<label :for="path" :class="{ 'faint': shouldBeDisabled }">
<template v-if="backendDescription">
{{ backendDescriptionLabel + ' ' }}
</template>
@ -16,7 +16,7 @@
class="number-input"
type="number"
:step="step || 1"
:disabled="disabled"
:disabled="shouldBeDisabled"
:min="min || 0"
:value="realDraftMode ? draft :state"
@change="update"
@ -31,6 +31,7 @@
<p
v-if="backendDescriptionDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ backendDescriptionDescription + ' ' }}
</p>

View file

@ -65,6 +65,9 @@ export default {
return value
}
},
visibleState () {
return this.realDraftMode ? this.draft : this.state
},
realSource () {
return this.source || this.defaultSource
},
@ -88,7 +91,6 @@ export default {
return this.disabled || (parentValue !== null ? (this.parentInvert ? parentValue : !parentValue) : false)
},
configSource () {
console.log('SRC', this.realSource)
switch (this.realSource) {
case 'profile':
return this.$store.state.profileConfig

View file

@ -3,7 +3,7 @@
v-if="matchesExpertLevel"
class="StringSetting"
>
<label :for="path">
<label :for="path" :class="{ 'faint': shouldBeDisabled }">
<template v-if="backendDescription">
{{ backendDescriptionLabel + ' ' }}
</template>
@ -15,7 +15,7 @@
:id="path"
class="string-input"
step="1"
:disabled="disabled"
:disabled="shouldBeDisabled"
:value="realDraftMode ? draft : state"
@change="update"
>
@ -29,6 +29,7 @@
<p
v-if="backendDescriptionDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ backendDescriptionDescription + ' ' }}
</p>