Compare commits
18 Commits
4f64cb71eb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a579f2e995 | |||
| d66cf4483b | |||
| ca08a3ced9 | |||
| af1a64f2dc | |||
| 084cbb2b5f | |||
| e67df056b6 | |||
| 67fbedba7d | |||
| 1161670865 | |||
| c983e0c99d | |||
| ccb7c6dbed | |||
| ba1a68a255 | |||
| 5702600095 | |||
| 306dd41e3b | |||
| c4475a1458 | |||
| 85afdbdbbe | |||
| 5dec469c24 | |||
| f38f06bef6 | |||
| a28fdb198b |
13
LICENSE
Normal file
13
LICENSE
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
Version 2, December 2004
|
||||||
|
|
||||||
|
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim or modified
|
||||||
|
copies of this license document, and changing it is allowed as long
|
||||||
|
as the name is changed.
|
||||||
|
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
Applicazione web per interfacciarsi a PizzaExpress, disponibile per il download su [questo repository](https://git.fiorencis.eu/EduProjects/PizzaExpress) ([release compilata](https://git.fiorencis.eu/EduProjects/PizzaExpress/releases))
|
||||||
|
|
||||||
## Informazioni su CORS
|
## Informazioni su CORS
|
||||||
Per svariati motivi il web frontend potrebbe non riuscire ad effettuare richieste API ad altri endpoint per direttive CORS.
|
Per svariati motivi il web frontend potrebbe non riuscire ad effettuare richieste API ad altri endpoint per direttive CORS.
|
||||||
In caso di errori CORS assicurarsi che:
|
In caso di errori CORS assicurarsi che:
|
||||||
|
|||||||
21
add.html
Normal file
21
add.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="it">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Aggiungi pizza</title>
|
||||||
|
<script src="script.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form id="addForm" onsubmit="handleAddPizza(event)" >
|
||||||
|
<label for="name">Nome</label><br>
|
||||||
|
<input type="text" id="name" name="nome" required><br>
|
||||||
|
<label for="prezzo">Prezzo</label><br>
|
||||||
|
<input type="number" step="0.01" id="price" name="prezzo" required><br>
|
||||||
|
<label for="note">Note</label><br>
|
||||||
|
<input type="text" id="note" name="note" required>
|
||||||
|
<br><br>
|
||||||
|
<input type="submit" value="Aggiungi">
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
12
index.html
12
index.html
@@ -12,10 +12,14 @@
|
|||||||
<h1>PizzaExpress</h1>
|
<h1>PizzaExpress</h1>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<button onclick="location.href='add.html'">+</button>
|
<div class="pageControls">
|
||||||
<button onclick="listPizze()">Aggiorna</button>
|
<div>
|
||||||
<br><br>
|
<button onclick="window.open('add.html', 'popup', 'width=400,height=300')">+</button>
|
||||||
<div id="tabellaPizze"></div>
|
<button onclick="listPizze()">Aggiorna</button>
|
||||||
|
<br><br>
|
||||||
|
</div>
|
||||||
|
<div id="tabellaPizze"></div>
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
27
script.js
27
script.js
@@ -1,4 +1,4 @@
|
|||||||
const apiUrl = "http://localhost:5011";
|
const apiUrl = "https://localhost:7297"; // Inserire qui l'URL del web server Kestrel
|
||||||
|
|
||||||
function listPizze(){
|
function listPizze(){
|
||||||
let reply;
|
let reply;
|
||||||
@@ -11,7 +11,7 @@ function listPizze(){
|
|||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((pizze) => {
|
.then((pizze) => {
|
||||||
// Creiamo la tabella
|
// Creiamo la tabella
|
||||||
let table = '<table><tr><th>ID</th><th>Nome</th><th>Prezzo</th><th>Azioni</th></tr>';
|
let table = '<table><tr><th>ID</th><th>Nome</th><th>Prezzo</th><th>Note</th><th>Azioni</th></tr>';
|
||||||
|
|
||||||
// Aggiungiamo ogni pizza come riga della tabella
|
// Aggiungiamo ogni pizza come riga della tabella
|
||||||
pizze.pizze.forEach(pizza => {
|
pizze.pizze.forEach(pizza => {
|
||||||
@@ -19,6 +19,7 @@ function listPizze(){
|
|||||||
<td>${pizza.id}</td>
|
<td>${pizza.id}</td>
|
||||||
<td>${pizza.nome}</td>
|
<td>${pizza.nome}</td>
|
||||||
<td>${pizza.prezzo.toFixed(2)}€</td>
|
<td>${pizza.prezzo.toFixed(2)}€</td>
|
||||||
|
<td>${pizza.note}</td>
|
||||||
<td><button class="editBtn" onclick="editPizza(${pizza.id})">Modifica</button>
|
<td><button class="editBtn" onclick="editPizza(${pizza.id})">Modifica</button>
|
||||||
<button class="delBtn" onclick="deletePizza(${pizza.id})">X</button></td>
|
<button class="delBtn" onclick="deletePizza(${pizza.id})">X</button></td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
@@ -84,14 +85,14 @@ function editPizza(id){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPizza(nome, id, prezzo){
|
function addPizza(nome, prezzo, note){
|
||||||
const myHeaders = new Headers();
|
const myHeaders = new Headers();
|
||||||
myHeaders.append("Content-Type", "application/json");
|
myHeaders.append("Content-Type", "application/json");
|
||||||
|
|
||||||
const raw = JSON.stringify({
|
const raw = JSON.stringify({
|
||||||
"id": id,
|
|
||||||
"nome": nome,
|
"nome": nome,
|
||||||
"prezzo": prezzo
|
"prezzo": prezzo,
|
||||||
|
"note": note
|
||||||
});
|
});
|
||||||
|
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
@@ -101,14 +102,24 @@ function addPizza(nome, id, prezzo){
|
|||||||
redirect: "follow"
|
redirect: "follow"
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch(apiUrl + "/api/pizze/" + id, requestOptions)
|
fetch(apiUrl + "/api/pizze", requestOptions)
|
||||||
.then((response) => response.text())
|
.then((response) => response.text())
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
alert("Pizza aggiunta con successo!");
|
alert("Pizza aggiunta con successo! Aggiorna la lista per mostrarla in pagina.");
|
||||||
listPizze();
|
window.close();
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
alert("Errore nell'aggiunta, controllare la console per dettagli sull'errore.");
|
alert("Errore nell'aggiunta, controllare la console per dettagli sull'errore.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleAddPizza(event){
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const nome = document.getElementById("name").value;
|
||||||
|
const prezzo = document.getElementById("price").value;
|
||||||
|
const note = document.getElementById("note").value;
|
||||||
|
|
||||||
|
addPizza(nome, prezzo, note);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user