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
	"sort"
17
	"strconv"
18
	"strings"
19

20
	"github.com/xuri/aurora/beanstalk"
21
)
22

23
// tplSampleJobEdit render a sample job edit form.
24
func tplSampleJobEdit(key string, alert string) string {
25 10
	var err error
26 10
	var buf, action, title, name, savedTo, saveTo, data, ST, tubeList, TTR strings.Builder
27 10
	if key == "" {
28 10
		action.WriteString(`?action=actionNewSample`)
29 10
		title.WriteString(`<h4 class="text-info">New sample job</h4>`)
30 10
		TTR.WriteString(strconv.Itoa(DefaultTTR))
31 10
	} else {
32 10
		action.WriteString(`?action=actionEditSample&key=`)
33 10
		action.WriteString(key)
34 10
		name.WriteString(html.EscapeString(getSampleJobNameByKey(key)))
35 10
		data.WriteString(html.EscapeString(getSampleJobDataByKey(key)))
36 10
		TTR.WriteString(strconv.Itoa(getSampleJobTtrByKey(key)))
37 10
		title.WriteString(`<h4 class="text-info">Edit: `)
38 10
		title.WriteString(name.String())
39 10
		title.WriteString(`</h4>`)
40
		for _, j := range sampleJobs.Jobs {
41 9
			if key == j.Key {
42
				for _, t := range j.Tubes {
43 0
					saveTo.WriteString(`<div class="control-group"><div class="controls"><label class="checkbox-inline"><input type="checkbox" name="tubes[`)
44 0
					saveTo.WriteString(t)
45 0
					saveTo.WriteString(`]" value="1" checked="checked">`)
46 0
					saveTo.WriteString(t)
47 0
					saveTo.WriteString(`</label></div></div>`)
48
				}
49
			}
50
		}
51
	}
52

53
	for _, server := range selfConf.Servers {
54 10
		var bstkConn *beanstalk.Conn
55 10
		tubeList.Reset()
56 10
		if bstkConn, err = beanstalk.Dial("tcp", server); err != nil {
57 10
			continue
58
		}
59 10
		tubes, _ := bstkConn.ListTubes()
60 10
		sort.Strings(tubes)
61 10
		bstkConn.Close()
62
		for _, v := range tubes {
63 10
			var checked string
64
			for _, j := range sampleJobs.Jobs {
65 9
				if j.Key == key {
66
					for _, t := range j.Tubes {
67 0
						if t == v {
68 0
							checked = `checked="checked"`
69
						}
70
					}
71
				}
72
			}
73 10
			tubeList.WriteString(`<div class="control-group"><div class="controls"><label class="checkbox-inline"><input type="checkbox" name="tubes[`)
74 10
			tubeList.WriteString(v)
75 10
			tubeList.WriteString(`]" value="1" `)
76 10
			tubeList.WriteString(checked)
77 10
			tubeList.WriteString(`>`)
78 10
			tubeList.WriteString(v)
79 10
			tubeList.WriteString(`</label></div></div>`)
80
		}
81 10
		ST.WriteString(`<div class="pull-left" style="padding-right: 35px;">`)
82 10
		ST.WriteString(server)
83 10
		ST.WriteString(`<blockquote>`)
84 10
		ST.WriteString(tubeList.String())
85 10
		ST.WriteString(`</blockquote></div>`)
86
	}
87 10
	if name.String() != "" {
88 0
		savedTo.WriteString(`<div class="pull-left" style="padding-right: 35px;">Saved to: <blockquote>`)
89 0
		savedTo.WriteString(saveTo.String())
90 0
		savedTo.WriteString(`</blockquote></div>`)
91
	}
92 10
	buf.WriteString(`<form name="sampleJobsEdit" action="`)
93 10
	buf.WriteString(action.String())
94 10
	buf.WriteString(`" method="POST"><div class="clearfix form-group"><div class="pull-left">`)
95 10
	buf.WriteString(title.String())
96 10
	buf.WriteString(`</div><div class="pull-right"><a href="./sample?action=manageSamples" class="btn btn-default btn-sm"><i class="glyphicon glyphicon-list"></i> Manage samples</a></div></div><div class="form-group"><fieldset>`)
97 10
	buf.WriteString(alert)
98 10
	buf.WriteString(`<div class="control-group"><label class="control-label" for="addsamplename"><b>Name *</b></label><div class="controls form-group"><input class="form-control input-sm focused" id="addsamplename" name="name" type="text" style="width: 15em;" required="" value="`)
99 10
	buf.WriteString(name.String())
100 10
	buf.WriteString(`" autocomplete="off"></div><label class="control-label" for="addsamplettr"><b>TTR (Default: <i>`)
101 10
	buf.WriteString(strconv.Itoa(DefaultTTR))
102 10
	buf.WriteString(`</i>) *</b></label><div class="controls form-group"><input class="form-control input-sm" id="addsamplettr" name="ttr" type="number" style="width: 15em;" required="" value="`)
103 10
	buf.WriteString(TTR.String())
104 10
	buf.WriteString(`" autocomplete="off"></div></div></fieldset><div class="clearfix"><label class="control-label"><b>Available on tubes *</b></label><br/>`)
105 10
	buf.WriteString(savedTo.String())
106 10
	buf.WriteString(ST.String())
107 10
	buf.WriteString(`</div><div><label class="control-label" for="jobdata"><b>Job data *</b></label><textarea name="jobdata" id="jobdata" class="form-control" required="" rows="3">`)
108 10
	buf.WriteString(data.String())
109 10
	buf.WriteString(`</textarea></div></div><div><input type="submit" class="btn btn-success" value="Save"/></div></form>`)
110 10
	return buf.String()
111
}

Read our documentation on viewing source code .

Loading