From 7aa80f1c68df586c1bc637c668666d29e84c3de7 Mon Sep 17 00:00:00 2001
From: alex <alex@alexloehr.net>
Date: Wed, 04 Jun 2025 08:45:42 +0000
Subject: [PATCH] use offset in url query

---
 vue/src/pages/Users.vue |   62 +++++++++++++++++++-----------
 1 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/vue/src/pages/Users.vue b/vue/src/pages/Users.vue
index 4496c1d..82b2825 100644
--- a/vue/src/pages/Users.vue
+++ b/vue/src/pages/Users.vue
@@ -2,31 +2,36 @@
 
 import {onMounted, reactive, ref} from "vue"
 import {useRoute} from "vue-router"
+import Pagination from "../components/Pagination.vue"
+import {getUsers} from "@/lib/api"
+import {useRouteQuery} from '@vueuse/router'
 
 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 offset = useRouteQuery("offset", 0, {transform: Number})
+const limit = 24
 const error = ref(null)
 
-onMounted(init)
+onMounted(() => init(offset.value))
 
 /////////////////////////////////////////////////////////////////////////
 
-async function init () {
-   const res = await fetch(`/api/users?token=jiuGfr432898D90290kjfsldkfn3hh8F`)
-   const data = await res.json()
+async function init (noffset = 0) {
+   const data = await getUsers(noffset, limit)
    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 to offset", offset)
+   return init(offset)
 }
 
 </script>
@@ -34,12 +39,19 @@
 <template>
 
    <div>
-      <h1>Users</h1>
+
+      <h1>
+         ILIAS Users
+         <!--         <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">
-         <table>
+
+         <Pagination :offset="users.offset" :limit="users.limit" :total="users.total" @go="go" />
+
+         <table class="w100p">
             <thead>
                <tr>
                   <th>usr_id</th>
@@ -47,27 +59,31 @@
                   <th>firstname</th>
                   <th>lastname</th>
                   <th>gender</th>
-                  <th>email</th>
+                  <!--                  <th>email</th>-->
                   <th>institution</th>
                   <th>department</th>
                </tr>
             </thead>
             <tbody>
                <tr v-for="user in users.data">
-                  <td>{{user.usr_id}}</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>
+                     <RouterLink :to="`/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>
                </tr>
             </tbody>
          </table>
       </div>
 
-      <pre>{{ users }}</pre>
+      <!--      <pre>{{ users }}</pre>-->
    </div>
 
 </template>

--
Gitblit v1.8.0