-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.html
160 lines (128 loc) · 5.47 KB
/
config.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Configuration Editor</title>
<meta charset="UTF-8">
<meta content="utf-8" http-equiv="encoding">
<link rel="stylesheet" href="./css/leaflet.css" />
<link rel="stylesheet" href="./css/hyfive-manual.css" />
<!-- Load own scripts type="text/javascript"-->
<script src="./js/ui.js" type="module"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<style>
</style>
</head>
<body>
<div id="whole">
<div id="navbar">
<img src="./assets/ProjectLogo.png" alt="ProjectLogo" id="logo"></img>
<div id="navbar-right">
<a href="./index.html">Charts</a>
<a href="./manual.html">Manual</a>
<a class="active" href="./config.html">Config</a>
</div>
</div>
<main>
<div>
<h1>Configuration Editor</h1>
<form id="jsonForm">
<label for="url">URL:</label>
<input type="text" id="url" name="url"><br>
<label for="token">Token:</label>
<input type="text" id="token" name="token"><br>
<label for="org">Organization:</label>
<input type="text" id="org" name="org"><br>
<label for="bucket">Bucket:</label>
<input type="text" id="bucket" name="bucket"><br>
<label for="username">Username:</label>
<input type="text" id="username" name="username"><br>
<label for="password">Password:</label>
<input type="text" id="password" name="password"><br>
<button type="submit">Save Changes</button>
</form>
</div>
<h2>Warning, this will permanently change files serverside! </h2>
</div>
</main>
<script>
// Create a new div element for the message
var messageDiv = document.createElement("div");
// Set the content of the message
messageDiv.innerHTML = "";
// Style the message (optional)
messageDiv.style.backgroundColor = "lightblue";
messageDiv.style.padding = "10px";
messageDiv.style.border = "1px solid #ccc";
messageDiv.style.textAlign = "center";
// Append the message to the body of the HTML document
document.body.appendChild(messageDiv);
// Get the JSON data and populate the form fields
fetch('./settings.json')
.then(response => response.json())
.then(data => {
// Work with the JSON data here
const jsonData = {
"url": data.url,
"token": data.token,
"org": data.org,
"bucket": data.bucket,
"username": data.username,
"password": data.password
};
const jsonForm = document.getElementById('jsonForm');
const inputs = jsonForm.elements;
for (const key in jsonData) {
if (inputs[key]) {
inputs[key].value = jsonData[key];
}
}
// Handle form submission
jsonForm.addEventListener('submit', function (event) {
event.preventDefault();
// Create a new JSON object with the updated values
const updatedData = {
"url": inputs.url.value,
"token": inputs.token.value,
"org": inputs.org.value,
"bucket": inputs.bucket.value,
"username": inputs.username.value,
"password": inputs.password.value
};
// You can now use the updatedData object as needed, e.g., send it to the server
fetch('./update-config.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(updatedData),
})
.then(response => response.text())
.then(data => {
console.log(data); // Server response message
messageDiv.innerHTML = "Success updating JSON on the server";
})
.catch(error => {
console.error('Error updating JSON on the server:', error);
messageDiv.innerHTML = "Error updating JSON on the server:', " + error;
});
});
})
.catch(error => {
console.error('Error fetching JSON:', error);
messageDiv.innerHTML = "Error updating JSON on the server:', " + error;
});
/*
const jsonData = {
"url": "http://hyfive.info:8086",
"token": "pD7hE8gVEAkEU2ewamqMCTNzoBOFuv3Qmyu6-awH5uaHhHc8ArgRgIkWGzFf_k0KYyVQ3XFIX7eed2uq27AdjQ==",
"org": "HyFive",
"bucket": "hyfive",
"username": "hyfive",
"password": "hyfive"
}; */
</script>
</body>
</html>