From d13e2360b6dad80da567348c1013353a2fc2297e Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Thu, 23 Oct 2025 14:28:10 +0000
Subject: [PATCH] GS-2375

---
 vue/src/pages/Users.vue |  110 +++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 82 insertions(+), 28 deletions(-)

diff --git a/vue/src/pages/Users.vue b/vue/src/pages/Users.vue
index 30b3b7c..6d7ff13 100644
--- a/vue/src/pages/Users.vue
+++ b/vue/src/pages/Users.vue
@@ -3,38 +3,60 @@
 import {onMounted, reactive, ref} from "vue"
 import {useRoute} from "vue-router"
 import Pagination from "../components/Pagination.vue"
+import {getUsers, routerBase, searchUsers} from "@/lib/api"
+import {useRouteQuery} from '@vueuse/router'
+import {onKeyStroke, useDebounceFn} from "@vueuse/core"
+
+document.title = `Users | globus-ilias-rest`
 
 const route = useRoute()
 const userId = route.params.userId
 const users = reactive({
    total: 0,
-   offset: 0,
+   offset: 0, // NO! USE offset BELOW!
    limit: 10,
    data: [],
 })
-const limit = 24
+const offset = useRouteQuery("offset", 0, {transform: Number})
+const limit = 22
 const error = ref(null)
 
-onMounted(init)
+onMounted(() => init(offset.value, search.value))
+
+/////// SEARCH ////////////////////////////////////////////////////////////////
+
+const search = useRouteQuery("search", "",)// {transform: s => s.trim()})
+async function _doSearch (asearch) {
+   console.log("doSEarch", asearch)
+   // return init(0, asearch)
+   // TODO offset muss zurückgesetzt werden wenn die Suche neu ist
+   // search.value = asearch
+   return init(0, asearch)
+   // return init(offset.value, asearch)
+}
+const doSearch = useDebounceFn(_doSearch, 333)
+
+function resetSearch () {
+   search.value = ''
+   init(0, "")
+}
 
 /////////////////////////////////////////////////////////////////////////
 
-async function init (offset = 0) {
-   const res = await fetch(`/api/users?offset=${offset}&limit=${limit}&token=jiuGfr432898D90290kjfsldkfn3hh8F`)
-   const data = await res.json()
+async function init (noffset = 0, search) {
+   console.log(">>> INIT", noffset, search)
+   const data = await getUsers(noffset, limit, search)
    console.log(data)
-   if (res.status === 200) {
-      Object.assign(users,data)
-   }
-   else {
-      error.value = `ERROR: ${res.status}`
-   }
+   Object.assign(users, data)
+   offset.value = noffset
 }
 
 function go (offset) {
-   console.log("go", offset)
-   return init(offset)
+   console.log("go to offset", offset)
+   return init(offset, search.value)
 }
+
+
 
 </script>
 
@@ -44,14 +66,23 @@
 
       <h1>
          ILIAS Users
-<!--         <small>{{users.offset}} - {{users.offset+users.data.length}} von {{users.total}}</small>-->
+         <!--         <small>{{users.offset}} - {{users.offset+users.data.length}} von {{users.total}}</small>-->
       </h1>
       <p>{{ userId }}</p>
       <p v-if="error">{{ error }}</p>
 
       <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">
+               <button type="button" @click="resetSearch">
+                  <div style="transform:scale(1.4); font-weight: bold;">&times;</div>
+               </button>
+            </div>
+            <Pagination :offset="users.offset" :limit="users.limit" :total="users.total" :current="users.data.length" @go="go" />
+         </div>
 
          <table class="w100p">
             <thead>
@@ -61,7 +92,7 @@
                   <th>firstname</th>
                   <th>lastname</th>
                   <th>gender</th>
-<!--                  <th>email</th>-->
+                  <!--                  <th>email</th>-->
                   <th>institution</th>
                   <th>department</th>
                </tr>
@@ -69,27 +100,50 @@
             <tbody>
                <tr v-for="user in users.data">
                   <td>
-                     <RouterLink :to="`/ui/user/${user.usr_id}`">
-                        {{user.usr_id}}
+                     <RouterLink :to="`${routerBase}/ui/user/${user.usr_id}`">
+                        {{ user.usr_id }}
                      </RouterLink>
                   </td>
-                  <td>{{user.login}}</td>
-                  <td>{{user.firstname}}</td>
-                  <td>{{user.lastname}}</td>
-                  <td>{{user.gender}}</td>
-<!--                  <td>{{ user.email}}</td>-->
-                  <td>{{user.institution}}</td>
-                  <td>{{user.department}}</td>
+                  <td>{{ user.login }}</td>
+                  <td>{{ user.firstname }}</td>
+                  <td>{{ user.lastname }}</td>
+                  <td>{{ user.gender }}</td>
+                  <!--                  <td>{{ user.email}}</td>-->
+                  <td>{{ user.institution }}</td>
+                  <td>{{ user.department }}</td>
                </tr>
             </tbody>
          </table>
       </div>
 
-      <pre>{{ users }}</pre>
+      <!--      <pre>{{ users }}</pre>-->
    </div>
 
 </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;
+
+.search
+   display flex;
+   gap .33em
+   align-items center;
+   button
+      display flex;
+      //background-color blue
+      align-items stretch
+      display grid
+      grid-template-columns 1fr
+      padding 0
+      min-width 1.33em
+      cursor pointer;
 
 </style>

--
Gitblit v1.8.0