Commit 9d78a43c authored by Vasil Merkul's avatar Vasil Merkul
Browse files

- create/delete flight

parent 6dc42444
......@@ -23,6 +23,15 @@ public class RestController {
return "index";
}
@RequestMapping("/manageflights")
public String tickets(){
return "flights";
}
......
......@@ -14,7 +14,9 @@ import java.util.Objects;
@Entity
@Table(name = "flight", schema = "airbook", catalog = "ear2018zs_22")
public class FlightEntity {
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE)
private Integer id;
@NotNull
private Integer planeid;
......
......@@ -88,7 +88,7 @@ public class TicketEntity {
}
@JsonIgnore
@ManyToOne(cascade = {CascadeType.ALL})
@ManyToOne(cascade = {CascadeType.PERSIST})
@JoinColumn(name = "passengerid", referencedColumnName = "id", nullable = false, insertable = false, updatable = false)
public PassengerEntity getPassengerByPassengerid() {
return passengerByPassengerid;
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Manage Flights</title>
<br>
<link rel="stylesheet" type="text/css" href="../flightsresources/style.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<div id = "flights"></div>
<hr>
<div class="card">
<div class="card-header">
Add Flight
</div>
<div class="card-body">
<form id="addFlightForm">
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputFrom">From</label>
<input type="text" name="department" class="form-control" id="inputFrom">
</div>
<div class="form-group col-md-4">
<label for="inputTo">To</label>
<input type="text" name="arrival" class="form-control" id="inputTo">
</div>
</div>
<div class="form-row">
<div class="form-group col-md-5">
<label for="inputArrival">Arrival</label>
<input type="datetime-local" name="arrilvalsdate" class="form-control" id="inputArrival">
</div>
<div class="form-group col-md-5">
<label for="inputDeparture">Departure</label>
<input type="datetime-local" name="departmentdate" class="form-control" id="inputDeparture">
</div>
<div class="form-group col-md-2">
<label for="inputDistance">Distance</label>
<input type="number" name="distance" class="form-control" id="inputDistance">
</div>
</div>
<button type="submit" class="btn btn-primary float-right">Add Flight</button>
</form>
</div>
</div>
<br>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script src="../flightsresources/common.js"></script>
</html>
\ No newline at end of file
......@@ -6,8 +6,8 @@
<button id="clickButton">Show Flights</button>
<br>
<br>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="common.js"></script>
<link rel="stylesheet" type="text/css" href="../bookresouces/style.css">
<script src="../bookresouces/common.js"></script>
</head>
<body>
<div id = "flights"></div>
......
$("form").submit(function() {
let formData = {}
$(this).serializeArray().forEach(function (value) {
formData["accept"] = true
if (value.value === "" || null) {
formData["accept"] = false
}
else {
formData[value.name] = value.value
}
})
if (formData.accept){
delete formData.accept
formData["id"] = Math.random() * (999 - 34) + 34
formData["airlineid"] = 2
formData["planeid"] = 3
formData["terminalid"] = 2
let xhr = new XMLHttpRequest();
xhr.open("POST", "flight/create/", false)
xhr.setRequestHeader("Content-Type", "application/json")
let data = JSON.stringify(formData)
xhr.send(data)
alert(xhr.status + ': ' + xhr.stack);
}
else {
alert("WTF ?! Control your data !!!")
}
event.preventDefault()
});
sendGetCheck();
function sendGetCheck() {
document.getElementById("flights").innerHTML = ""
let xhr = new XMLHttpRequest();
// 2. configure GET for URL 'flights.json'
xhr.open('GET', 'flight/getAllFlight', false);
// 3. send request
xhr.send();
// 4. if response status 200, then error
if (xhr.status != 200) {
alert(xhr.status + ': ' + xhr.statusText);
} else {
let flightsResponse = JSON.parse(xhr.response);
let allFlights = document.createElement('span')
for (let i in flightsResponse){
let flightCard = document.createElement('div')
flightCard.className = "card"
flightCard.innerHTML = createFlightCard(flightsResponse[i])
allFlights.appendChild(flightCard)
allFlights.appendChild(document.createElement('br'))
}
document.getElementById("flights").appendChild(allFlights);
}
}
function createFlightCard(flightobject){
let flightHeader = "<div class=\"card-header\">\n" +
"\n" + flightobject.department + " &#x27A1 " + flightobject.arrival +
" <a href='#' onclick=deleteFlight(" + flightobject.id + ")><i class=\"material-icons float-right\">delete</i></a> \n" +
" </div>"
console.log(flightobject)
let flightBody = "<div class=\"card-body\">\n" +
" <blockquote class=\"blockquote mb-0\">\n" +
"<p> departure: " + new Date(flightobject.departmentdate).toLocaleString("cs-CZ") + "</p>" +
" <p> arrival: " + new Date(flightobject.arrilvalsdate).toLocaleString("cs-CZ") + "</p>\n" +
" <p> distance: " + flightobject.distance + "</p>\n" +
" </div>"
return flightHeader + flightBody;
}
function deleteFlight(flightId) {
let xhr = new XMLHttpRequest();
xhr.open('delete', 'flight/delete/' + flightId,false)
xhr.send()
sendGetCheck()
}
.card {
width: 50%;
margin-left: 5%;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment