dba/users
library moduleRA
Summary
Users page.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : users/users.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:users
Arities: dba:users#3RA
dba:users
(
$sort
as
xs:string
, $error
as
xs:string?
, $info
as
xs:string?
)
as
element(html)
- sort
as
xs:string
table sort key - error
as
xs:string?
error message - info
as
xs:string?
info message
element(html)
page
Invokes 11 functions from 4 modules
- html:button#2
- html:button#3
- html:js#1
- html:table#5
- html:wrap#2
- {http://basex.org/modules/session}get#1
- {http://basex.org/modules/user}info#0
- {http://basex.org/modules/user}list-details#0
- {http://www.w3.org/2005/xpath-functions}serialize#1
- {http://www.w3.org/2005/xpath-functions}string#1
- {http://www.w3.org/2005/xpath-functions}true#0
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/users') |
%rest:query-param | ('sort','{$sort}','name') |
%rest:query-param | ('error','{$error}') |
%rest:query-param | ('info','{$info}') |
%output:method | ('html') |
Source ( 56 lines)
function dba:users(
$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,
'css': 'codemirror/lib/codemirror.css',
'scripts': ('codemirror/lib/codemirror.js', 'codemirror/mode/xml/xml.js')
},
<tr>
<td>
<form action='{ $dba:CAT }' method='post' class='update'>
<h2>Users</h2>
{
let $headers := (
map { 'key': 'name', 'label': 'Name' },
map { 'key': 'permission', 'label': 'Permission' },
map { 'key': 'you', 'label': 'You' }
)
let $entries := (
let $current := session:get($config:SESSION-KEY)
for $user in user:list-details()
let $name := string($user/@name)
return map {
'name': $name,
'permission': $user/@permission,
'you': if($current = $name) then '✓' else '–'
}
)
let $buttons := (
html:button('user-create', 'Create…'),
html:button('user-drop', 'Drop', true())
)
let $options := map { 'link': 'user', 'sort': $sort }
return html:table($headers, $entries, $buttons, map { }, $options)
}
</form>
<div> </div>
</td>
<td class='vertical'/>
<td>
<form action='users-info' method='post'>{
<h3>Extra Information</h3>,
html:button('save', 'Save'),
<div class='small'/>,
<textarea name='info' id='editor' spellcheck='false'>{
serialize(user:info())
}</textarea>,
html:js('loadCodeMirror("xml", true);')
}</form>
</td>
</tr>
)
}
4.2 dba:users-redirect
Arities: dba:users-redirect#3R
dba:users-redirect
(
$action
as
xs:string
, $names
as
xs:string*
, $ids
as
xs:string*
)
as
element(rest:response)
- action
as
xs:string
action to perform - names
as
xs:string*
names of users - ids
as
xs:string*
ids
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/users') |
%rest:query-param | ('action','{$action}') |
%rest:query-param | ('name','{$names}') |
%rest:query-param | ('id','{$ids}') |
Source ( 10 lines)
function dba:users-redirect(
$action as xs:string,
$names as xs:string*,
$ids as xs:string*
) as element(rest:response) {
web:redirect($action,
if($action = 'user-create') then map { }
else map { 'name': $names, 'redirect': $dba:CAT }
)
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
config | dba/config |
dba | dba/users 2 3 4 5 6 7 |
html | dba/html |
output | http://www.w3.org/2010/xslt-xquery-serialization |
rest | http://exquery.org/ns/restxq |
6 RestXQ
Paths defined 2.
Path | Method | Function |
---|---|---|
/dba/users | GET | dba:users#3 |
/dba/users | POST | dba:users-redirect#3 |
Source Code
(:~
: Users page.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/users';
import module namespace config = 'dba/config' at '../lib/config.xqm';
import module namespace html = 'dba/html' at '../lib/html.xqm';
(:~ Top category :)
declare variable $dba:CAT := 'users';
(:~
: Returns the users page.
: @param $sort table sort key
: @param $error error message
: @param $info info message
: @return page
:)
declare
%rest:GET
%rest:path('/dba/users')
%rest:query-param('sort', '{$sort}', 'name')
%rest:query-param('error', '{$error}')
%rest:query-param('info', '{$info}')
%output:method('html')
function dba:users(
$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,
'css': 'codemirror/lib/codemirror.css',
'scripts': ('codemirror/lib/codemirror.js', 'codemirror/mode/xml/xml.js')
},
<tr>
<td>
<form action='{ $dba:CAT }' method='post' class='update'>
<h2>Users</h2>
{
let $headers := (
map { 'key': 'name', 'label': 'Name' },
map { 'key': 'permission', 'label': 'Permission' },
map { 'key': 'you', 'label': 'You' }
)
let $entries := (
let $current := session:get($config:SESSION-KEY)
for $user in user:list-details()
let $name := string($user/@name)
return map {
'name': $name,
'permission': $user/@permission,
'you': if($current = $name) then '✓' else '–'
}
)
let $buttons := (
html:button('user-create', 'Create…'),
html:button('user-drop', 'Drop', true())
)
let $options := map { 'link': 'user', 'sort': $sort }
return html:table($headers, $entries, $buttons, map { }, $options)
}
</form>
<div> </div>
</td>
<td class='vertical'/>
<td>
<form action='users-info' method='post'>{
<h3>Extra Information</h3>,
html:button('save', 'Save'),
<div class='small'/>,
<textarea name='info' id='editor' spellcheck='false'>{
serialize(user:info())
}</textarea>,
html:js('loadCodeMirror("xml", true);')
}</form>
</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/users')
%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,
if($action = 'user-create') then map { }
else map { 'name': $names, 'redirect': $dba:CAT }
)
};