This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
131 lines (128 loc) · 3.66 KB
/
app.js
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
/*
* Created on Tue Nov 03 2020
*
* This file is a part of the TerrabaseDB setup app
* Copyright (c) 2020, Sayan Nandan <ohsayan at outlook dot com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
const host = document.getElementById("host");
const port = document.getElementById("port");
const snapevery = document.getElementById("snapevery");
const snapkeep = document.getElementById("snapkeep");
const bgsaveDur = document.getElementById('bgsavedur');
const snapEnabled = document.getElementById('snap-y');
const bgsaveEnabled = document.getElementById('bgsave-y');
const res = document.getElementById("res");
const code = document.getElementById("launch-code");
$(document).ready(function () {
$('[data-toggle="tooltip"]').tooltip();
});
function snapBtn() {
if (snapEnabled.checked) {
snapevery.disabled = false;
snapevery.placeholder = "Duration";
snapkeep.disabled = false;
snapkeep.placeholder = "Number of snapshots";
} else {
snapevery.disabled = true;
snapevery.placeholder = "";
snapkeep.disabled = true;
snapkeep.placeholder = "";
}
}
function bgsaveBtn() {
if (bgsaveEnabled.checked) {
bgsaveDur.disabled = false;
bgsaveDur.placeholder = "120";
} else {
bgsaveDur.disabled = true;
bgsaveDur.placeholder = "";
}
}
function check() {
var command = "sdb";
var host_val = host.value.toString();
if (host_val.length === 0) {
host_val = "127.0.0.1";
}
command += " -h " + host_val;
var port_val = 2003;
if (port.value.length != 0) {
var pv = parseInt(port.value.toString());
if (isNaN(pv)) {
alert("Invalid value for port!");
res.hidden = true;
scrollUp();
return;
} else {
port_val = pv;
}
}
if ((port_val > 65535) || (port_val < 0)) {
alert("Invalid port range!");
res.hidden = true;
scrollUp();
return;
}
command += " -p " + port_val.toString();
if (bgsaveEnabled.checked) {
var dur = bgsaveDur.value;
if (!dur.length == 0) {
if (isNaN(parseInt(dur))) {
alert("Invalid value for BGSAVE duration!");
res.hidden = true;
scrollUp();
return;
} else {
command += " --saveduration " + dur;
}
}
} else {
command += " --nosave";
}
if (snapEnabled.checked) {
var every = snapevery.value.toString();
var atmost = snapkeep.value.toString();
var every = parseInt(every);
if (!isNaN(every)) {
command += " --snapevery " + every;
} else {
alert("Invalid value for snapshot duration");
res.hidden = true;
scrollUp();
return;
}
var keep = parseInt(atmost);
if (isNaN(keep)) {
alert("Invalid value for number of snapshots!");
res.hidden = true;
scrollUp();
return;
} else {
command += " --snapkeep " + keep;
}
}
code.innerText = command;
code.readOnly = true;
res.hidden = false;
scrollDown();
}
function scrollDown() {
$("html, body").animate({ scrollTop: $(document).height() - $(window).height() });
}
function scrollUp() {
$("html, body").animate({ scrollTop: 0 });
}