[feat] sort nam eby displaymode setting

This commit is contained in:
Tim Gröger 2024-10-08 14:31:43 +02:00
parent cf82684ce4
commit e99d123156
2 changed files with 21 additions and 12 deletions

View File

@ -1,21 +1,12 @@
<template> <template>
<q-select <q-select v-model="selected" filled :label="label" :options="users" :option-label="showName" option-value="userid"
v-model="selected" map-options use-input input-debounce="0" @filter="filterFn" />
filled
:label="label"
:options="users"
option-label="display_name"
option-value="userid"
map-options
use-input
input-debounce="0"
@filter="filterFn"
/>
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, defineComponent, PropType, onBeforeMount, ref } from 'vue'; import { computed, defineComponent, PropType, onBeforeMount, ref } from 'vue';
import { useUserStore } from '@flaschengeist/api'; import { useUserStore } from '@flaschengeist/api';
import { DisplayNameMode } from '../models';
export default defineComponent({ export default defineComponent({
name: 'UserSelector', name: 'UserSelector',
@ -29,6 +20,7 @@ export default defineComponent({
onBeforeMount(() => { onBeforeMount(() => {
void userStore.getUsers(false); void userStore.getUsers(false);
void userStore.getDisplayNameModeSetting(true);
}); });
const users = computed(() => const users = computed(() =>
@ -66,11 +58,26 @@ export default defineComponent({
get: () => props.modelValue, get: () => props.modelValue,
set: (value: FG.User | undefined) => (value ? emit('update:modelValue', value) : undefined), set: (value: FG.User | undefined) => (value ? emit('update:modelValue', value) : undefined),
}); });
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}`;
}
}
return { return {
selected, selected,
users, users,
filterFn, filterFn,
showName,
}; };
}, },
}); });

View File

@ -1,6 +1,7 @@
import { FG_Plugin } from '@flaschengeist/types'; import { FG_Plugin } from '@flaschengeist/types';
import { defineAsyncComponent } from 'vue'; import { defineAsyncComponent } from 'vue';
import routes from './routes'; import routes from './routes';
import { DisplayNameMode } from './models';
const plugin: FG_Plugin.Plugin = { const plugin: FG_Plugin.Plugin = {
id: 'users', id: 'users',
@ -27,3 +28,4 @@ const plugin: FG_Plugin.Plugin = {
}; };
export default plugin; export default plugin;
export { DisplayNameMode };