-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web-ui): replace dropdown menus with checkboxes
- Loading branch information
1 parent
e00c458
commit 60d7c1c
Showing
14 changed files
with
351 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<script setup> | ||
const model = defineModel({ required: true }); | ||
const slots = defineSlots(); | ||
const props = defineProps({ | ||
class: { | ||
type: String, | ||
default: "" | ||
}, | ||
desc: { | ||
type: String, | ||
default: null | ||
}, | ||
id: { | ||
type: String, | ||
required: true | ||
}, | ||
label: { | ||
type: String, | ||
default: null | ||
}, | ||
localePrefix: { | ||
type: String, | ||
default: "missing-prefix" | ||
}, | ||
checkedByDef: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
uncheckedByDef: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}); | ||
// Add the mandatory class values | ||
const extendedClassStr = (() => { | ||
let values = props.class.split(" "); | ||
if (!values.includes("form-check")) { | ||
values.push("form-check"); | ||
} | ||
return values.join(" "); | ||
})(); | ||
// Determine the true/false values for the checkbox | ||
const checkboxValues = (() => { | ||
const mappedValues = (() => { | ||
// Try literal values first | ||
let value = model.value; | ||
if (value === true || value === false) { | ||
return [true, false]; | ||
} | ||
if (value === 1 || value === 0) { | ||
return [1, 0]; | ||
} | ||
// Try mapping strings next (first in the list will be used as fallback) | ||
const stringPairs = [ | ||
["true", "false"], | ||
["1", "0"], | ||
["enabled", "disabled"], | ||
["enable", "disable"], | ||
["yes", "no"], | ||
["on", "off"] | ||
]; | ||
value = `${value}`.toLowerCase().trim(); | ||
for (const pair of stringPairs) { | ||
if (value === pair[0] || value === pair[1]) { | ||
return pair; | ||
} | ||
} | ||
// Return default if nothing matches | ||
console.error(`Checkbox value ${model.value} (${value}) did not match any acceptable pattern!`); | ||
return stringPairs[0]; | ||
})(); | ||
return { truthy: mappedValues[0], falsy: mappedValues[1] }; | ||
})(); | ||
const labelField = props.label ?? `${props.localePrefix}.${props.id}`; | ||
const descField = props.desc ?? `${props.localePrefix}.${props.id}_desc`; | ||
const showDesc = props.desc !== "" || Object.entries(slots).length > 0; | ||
const showDefValue = props.checkedByDef || props.uncheckedByDef; | ||
const defValue = props.checkedByDef === props.uncheckedByDef ? "INVALID" : | ||
props.checkedByDef ? "_common.enabled_def_cbox" : "_common.disabled_def_cbox"; | ||
</script> | ||
<template> | ||
<div :class="extendedClassStr"> | ||
<label :for="props.id" :class="`form-check-label${showDesc ? ' mb-2' : ''}`"> | ||
{{ $t(labelField) }} | ||
<div class="mt-0 form-text" v-if="showDefValue"> | ||
{{ $t(defValue) }} | ||
</div> | ||
</label> | ||
<input type="checkbox" | ||
class="form-check-input" | ||
:id="props.id" | ||
v-model="model" | ||
:true-value="checkboxValues.truthy" | ||
:false-value="checkboxValues.falsy" /> | ||
<div class="form-text" v-if="showDesc"> | ||
{{ $t(descField) }} | ||
<slot></slot> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.