mirror of
https://github.com/karma-riuk/crab-webapp.git
synced 2025-07-05 06:08:13 +02:00
added simple fronted
This commit is contained in:
62
public/index.html
Normal file
62
public/index.html
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Dataset Downloader & Answer Uploader</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 2em auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldset {
|
||||||
|
margin-bottom: 1.5em;
|
||||||
|
padding: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
padding: 0.5em 1em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Crab Webapp</h1>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<legend><strong>Download a Dataset</strong></legend>
|
||||||
|
<label for="datasetSelect">Dataset:</label>
|
||||||
|
<select id="datasetSelect">
|
||||||
|
<option value="comment_generation">comment_generation</option>
|
||||||
|
<option value="code_refinement">code_refinement</option>
|
||||||
|
</select>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="withContext">
|
||||||
|
Include context
|
||||||
|
</label>
|
||||||
|
<br /><br />
|
||||||
|
<button id="downloadBtn">Download</button>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<legend><strong>Upload Your Answers</strong></legend>
|
||||||
|
<label for="answerType">Type:</label>
|
||||||
|
<select id="answerType">
|
||||||
|
<option value="comments">Comments</option>
|
||||||
|
<option value="refinement">Refinement</option>
|
||||||
|
</select>
|
||||||
|
<br /><br />
|
||||||
|
<input type="file" id="fileInput" accept="application/json" />
|
||||||
|
<br /><br />
|
||||||
|
<button id="uploadBtn">Upload JSON</button>
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
|
<div id="status" style="color: green;"></div>
|
||||||
|
|
||||||
|
<script src="js/index.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
36
public/js/index.js
Normal file
36
public/js/index.js
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// Download logic
|
||||||
|
document.getElementById('downloadBtn').onclick = () => {
|
||||||
|
const ds = document.getElementById('datasetSelect').value;
|
||||||
|
const withCtx = document.getElementById('withContext').checked;
|
||||||
|
const url = `/datasets/download/${ds}` + (withCtx ? '?withContext=true' : '');
|
||||||
|
window.location = url;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Upload logic
|
||||||
|
document.getElementById('uploadBtn').onclick = async () => {
|
||||||
|
const type = document.getElementById('answerType').value;
|
||||||
|
const fileInput = document.getElementById('fileInput');
|
||||||
|
if (!fileInput.files.length) {
|
||||||
|
return alert('Please choose a JSON file first.');
|
||||||
|
}
|
||||||
|
const file = fileInput.files[0];
|
||||||
|
const form = new FormData();
|
||||||
|
form.append('file', file);
|
||||||
|
|
||||||
|
const res = await fetch(`/answers/submit/${type}`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: form
|
||||||
|
});
|
||||||
|
|
||||||
|
const json = await res.json();
|
||||||
|
console.log(json)
|
||||||
|
const statusEl = document.getElementById('status');
|
||||||
|
if (res.ok) {
|
||||||
|
statusEl.style.color = 'green';
|
||||||
|
statusEl.textContent = json.message || 'Upload succeeded!';
|
||||||
|
} else {
|
||||||
|
statusEl.style.color = 'red';
|
||||||
|
statusEl.textContent = json.error + (json.message ? (': ' + json.message) : '');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -13,6 +13,7 @@ app.use(cors());
|
|||||||
app.use(json());
|
app.use(json());
|
||||||
|
|
||||||
// Use routes
|
// Use routes
|
||||||
|
app.use(express.static("public"));
|
||||||
app.use('/', routes);
|
app.use('/', routes);
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
|
Reference in New Issue
Block a user