1
// Copyright 2016 - 2020 The aurora Authors. All rights reserved. Use of this
2
// source code is governed by a MIT license that can be found in the LICENSE
3
// file.
4
//
5
// The aurora is a web-based beanstalkd queue server console written in Go
6
// and works on macOS, Linux and Windows machines. Main idea behind using Go
7
// for backend development is to utilize ability of the compiler to produce
8
// zero-dependency binaries for multiple platforms. aurora was created as an
9
// attempt to build very simple and portable application to work with local or
10
// remote beanstalkd server.
11

12
package main
13

14
import (
15
	"html"
16
	"net/url"
17
	"strconv"
18
	"strings"
19
)
20

21
// currentTubeSearchResults constructs a search result table by given server,
22
// tube, search result limit and search content.
23
func currentTubeSearchResults(server string, tube string, limit string, searchStr string, result []SearchResult) string {
24 9
	var buf, tr strings.Builder
25 9
	if len(result) == 0 {
26 9
		buf.WriteString(`<br/>No results found for <b>`)
27 9
		buf.WriteString(html.EscapeString(searchStr))
28 9
		buf.WriteString(`</b> in tube: <b>`)
29 9
		buf.WriteString(tube)
30 9
		buf.WriteString(`</b>`)
31 9
		return buf.String()
32
	}
33
	for k, job := range result {
34 9
		tr.WriteString(`<tr><td>`)
35 9
		tr.WriteString(strconv.Itoa(int(job.ID)))
36 9
		tr.WriteString(`</td><td>`)
37 9
		tr.WriteString(job.State)
38 9
		tr.WriteString(`</td><td class="ellipsize">`)
39 9
		tr.WriteString(html.EscapeString(job.Data))
40 9
		tr.WriteString(`</td><td><div class="dropdown btn-group-xs"><button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu`)
41 9
		tr.WriteString(strconv.Itoa(k))
42 9
		tr.WriteString(`" data-toggle="dropdown" aria-expanded="true"> Actions <span class="caret"></span></button><ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu`)
43 9
		tr.WriteString(strconv.Itoa(k))
44 9
		tr.WriteString(`"><li role="presentation"><a role="menuitem" class="addSample" data-jobid="`)
45 9
		tr.WriteString(strconv.Itoa(int(job.ID)))
46 9
		tr.WriteString(`" href="?server=`)
47 9
		tr.WriteString(server)
48 9
		tr.WriteString(`&tube=`)
49 9
		tr.WriteString(url.QueryEscape(tube))
50 9
		tr.WriteString(`&action=addSample"><i class="glyphicon glyphicon-plus glyphicon-white"></i> Add to samples </a></li><li role="presentation"><a role="menuitem" href="?server=`)
51 9
		tr.WriteString(server)
52 9
		tr.WriteString(`&tube=`)
53 9
		tr.WriteString(url.QueryEscape(tube))
54 9
		tr.WriteString(`&state=`)
55 9
		tr.WriteString(job.State)
56 9
		tr.WriteString(`&action=deleteJob&jobid=`)
57 9
		tr.WriteString(strconv.Itoa(int(job.ID)))
58 9
		tr.WriteString(`"><i class="glyphicon glyphicon-remove glyphicon-white"></i> Delete</a> </li><li role="presentation"><a role="menuitem" href="?server=`)
59 9
		tr.WriteString(server)
60 9
		tr.WriteString(`&tube=`)
61 9
		tr.WriteString(url.QueryEscape(tube))
62 9
		tr.WriteString(`&state=`)
63 9
		tr.WriteString(job.State)
64 9
		tr.WriteString(`&action=kickJob&jobid=`)
65 9
		tr.WriteString(strconv.Itoa(int(job.ID)))
66 9
		tr.WriteString(`"><i class="glyphicon glyphicon-forward glyphicon-white"></i> Kick </a></li></ul></div></td></tr>`)
67
	}
68 9
	buf.WriteString(`<section id="actionsRow"><a class="btn btn-default btn-sm" href="?server=`)
69 9
	buf.WriteString(server)
70 9
	buf.WriteString(`&tube=`)
71 9
	buf.WriteString(url.QueryEscape(tube))
72 9
	buf.WriteString(`"><i class="glyphicon glyphicon-backward"></i>  &nbsp;Back to tube</a></section><section id="searchResult"><div class="row"><div class="col-sm-12"><table class="table table-striped table-hover" style="table-layout:fixed;"><thead><tr><th class="col-md-1">id</th><th class="col-md-1">state</th><th>data</th><th class="col-md-1">action</th></tr></thead><tbody>`)
73 9
	buf.WriteString(tr.String())
74 9
	buf.WriteString(`</tbody></table></div></div>First `)
75 9
	buf.WriteString(limit)
76 9
	buf.WriteString(` rows are displayed for each state.<br/><br/></section>`)
77 9
	return buf.String()
78
}

Read our documentation on viewing source code .

Loading