dba/users  library module
URA

Summary

Add new pattern.
Tags

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

__source : users/pattern-add.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

3.2 $dba:SUB

Summary
Sub category
Type
xs:string

Functions

4.1 dba:create

Arities: dba:create#3UR

Summary
Creates a pattern.
Signature
dba:create ( $name as xs:string, $perm as xs:string, $pattern as xs:string )  as empty-sequence()
Parameters
  • name as xs:string user name
  • perm as xs:string permission
  • pattern as xs:string pattern
Return
  • empty-sequence()redirection
Invokes 2 functions from 2 modules
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

    Summary
    Form for adding a new pattern.
    Signature
    dba:pattern-add ( $name as xs:string, $pattern as xs:string?, $perm as xs:string, $error as xs:string? )  as element(html)
    Parameters
    • name as xs:string user name
    • pattern as xs:string? entered pattern
    • perm as xs:string chosen permission
    • error as xs:string? error string
    Return
    • element(html)page
    Invokes 6 functions from 2 modules
    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') } &#xa0;
                      <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:

      PrefixUri
      annhttp://www.w3.org/2012/xquery
      dbadba/users 2 3 4 5 6 7
      htmldba/html
      optionsdba/options
      outputhttp://www.w3.org/2010/xslt-xquery-serialization
      resthttp://exquery.org/ns/restxq
      utildba/util

      6 RestXQ

      Paths defined 2.

      PathMethodFunction
      /dba/pattern-addGETdba:pattern-add#4
      /dba/pattern-addPOSTdba: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') } &#xa0;
                      <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
          })
        }
      };