285 lines
9.0 KiB
HTML
285 lines
9.0 KiB
HTML
<!------------------------------------------------------------------------------
|
|
#
|
|
# P4U Script for converting Baskets from Digikey / Mouser to P4U format
|
|
# Created by Jonas Lingua & Noah Piqué
|
|
# Date: 30.11.2023
|
|
# Version 1.4
|
|
#
|
|
------------------------------------------------------------------------------->
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<!-- Titel der Webseite -->
|
|
<meta charset="UTF-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE edge" />
|
|
<meta lang="en" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<!-- Favicon -->
|
|
<link rel="icon" href="logo.png" type="image/x-icon" />
|
|
<link rel="shortcut icon" href="logo.png" type="image/x-icon" />
|
|
<link
|
|
rel="stylesheet"
|
|
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
|
|
/>
|
|
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
|
|
|
<title>P4U-Converter</title>
|
|
|
|
<!-- Styling für den Bereich, in den Dateien gezogen werden können -->
|
|
<style>
|
|
body {
|
|
margin: 20px;
|
|
font-family: "Roboto", sans-serif;
|
|
background-color: #f8f9fa;
|
|
color: #495057;
|
|
}
|
|
.container {
|
|
padding: 20px;
|
|
border: 1px solid #ced4da;
|
|
margin: 20px;
|
|
background-color: #ffffff;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
border-radius: 10px;
|
|
}
|
|
#dropArea {
|
|
border: 2px dashed #6c757d;
|
|
padding: 30px;
|
|
text-align: center;
|
|
margin: 10px 0;
|
|
background-color: #f1f1f1;
|
|
border-radius: 10px;
|
|
transition: border-color 0.3s ease;
|
|
}
|
|
#dropArea.dragover {
|
|
border-color: #007bff;
|
|
background-color: #e8f0fe;
|
|
}
|
|
h1 {
|
|
color: #007bff;
|
|
}
|
|
|
|
#infoField {
|
|
margin-top: 20px;
|
|
}
|
|
.custom-control {
|
|
margin: 10px 0; /* Abstand über und unter dem On-Off-Slider */
|
|
}
|
|
|
|
#uploadButton:hover,
|
|
#exitButton:hover,
|
|
#fileInput-label:hover,
|
|
#download-label:hover {
|
|
background-color: #007bff;
|
|
color: #fff;
|
|
}
|
|
|
|
#creatorField {
|
|
position: absolute;
|
|
bottom: 0;
|
|
right: 0;
|
|
color: #6c757d;
|
|
margin: 10px;
|
|
}
|
|
|
|
#fileInput {
|
|
display: none;
|
|
}
|
|
|
|
#fileInput-label,
|
|
#download-label {
|
|
font-size: 1.2em;
|
|
padding: 8px 15px;
|
|
width: 200px;
|
|
text-align: center;
|
|
border: 1px solid #007bff; /* Blaue Rahmenfarbe */
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
transition: background-color 0.3s ease; /* Sanfter Farbübergang bei Hover */
|
|
display: inline-block;
|
|
}
|
|
|
|
#fileInput-label:hover,
|
|
#download-label:hover {
|
|
background-color: #007bff; /* Farbänderung bei Hover */
|
|
color: #fff; /* Textfarbe ändern, um besser sichtbar zu sein */
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- Infofeld am Ende der Webseite -->
|
|
<div id="creatorField">
|
|
Created by <a href="mailto:jonas.lingua@psi.ch">Jonas Lingua</a> &
|
|
<a href="mailto:noah.pique@psi.ch">Noah Piqué</a>
|
|
</div>
|
|
|
|
<!-- Überschrift der Seite -->
|
|
<h1>P4U-Converter</h1>
|
|
|
|
<!-- Infofeld -->
|
|
<div id="infoField">
|
|
Upload-Informations: <br />
|
|
Convert your Digikey, Mouser and Farnell baskets to P4U standard. <br />
|
|
Just upload your files here. <br />
|
|
File conditions: <br />
|
|
Digikey -> csv file in chf! <br />
|
|
Mouser -> xls file in euros!
|
|
</div>
|
|
|
|
<!-- On-Off-Slider -->
|
|
<div class="custom-control custom-switch">
|
|
<input
|
|
type="checkbox"
|
|
class="custom-control-input"
|
|
id="mySwitch"
|
|
checked
|
|
/>
|
|
<label class="custom-control-label" for="mySwitch">Fasttrack</label>
|
|
</div>
|
|
|
|
<!-- Bereich (DropArea), in den Dateien gezogen werden können -->
|
|
<div
|
|
id="dropArea"
|
|
ondrop="handleDrop(event)"
|
|
ondragover="allowDrop(event)"
|
|
ondragleave="disallowDrop(event)"
|
|
>
|
|
Drop a file to upload
|
|
</div>
|
|
|
|
<!-- Formular zum manuellen Auswählen von Dateien -->
|
|
<form
|
|
method="POST"
|
|
action="/upload"
|
|
enctype="multipart/form-data"
|
|
id="uploadForm"
|
|
onsubmit="return false;"
|
|
>
|
|
<input type="file" name="file" id="fileInput" onchange="uploadFile()" />
|
|
<label id="fileInput-label" for="fileInput">Select a basket</label>
|
|
</form>
|
|
|
|
<!-- Anzeige von Meldungen nach dem Hochladen der Datei -->
|
|
<p id="uploadMessage"></p>
|
|
|
|
<!-- Button zum Öffnen der Unterseite /download_output -->
|
|
<button
|
|
id="downloadButton"
|
|
style="display: none"
|
|
onclick="openDownloadPage()"
|
|
>
|
|
Download Output
|
|
</button>
|
|
<label id="download-label" for="downloadButton" style="display: none"
|
|
>Download Output</label
|
|
>
|
|
|
|
<script>
|
|
const slider = document.getElementById("mySwitch");
|
|
slider.addEventListener("change", function () {
|
|
const newStatus = slider.checked;
|
|
updateSliderStatus(newStatus);
|
|
});
|
|
|
|
function updateSliderStatus(newStatus) {
|
|
fetch("/update_slider_status", {
|
|
method: "POST",
|
|
body: JSON.stringify({ fasttrack_status: newStatus }),
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
}).then((response) => {
|
|
if (response.ok) {
|
|
// Erfolgreiche Aktualisierung
|
|
console.log("Slider-Status aktualisiert");
|
|
} else {
|
|
// Fehler bei der Aktualisierung
|
|
console.error("Fehler bei der Aktualisierung des Slider-Status");
|
|
}
|
|
});
|
|
}
|
|
|
|
// Funktion zum Hochladen einer ausgewählten Datei
|
|
function uploadFile() {
|
|
const fileInput = document.getElementById("fileInput");
|
|
const file = fileInput.files[0];
|
|
if (file) {
|
|
const formData = new FormData();
|
|
formData.append("file", file);
|
|
// Senden des Formulardatenobjekts an den Server
|
|
sendFormData(formData);
|
|
}
|
|
}
|
|
|
|
// Funktion zum Senden von Formulardaten an den Server
|
|
function sendFormData(formData) {
|
|
fetch("/upload", {
|
|
method: "POST", // HTTP POST-Anfrage
|
|
body: formData, // Die Formulardaten, die die Datei enthalten
|
|
})
|
|
.then((response) => response.text())
|
|
.then((message) => {
|
|
// Anzeigen der Serverantwort (Nachricht) auf der Webseite
|
|
document.getElementById("uploadMessage").innerHTML = message;
|
|
clearFileInput(); // Zurücksetzen des Datei-Eingabefelds
|
|
// Anzeigen des Download-Buttons nach erfolgreichem Hochladen
|
|
document.getElementById("download-label").style.display = "block";
|
|
})
|
|
.catch((error) => {
|
|
console.error(error);
|
|
// Anzeigen einer Fehlermeldung im Falle eines Fehlers
|
|
document.getElementById("uploadMessage").textContent =
|
|
"Error during uploading the file.";
|
|
});
|
|
}
|
|
|
|
// Zurücksetzen des Datei-Eingabefelds
|
|
function clearFileInput() {
|
|
const fileInput = document.getElementById("fileInput");
|
|
fileInput.value = "";
|
|
}
|
|
|
|
// Funktion zum Verarbeiten des Ziehens und Ablegens von Dateien in den Bereich
|
|
function handleDrop(event) {
|
|
event.preventDefault();
|
|
const dropArea = document.getElementById("dropArea");
|
|
dropArea.style.borderColor = "#ccc"; // Ändern der Rahmenfarbe auf Grau
|
|
dropArea.classList.remove("dragover"); // Entfernen der Klasse für die Schraffierung
|
|
|
|
const formData = new FormData();
|
|
const file = event.dataTransfer.files[0];
|
|
if (file) {
|
|
formData.append("file", file);
|
|
// Senden des Formulardatenobjekts an den Server (ähnlich wie bei uploadFile)
|
|
sendFormData(formData);
|
|
}
|
|
}
|
|
|
|
// Funktion zum Erlauben des Ziehens von Dateien in den Bereich
|
|
function allowDrop(event) {
|
|
event.preventDefault();
|
|
const dropArea = document.getElementById("dropArea");
|
|
dropArea.style.borderColor = "blue"; // Ändern der Rahmenfarbe auf Blau
|
|
dropArea.classList.add("dragover"); // Hinzufügen der Klasse für die Schraffierung
|
|
}
|
|
|
|
// Funktion zum Verbieten des Ziehens von Dateien in den Bereich
|
|
function disallowDrop(event) {
|
|
event.preventDefault();
|
|
const dropArea = document.getElementById("dropArea");
|
|
dropArea.style.borderColor = "#ccc"; // Ändern der Rahmenfarbe auf Grau
|
|
dropArea.classList.remove("dragover"); // Entfernen der Klasse für die Schraffierung
|
|
}
|
|
|
|
// Funktion zum Öffnen der Unterseite /download_output
|
|
function openDownloadPage() {
|
|
window.location.href = "/download_output";
|
|
// Ausblenden des Buttons nach dem Klicken
|
|
document.getElementById("download-label").style.display = "none";
|
|
document.getElementById("uploadMessage").innerHTML = "";
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|