-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.go
261 lines (231 loc) · 6.86 KB
/
gui.go
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
package main
import (
"container/list"
"fmt"
"github.com/webview/webview"
)
var indexHTML = `
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!--<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>-->
<script type="text/javascript">
function connectForm(self){
var host = document.getElementById('influxdb_host').value;
var port = document.getElementById('influxdb_port').value;
var username = document.getElementById('influxdb_username').value;
var password = document.getElementById('influxdb_password').value;
var msg = host+";"+port+";"+username+";"+password;
external.invoke('connectInfluxDB:'+msg);
return false;
}
function createQuery(){
var query = document.getElementById('influxdb_query').value;
var database = document.getElementById('inluxdb_db').value;
var data = {
query: query,
database: database
};
external.invoke('createInfluxDBQuery:'+JSON.stringify(data));
return false;
}
function toggleConnectionStatus(){
var connectionStatus = document.getElementById('connection_status');
if(connectionStatus.className == "not_connected"){
connectionStatus.classList.remove("not_connected");
connectionStatus.classList.add("connected");
}
else {
connectionStatus.classList.remove("connected");
connectionStatus.classList.add("not_connected");
}
}
function toggleHistory(self){
var historyContainer = document.getElementById('history_container');
if(historyContainer.className == "hidden"){
historyContainer.classList.remove("hidden");
self.classList.remove("no_history");
self.classList.add("history");
}
else {
historyContainer.classList.add("hidden");
self.classList.remove("history");
self.classList.add("no_history");
}
}
function setQuery(query) {
document.getElementById('influxdb_query').value = query;
}
</script>
<style>
html, body {
margin: 0;
padding: 0;
overflow: hidden;
}
header {
width: 100vw;
height: 3em;
background: #ccc;
padding-top: 0.5em;
padding-left: 1em;
}
#connect_container form {
width: 70%
float: left;
}
#influxdb_host {
width: 20%;
}
#connection_status {
float: right;
margin-right: 2em;
position: relative;
top: -1.7em;
}
#show_history {
float: right;
margin-right: 0.5em;
cursor: pointer;
font-size: 2em;
position: relative;
top: -1.2em;
}
#query_input_container {
width: 100vw;
height: 100%;
padding-left: 1em;
}
#influxdb_query {
width: 70%;
}
#query_content_container {
width: 100vw;
height: 100%;
}
#query_content {
width: 96%;
margin-left: 2%;
height: 40em;
}
.connected, .history {
color: #4CAF50;
}
.not_connected, .no_history {
color: #f44336;
}
.hidden {
display: none;
}
input[type=submit] {
background-color: #008CBA;
border: none;
color: white;
padding: 8px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 12px;
font-weight: bold;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
}
select, input[type=text], input[type=password] {
border: 1px solid #80e5ff;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
border-radius: 4px;
padding: 3px;
}
#history_container {
width: 100vw;
height: 100%;
padding-left: 1em;
padding-right: 1em;
}
#history_content_dropdown {
width: 95%;
}
</style>
</head>
<body>
<div id="app">
<header>
<div id="connect_container">
<form onsubmit="return connectForm(this)">
<input type="text" placeholder="Hostname" id="influxdb_host" name="influxdb_host" />
<input type="text" placeholder="Port" id="influxdb_port" name="influxdb_port" />
<input type="text" placeholder="Username" id="influxdb_username" name="influxdb_username" />
<input type="password" placeholder="Password" id="influxdb_password" name="influxdb_password" />
<input type="submit" value="Connect" />
</form>
<span id="connection_status" title="Connection status"class="not_connected">●</span>
<span onClick='toggleHistory(this);' id="show_history" title="Show history" class="no_history">⏍</span>
</div>
</header>
<div id="query_input_container">
<form onsubmit="return createQuery()">
<input type="text" placeholder="Query" id="influxdb_query" name="influxdb_query" />
<select name="inluxdb_db" id="inluxdb_db">
<option value="">Database</option>
</select>
<input type="submit" value="Send query" />
</form>
</div>
<div id="history_container" class="hidden">
<select onchange="setQuery(this.options[this.selectedIndex].value)" id="history_content_dropdown">
<option value="SHOW MEASUREMENTS;">SHOW MEASUREMENTS;</option>
<option value="SELECT * FROM measurement LIMIT 1;">SELECT * FROM measurement LIMIT 1;</option>
<option value="SHOW DATABASES;">SHOW DATABASES;</option>
</select>
</div>
<div id="query_content_container">
<textarea id="query_content"></textarea>
</div>
</div>
</body>
</html>
`
func createAlertDialog(w webview.WebView, message string, errMessage string) {
w.Dialog(webview.DialogTypeAlert, webview.DialogFlagError, message, errMessage)
}
func writeHistoryLogs(w webview.WebView, content string) {
data := fmt.Sprintf("document.getElementById('history_content_dropdown').innerHTML = \"%s\";", content)
w.Eval(data)
}
func createInfluxDBQueryResponse(data string) string {
cmd := fmt.Sprintf("window.mv.viewmodel.queryResult(\"%v\");", data)
//cmd := `window.mv.viewmodel.queryResult("` + data + `");`
fmt.Printf("Query result: %v", cmd)
return cmd
}
func createInfluxDBQueryResponseJSON(data string) string {
cmd := fmt.Sprintf("window.populateDataTable(%v);", data)
fmt.Printf("JSON cmd: %v", cmd)
return cmd
}
func popluateConnections(w webview.WebView, connections *list.List) {
data := "window.mv.viewmodel.setConnections(["
for connection := connections.Front(); connection != nil; connection = connection.Next() {
option := fmt.Sprintf("'%v'", connection.Value)
data = fmt.Sprintf("%s%s,", data, option)
//fmt.Printf("connection: %v", connection.Value)
}
data = fmt.Sprintf("%s]);", data)
fmt.Printf("connection cmd: %s", data)
w.Eval(data)
}
func updateConnectionStatus(w webview.WebView, status bool) {
cmd := fmt.Sprintf("window.mv.viewmodel.setConnection(%v);", status)
w.Eval(cmd)
}
func populateDatabases(w webview.WebView, databases *list.List) {
cmd := "window.mv.viewmodel.setDatabases(["
for database := databases.Front(); database != nil; database = database.Next() {
cmd = fmt.Sprintf("%s'%v',", cmd, database.Value)
}
cmd = fmt.Sprintf("%s]);", cmd)
w.Eval(cmd)
}