REST Service for POPCORN - ILIAS
alex
2025-08-01 39bb717c40c538bc16f1cef7d9737ac619a0ead4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<script setup>
 
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, // NO! USE offset BELOW!
   limit: 10,
   data: [],
})
const offset = useRouteQuery("offset", 0, {transform: Number})
const limit = 22
const error = ref(null)
 
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 (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
}
 
function go (offset) {
   console.log("go to offset", offset)
   return init(offset, search.value)
}
 
 
 
</script>
 
<template>
 
   <div>
 
      <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">
 
         <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>
               <tr>
                  <th>usr_id</th>
                  <th>login</th>
                  <th>firstname</th>
                  <th>lastname</th>
                  <th>gender</th>
                  <!--                  <th>email</th>-->
                  <th>institution</th>
                  <th>department</th>
               </tr>
            </thead>
            <tbody>
               <tr v-for="user in users.data">
                  <td>
                     <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>
               </tr>
            </tbody>
         </table>
      </div>
 
      <!--      <pre>{{ users }}</pre>-->
   </div>
 
</template>
 
<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>