Skip to content

Commit 8cc060c

Browse files
[MOD] XQuery, job:result (+DBA): Options argument added
1 parent 1a842cc commit 8cc060c

File tree

17 files changed

+181
-126
lines changed

17 files changed

+181
-126
lines changed

basex-api/src/main/webapp/dba/databases/database.xqm

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ function dba:database(
151151
<div class='small'/>,
152152
<textarea name='output' id='output' readonly='' spellcheck='false'/>,
153153
html:focus('input'),
154-
html:js('loadCodeMirror("xml", false); queryResource(true);')
154+
html:js('loadCodeMirror("xml", false, true); queryResource(true);')
155155
) else if($db-exists) then (
156156
<h2>Information</h2>,
157157
html:properties(db:info($name))

basex-api/src/main/webapp/dba/jobs/job-result.xqm

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function dba:job-result(
2222
) as item()+ {
2323
let $details := job:list-details($id)
2424
return if(empty($details)) then (
25-
dba:job-result($id, false(), 'Job is defunct.')
25+
dba:job-result($id, false(), 'Job has expired.')
2626
) else if($details/@state != 'cached') then (
2727
dba:job-result($id, false(), 'Result is not available yet.')
2828
) else (

basex-api/src/main/webapp/dba/jobs/jobs.xqm

+69-45
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ function dba:jobs(
3333
$error as xs:string?,
3434
$info as xs:string?
3535
) as element(html) {
36-
html:wrap(map { 'header': $dba:CAT, 'info': $info, 'error': $error },
36+
html:wrap(map {
37+
'header': $dba:CAT, 'info': $info, 'error': $error,
38+
'css': 'codemirror/lib/codemirror.css',
39+
'scripts': ('codemirror/lib/codemirror.js', 'codemirror/mode/xml/xml.js')
40+
},
3741
<tr>{
3842
<td>
3943
<form action='{ $dba:CAT }' method='post' class='update'>
4044
<h2>Jobs</h2>
4145
{
4246
let $headers := (
4347
map { 'key': 'id', 'label': 'ID' },
44-
map { 'key': 'type', 'label': 'Type' },
4548
map { 'key': 'state', 'label': 'State' },
4649
map { 'key': 'duration', 'label': 'Dur.', 'type': 'number', 'order': 'desc' },
4750
map { 'key': 'user', 'label': 'User' },
@@ -62,7 +65,6 @@ function dba:jobs(
6265
order by $sec descending, $start descending
6366
return map {
6467
'id': $id,
65-
'type': $details/@type,
6668
'state': $details/@state,
6769
'duration': html:duration($sec),
6870
'user': $details/@user,
@@ -90,50 +92,72 @@ function dba:jobs(
9092
let $cached := $details/@state = 'cached'
9193
return (
9294
<td class='vertical'/>,
93-
<td>{
94-
<h2>Job: { $job }</h2>,
95-
if($details) then (
96-
<form action='jobs' method='post' id='jobs'>
97-
<input type='hidden' name='id' value='{ $job }'/>
98-
{
99-
html:button('job-result', 'Download', false(),
100-
if($cached) then () else map { 'disabled': '' }), ' ',
101-
html:button('job-remove', 'Remove', false())
102-
}
103-
</form>,
104-
<h3>General Information</h3>,
105-
<table>{
106-
for $value in $details/@*
107-
for $name in name($value)[. != 'id']
108-
return <tr>
109-
<td><b>{ util:capitalize($name) }</b></td>
110-
<td>{ string($value) }</td>
111-
</tr>
112-
}</table>,
113-
let $bindings := job:bindings($job)
114-
where map:size($bindings) > 0
115-
return (
116-
<h3>Query Bindings</h3>,
95+
<td>
96+
<form action='jobs' method='post' id='jobs'>{
97+
<input type='hidden' name='id' value='{ $job }'/>,
98+
<h2>{
99+
'Job: ', $job, '&#xa0;',
100+
if($details) then html:button('job-remove', 'Remove', false())
101+
}</h2>,
102+
103+
if($details) then (
104+
<h3>General Information</h3>,
117105
<table>{
118-
map:for-each($bindings, function($key, $value) {
119-
<tr>
120-
<td><b>{ $key ?? '$' || $key !! 'Context' }</b></td>
121-
<td><code>{
122-
util:chop(serialize($value, map { 'method': 'basex' }), 1000)
123-
}</code></td>
124-
</tr>
106+
for $value in $details/@*
107+
for $name in name($value)[. != 'id']
108+
return <tr>
109+
<td><b>{ util:capitalize($name) }</b></td>
110+
<td>{ string($value) }</td>
111+
</tr>
112+
}</table>,
113+
114+
let $bindings := job:bindings($job)
115+
where map:size($bindings) > 0
116+
return (
117+
<h3>Query Bindings</h3>,
118+
<table>{
119+
map:for-each($bindings, function($key, $value) {
120+
<tr>
121+
<td><b>{ $key ?? '$' || $key !! 'Context' }</b></td>
122+
<td><code>{
123+
util:chop(serialize($value, map { 'method': 'basex' }), 1000)
124+
}</code></td>
125+
</tr>
126+
})
127+
}
128+
</table>
129+
),
130+
131+
<h3>Query</h3>,
132+
<textarea readonly='' spellcheck='false' rows='5'>{
133+
string($details)
134+
}</textarea>,
135+
136+
if($cached) then (
137+
let $result := util:serialize(try {
138+
job:result($job, map { 'keep': true() })
139+
} catch * {
140+
'Stopped at ' || $err:module || ', ' || $err:line-number || '/' ||
141+
$err:column-number || ':' || string:nl() || $err:description
125142
})
126-
}
127-
</table>
128-
),
129-
<h3>Job String</h3>,
130-
<textarea readonly='' rows='10'>{
131-
string($details)
132-
}</textarea>
133-
) else (
134-
'Job is defunct.'
135-
)
136-
}</td>
143+
where $result
144+
return (
145+
<h3>{
146+
'Result', '&#xa0;',
147+
html:button('job-result', 'Download')
148+
}
149+
</h3>,
150+
<textarea name='output' id='output' readonly='' spellcheck='false'>{
151+
$result
152+
}</textarea>,
153+
html:js('loadCodeMirror("xml");')
154+
)
155+
)
156+
) else (
157+
'Job has expired.'
158+
)
159+
}</form>
160+
</td>
137161
)
138162
) else()
139163
}</tr>

basex-api/src/main/webapp/dba/lib/util.xqm

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ declare function util:query(
2525
) as xs:string {
2626
let $bindings := $context ! map { '': $context }
2727
let $result := xquery:eval($query, $bindings, util:query-options())
28-
return util:finalize($result)
28+
return util:serialize($result)
2929
};
3030

3131
(:~
@@ -39,16 +39,16 @@ declare %updating function util:update-query(
3939
xquery:eval-update($query, (), util:query-options()),
4040

4141
let $result := update:cache(true())
42-
return update:output(util:finalize($result))
42+
return update:output(util:serialize($result))
4343
};
4444

4545
(:~
4646
: Finalizes the result of an evaluated query.
47-
: @param $result query result
47+
: @param $result query result
4848
: @return empty sequence
4949
:)
50-
declare %private function util:finalize(
51-
$result as item()*
50+
declare function util:serialize(
51+
$result as item()*
5252
) as xs:string {
5353
(: serialize more characters than requested, because limit represents number of bytes :)
5454
let $limit := options:get($options:MAXCHARS)

basex-api/src/main/webapp/dba/queries/queries.xqm

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function dba:queries(
7676
<td width='50%'>{
7777
<h2 class='right'>Result</h2>,
7878
<textarea name='output' id='output' readonly=''/>,
79-
html:js('loadCodeMirror("xquery", true);'),
79+
html:js('loadCodeMirror("xquery", true, true);'),
8080
for $name in head(($file, config:query())[.])
8181
return html:js('openQuery("' || $name || '");')
8282
}</td>

basex-api/src/main/webapp/dba/queries/query-close.xqm

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ declare
1515
%rest:POST
1616
%rest:path('/dba/query-close')
1717
%rest:query-param('name', '{$name}')
18-
function dba:query-save(
18+
function dba:query-close(
1919
$name as xs:string
2020
) as empty-sequence() {
2121
config:query('')

basex-api/src/main/webapp/dba/settings/settings.xqm

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function dba:settings(
4949
<tr>
5050
<td width='33%'>
5151
<form action='settings' method='post'>
52-
<h2>Settings » { html:button('save', 'Save') }</h2>
52+
<h2>Settings » { html:button('update', 'Update') }</h2>
5353
<h3>Queries</h3>
5454
<table>
5555
{
@@ -101,14 +101,14 @@ function dba:settings(
101101
};
102102

103103
(:~
104-
: Saves the settings.
104+
: Updates the settings.
105105
: @return redirection
106106
:)
107107
declare
108108
%rest:POST
109109
%rest:path('/dba/settings')
110-
function dba:settings-save(
110+
function dba:settings-update(
111111
) as element(rest:response) {
112112
options:save(html:parameters()),
113-
web:redirect($dba:CAT, map { 'info': 'Settings were saved.' })
113+
web:redirect($dba:CAT, map { 'info': 'Settings were updated.' })
114114
};

basex-api/src/main/webapp/dba/static/js.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function buttons(source) {
3434

3535
var values = [
3636
"backup", "backup-drop", "backup-restore", "backup-create-all", "backup-restore-all",
37-
"db-drop", "db-optimize", "db-optimize-all", "delete",
37+
"db-drop", "db-optimize", "db-optimize-all", "delete", "job-remove",
3838
"file-delete", "job-stop", "log-delete", "session-kill",
3939
"pattern-drop", "user-drop"
4040
];
@@ -264,15 +264,17 @@ var _edit;
264264
* Loads the code mirror editor extension.
265265
* @param {string} language programming language (syntax highlighting)
266266
* @param {boolean} edit editor flag (vs. read-only view)
267+
* @param {boolean} resize text areas to full height
267268
*/
268-
function loadCodeMirror(language, edit) {
269+
function loadCodeMirror(language, edit, resize) {
269270
_edit = edit;
270271
if (CodeMirror && dispatchEvent) {
271272
if(edit) {
272273
var editorArea = document.getElementById("editor");
273274
_editorMirror = CodeMirror.fromTextArea(editorArea, {
274275
mode: language,
275276
lineNumbers: true,
277+
lineWrapping: true,
276278
extraKeys: {
277279
"Ctrl-Enter" : function(cm) { runQuery(); },
278280
"Cmd-Enter" : function(cm) { runQuery(); },
@@ -285,14 +287,19 @@ function loadCodeMirror(language, edit) {
285287
}
286288

287289
var outputArea = document.getElementById("output");
288-
_outputMirror = CodeMirror.fromTextArea(outputArea, {
289-
mode: "xml",
290-
readOnly: true
291-
});
292-
_outputMirror.display.wrapper.style.border = "solid 1px grey";
293-
294-
window.addEventListener("load", setDisplayHeight);
295-
window.addEventListener("resize", setDisplayHeight);
290+
if(outputArea != null) {
291+
_outputMirror = CodeMirror.fromTextArea(outputArea, {
292+
mode: "xml",
293+
lineWrapping: true,
294+
readOnly: true
295+
});
296+
_outputMirror.display.wrapper.style.border = "solid 1px grey";
297+
}
298+
299+
if(resize) {
300+
window.addEventListener("load", setDisplayHeight);
301+
window.addEventListener("resize", setDisplayHeight);
302+
}
296303
}
297304
}
298305

basex-api/src/main/webapp/dba/users/user-edit.xqm basex-api/src/main/webapp/dba/users/user-update.xqm

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(:~
2-
: Edit user.
2+
: Updates user information.
33
:
44
: @author Christian Grün, BaseX Team 2005-22, BSD License
55
:)
@@ -11,7 +11,7 @@ import module namespace util = 'dba/util' at '../lib/util.xqm';
1111
declare variable $dba:SUB := 'user';
1212

1313
(:~
14-
: Edits a user.
14+
: Updates a user.
1515
: @param $name username
1616
: @param $newname new name
1717
: @param $pw password
@@ -21,13 +21,13 @@ declare variable $dba:SUB := 'user';
2121
declare
2222
%updating
2323
%rest:POST
24-
%rest:path('/dba/user-edit')
24+
%rest:path('/dba/user-update')
2525
%rest:form-param('name', '{$name}')
2626
%rest:form-param('newname', '{$newname}')
2727
%rest:form-param('pw', '{$pw}')
2828
%rest:form-param('perm', '{$perm}')
2929
%rest:form-param('info', '{$info}')
30-
function dba:user-edit(
30+
function dba:user-update(
3131
$name as xs:string,
3232
$newname as xs:string,
3333
$pw as xs:string,
@@ -58,10 +58,10 @@ function dba:user-edit(
5858
where not(deep-equal(user:info($name), $xml))
5959
return user:update-info($xml, $name)
6060
),
61-
util:redirect($dba:SUB, map { 'name': $newname, 'info': 'User was saved.' })
61+
util:redirect($dba:SUB, map { 'name': $newname, 'info': 'User was updated.' })
6262
} catch * {
6363
let $error := if ($err:code != xs:QName('err:FODC0006')) then $err:description else
64-
'Information must be XML with an info root element.'
64+
'XML with "info" root element expected.'
6565
return util:redirect($dba:SUB, map {
6666
'name': $name, 'newname': $newname, 'pw': $pw, 'perm': $perm, 'error': $error
6767
})

basex-api/src/main/webapp/dba/users/user.xqm

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ function dba:user(
5151
},
5252
<tr>
5353
<td>
54-
<form action='user-edit' method='post' autocomplete='off'>
54+
<form action='user-update' method='post' autocomplete='off'>
5555
<!-- force chrome not to autocomplete form -->
5656
<input style='display:none' type='text' name='fake1'/>
5757
<input style='display:none' type='password' name='fake2'/>
5858
<h2>{
5959
html:link('Users', $dba:CAT), ' » ',
6060
$name, ' » ',
61-
html:button('save', 'Save')
61+
html:button('update', 'Update')
6262
}</h2>
6363
<input type='hidden' name='name' value='{ $name }'/>
6464
<table>{

basex-api/src/main/webapp/dba/users/users-info.xqm

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(:~
2-
: Save users information.
2+
: Updates users information.
33
:
44
: @author Christian Grün, BaseX Team 2005-22, BSD License
55
:)
@@ -11,7 +11,7 @@ import module namespace util = 'dba/util' at '../lib/util.xqm';
1111
declare variable $dba:CAT := 'users';
1212

1313
(:~
14-
: Saves users information.
14+
: Updates users information.
1515
: @param $info users information
1616
: @return redirection
1717
:)
@@ -33,9 +33,9 @@ function dba:users-info(
3333
where not(deep-equal(user:info(), $xml))
3434
return user:update-info($xml),
3535

36-
util:redirect($dba:CAT, map { 'info': 'User was saved.' })
36+
util:redirect($dba:CAT, map { 'info': 'User information was updated.' })
3737
} catch err:FODC0006 {
38-
util:redirect($dba:CAT, map { 'error': 'Information must be XML with an info root element.' })
38+
util:redirect($dba:CAT, map { 'error': 'XML with "info" root element expected.' })
3939
} catch * {
4040
util:redirect($dba:CAT, map { 'error': $err:description })
4141
}

basex-api/src/main/webapp/dba/users/users.xqm

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function dba:users(
7070
<td>
7171
<form action='users-info' method='post'>{
7272
<h2>User Information</h2>,
73-
html:button('save', 'Save'),
73+
html:button('update', 'Update'),
7474
<div class='small'/>,
7575
<textarea name='info' id='editor' spellcheck='false'>{
7676
serialize(user:info())

0 commit comments

Comments
 (0)