dba/sessions  library module
RA

Summary

Sessions page.
Tags

Author: Christian Grün, BaseX Team 2005-21, BSD License

__source : sessions/sessions-list.xqm

Related documents
ViewDescriptionFormat
xqdocxqDoc xml file from the source modulexml
xqparsexqparse xml file from the source modulexml

Imports

This module is imported by 0 modules. It imports 3 modules.

(None)
imports
this
imports

Variables

3.1 $dba:CAT

Summary
Top category
Type
xs:string

Functions

4.1 dba:sessions

Arities: dba:sessions#3RA

Summary
Sessions page.
Signature
dba:sessions ( $sort as xs:string, $error as xs:string?, $info as xs:string? )  as element(html)
Parameters
  • sort as xs:string table sort key
  • error as xs:string? error message
  • info as xs:string? info message
Return
  • element(html)page
Invokes 12 functions from 6 modules
  • html:button#3
  • html:table#5
  • html:wrap#2
  • util:chop#2
  • {http://basex.org/modules/admin}sessions#0
  • {http://basex.org/modules/session}id#0
  • {http://basex.org/modules/sessions}accessed#1
  • {http://basex.org/modules/sessions}get#2
  • {http://basex.org/modules/sessions}ids#0
  • {http://basex.org/modules/sessions}names#1
  • {http://www.w3.org/2005/xpath-functions}serialize#2
  • {http://www.w3.org/2005/xpath-functions}true#0
Invoked by 0 functions from 0 modules
    Annotations
    %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': 'dateTime', '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: dba:users-redirect#3R

    Summary
    Redirects to the specified action.
    Signature
    dba:users-redirect ( $action as xs:string, $names as xs:string*, $ids as xs:string* )  as element(rest:response)
    Parameters
    • action as xs:string action to perform
    • names as xs:string* names of users
    • ids as xs:string* ids
    Return
    • element(rest:response)redirection
    Invokes 1 functions from 1 modules
    • {http://basex.org/modules/web}redirect#2
    Invoked by 0 functions from 0 modules
      Annotations
      %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:

      PrefixUri
      configdba/config
      dbadba/sessions 2
      htmldba/html
      outputhttp://www.w3.org/2010/xslt-xquery-serialization
      resthttp://exquery.org/ns/restxq
      utildba/util

      6 RestXQ

      Paths defined 2.

      PathMethodFunction
      /dba/sessionsGETdba:sessions#3
      /dba/sessionsPOSTdba:users-redirect#3

      Source Code

      (:~
       : Sessions page.
       :
       : @author Christian Grün, BaseX Team 2005-21, 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': 'dateTime', '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 })
      };