|
|
@@ -30,7 +30,7 @@ Champs autocomplete dédié à la recherche des Accesses d'une structure
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import type { PropType, ComputedRef, Ref } from 'vue'
|
|
|
+import type {PropType, ComputedRef, Ref, WatchStopHandle} from 'vue'
|
|
|
import { computed } from 'vue'
|
|
|
import * as _ from 'lodash-es'
|
|
|
import { useEntityFetch } from '~/composables/data/useEntityFetch'
|
|
|
@@ -161,12 +161,11 @@ interface ListItem {
|
|
|
const { fetchCollection } = useEntityFetch()
|
|
|
const i18n = useI18n()
|
|
|
|
|
|
-
|
|
|
const activeIds = computed(() => {
|
|
|
if (Array.isArray(props.modelValue)) {
|
|
|
return props.modelValue
|
|
|
}
|
|
|
- if (props.modelValue !== null && typeof props.modelValue === 'object') {
|
|
|
+ if (props.modelValue !== null) {
|
|
|
return [props.modelValue]
|
|
|
}
|
|
|
return []
|
|
|
@@ -176,19 +175,27 @@ const activeIds = computed(() => {
|
|
|
/**
|
|
|
* Query transmise à l'API lors de l'initialisation afin de récupérer les items actifs
|
|
|
*/
|
|
|
-const queryActive = new Query(
|
|
|
- new OrderBy(props.listLabel, ORDER_BY_DIRECTION.ASC),
|
|
|
- new PageFilter(ref(1), ref(20)),
|
|
|
- new InArrayFilter(props.listValue, activeIds),
|
|
|
- )
|
|
|
+const queryActive = computed(() => {
|
|
|
+ return new Query(
|
|
|
+ new OrderBy(props.listLabel, ORDER_BY_DIRECTION.ASC),
|
|
|
+ new PageFilter(ref(1), ref(20)),
|
|
|
+ new InArrayFilter(props.listValue, activeIds),
|
|
|
+ )
|
|
|
+ }
|
|
|
+)
|
|
|
|
|
|
/**
|
|
|
* On commence par fetcher les models déjà actifs, pour affichage des labels correspondant
|
|
|
*/
|
|
|
const {
|
|
|
data: collectionActive,
|
|
|
- status: statusActive
|
|
|
-} = fetchCollection(props.model, null, queryActive)
|
|
|
+ status: statusActive,
|
|
|
+ refresh: refreshActive
|
|
|
+} = fetchCollection(props.model, null, queryActive.value)
|
|
|
+
|
|
|
+const unwatch: WatchStopHandle = watch(activeIds, ()=>{
|
|
|
+ refreshActive()
|
|
|
+})
|
|
|
|
|
|
/**
|
|
|
* Saisie de l'utilisateur utilisée pour filtrer la recherche
|
|
|
@@ -260,9 +267,6 @@ const refreshDebounced: _.DebouncedFunc<() => void> = _.debounce(async () => {
|
|
|
await refreshSearch()
|
|
|
}, inputDelay)
|
|
|
|
|
|
-// ### Events
|
|
|
-const emit = defineEmits(['update:model-value'])
|
|
|
-
|
|
|
/**
|
|
|
* La recherche textuelle a changé.
|
|
|
* @param event
|
|
|
@@ -279,6 +283,8 @@ const onUpdateSearch = (event: string) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// ### Events
|
|
|
+const emit = defineEmits(['update:model-value'])
|
|
|
/**
|
|
|
* Quand un item est sélectionné
|
|
|
* @param event
|
|
|
@@ -297,6 +303,7 @@ onBeforeUnmount(() => {
|
|
|
clearNuxtData('/^' + props.model.entity + '_many_/')
|
|
|
useRepo(props.model).flush()
|
|
|
}
|
|
|
+ unwatch()
|
|
|
})
|
|
|
</script>
|
|
|
|