mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-18 21:16:31 +00:00
Allow arbitrary custom field value search via search param
This commit is contained in:
parent
3e9d6ff416
commit
c2dda9599a
2 changed files with 18 additions and 3 deletions
|
@ -104,12 +104,13 @@ export function useQuickSearch() {
|
||||||
// Regardless of what we do next, we also clear the code buffer here:
|
// Regardless of what we do next, we also clear the code buffer here:
|
||||||
codeBuffer.value = "";
|
codeBuffer.value = "";
|
||||||
|
|
||||||
|
// TODO: Is there a good reason to not expose custom fields via search syntax?
|
||||||
router.push({
|
router.push({
|
||||||
path: "/items",
|
path: "/items",
|
||||||
query: {
|
query: {
|
||||||
q: "",
|
q: "",
|
||||||
fieldSelector: "true",
|
fieldSelector: "true",
|
||||||
fields: [encodeURIComponent(`Barcode=${validCode}`)],
|
fields: [`Barcode=${validCode}`],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -77,6 +77,10 @@
|
||||||
const qFields = route.query.fields as string[];
|
const qFields = route.query.fields as string[];
|
||||||
if (qFields) {
|
if (qFields) {
|
||||||
fieldTuples.value = qFields.map(f => f.split("=") as [string, string]);
|
fieldTuples.value = qFields.map(f => f.split("=") as [string, string]);
|
||||||
|
// After loading for the first time, we keep track of the field tuples at this point,
|
||||||
|
// and use them as possible field values even if they're not included in the list of values for
|
||||||
|
// the given field:
|
||||||
|
fieldTuplesOnMount.value = fieldTuples.value;
|
||||||
|
|
||||||
for (const t of fieldTuples.value) {
|
for (const t of fieldTuples.value) {
|
||||||
if (t[0] && t[1]) {
|
if (t[0] && t[1]) {
|
||||||
|
@ -139,6 +143,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
const fieldTuples = ref<[string, string][]>([]);
|
const fieldTuples = ref<[string, string][]>([]);
|
||||||
|
const fieldTuplesOnMount = ref<[string, string][]>([]);
|
||||||
const fieldValuesCache = ref<Record<string, string[]>>({});
|
const fieldValuesCache = ref<Record<string, string[]>>({});
|
||||||
|
|
||||||
const { data: allFields } = useAsyncData(async () => {
|
const { data: allFields } = useAsyncData(async () => {
|
||||||
|
@ -173,6 +178,15 @@
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fieldValuesFromCache(field: string) {
|
||||||
|
const fieldValues = fieldValuesCache.value[field] ?? [];
|
||||||
|
const valuesFromFirstMount = fieldTuplesOnMount.value
|
||||||
|
.filter(([fieldName]) => fieldName === field)
|
||||||
|
.map(([_, fieldValue]) => fieldValue);
|
||||||
|
|
||||||
|
return [...valuesFromFirstMount, ...fieldValues];
|
||||||
|
}
|
||||||
|
|
||||||
watch(advanced, (v, lv) => {
|
watch(advanced, (v, lv) => {
|
||||||
if (v === false && lv === true) {
|
if (v === false && lv === true) {
|
||||||
selectedLocations.value = [];
|
selectedLocations.value = [];
|
||||||
|
@ -399,8 +413,8 @@
|
||||||
<label class="label">
|
<label class="label">
|
||||||
<span class="label-text">Field Value</span>
|
<span class="label-text">Field Value</span>
|
||||||
</label>
|
</label>
|
||||||
<select v-model="fieldTuples[idx][1]" class="select-bordered select" :items="fieldValuesCache[f[0]]">
|
<select v-model="fieldTuples[idx][1]" class="select-bordered select" :items="fieldValuesFromCache(f[0])">
|
||||||
<option v-for="v in fieldValuesCache[f[0]]" :key="v" :value="v">{{ v }}</option>
|
<option v-for="v in fieldValuesFromCache(f[0])" :key="v" :value="v">{{ v }}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
|
|
Loading…
Reference in a new issue