-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.html
285 lines (266 loc) · 11.1 KB
/
index.html
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection" />
<link type="text/css" rel="stylesheet" href="css/index.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PineSQL</title>
</head>
<body>
<header>
<div class="row">
<div class="input-field col s12">
<div><div id="ping">Connect to server first</div><div id="exectime">Execute a function to measure time</div></div>
<div class="divider"></div>
<div class="row"></div>
<input name="run" placeholder="PineSQL-friendly commands only" id="cmd" type="text" style="color: black; -webkit-app-region: no-drag;">
<input name="param" placeholder="Function parameter" id="param" type="text" style="color: black; display: none;">
<input id="prevValue" name="prevValue" type="hidden">
<a class="waves-effect waves-light btn" id="run" name="run">Run</a>
<a class="waves-effect waves-teal btn-flat" id="prevButton" name="prevButton">Previous command</a>
<a class="waves-effect waves-teal btn-flat" id="buildButton" name="buildButton">Build result</a>
<div class="chip right" id="chip_cmd" title="Use 'help' to get available commands">
No command assigned
</div>
</div>
</div>
</header>
<main>
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s12">
<textarea id="log" class="materialize-textarea" readonly></textarea>
</div>
</div>
</form>
</div>
</main>
<script>
if (typeof module === 'object') {
window.module = module;
module = undefined;
}
</script>
<script src="js/base.js"></script>
<script>
const mysql = require('mysql')
const electron = require('electron')
const ipc = require('electron').ipcRenderer
const request = require('request')
const compareVersions = require('compare-versions');
const settings = require('electron-settings')
const fs = require('fs');
const run = document.getElementById('run')
const cmd = document.getElementById('cmd')
const log = document.getElementById('log')
const chip = document.getElementById('chip_cmd')
const paraminput = document.getElementById('param')
const prevValue = document.getElementById('prevValue')
const prevButton = document.getElementById('prevButton')
const buildButton = document.getElementById('buildButton')
const pingObj = document.getElementById("ping")
const exectime = document.getElementById("exectime")
const pjson = require('./package.json');
/* const lang_settings = require('./lang/main.json')
let lang
const lang_avail = lang_settings.list
ipc.send("lang_detect")
ipc.on('lang_detect_reply', (event, arg) => {
if (lang_avail.includes(arg)) {
lang = require('./lang/' + lang_settings.packages[arg])
console.log("Language detected: " + arg)
} else {
lang = require('./lang/en-US.json')
console.log("Using default language: en-US")
}
}) */
console.log("PineSQL " + pjson.version)
run.addEventListener('click', function(event) {
const split = cmd.value.split(" ");
let port
let portSplit
let build
switch (split[0]) {
case "connect":
appendLog("Command 'connect' is deprecated, use 'ping' instead", "ERROR")
break;
case "exit":
ipc.send('exit');
break;
case "query":
portSplit = split[1].split(":")
port = typeof portSplit[1] === 'undefined' ? 3306 : portSplit[1];
appendLog("Executing " + paraminput.value + " " + "on " + portSplit[0] + ":" + port, "QUERY")
query(portSplit[0], split[2], split[3], paraminput.value, port)
break;
case "querydb":
portSplit = split[1].split(":")
port = typeof portSplit[1] === 'undefined' ? 3306 : portSplit[1];
if (split[5] == "build") {
build = 1
} else {
build = 0
}
appendLog("Executing " + paraminput.value + " " + "on " + split[4] + " in " + portSplit[0] + ":" + port, "QUERYDB")
querydb(portSplit[0], split[2], split[3], paraminput.value, split[4], port, build)
break;
case "ping":
portSplit = split[1].split(":")
port = typeof portSplit[1] === 'undefined' ? 3306 : portSplit[1];
appendLog("Sending ping to " + portSplit[0] + ":" + port + " " + split[2], "CONNECT")
ping(portSplit[0], split[2], split[3], port)
break;
case "clear":
log.value = "";
M.textareaAutoResize($('#log'));
break;
case "help":
electron.shell.openExternal("https://github.com/ivan770/pinesql/wiki/PineSQL-friendly-commands")
break;
default:
appendLog("Error! Command not found.", "ERROR")
break;
}
prevValue.value = cmd.value;
cmd.value = ""
paraminput.value = ""
chip.innerText = "No command assigned"
chip.title = "Use 'help' to get available commands"
paraminput.style.display = "none"
})
prevButton.addEventListener('click', function(event) {
cmd.value = prevValue.value
detect()
})
/* document.addEventListener("keydown", function(e) {
if (e.which === 123) {
ipc.send('developer')
}
}); */
cmd.addEventListener("keydown", function(e) {
if (e.which === 13) {
run.click()
}
});
cmd.addEventListener("keydown", function(e) {
if (e.which === 38) {
cmd.value = prevValue.value
}
});
paraminput.addEventListener("keydown", function(e) {
if (e.which === 13) {
run.click()
}
});
buildButton.addEventListener("click" , function (e) {
ipc.send('buildOpen')
})
function detect() {
var split = cmd.value.split(" ");
switch (split[0]) {
case "exit":
chip.title = "'exit'"
paraminput.style.display = "none"
chip.innerText = "Quit PineSQL"
break;
case "query":
chip.title = "'query hostname username password'"
paraminput.style.display = "inline"
chip.innerText = "Execute SQL"
break;
case "querydb":
chip.title = "'querydb hostname username password database build'"
paraminput.style.display = "inline"
chip.innerText = "Execute SQL on database"
break;
case "ping":
chip.title = "'ping hostname username password'"
paraminput.style.display = "none"
chip.innerText = "Send ping to server"
break;
case "clear":
chip.title = "'clear'"
paraminput.style.display = "none"
chip.innerText = "Clear logs"
break;
case "help":
chip.title = "'help'"
paraminput.style.display = "none"
chip.innerText = "Open help page"
break;
default:
chip.title = "Use 'help' to get available commands"
paraminput.style.display = "none"
chip.innerText = "No command assigned"
break;
}
}
if(settings.has('settings_build') === true){
if(typeof settings.get('settings_build') === "boolean"){
if(settings.get('settings_build') === true){
buildButton.style.display = "inline"
} else {
buildButton.style.display = "none"
}
}
}
if(settings.has('settings_functiontime') === true){
if(typeof settings.get('settings_functiontime') === "boolean"){
if(settings.get('settings_functiontime') === true){
exectime.style.display = "inline"
} else {
exectime.style.display = "none"
}
}
}
if(settings.has('settings_developer') === true){
if(typeof settings.get('settings_developer') === "boolean"){
if(settings.get('settings_developer') === true){
ipc.send('developer')
}
}
}
if(settings.has('settings_update') === true){
if(typeof settings.get('settings_update') === "boolean"){
if(settings.get('settings_update') === true){
updateCheck()
}
}
}
cmd.addEventListener("keyup", detect);
document.addEventListener('drop', function (e) {
e.preventDefault();
e.stopPropagation();
for (let f of e.dataTransfer.files) {
if(f.path.slice((f.path.lastIndexOf(".") - 1 >>> 0) + 2) === "psql"){
if(f.size < 2048){
if(typeof JSON.parse(fs.readFileSync(f.path).toString()).main === "undefined" || typeof JSON.parse(fs.readFileSync(f.path).toString()).param === "undefined"){
appendLog("'main' or 'param' empty", "SCRIPT")
} else {
cmd.value = JSON.parse(fs.readFileSync(f.path).toString()).main
paraminput.value = JSON.parse(fs.readFileSync(f.path).toString()).param
detect()
}
} else {
appendLog("Too large file", "SCRIPT")
}
} else {
appendLog("Only .psql files supported", "SCRIPT")
}
}
});
document.addEventListener('dragover', function (e) {
e.preventDefault();
e.stopPropagation();
});
</script>
<script src="js/commands.js"></script>
<script src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<script>
if (window.module) module = window.module;
</script>
</body>
</html>