REST Service for POPCORN - ILIAS
alex
2025-06-06 e6b083fb7441ebdf65230517509af3c55c0c808c
GS-2147
5 files modified
42 ■■■■ changed files
lib/db.js 2 ●●● patch | view | raw | blame | history
lib/search.js 23 ●●●● patch | view | raw | blame | history
settings.default.json 4 ●●●● patch | view | raw | blame | history
vue/src/assets/styles.styl 7 ●●●●● patch | view | raw | blame | history
vue/src/pages/Users.vue 6 ●●●●● patch | view | raw | blame | history
lib/db.js
@@ -56,7 +56,7 @@
   }
   else {
      const ids = searchLib.search(search)
      if (!ids.length) return getUserSearchQuery(offset, limit) // nothing found
      // if (!ids.length) return getUserSearchQuery(offset, limit) // nothing found
      return `SELECT ${sel}
              FROM ${database}.usr_data AS ud
              WHERE login REGEXP '^[0-9]+$'
lib/search.js
@@ -1,11 +1,14 @@
const _ = require("lodash")
const {Index, Document, Worker} = require("flexsearch")
const settings = require("../settings")
const fs = require("node:fs")
/////////////////////////////////////////////////////////////////////////
// Message index
const options = {
   tokenize: "full",
   // tokenize: "full",
   tokenize: "forward",
   split: true,
}
@@ -77,8 +80,17 @@
async function doIndex () {
   const start = Date.now()
   console.log("++ START indexing Users...")
   let users = require("../users.json")
   // users = users.slice(10)
   const {readFromFile, file} = settings.search
   let users
   if (readFromFile) {
      users = fs.readFileSync(file, "utf8")
      users = JSON.parse(users)
   }
   else {
      // TODO zweite möglichkeit "readFromApi" implementieren
   }
   for (const user of users) {
      addUser(user)
@@ -109,8 +121,9 @@
/////// idxMessage FNS ////////////////////////////////////////////////////////////////
function getUserString (user) {
   const {usr_id, firstname, lastname} = user
   return `${usr_id} ${firstname} ${lastname}`.trim()
   const {usr_id, firstname, lastname, institution, department} = user
   return `${usr_id} ${firstname} ${lastname} ${institution} ${department}`.trim()
   // return `${usr_id} ${firstname} ${lastname}`.trim()
}
function addUser (user) {
settings.default.json
@@ -7,5 +7,9 @@
      "database": "ilias",
      "user": "root",
      "password": "paaa322ss"
   },
   "search": {
      "readFromFile": true,
      "file": "users-local.json"
   }
}
vue/src/assets/styles.styl
@@ -33,3 +33,10 @@
   white-space nowrap
input[type=text], input[type=password]
   padding .11em .22em
   border 3px solid #aaa
   &:focus
      border 3px solid orange
      outline none
vue/src/pages/Users.vue
@@ -19,16 +19,18 @@
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, 500)
const doSearch = useDebounceFn(_doSearch, 333)
/////////////////////////////////////////////////////////////////////////