open-organism-observer/sample_intake.html

139 lines
4.2 KiB
HTML
Raw Normal View History

2025-01-16 03:26:23 +01:00
<!--- this is the main file --->
<!DOCTYPE html>
<html>
<head>
<link href="bootstrap-5.0.2-dist/css/bootstrap.min.css" rel="stylesheet" ></link>
<script src="bootstrap-5.0.2-dist/js/bootstrap.bundle.min.js" ></script>
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css"</link>
2025-01-23 14:18:10 +01:00
<meta charset="utf-8">
2025-01-16 03:26:23 +01:00
<style>
#map {
height: 30em;
width: 100%;
}
</style>
</head>
<h1>Add Sample</h1>
<form class="needs-validation" id = "sample">
2025-01-16 03:26:23 +01:00
<div class="row">
<div class="col">
<label class = "form-label" for="name">
Name of Sample
</label>
</div>
<div class="col">
<input class="form-control" type="text" name="name" id = "Name"
placeholder="choose a name for your sample">
</input>
</div>
</div>
<div class="row">
<div class="col">
<label class = "form-label" for="type">Sample Type</label>
</div>
<div class="col">
<input class="form-control" type="text" name="type"
placeholder="e.g. compost"
id = "Type"></input>
</div>
</div>
<div class="row">
<div class="col">
<label class = "form-label" for="time_collection">Collection Time</label>
</div>
<div class="col">
<input class="form-control" type="datetime-local" name="time_collection"
id = "Date_Collected"></input>
</div>
</div>
<div class="row">
<div class="col">
<label class="form-label" for="notes">Notes</label>
</div>
<div class="col">
<textarea class="form-control" name="notes" id = "Notes"
placeholder="Notes about the sample"
rows="1"
cols="60"
></textarea>
</div>
</div>
<div class="row">
<div class="col">
<label class = "form-label" for="location">Location of Sample</label>
</div>
<div class="col">
2025-01-23 14:28:04 +01:00
<input class="form-control" name="location" id="Location" value=""></input>
2025-01-16 03:26:23 +01:00
</div>
</div>
<button class="btn btn-primary float-end" type="submit"> submit </button>
2025-01-16 03:26:23 +01:00
<div id="map"></div>
</form>
<script>
var map = L.map('map').fitWorld();
2025-01-23 14:28:04 +01:00
var sample_form = document.getElementById("sample");
2025-01-16 03:26:23 +01:00
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
maxNativeZoom:19,
maxZoom:25}).addTo(map);
var marker = {};
map.on('click', function(ev){
var latlng = map.mouseEventToLatLng(ev.originalEvent);
console.log(latlng.lat + ', ' + latlng.lng);
2025-01-23 14:28:04 +01:00
sample_form.location.value = latlng.lat + ', ' + latlng.lng;
2025-01-16 03:26:23 +01:00
if (marker != undefined) {
map.removeLayer(marker);
};
marker = L.marker([latlng.lat,latlng.lng]).addTo(map);
});
map.setView([53.518203, 9.983701], 16);
</script>
<script>
var db;
let openRequest = indexedDB.open("my_db");
openRequest.onerror = function() {
console.error("Error", openRequest.error);
};
openRequest.onsuccess = function() {
db = openRequest.result;
// continue working with database using db object
};
const form = document.getElementById("sample");
form.addEventListener("submit", add);
2025-01-23 14:28:04 +01:00
function add(event){
2025-01-23 14:28:04 +01:00
event.preventDefault();
2025-01-16 03:26:23 +01:00
let sample = {
"Name" : document.getElementById("Name").value,
"Type" : document.getElementById("Type").value,
2025-01-29 15:46:28 +01:00
"Date_Collected" : new Date(document.getElementById("Date_Collected").value),
2025-01-23 14:28:04 +01:00
"Place" : document.getElementById("Location").value,
2025-01-16 03:26:23 +01:00
"Notes" : document.getElementById("Notes").value
}
let transaction = db.transaction(["sample"], "readwrite");
let objectStore = transaction.objectStore("sample");
let add_request = objectStore.add(sample); // (3)
transaction.oncomplete = (event) => {
console.log("All done!");
};
transaction.onerror = (event) => {
console.log("something went wrong");
// Don't forget to handle errors!
};
2025-01-16 03:26:23 +01:00
}
</script>
</html>