dba/users
library moduleURA
Summary
Add new pattern.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : users/pattern-add.xqm
Imports
This module is imported by 0 modules. It imports 3 modules.
Variables
Functions
4.1 dba:create
Arities: dba:create#3UR
dba:create
(
$name
as
xs:string
, $perm
as
xs:string
, $pattern
as
xs:string
)
as
empty-sequence()
- name
as
xs:string
user name - perm
as
xs:string
permission - pattern
as
xs:string
pattern
empty-sequence()
redirection
Invokes 2 functions from 2 modules
- util:redirect#2
- {http://basex.org/modules/user}grant#3
Invoked by 0 functions from 0 modules
Annotations
%updating | () |
%rest:POST | () |
%rest:path | ('/dba/pattern-add') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('perm','{$perm}') |
%rest:query-param | ('pattern','{$pattern}') |
Source ( 14 lines)
function dba:create(
$name as xs:string,
$perm as xs:string,
$pattern as xs:string
) as empty-sequence() {
try {
user:grant($name, $perm, $pattern),
util:redirect($dba:SUB, map { 'name': $name, 'info': 'Pattern was created.' })
} catch * {
util:redirect('pattern-add', map {
'name': $name, 'perm': $perm, 'pattern': $pattern, 'error': $err:description
})
}
}
4.2 dba:pattern-add
Arities: dba:pattern-add#4RA
dba:pattern-add
(
$name
as
xs:string
, $pattern
as
xs:string?
, $perm
as
xs:string
, $error
as
xs:string?
)
as
element(html)
- name
as
xs:string
user name - pattern
as
xs:string?
entered pattern - perm
as
xs:string
chosen permission - error
as
xs:string?
error string
element(html)
page
Invokes 6 functions from 2 modules
- html:button#2
- html:focus#1
- html:link#2
- html:link#3
- html:wrap#2
- {http://www.w3.org/2005/xpath-functions}position#0
Invoked by 0 functions from 0 modules
Annotations
%rest:GET | () |
%rest:path | ('/dba/pattern-add') |
%rest:query-param | ('name','{$name}') |
%rest:query-param | ('pattern','{$pattern}') |
%rest:query-param | ('perm','{$perm}','write') |
%rest:query-param | ('error','{$error}') |
%output:method | ('html') |
Source ( 43 lines)
function dba:pattern-add(
$name as xs:string,
$pattern as xs:string?,
$perm as xs:string,
$error as xs:string?
) as element(html) {
html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
<tr>
<td>
<form action='pattern-add' method='post' autocomplete='off'>
<h2>{
html:link('Users', $dba:CAT), ' » ',
html:link($name, $dba:SUB, map { 'name': $name }), ' » ',
html:button('create', 'Add Pattern')
}</h2>
<input type='hidden' name='name' value='{ $name }'/>
<table>
<tr>
<td>Pattern:</td>
<td>
<input type='text' name='pattern' value='{ $pattern }' id='pattern'/>
{ html:focus('pattern') }  
<span class='note'>…support for <a target='_blank'
href='https://docs.basex.org/wiki/Commands#Glob_Syntax'>glob syntax</a>.</span>
<div class='small'/>
</td>
</tr>
<tr>
<td>Permission:</td>
<td>
<select name='perm' size='3'>{
for $p in $options:PERMISSIONS[position() = 1 to 3]
return element option { attribute selected { }[$p = $perm], $p }
}</select>
<div class='small'/>
</td>
</tr>
</table>
</form>
</td>
</tr>
)
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
ann | http://www.w3.org/2012/xquery |
dba | dba/users 2 3 4 5 6 7 |
html | dba/html |
options | dba/options |
output | http://www.w3.org/2010/xslt-xquery-serialization |
rest | http://exquery.org/ns/restxq |
util | dba/util |
6 RestXQ
Paths defined 2.
Path | Method | Function |
---|---|---|
/dba/pattern-add | GET | dba:pattern-add#4 |
/dba/pattern-add | POST | dba:create#3 |
Source Code
(:~
: Add new pattern.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/users';
import module namespace html = 'dba/html' at '../lib/html.xqm';
import module namespace options = 'dba/options' at '../lib/options.xqm';
import module namespace util = 'dba/util' at '../lib/util.xqm';
(:~ Top category :)
declare variable $dba:CAT := 'users';
(:~ Sub category :)
declare variable $dba:SUB := 'user';
(:~
: Form for adding a new pattern.
: @param $name user name
: @param $pattern entered pattern
: @param $perm chosen permission
: @param $error error string
: @return page
:)
declare
%rest:GET
%rest:path('/dba/pattern-add')
%rest:query-param('name', '{$name}')
%rest:query-param('pattern', '{$pattern}')
%rest:query-param('perm', '{$perm}', 'write')
%rest:query-param('error', '{$error}')
%output:method('html')
function dba:pattern-add(
$name as xs:string,
$pattern as xs:string?,
$perm as xs:string,
$error as xs:string?
) as element(html) {
html:wrap(map { 'header': ($dba:CAT, $name), 'error': $error },
<tr>
<td>
<form action='pattern-add' method='post' autocomplete='off'>
<h2>{
html:link('Users', $dba:CAT), ' » ',
html:link($name, $dba:SUB, map { 'name': $name }), ' » ',
html:button('create', 'Add Pattern')
}</h2>
<input type='hidden' name='name' value='{ $name }'/>
<table>
<tr>
<td>Pattern:</td>
<td>
<input type='text' name='pattern' value='{ $pattern }' id='pattern'/>
{ html:focus('pattern') }  
<span class='note'>…support for <a target='_blank'
href='https://docs.basex.org/wiki/Commands#Glob_Syntax'>glob syntax</a>.</span>
<div class='small'/>
</td>
</tr>
<tr>
<td>Permission:</td>
<td>
<select name='perm' size='3'>{
for $p in $options:PERMISSIONS[position() = 1 to 3]
return element option { attribute selected { }[$p = $perm], $p }
}</select>
<div class='small'/>
</td>
</tr>
</table>
</form>
</td>
</tr>
)
};
(:~
: Creates a pattern.
: @param $name user name
: @param $perm permission
: @param $pattern pattern
: @return redirection
:)
declare
%updating
%rest:POST
%rest:path('/dba/pattern-add')
%rest:query-param('name', '{$name}')
%rest:query-param('perm', '{$perm}')
%rest:query-param('pattern', '{$pattern}')
function dba:create(
$name as xs:string,
$perm as xs:string,
$pattern as xs:string
) as empty-sequence() {
try {
user:grant($name, $perm, $pattern),
util:redirect($dba:SUB, map { 'name': $name, 'info': 'Pattern was created.' })
} catch * {
util:redirect('pattern-add', map {
'name': $name, 'perm': $perm, 'pattern': $pattern, 'error': $err:description
})
}
};