dba/sessions 
                    library moduleRA
Summary
Sessions page.
- Authors
 - Christian Grün, BaseX Team 2005-23, BSD License
 
Imports
This module is imported by 0 modules. It imports 3 modules.
Variables
Functions
4.1 dba:sessions
Arities: #3RA
dba:sessions
		  ( 
			$sort as xs:string, $error as xs:string?, $info as xs:string? ) as element(html)- sort
asxs:stringtable sort key - error
asxs:string?error message - info
asxs:string?info message 
element(html)page
Invoked by 0 functions from 0 modules
Annotations (6)
%rest:GET | () | 
%rest:path | ('/dba/sessions') | 
%rest:query-param | ('sort','{$sort}','access') | 
%rest:query-param | ('error','{$error}') | 
%rest:query-param | ('info','{$info}') | 
%output:method | ('html') | 
Source ( 64 lines)
function dba:sessions(
  $sort   as xs:string,
  $error  as xs:string?,
  $info   as xs:string?
) as element(html) {
  html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },
    <tr>
      <td>
        <form action='{ $dba:CAT }' method='post' class='update'>
        <h2>Web Sessions</h2>
        {
          let $headers := (
            map { 'key': 'id', 'label': 'ID', 'type': 'id' },
            map { 'key': 'name', 'label': 'Name' },
            map { 'key': 'value', 'label': 'Value' },
            map { 'key': 'access', 'label': 'Last Access', 'type': 'time', 'order': 'desc' },
            map { 'key': 'you', 'label': 'You' }
          )
          let $entries :=
            for $id in sessions:ids()
            let $access := sessions:accessed($id)
            let $you := if(session:id() = $id) then '✓' else '–'
            (: supported session ids (application-specific, can be extended) :)
            for $name in sessions:names($id)[. = ($config:SESSION-KEY, 'id')]
            let $value := try {
              sessions:get($id, $name)
            } catch sessions:get {
              '–' (: non-XQuery session value :)
            }
            let $string := util:chop(serialize($value, map { 'method': 'basex' }), 20)
            order by $access descending
            return map {
              'id': $id || '|' || $name,
              'name': $name,
              'value': $string,
              'access': $access,
              'you': $you
            }
          let $buttons := (
            html:button('session-kill', 'Kill', true())
          )
          let $options := map { 'sort': $sort, 'presort': 'access' }
          return html:table($headers, $entries, $buttons, map { }, $options)
        }
        </form>
      </td>
      <td class='vertical'/>
      <td>
        <h2>Database Sessions</h2>
        {
          let $headers := (
            map { 'key': 'address', 'label': 'Address' },
            map { 'key': 'user', 'label': 'User' }
          )
          let $entries := admin:sessions() ! map {
            'address': @address,
            'user': @user
          }
          return html:table($headers, $entries, (), map { }, map { })
        }
      </td>
    </tr>
  )
}4.2 dba:users-redirect
Arities: #3R
dba:users-redirect
		  ( 
			$action as xs:string, $names as xs:string*, $ids as xs:string* ) as element(rest:response)- action
asxs:stringaction to perform - names
asxs:string*names of users - ids
asxs:string*ids 
element(rest:response)redirection
Invoked by 0 functions from 0 modules
Annotations (5)
%rest:POST | () | 
%rest:path | ('/dba/sessions') | 
%rest:query-param | ('action','{$action}') | 
%rest:query-param | ('name','{$names}') | 
%rest:query-param | ('id','{$ids}') | 
Source ( 7 lines)
function dba:users-redirect(
  $action  as xs:string,
  $names   as xs:string*,
  $ids     as xs:string*
) as element(rest:response) {
  web:redirect($action, map { 'id': $ids })
}Namespaces
The following namespaces are defined:
| Prefix | Uri | 
|---|---|
| admin | http://basex.org/modules/admin | 
| config | dba/config | 
| dba | dba/sessions 2 | 
| html | dba/html | 
| output | http://www.w3.org/2010/xslt-xquery-serialization | 
| rest | http://exquery.org/ns/restxq | 
| session | http://basex.org/modules/session | 
| sessions | http://basex.org/modules/sessions | 
| util | dba/util | 
| web | http://basex.org/modules/web | 
| xs | http://www.w3.org/2001/XMLSchema | 
6 RestXQ
Paths defined 2.
| Path | Method | Function | 
|---|---|---|
| /dba/sessions | GET | dba:sessions#3 | 
| /dba/sessions | POST | dba:users-redirect#3 | 
Source Code
(:~
 : Sessions page.
 :
 : @author Christian Grün, BaseX Team 2005-23, BSD License
 :)
module namespace dba = 'dba/sessions';
import module namespace config = 'dba/config' at '../lib/config.xqm';
import module namespace html = 'dba/html' at '../lib/html.xqm';
import module namespace util = 'dba/util' at '../lib/util.xqm';
(:~ Top category :)
declare variable $dba:CAT := 'sessions';
(:~
 : Sessions page.
 : @param  $sort   table sort key
 : @param  $error  error message
 : @param  $info   info message
 : @return page
 :)
declare
  %rest:GET
  %rest:path('/dba/sessions')
  %rest:query-param('sort',  '{$sort}', 'access')
  %rest:query-param('error', '{$error}')
  %rest:query-param('info',  '{$info}')
  %output:method('html')
function dba:sessions(
  $sort   as xs:string,
  $error  as xs:string?,
  $info   as xs:string?
) as element(html) {
  html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },
    <tr>
      <td>
        <form action='{ $dba:CAT }' method='post' class='update'>
        <h2>Web Sessions</h2>
        {
          let $headers := (
            map { 'key': 'id', 'label': 'ID', 'type': 'id' },
            map { 'key': 'name', 'label': 'Name' },
            map { 'key': 'value', 'label': 'Value' },
            map { 'key': 'access', 'label': 'Last Access', 'type': 'time', 'order': 'desc' },
            map { 'key': 'you', 'label': 'You' }
          )
          let $entries :=
            for $id in sessions:ids()
            let $access := sessions:accessed($id)
            let $you := if(session:id() = $id) then '✓' else '–'
            (: supported session ids (application-specific, can be extended) :)
            for $name in sessions:names($id)[. = ($config:SESSION-KEY, 'id')]
            let $value := try {
              sessions:get($id, $name)
            } catch sessions:get {
              '–' (: non-XQuery session value :)
            }
            let $string := util:chop(serialize($value, map { 'method': 'basex' }), 20)
            order by $access descending
            return map {
              'id': $id || '|' || $name,
              'name': $name,
              'value': $string,
              'access': $access,
              'you': $you
            }
          let $buttons := (
            html:button('session-kill', 'Kill', true())
          )
          let $options := map { 'sort': $sort, 'presort': 'access' }
          return html:table($headers, $entries, $buttons, map { }, $options)
        }
        </form>
      </td>
      <td class='vertical'/>
      <td>
        <h2>Database Sessions</h2>
        {
          let $headers := (
            map { 'key': 'address', 'label': 'Address' },
            map { 'key': 'user', 'label': 'User' }
          )
          let $entries := admin:sessions() ! map {
            'address': @address,
            'user': @user
          }
          return html:table($headers, $entries, (), map { }, map { })
        }
      </td>
    </tr>
  )
};
(:~
 : Redirects to the specified action.
 : @param  $action  action to perform
 : @param  $names   names of users
 : @param  $ids     ids
 : @return redirection
 :)
declare
  %rest:POST
  %rest:path('/dba/sessions')
  %rest:query-param('action', '{$action}')
  %rest:query-param('name',   '{$names}')
  %rest:query-param('id',     '{$ids}')
function dba:users-redirect(
  $action  as xs:string,
  $names   as xs:string*,
  $ids     as xs:string*
) as element(rest:response) {
  web:redirect($action, map { 'id': $ids })
};