Task Engine

/views/vtask/Detail.html (2.1 KB)

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{% import (
"{{{ .Package }}}/app"
"{{{ .Package }}}/app/controller/cutil"
"{{{ .Package }}}/app/lib/task"
"{{{ .Package }}}/app/util"
"{{{ .Package }}}/views/components"
"{{{ .Package }}}/views/components/view"
"{{{ .Package }}}/views/components/edit"
"{{{ .Package }}}/views/layout"
"{{{ .Package }}}/views/vexec"
) %}

{% code type Detail struct {
layout.Basic
Task *task.Task
Result *task.Result
Args util.ValueMap
SocketURL string
} %}

{% func (p *Detail) Body(as *app.State, ps *cutil.PageState) %}
<div class="card">
<h3>{%= components.SVGIcon(p.Task.IconSafe(), ps) %} {%s p.Task.TitleSafe() %}</h3>
<form action="{%s p.Task.WebPath() %}/run" method="get">
<table class="mt expanded">
<tbody>
{%= edit.TableEditorNoTable(p.Task.Key, p.Task.Fields(), p.Args) %}
<tr>
<td colspan="2">
<button type="submit">Run</button>
<button type="submit" name="async" value="true">Start</button>
</td>
</tr>
</tbody>
</table>
</form>
</div>
{%- if p.Result != nil -%}
{%= Result(as, p.Result, ps) %}
{%- endif -%}

{%- if p.SocketURL != "" -%}
<script>
function processMessage(m) {
if (m.cmd === "complete") {
const deets = document.getElementById("result-detail");
deets.innerHTML = m.param.html;
}
}
</script>
{%= SocketContent(as, "task-output", p.Task, p.SocketURL, ps, "processMessage(m)") %}
{%- endif -%}
{% endfunc %}

{% func SocketContent(as *app.State, key string, t *task.Task, u string, ps *cutil.PageState, callbacks ...string) %}
<div class="card">
<div class="right">{%= view.TimestampRelative(util.TimeCurrentP(), false) %}</div>
<h3>{%= components.SVGIcon("file", ps) %} {%s t.TitleSafe() %} Logs</h3>
<div class="mt">{%= components.Terminal("task-output", "Starting task [" + t.TitleSafe() + "]...") %}</div>
</div>
<div id="result-detail"></div>
{%= vexec.ExecScript(key, u, as.Debug, ps, callbacks...) %}
{% endfunc %}