mirror of
https://github.com/jpros/tacticalrmm-web.git
synced 2026-03-02 08:12:12 +00:00
45 lines
899 B
JavaScript
45 lines
899 B
JavaScript
|
|
import { ref } from "vue"
|
|
import { fetchUsers } from "@/api/accounts"
|
|
import { formatUserOptions } from "@/utils/format"
|
|
|
|
export function useUserDropdown() {
|
|
|
|
const userOptions = ref([])
|
|
const userDropdownLoading = ref(false)
|
|
|
|
async function getUserOptions(flat = false) {
|
|
userOptions.value = formatUserOptions(await fetchUsers(), flat)
|
|
}
|
|
|
|
function getDynamicUserOptions(val, update, abort) {
|
|
if (!val || val.length < 2) {
|
|
abort()
|
|
return
|
|
}
|
|
|
|
update(async () => {
|
|
userDropdownLoading.value = true
|
|
|
|
const params = {
|
|
search: val.toLowerCase()
|
|
}
|
|
|
|
const options = await fetchUsers(params)
|
|
|
|
userOptions.value = options.map(user => user.username)
|
|
userDropdownLoading.value = false
|
|
})
|
|
}
|
|
|
|
return {
|
|
//data
|
|
userOptions,
|
|
userDropdownLoading,
|
|
|
|
//methods
|
|
getUserOptions,
|
|
getDynamicUserOptions
|
|
}
|
|
}
|