dba/settings  library module
RA

Summary

Settings page.
Tags

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

__source : settings/settings.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 2 modules.

(None)
imports
this
imports

Variables

3.1 $dba:CAT

Summary
Top category
Type
xs:string

Functions

4.1 dba:settings

Arities: dba:settings#2RA

Summary
Settings page.
Signature
dba:settings ( $error as xs:string?, $info as xs:string? )  as element(html)
Parameters
  • error as xs:string? error string
  • info as xs:string? info string
Return
  • element(html)page
Invokes 6 functions from 4 modules
Invoked by 0 functions from 0 modules
    Annotations
    %rest:GET()
    %rest:path('/dba/settings')
    %rest:query-param('error','{$error}')
    %rest:query-param('info','{$info}')
    %output:method('html')
    Source ( 76 lines)
    function dba:settings(
      $error  as xs:string?,
      $info   as xs:string?
    ) as element(html) {
      let $system := html:properties(db:system())
      let $table-row := function($items) {
        <tr><td>{ $items }</td></tr>
      }
      let $number := function($key, $label) {
        $table-row((
          $label,
          <br/>,
          <input name='{ $key }' type='number' value='{ options:get($key) }'/>
        ))
      }
      let $string := function($key, $label) {
        $table-row((
          $label,
          <br/>,
          <input name='{ $key }' type='text' value='{ options:get($key) }'/>
        ))
      }
      return html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },
        <tr>
          <td width='33%'>
            <form action='settings' method='post'>
              <h2>Settings » { html:button('save', 'Save') }</h2>
              <h3>Queries</h3>
              <table>
                {
                  $number($options:TIMEOUT, 'Timeout, in seconds (0 = disabled)'),
                  $number($options:MEMORY, 'Memory limit, in MB (0 = disabled)'),
                  $number($options:MAXCHARS, 'Maximum output size')
                }
                <tr>
                  <td colspan='2'>Permission:</td>
                </tr>
                <tr>
                  <td>
                    <select name='permission'>{
                      let $pm := options:get($options:PERMISSION)
                      for $p in $options:PERMISSIONS
                      return element option { attribute selected { }[$p = $pm], $p }
                    }</select>
                  </td>
                </tr>
              </table>
              <h3>Tables</h3>
              <table>{
                $number($options:MAXROWS,  'Displayed table rows')
              }</table>
              <h3>Logs</h3>
              <table>{
                $string($options:IGNORE-LOGS, <span>Ignore entries (e.g. <code>/dba</code>):</span>)
              }</table>
            </form>
          </td>
          <td class='vertical'/>
          <td width='33%'>
            <form action='settings-gc' method='post'>
              <h2>Global Options » { html:button('gc', 'GC') }</h2>
              <table>{
                $system/tr[th][3]/preceding-sibling::tr[not(th)]
              }</table>
            </form>
          </td>
          <td class='vertical'/>
          <td width='33%'>
            <h2>Local Options</h2>
            <table>{
              $system/tr[th][3]/following-sibling::tr
            }</table>
          </td>
        </tr>
      )
    }

    4.2 dba:settings-save

    Arities: dba:settings-save#0R

    Summary
    Saves the settings.
    Signature
    dba:settings-save ( )  as element(rest:response)
    Return
    • element(rest:response)redirection
    Invokes 3 functions from 3 modules
    Invoked by 0 functions from 0 modules
      Annotations
      %rest:POST()
      %rest:path('/dba/settings')
      Source ( 5 lines)
      function dba:settings-save(
      ) as element(rest:response) {
        options:save(html:parameters()),
        web:redirect($dba:CAT, map { 'info': 'Settings were saved.' })
      }

      Namespaces

      The following namespaces are defined:

      PrefixUri
      dbadba/settings 2
      htmldba/html
      optionsdba/options
      outputhttp://www.w3.org/2010/xslt-xquery-serialization
      resthttp://exquery.org/ns/restxq

      6 RestXQ

      Paths defined 2.

      PathMethodFunction
      /dba/settingsGETdba:settings#2
      /dba/settingsPOSTdba:settings-save#0

      Source Code

      (:~
       : Settings page.
       :
       : @author Christian Grün, BaseX Team 2005-21, BSD License
       :)
      module namespace dba = 'dba/settings';
      
      import module namespace options = 'dba/options' at '../lib/options.xqm';
      import module namespace html = 'dba/html' at '../lib/html.xqm';
      
      (:~ Top category :)
      declare variable $dba:CAT := 'settings';
      
      (:~
       : Settings page.
       : @param  $error  error string
       : @param  $info   info string
       : @return page
       :)
      declare
        %rest:GET
        %rest:path('/dba/settings')
        %rest:query-param('error', '{$error}')
        %rest:query-param('info',  '{$info}')
        %output:method('html')
      function dba:settings(
        $error  as xs:string?,
        $info   as xs:string?
      ) as element(html) {
        let $system := html:properties(db:system())
        let $table-row := function($items) {
          <tr><td>{ $items }</td></tr>
        }
        let $number := function($key, $label) {
          $table-row((
            $label,
            <br/>,
            <input name='{ $key }' type='number' value='{ options:get($key) }'/>
          ))
        }
        let $string := function($key, $label) {
          $table-row((
            $label,
            <br/>,
            <input name='{ $key }' type='text' value='{ options:get($key) }'/>
          ))
        }
        return html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },
          <tr>
            <td width='33%'>
              <form action='settings' method='post'>
                <h2>Settings » { html:button('save', 'Save') }</h2>
                <h3>Queries</h3>
                <table>
                  {
                    $number($options:TIMEOUT, 'Timeout, in seconds (0 = disabled)'),
                    $number($options:MEMORY, 'Memory limit, in MB (0 = disabled)'),
                    $number($options:MAXCHARS, 'Maximum output size')
                  }
                  <tr>
                    <td colspan='2'>Permission:</td>
                  </tr>
                  <tr>
                    <td>
                      <select name='permission'>{
                        let $pm := options:get($options:PERMISSION)
                        for $p in $options:PERMISSIONS
                        return element option { attribute selected { }[$p = $pm], $p }
                      }</select>
                    </td>
                  </tr>
                </table>
                <h3>Tables</h3>
                <table>{
                  $number($options:MAXROWS,  'Displayed table rows')
                }</table>
                <h3>Logs</h3>
                <table>{
                  $string($options:IGNORE-LOGS, <span>Ignore entries (e.g. <code>/dba</code>):</span>)
                }</table>
              </form>
            </td>
            <td class='vertical'/>
            <td width='33%'>
              <form action='settings-gc' method='post'>
                <h2>Global Options » { html:button('gc', 'GC') }</h2>
                <table>{
                  $system/tr[th][3]/preceding-sibling::tr[not(th)]
                }</table>
              </form>
            </td>
            <td class='vertical'/>
            <td width='33%'>
              <h2>Local Options</h2>
              <table>{
                $system/tr[th][3]/following-sibling::tr
              }</table>
            </td>
          </tr>
        )
      };
      
      (:~
       : Saves the settings.
       : @return redirection
       :)
      declare
        %rest:POST
        %rest:path('/dba/settings')
      function dba:settings-save(
      ) as element(rest:response) {
        options:save(html:parameters()),
        web:redirect($dba:CAT, map { 'info': 'Settings were saved.' })
      };