forked from sugarlabs/musicblocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-widget.html
More file actions
38 lines (35 loc) · 1.14 KB
/
git-widget.html
File metadata and controls
38 lines (35 loc) · 1.14 KB
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
<!DOCTYPE html>
<html>
<head><title>Git Widget</title></head>
<body>
<h2>Commit to Git</h2>
<form id="commitForm">
<input type="file" name="file" required />
<input type="text" name="message" placeholder="Commit message" required />
<button type="submit">Commit</button>
</form>
<h2>History</h2>
<button onclick="fetchLog()">Refresh Log</button>
<ul id="logList"></ul>
<script>
document.getElementById('commitForm').addEventListener('submit', async function(e) {
e.preventDefault();
const formData = new FormData(this);
const res = await fetch('http://localhost:8000/commit', { method: 'POST', body: formData });
const data = await res.json();
alert(data.message);
});
async function fetchLog() {
const res = await fetch('http://localhost:8000/log');
const data = await res.json();
const logList = document.getElementById('logList');
logList.innerHTML = '';
data.commits.forEach(c => {
const li = document.createElement('li');
li.textContent = `${c.date} - ${c.message}`;
logList.appendChild(li);
});
}
</script>
</body>
</html>