dba/jobs
library moduleRA
Summary
Jobs page.
- Tags
Author: Christian Grün, BaseX Team 2005-21, BSD License
__source : jobs/jobs.xqm
Imports
This module is imported by 0 modules. It imports 2 modules.
Variables
Functions
4.1 dba:jobs
Arities: dba:jobs#4RA
dba:jobs
(
$sort
as
xs:string
, $job
as
xs:string?
, $error
as
xs:string?
, $info
as
xs:string?
)
as
element(html)
- sort
as
xs:string
table sort key - job
as
xs:string?
highlighted job - error
as
xs:string?
error message - info
as
xs:string?
info message
element(html)
page
Invokes 17 functions from 5 modules
- html:button#3
- html:button#4
- html:duration#1
- html:table#5
- html:wrap#2
- util:capitalize#1
- util:chop#2
- {http://basex.org/modules/jobs}current#0
- {http://basex.org/modules/jobs}list-details#0
- {http://basex.org/modules/jobs}list-details#1
- {http://www.w3.org/2001/XMLSchema}dayTimeDuration#1
- {http://www.w3.org/2005/xpath-functions}exists#1
- {http://www.w3.org/2005/xpath-functions}false#0
- {http://www.w3.org/2005/xpath-functions}name#1
- {http://www.w3.org/2005/xpath-functions}not#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/jobs') |
%rest:query-param | ('sort','{$sort}','duration') |
%rest:query-param | ('job','{$job}') |
%rest:query-param | ('error','{$error}') |
%rest:query-param | ('info','{$info}') |
%output:method | ('html') |
Source ( 94 lines)
function dba:jobs(
$sort as xs:string,
$job 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 width='60%'>
<form action='{ $dba:CAT }' method='post' class='update'>
<h2>Jobs</h2>
{
let $headers := (
map { 'key': 'id', 'label': 'ID' },
map { 'key': 'type', 'label': 'Type' },
map { 'key': 'state', 'label': 'State' },
map { 'key': 'duration', 'label': 'Dur.', 'type': 'number', 'order': 'desc' },
map { 'key': 'user', 'label': 'User' },
map { 'key': 'you', 'label': 'You' },
map { 'key': 'time', 'label': 'Time', 'type': 'dateTime', 'order': 'desc' }
)
let $entries :=
let $curr := jobs:current()
for $details in jobs:list-details()
let $id := $details/@id
let $sec := (
let $dur := xs:dayTimeDuration($details/@duration)
return if(exists($dur)) then $dur div xs:dayTimeDuration('PT1S') else 0
)
order by $sec descending, $details/@start descending
return map {
'id': $id,
'type': $details/@type,
'state': $details/@state,
'duration': html:duration($sec),
'user': $details/@user,
'you': if($id = $curr) then '✓' else '–',
'time': $details/@time
}
let $buttons := (
html:button('job-stop', 'Stop', true())
)
let $options := map { 'sort': $sort, 'presort': 'duration' }
return html:table($headers, $entries, $buttons, map { }, $options) update {
(: replace job ids with links :)
for $tr at $p in tr[not(th)]
for $entries in $entries[$p][?you = '–']
let $text := $tr/td[1]/text()
return replace node $text with <a href='?job={ $entries?id }'>{ $text }</a>
}
}
</form>
</td>,
if($job) then (
let $details := jobs:list-details($job)
let $cached := $details/@state = 'cached'
return (
<td class='vertical'/>,
<td width='40%'>{
<h3>{ $job }</h3>,
if($details) then (
<form action='jobs' method='post' id='jobs'>
<input type='hidden' name='id' value='{ $job }'/>
{
let $disabled := map { 'disabled': '' }
return (
html:button('job-stop', 'Stop', true(), $disabled[$cached]), ' ',
html:button('job-result', 'Download', false(), $disabled[not($cached)]), ' ',
html:button('job-discard', 'Discard', false(), $disabled[not($cached)]), ' '
)
}
</form>,
<table>{
for $value in $details/@*
for $name in name($value)[. != 'id']
return <tr>
<td><b>{ util:capitalize($name) }</b></td>
<td>{ string($value) }</td>
</tr>,
<tr>
<td><b>Description</b></td>
<td>{ util:chop($details, 500) }</td>
</tr>
}</table>
) else (
'Job is defunct.'
)
}</td>
)
) else()
}</tr>
)
}
4.2 dba:jobs-redirect
Arities: dba:jobs-redirect#2R
dba:jobs-redirect
(
$action
as
xs:string
, $ids
as
xs:string*
)
as
element(rest:response)
- action
as
xs:string
action to perform - 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/jobs') |
%rest:query-param | ('action','{$action}') |
%rest:query-param | ('id','{$ids}') |
Source ( 6 lines)
function dba:jobs-redirect(
$action as xs:string,
$ids as xs:string*
) as element(rest:response) {
web:redirect($action, map { 'id': $ids })
}
Namespaces
The following namespaces are defined:
Prefix | Uri |
---|---|
dba | dba/jobs 2 3 |
html | dba/html |
output | http://www.w3.org/2010/xslt-xquery-serialization |
rest | http://exquery.org/ns/restxq |
util | dba/util |
Source Code
(:~
: Jobs page.
:
: @author Christian Grün, BaseX Team 2005-21, BSD License
:)
module namespace dba = 'dba/jobs';
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 := 'jobs';
(:~
: Jobs page.
: @param $sort table sort key
: @param $job highlighted job
: @param $error error message
: @param $info info message
: @return page
:)
declare
%rest:GET
%rest:path('/dba/jobs')
%rest:query-param('sort', '{$sort}', 'duration')
%rest:query-param('job', '{$job}')
%rest:query-param('error', '{$error}')
%rest:query-param('info', '{$info}')
%output:method('html')
function dba:jobs(
$sort as xs:string,
$job 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 width='60%'>
<form action='{ $dba:CAT }' method='post' class='update'>
<h2>Jobs</h2>
{
let $headers := (
map { 'key': 'id', 'label': 'ID' },
map { 'key': 'type', 'label': 'Type' },
map { 'key': 'state', 'label': 'State' },
map { 'key': 'duration', 'label': 'Dur.', 'type': 'number', 'order': 'desc' },
map { 'key': 'user', 'label': 'User' },
map { 'key': 'you', 'label': 'You' },
map { 'key': 'time', 'label': 'Time', 'type': 'dateTime', 'order': 'desc' }
)
let $entries :=
let $curr := jobs:current()
for $details in jobs:list-details()
let $id := $details/@id
let $sec := (
let $dur := xs:dayTimeDuration($details/@duration)
return if(exists($dur)) then $dur div xs:dayTimeDuration('PT1S') else 0
)
order by $sec descending, $details/@start descending
return map {
'id': $id,
'type': $details/@type,
'state': $details/@state,
'duration': html:duration($sec),
'user': $details/@user,
'you': if($id = $curr) then '✓' else '–',
'time': $details/@time
}
let $buttons := (
html:button('job-stop', 'Stop', true())
)
let $options := map { 'sort': $sort, 'presort': 'duration' }
return html:table($headers, $entries, $buttons, map { }, $options) update {
(: replace job ids with links :)
for $tr at $p in tr[not(th)]
for $entries in $entries[$p][?you = '–']
let $text := $tr/td[1]/text()
return replace node $text with <a href='?job={ $entries?id }'>{ $text }</a>
}
}
</form>
</td>,
if($job) then (
let $details := jobs:list-details($job)
let $cached := $details/@state = 'cached'
return (
<td class='vertical'/>,
<td width='40%'>{
<h3>{ $job }</h3>,
if($details) then (
<form action='jobs' method='post' id='jobs'>
<input type='hidden' name='id' value='{ $job }'/>
{
let $disabled := map { 'disabled': '' }
return (
html:button('job-stop', 'Stop', true(), $disabled[$cached]), ' ',
html:button('job-result', 'Download', false(), $disabled[not($cached)]), ' ',
html:button('job-discard', 'Discard', false(), $disabled[not($cached)]), ' '
)
}
</form>,
<table>{
for $value in $details/@*
for $name in name($value)[. != 'id']
return <tr>
<td><b>{ util:capitalize($name) }</b></td>
<td>{ string($value) }</td>
</tr>,
<tr>
<td><b>Description</b></td>
<td>{ util:chop($details, 500) }</td>
</tr>
}</table>
) else (
'Job is defunct.'
)
}</td>
)
) else()
}</tr>
)
};
(:~
: Redirects to the specified action.
: @param $action action to perform
: @param $ids ids
: @return redirection
:)
declare
%rest:POST
%rest:path('/dba/jobs')
%rest:query-param('action', '{$action}')
%rest:query-param('id', '{$ids}')
function dba:jobs-redirect(
$action as xs:string,
$ids as xs:string*
) as element(rest:response) {
web:redirect($action, map { 'id': $ids })
};