-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.html
126 lines (108 loc) · 3.92 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Configuration Page</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
label {
display: block;
margin-bottom: 8px;
}
input {
margin-bottom: 15px;
}
button {
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>Configuration Page</h1>
<form id="configForm">
<label for="pomosBeforeLongRest">Pomos Before Long Rest:</label>
<input type="number" id="pomosBeforeLongRest" name="pomosBeforeLongRest" required>
<label for="pomoCount">Current pomo:</label>
<input type="number" id="pomoCount" name="pomoCount" required>
<label for="pomoTime">Pomo Time (seconds):</label>
<input type="number" id="focusTime" name="focusTime" required>
<label for="shortRestTime">Short Rest Time (seconds):</label>
<input type="number" id="shortRestTime" name="shortRestTime" required>
<label for="longRestTime">Long Rest Time (seconds):</label>
<input type="number" id="longRestTime" name="longRestTime" required>
<label for="currTime">Current Time:</label>
<input type="number" id="currTime" name="currTime" required>
<label for="isResting">Is Resting:</label>
<input type="checkbox" id="isResting" name="isResting">
<label for="isLongResting">Is Long Resting:</label>
<input type="checkbox" id="isLongResting" name="isLongResting">
<br><br>
<button type="button" onclick="submitForm()">Save Configuration</button>
</form>
<script>
// On load, set config page values to values on /json-endpoint
fetch('/json-endpoint')
.then(response => response.json())
.then(data => {
document.getElementById('pomosBeforeLongRest').value = data.pomosBeforeLongRest;
document.getElementById('shortRestTime').value = data.shortRestTime;
document.getElementById('longRestTime').value = data.longRestTime;
document.getElementById('focusTime').value = data.focusTime;
document.getElementById('currTime').value = data.currTime;
document.getElementById('isResting').checked = data.isResting;
document.getElementById('isLongResting').checked = data.isLongResting;
document.getElementById('pomoCount').value = data.pomoCount;
})
.catch(error => {
console.error('Error fetching config:', error);
});
function submitForm() {
// Get values from the form
const pomosBeforeLongRest = document.getElementById('pomosBeforeLongRest').value;
const shortRestTime = document.getElementById('shortRestTime').value;
const longRestTime = document.getElementById('longRestTime').value;
const currTime = document.getElementById('currTime').value;
const focusTime = document.getElementById('focusTime').value;
const isResting = document.getElementById('isResting').checked;
const isLongResting = document.getElementById('isLongResting').checked;
const pomoCount = document.getElementById('pomoCount').value;
// Send the values to the server (you might want to use AJAX for this)
fetch('/save-config', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
pomosBeforeLongRest,
shortRestTime,
longRestTime,
currTime,
focusTime,
pomoCount,
isResting,
isLongResting
}),
})
.then(response => response.json())
.then(data => {
console.log('Config saved:', data);
})
.catch(error => {
console.error('Error saving config:', error);
});
}
</script>
</body>
</html>