|
|
@@ -123,7 +123,7 @@ const i18n = useI18n()
|
|
|
const accessToItem = (access: Access): AccessListItem => {
|
|
|
return {
|
|
|
id: access.id,
|
|
|
- title: access.person ? `${access.person.givenName} ${access.person.name}` : i18n.t('unknown')
|
|
|
+ title: access.person ? `${access.person.name} ${access.person.givenName}` : i18n.t('unknown')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -142,7 +142,7 @@ const nameFilter: Ref<string | null> = ref(null)
|
|
|
* Query transmise à l'API lors des changements de filtre de recherche
|
|
|
*/
|
|
|
const query: ComputedRef<AnyJson> = computed(() => {
|
|
|
- let q: AnyJson = {'groups[]': 'access_people_ref'}
|
|
|
+ let q: AnyJson = {'groups[]': 'access_people_ref', 'order[name]': 'asc'}
|
|
|
|
|
|
if (!initialized.value && props.modelValue) {
|
|
|
if (Array.isArray(props.modelValue) && props.modelValue.length > 0) {
|
|
|
@@ -153,7 +153,7 @@ const query: ComputedRef<AnyJson> = computed(() => {
|
|
|
return q
|
|
|
}
|
|
|
|
|
|
- if (nameFilter.value !== null) {
|
|
|
+ if (nameFilter.value) {
|
|
|
q['fullname'] = nameFilter.value
|
|
|
}
|
|
|
|
|
|
@@ -169,23 +169,32 @@ const { data: collection, pending, refresh } = await fetchCollection(
|
|
|
query
|
|
|
)
|
|
|
initialized.value = true
|
|
|
+// On relance une requête pour récupérer la première page
|
|
|
+refresh()
|
|
|
|
|
|
/**
|
|
|
* Contenu de la liste autocomplete
|
|
|
*/
|
|
|
const items: ComputedRef<Array<AccessListItem>> = computed(() => {
|
|
|
- let items = props.modelValue.map(getFromStore).map(accessToItem)
|
|
|
+ if (pending.value || !collection.value) {
|
|
|
+ return []
|
|
|
+ }
|
|
|
|
|
|
//@ts-ignore
|
|
|
const fetchedItems = collection.value.items.map(accessToItem)
|
|
|
|
|
|
- for (let item of fetchedItems) {
|
|
|
- if (!items.some((existingItem: AccessListItem) => existingItem.id === item.id)) {
|
|
|
- items.push(item)
|
|
|
+ // move the active items to the top and sort by name
|
|
|
+ fetchedItems.sort((a, b) => {
|
|
|
+ if (props.modelValue.includes(a.id) && !props.modelValue.includes(b.id)) {
|
|
|
+ return -1
|
|
|
+ } else if (!props.modelValue.includes(a.id) && props.modelValue.includes(b.id)) {
|
|
|
+ return 1
|
|
|
+ } else {
|
|
|
+ return a.title.localeCompare(b.title)
|
|
|
}
|
|
|
- }
|
|
|
+ })
|
|
|
|
|
|
- return ArrayUtils.sortObjectsByProp(items, 'title') as Array<AccessListItem>
|
|
|
+ return fetchedItems
|
|
|
})
|
|
|
|
|
|
|
|
|
@@ -220,7 +229,6 @@ const onUpdateModelValue = (event: Array<number>) => {
|
|
|
}
|
|
|
emit('update:model-value', event)
|
|
|
}
|
|
|
-
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|