REST Service for POPCORN - ILIAS
alex
2025-06-06 21e9157e4ff93806321d55691af60c9e414e5e22
vue/src/pages/Users.vue
@@ -3,8 +3,9 @@
import {onMounted, reactive, ref} from "vue"
import {useRoute} from "vue-router"
import Pagination from "../components/Pagination.vue"
import {getUsers, routerBase} from "@/lib/api"
import {getUsers, routerBase, searchUsers} from "@/lib/api"
import {useRouteQuery} from '@vueuse/router'
import {onKeyStroke, useDebounceFn} from "@vueuse/core"
const route = useRoute()
const userId = route.params.userId
@@ -15,15 +16,27 @@
   data: [],
})
const offset = useRouteQuery("offset", 0, {transform: Number})
const limit = 24
const limit = 22
const error = ref(null)
onMounted(() => init(offset.value))
onMounted(() => init(offset.value, search.value))
/////// SEARCH ////////////////////////////////////////////////////////////////
const search = useRouteQuery("search", "",)// {transform: s => s.trim()})
async function _doSearch (search) {
   console.log("doSEarch", search)
   // return init(0, search)
   // TODO offset muss zurückgesetzt werden wenn die Suche neu ist
   return init(offset.value, search)
}
const doSearch = useDebounceFn(_doSearch, 333)
/////////////////////////////////////////////////////////////////////////
async function init (noffset = 0) {
   const data = await getUsers(noffset, limit)
async function init (noffset = 0, search) {
   console.log(">>> INIT", noffset, search)
   const data = await getUsers(noffset, limit, search)
   console.log(data)
   Object.assign(users, data)
   offset.value = noffset
@@ -31,8 +44,10 @@
function go (offset) {
   console.log("go to offset", offset)
   return init(offset)
   return init(offset, search.value)
}
</script>
@@ -49,7 +64,13 @@
      <div class="users">
         <Pagination :offset="users.offset" :limit="users.limit" :total="users.total" @go="go" />
         <div class="users-header">
            <div class="search">
               Search
               <input @keyup="doSearch(search)" v-model="search" type="text" size="30">
            </div>
            <Pagination :offset="users.offset" :limit="users.limit" :total="users.total" @go="go" />
         </div>
         <table class="w100p">
            <thead>
@@ -88,6 +109,15 @@
</template>
<style scoped>
<style scoped lang="stylus">
.users-header
   display flex;
   align-items center
   justify-content space-around
   margin-bottom 1em;
   margin-top -.5em;
   border 1px dotted #ccc
   background-color #eee;
</style>