Skip to content

Commit eaea712

Browse files
committed
Select marks by name
1 parent b9fc552 commit eaea712

3 files changed

Lines changed: 67 additions & 4 deletions

File tree

‎frontend/src/components/FormModal.vue‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ const props = defineProps<Props>();
2424
defineEmits(['update:open']);
2525
2626
const showPassword = ref<{ [key: string]: boolean }>({});
27+
const focusedField = ref<string | null>(null);
2728
29+
const unfocus = () => {
30+
// Source - https://stackoverflow.com/a/56899483
31+
// Posted by Wilco, modified by community. See post 'Timeline' for change history
32+
// Retrieved 2026-03-08, License - CC BY-SA 4.0
33+
34+
if (document.activeElement instanceof HTMLElement) document.activeElement.blur();
35+
};
2836
</script>
2937
<template>
3038
<div
@@ -60,7 +68,7 @@ const showPassword = ref<{ [key: string]: boolean }>({});
6068
>
6169
<label :for="field.key" class="text-sm text-gray-300">{{ field.name }}</label>
6270
<select
63-
v-if="field.choices"
71+
v-if="field.choices && field.type === 'text'"
6472
:id="field.key"
6573
v-model="field.value"
6674
class="rounded-md border border-black bg-theme-nav p-2 text-white"
@@ -74,6 +82,34 @@ const showPassword = ref<{ [key: string]: boolean }>({});
7482
{{ choice.value }}
7583
</option>
7684
</select>
85+
<div v-else-if="field.choices && field.type === 'number'" class="relative inline-block">
86+
<input
87+
:id="field.key"
88+
v-model="field.value"
89+
type="number"
90+
class="w-full rounded-md border border-black bg-theme-nav p-2 text-white"
91+
:required="field.required"
92+
:list="`${field.key}-choices`"
93+
@focus="focusedField = field.key"
94+
@blur="focusedField = null"
95+
>
96+
<ul
97+
v-show="focusedField === field.key"
98+
:id="`${field.key}-choices`"
99+
class="absolute z-20 mt-1 max-h-48 w-full overflow-y-auto rounded-md border border-black bg-theme-nav shadow-lg"
100+
@mousedown.prevent
101+
>
102+
<li
103+
v-for="choice in field.choices"
104+
:key="choice.key"
105+
class="cursor-pointer px-3 py-2 text-sm text-gray-200 hover:bg-black/30 hover:text-white"
106+
@click="field.value = choice.key; unfocus()"
107+
@keydown.enter="field.value = choice.key; unfocus()"
108+
>
109+
{{ choice.value }}
110+
</li>
111+
</ul>
112+
</div>
77113
<textarea
78114
v-else-if="field.type === 'textarea'"
79115
:id="field.key"

‎frontend/src/views/Management/Devices.vue‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
<script setup lang="ts">
2+
import { storeToRefs } from 'pinia';
3+
import { onMounted } from 'vue';
24
import ManagementMenu from '@/components/ManagementMenu.vue';
35
import PaginatedTable from '@/components/PaginatedTable.vue';
46
import type { Device } from '@/models/device';
57
import { useDeviceStore } from '@/stores/devices.store';
68
7-
const { deleteDevice, editDevice } = useDeviceStore();
9+
const deviceStore = useDeviceStore();
10+
11+
const { deleteDevice, editDevice, fetch_marks } = deviceStore;
12+
13+
const { marks } = storeToRefs(deviceStore);
814
915
const queryParams = window.location.search;
1016
17+
onMounted(async () => {
18+
await fetch_marks();
19+
});
1120
</script>
1221

1322
<template>
@@ -97,6 +106,10 @@ const queryParams = window.location.search;
97106
name: 'Mark',
98107
key: 'mark',
99108
type: 'number',
109+
choices: marks.map((mark) => ({
110+
key: mark.value.toString(),
111+
value: `${mark.value} - ${mark.name}`,
112+
})),
100113
},
101114
],
102115
},
@@ -167,7 +180,7 @@ const queryParams = window.location.search;
167180
},
168181
],
169182
},
170-
function: async (device, fields) => { },
183+
function: async () => {},
171184
},
172185
]"
173186
/>

‎frontend/src/views/Management/Users.vue‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
import { storeToRefs } from 'pinia';
3+
import { onMounted } from 'vue';
24
import ManagementMenu from '@/components/ManagementMenu.vue';
35
import PaginatedTable from '@/components/PaginatedTable.vue';
46
import type { Device } from '@/models/device';
@@ -11,10 +13,18 @@ const {
1113
create_user, reset_password, delete_user, edit_user,
1214
} = useUserStore();
1315
16+
const deviceStore = useDeviceStore();
17+
1418
const {
1519
change_userdevice_marks,
16-
} = useDeviceStore();
20+
fetch_marks,
21+
} = deviceStore;
22+
23+
const { marks } = storeToRefs(deviceStore);
1724
25+
onMounted(async () => {
26+
await fetch_marks();
27+
});
1828
</script>
1929

2030
<template>
@@ -246,6 +256,10 @@ const {
246256
name: `Mark de ${device.name} (${device.ip})`,
247257
key: device.id,
248258
type: 'number',
259+
choices: marks.map((mark) => ({
260+
key: mark.value.toString(),
261+
value: `${mark.value} - ${mark.name}`,
262+
})),
249263
value: device.mark,
250264
required: true,
251265
device,

0 commit comments

Comments
 (0)