2021-05-25 13:58:01 +00:00
|
|
|
<template>
|
2024-10-08 12:31:43 +00:00
|
|
|
<q-select v-model="selected" filled :label="label" :options="users" :option-label="showName" option-value="userid"
|
|
|
|
map-options use-input input-debounce="0" @filter="filterFn" />
|
2021-05-25 13:58:01 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2024-04-11 08:31:19 +00:00
|
|
|
import { computed, defineComponent, PropType, onBeforeMount, ref } from 'vue';
|
2021-05-25 13:58:01 +00:00
|
|
|
import { useUserStore } from '@flaschengeist/api';
|
2024-10-08 12:31:43 +00:00
|
|
|
import { DisplayNameMode } from '../models';
|
2021-05-25 13:58:01 +00:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'UserSelector',
|
|
|
|
props: {
|
|
|
|
label: { type: String, default: 'Benutzer' },
|
|
|
|
modelValue: { default: undefined, type: Object as PropType<FG.User | undefined> },
|
|
|
|
},
|
|
|
|
emits: { 'update:modelValue': (user: FG.User) => !!user },
|
|
|
|
setup(props, { emit }) {
|
|
|
|
const userStore = useUserStore();
|
|
|
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
void userStore.getUsers(false);
|
2024-10-08 12:31:43 +00:00
|
|
|
void userStore.getDisplayNameModeSetting(true);
|
2021-05-25 13:58:01 +00:00
|
|
|
});
|
|
|
|
|
2024-04-11 08:31:19 +00:00
|
|
|
const users = computed(() =>
|
|
|
|
userStore.users.filter((user) => {
|
|
|
|
let names = filter.value.toLowerCase().split(' ');
|
|
|
|
if (names.length < 1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (names.length === 1) {
|
|
|
|
let name = names[0];
|
|
|
|
return (
|
|
|
|
user.lastname.toLowerCase().includes(name) ||
|
|
|
|
user.firstname.toLowerCase().includes(name)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (names.length === 2) {
|
|
|
|
let name1 = names[0];
|
|
|
|
let name2 = names[1];
|
|
|
|
return (
|
|
|
|
(user.lastname.toLowerCase().includes(name1) &&
|
|
|
|
user.firstname.toLowerCase().includes(name2)) ||
|
|
|
|
(user.lastname.toLowerCase().includes(name2) &&
|
|
|
|
user.firstname.toLowerCase().includes(name1))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
const filter = ref<string>('');
|
|
|
|
const filterFn = (val: string, update: () => void) => {
|
|
|
|
filter.value = val;
|
|
|
|
update();
|
|
|
|
};
|
2021-05-25 13:58:01 +00:00
|
|
|
const selected = computed({
|
|
|
|
get: () => props.modelValue,
|
|
|
|
set: (value: FG.User | undefined) => (value ? emit('update:modelValue', value) : undefined),
|
|
|
|
});
|
2024-10-08 12:31:43 +00:00
|
|
|
function showName(user: FG.User) {
|
|
|
|
switch (userStore.userSettings.display_name) {
|
|
|
|
case DisplayNameMode.DISPLAYNAME:
|
|
|
|
return user.display_name;
|
|
|
|
case DisplayNameMode.FIRSTNAME:
|
|
|
|
return user.firstname;
|
|
|
|
case DisplayNameMode.LASTNAME:
|
|
|
|
return user.lastname;
|
|
|
|
case DisplayNameMode.FIRSTNAME_LASTNAME:
|
|
|
|
return `${user.firstname} ${user.lastname}`;
|
|
|
|
case DisplayNameMode.LASTNAME_FIRSTNAME:
|
|
|
|
return `${user.lastname}, ${user.firstname}`;
|
|
|
|
}
|
|
|
|
}
|
2021-05-25 13:58:01 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
selected,
|
|
|
|
users,
|
2024-04-11 08:31:19 +00:00
|
|
|
filterFn,
|
2024-10-08 12:31:43 +00:00
|
|
|
showName,
|
2021-05-25 13:58:01 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|