This commit is contained in:
s452111 2020-01-20 16:20:40 +01:00
parent 56a9101d62
commit e6fb28d990
4 changed files with 218 additions and 284 deletions

View File

@ -1,7 +1,8 @@
function sendGetRequest() { 
function sendGetRequest() {
let result = document.querySelector('.result'); let result = document.querySelector('.result');
let fuel_type = document.getElementById('fuel_type'); let fuel_type = document.getElementById('fuel_type');
let seats = document.getElementsByClassName('seats')[0]; let seats = document.getElementsByClassName('seats');
let doors = document.getElementById('doors'); let doors = document.getElementById('doors');
let maximum_price = document.getElementById('maximum_price'); let maximum_price = document.getElementById('maximum_price');
let max_years_old = document.getElementById('max_years_old'); let max_years_old = document.getElementById('max_years_old');
@ -11,60 +12,100 @@
let gearbox = document.getElementById('gearbox'); let gearbox = document.getElementById('gearbox');
let drive_type = document.getElementById('drive_type'); let drive_type = document.getElementById('drive_type');
let request = new XMLHttpRequest(); let request = new XMLHttpRequest();
// let url = "https://jsonplaceholder.typicode.com/photos";
// let url = "https://webhook.site/b1792c3d-cd5a-4c29-8e9c-1ff9f84653eb";
// let url = "http://34.65.132.148:8080";
let url = "http://localhost:8080/car/api/search"; let url = "http://localhost:8080/car/api/search";
var params = []; var params = [];
if(fuel_type.value != -1){ if (fuel_type.value != -1) {
params.push("fuel_type="+fuel_type.options[fuel_type.value].text); params.push("fuel_type=" + fuel_type.options[fuel_type.value].text);
} }
if(seats.value > 0){ if (seats.value > 0) {
params.push("seats="+seats.value); params.push("seats=" + seats.value);
} }
if(doors.value != -1){ if (doors.value != -1) {
params.push("doors="+doors.options[doors.value].text); params.push("doors=" + doors.options[doors.value].text);
} }
if(maximum_price.value > 0){ if (maximum_price.value > 0) {
params.push("maximum_price="+maximum_price.value); params.push("maximum_price=" + maximum_price.value);
} }
if(max_years_old.value > 0){ if (max_years_old.value > 0) {
params.push("max_years_old="+max_years_old.value); params.push("max_years_old=" + max_years_old.value);
} }
if(engine_power_from.value > 0){ if (engine_power_from.value > 0) {
params.push("engine_power_from="+engine_power_from.value); params.push("engine_power_from=" + engine_power_from.value);
} }
if(engine_power_to.value > 0){ if (engine_power_to.value > 0) {
params.push("engine_power_to="+engine_power_to.value); params.push("engine_power_to=" + engine_power_to.value);
} }
if(body_type.value != -1){ if (body_type.value != -1) {
params.push("body_type="+body_type.value); params.push("body_type=" + body_type.value);
} }
if(gearbox.value != -1){ if (gearbox.value != -1) {
params.push("gearbox="+gearbox.value); params.push("gearbox=" + gearbox.value);
} }
if(drive_type.value != -1){ if (drive_type.value != -1) {
params.push("drive_type="+drive_type.value); params.push("drive_type=" + drive_type.value);
} }
var buff = ""; var buff = "";
if(params.length>0){ if (params.length > 0) {
buff += "?"; buff += "?";
for (var i = 0, len = params.length; i < len; i++) { for (var i = 0, len = params.length; i < len; i++) {
buff += params[i]; buff += params[i];
buff += "\&"; buff += "\&";
} }
buff = buff.substr(0, buff.length-1); //obcinanie ostatego znaku buff = buff.substr(0, buff.length - 1); //obcinanie ostatego znaku
} }
console.log("Debug: " + buff); console.log("Debug: " + buff);
request.open("GET", url+buff, true); // request.open("GET", url + buff, true);
request.setRequestHeader("Content-Type", "text/html"); // request.setRequestHeader("Content-Type", "text/html");
request.send(); // request.send();
request.onreadystatechange = function () { // request.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) { // if (request.readyState === 4 && request.status === 200) {
//
// // Print received data from server
// result.innerHTML = this.responseText;
// // Simulate an HTTP redirect:
// window.location.replace("/wynik.html");
//
// }
// };
$.getJSON(url+buff, function( data ) {
var cars_data = '';
$.each(data, function (key, value) {
cars_data += '<tr>';
cars_data += '<td>' + value.brand + '</td>';
cars_data += '<td>' + value.model + '</td>';
cars_data += '<td>' + value.version + '</td>';
cars_data += '<td>' + value.year + '</td>';
cars_data += '<td>' + value.engine_power + '</td>';
cars_data += '<td>' + value.engine_capacity + '</td>';
cars_data += '<td>' + value.transmission + '</td>';
cars_data += '<td>' + value.drive + '</td>';
cars_data += '<td>' + value.body_type + '</td>';
cars_data += '<td>' + value.doors + '</td>';
cars_data += '<td>' + value.seats + '</td>';
cars_data += '<td>' + value.price_from + '</td>';
cars_data += '<td>' + value.price_to + '</td>';
cars_data += '<td>' + value.average + '</td>';
cars_data += '<td>' + value.rating + '</td>';
cars_data += '<td>' + value.fuel + '</td>';
cars_data += '<td>' + value.fuelEconomy + '</td>';
cars_data += '<td>' + value.car_pros + '</td>';
cars_data += '<td>' + value.car_cons + '</td>';
cars_data += '</tr>';
});
$('#table').append(cars_data);
});
// window.location.href = "../wynik.html";
// var myJsonString = JSON.stringify(data);
// $(function () {
// $('#table').bootstrapTable({
// data: myJsonString1
// });
// $('#table').bootstrapTable('load', myJsonString1);
// });
// console.log(myJsonString);
// Print received data from server
result.innerHTML = this.responseText;
}
};
} }

View File

@ -28,171 +28,124 @@
<link rel="stylesheet" href="css/animate.min.css"> <link rel="stylesheet" href="css/animate.min.css">
<link rel="stylesheet" href="css/jquery-ui.css"> <link rel="stylesheet" href="css/jquery-ui.css">
<link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<script src="js/sendingRequest.js"></script>
</head> </head>
<body> <body>
<header id="header"> <div class="container-fluid">
<div class="main-menu"> <form class="col">
<div class="row align-items-center d-flex"> <div class="form-row">
<a href="index.html"><img src="img/car4you.png" alt="" title="" width="100px" /></a> <div class="form-group">
<nav id="nav-menu-container"> <label for="fuel_type">Typ paliwa</label>
<ul class="nav-menu"> <select class="form-control" id="fuel_type">
<li class="menu-active"><a href="index.html">Strona główna</a></li> <option value="-1">Dowolny</option>
<li><a href="opis.html">O nas</a></li> <option value="1">Benzyna</option>
<li><a href="ankieta.html">Rekomendacja</a></li> <option value="2">Benzyna+LPG</option>
</ul> <option value="3">Diesel</option>
</nav><!-- #nav-menu-container --> </select>
</div>
<div class="form-group">
<label for="seats"> Liczba miejsc: </label>
<input class="form-control" type="text" id="seats" placeholder="2/3/4">
</div>
<div class="form-group">
<label for="doors">Liczba drzwi</label>
<select class="form-control" id="doors">
<option value="-1">Dowolna</option>
<option value="1">3</option>
<option value="2">5</option>
<option value="3">większa niż 5</option>
</select>
</div>
<div class="form-group">
<label for="maximum_price"> Budżet </label>
<input class="form-control" type="text" id="maximum_price">
</div>
<div class="form-group">
<label for="max_years_old"> Maksymalny wiek pojazdu </label>
<input class="form-control" type="text" id="max_years_old">
</div> </div>
</div> </div>
</header> <div class="form-row">
<!-- start banner Area --> <div class="form-group">
<label for="engine_power_from">Moc silnika (od) </label>
<input class="form-control" type="text" id="engine_power_from">
</div>
<section class="banner-area relative" id="home"> <div class="form-group">
<div class="text-center"> <label for="engine_power_to">Moc silnika (do) </label>
<div class="overlay overlay-bg"></div> <input class="form-control" type="text" id="engine_power_to">
<div class="row fullscreen d-flex justify-content-between"> </div>
<div class="banner-content col-lg-12 col-md-12">
<div class="col-lg-10 col-md-10 header-right ">
<h4 class="pb-10">Uzupełnij pola</h4>
<form class="form" name="myForm" action="sendingRequest.js" method="post" enctype="application/x-www-form-urlencoded">
<div class="form-group">
Typ paliwa:
<div class="default-select">
<select id="fuel_type">
<option value="-1">Dowolny</option>
<option value="1">Benzyna</option>
<option value="2">Benzyna+LPG</option>
<option value="3">Diesel</option>
</select>
</div>
</div>
<div class="form-group">
Liczba miejsc:
<div class="default-select">
<input class="seats" id="seats">
</input>
</div>
</div>
<div class="form-group">
<div class="default-select">
Liczba drzwi:
<select id="doors">
<option value="-1">Dowolna</option>
<option value="1">3</option>
<option value="2">5</option>
<option value="3">większa niż 5</option>
</select>
</div>
</div>
<div class="form-group">
<div class="default-select">
Budżet:
<input id="maximum_price">
</input>
</div>
</div>
<div class="form-group">
<div class="default-select">
Maksymalny wiek pojazdu:
<input id="max_years_old">
</input>
</div>
</div>
<div class="form-group"> <div class="form-group ">
<div class="default-select"> <label for="body_type">Typ nadwozia </label>
Moc od: <select class="form-control" id="body_type">
<input id="engine_power_from"> <option value="-1">Dowolny</option>
</input> <option value="hetchback">Hetchback</option>
</div> <option value="SUV">SUV</option>
</div> <option value="coupe">Coupe</option>
<option value="sedan">Sedan</option>
</select>
</div>
<div class="form-group"> <div class="form-group">
<div class="default-select"> <label for="gearbox">Skrzynia biegów </label>
Moc do: <select class="form-control" id="gearbox">
<input id="engine_power_to"> <option value="-1">Dowolna</option>
</input> <option value="Manual">Manualna</option>
</div> <option value="Automatic">Automatyczna</option>
</div> </select>
</div>
<div class="form-group"> <div class="form-group">
<div class="default-select"> <label for="drive_type"> Rodzaj napędu </label>
Typ nadwozia: <select class="form-control" id="drive_type">
<select id="body_type"> <option value="-1">Dowolny</option>
<option value="-1">Dowolny</option> <option value="przednie">Na przednie koła</option>
<option value="hetchback">Hetchback</option> <option value="tylnie">Na tylnie koła</option>
<option value="SUV">SUV</option> <option value="4x4">Na cztery koła</option>
<option value="coupe">Coupe</option> </select>
<option value="sedan">Sedan</option>
</select>
</div>
</div>
<div class="form-group">
<div class="default-select">
Skrzynia biegów:
<select id="gearbox">
<option value="-1">Dowolna</option>
<option value="Manual">Manualna</option>
<option value="Automatic">Automatyczna</option>
</select>
</div>
</div>
<div class="form-group">
<div class="default-select">
Rodzaj napędu:
<select id="drive_type">
<option value="-1">Dowolny</option>
<option value="przednie">Na przednie koła</option>
<option value="tylnie">Na tylnie koła</option>
<option value="4x4">Na cztery koła</option>
</select>
</div>
</div>
<div class="form-group">
<input value="Szukaj" class="primary-btn" onclick="sendGetRequest()" />
<div class="result">
<!-- result list-->
</div>
</div>
<div id="wypisywanie"></div>
</form>
</div>
</div>
</div> </div>
</div> </div>
</section> <button type="button" class="btn btn-warning" onclick="sendGetRequest()">Rekomenduj auta!</button>
</form>
<div class="container-fluid">
<table class="table table-bordered table-striped col" id="table">
<tr>
<th>Marka</th>
<th>Model</th>
<th>Wersja</th>
<th>Rok produkcji</th>
<th>Moc silnika [KM]</th>
<th>Pojemność silnika</th>
<th>Skrzynia biegów</th>
<th>Napęd</th>
<th>Typ auta</th>
<th>Liczba drzwi</th>
<th>Liczba miejsc</th>
<th>Ceny od</th>
<th>Ceny do</th>
<th>Srednio</th>
<th>Rodzaj paliwa</th>
<th>Srednie spalanie</th>
<th>Zalety</th>
<th>Wady</th>
</tr>
</table>
</div>
</div>
<!-- End banner Area -->
<!-- start footer Area -->
<footer class="footer-area section-gap">
<div class="container">
<div class="row">
<div class="col-lg-2 col-md-6 col-sm-6">
<div class="single-footer-widget">
<h6>Szybkie linki</h6>
<ul>
<li><a href="https://www.autocentrum.pl/">Auto Centrum</a></li>
<li><a href="https://www.otomoto.pl/">OTOMOTO</a></li>
</ul>
</div>
</div>
<p class="mt-80 mx-auto footer-text col-lg-12">
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
Copyright &copy;
<script>document.write(new Date().getFullYear());</script> Wszelkie prawa zastrzeżone
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
</p>
</div>
</div>
<img class="footer-bottom" alt="">
</footer>
<!-- End footer Area -->
<script src="js/sendingRequest.js"></script>
</body> </body>
</html> </html>

View File

@ -1,99 +1,39 @@
<!DOCTYPE html> <!doctype html>
<html lang="zxx" class="no-js"> <html lang="en">
<head> <head>
<!-- Mobile Specific Meta --> <!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Favicon-->
<link rel="shortcut icon " href="img/car4you.png">
<!-- Author Meta -->
<meta name="author" content="colorlib">
<!-- Meta Description -->
<meta name="description" content="">
<!-- Meta Keyword -->
<meta name="keywords" content="">
<!-- meta character set -->
<meta charset="UTF-8">
<!-- Site Title -->
<title>Car4You</title>
<link href="https://fonts.googleapis.com/css?family=Poppins:100,200,400,300,500,600,700" rel="stylesheet"> <!-- Bootstrap CSS -->
<!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
CSS <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
============================================= --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.css">
<link rel="stylesheet" href="css/linearicons.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<link rel="stylesheet" href="css/font-awesome.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/bootstrap.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.js"></script>
<link rel="stylesheet" href="css/magnific-popup.css">
<link rel="stylesheet" href="css/nice-select.css"> <title>Hello, world!</title>
<link rel="stylesheet" href="css/animate.min.css">
<link rel="stylesheet" href="css/jquery-ui.css">
<link rel="stylesheet" href="css/main.css">
</head> </head>
<body> <body>
<header id="header"> <div class="container">
<div class="container main-menu"> <table class="table" id="table" data-toggle="table">
<div class="row align-items-center justify-content-between d-flex "> <thead>
<a href="index.html"><img src="img/car4you.png" alt="" title="" width="100px" /></a> <tr>
<nav id="nav-menu-container"> <th scope="col">#</th>
<ul class="nav-menu"> <th data-field="brand" >Marka</th>
<li class="menu-active"><a href="index.html">Strona główna</a></li> <th data-field="model" scope="col">Model</th>
<li><a href="opis.html">O nas</a></li> <th data-field="version" scope="col">Wersja</th>
<li><a href="ankieta.html">Rekomendacja</a></li> <th data-field="year" scope="col">Rok produkcji</th>
<li><a href="lista.html">Galeria</a></li> <th data-field="engine_power" scope="col">Moc silnika [KM]</th>
</ul> </tr>
</nav><!-- #nav-menu-container --> </thead>
</div> </table>
</div> </div>
<!-- Optional JavaScript -->
</header><!-- #header --> <!-- jQuery first, then Popper.js, then Bootstrap JS -->
<!-- start banner Area --> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<section class="banner-area" id="home"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<div class="text-center">
<div class="overlay overlay-bg"></div>
<div class="container">
<div class="row fullscreen d-flex align-items-center justify-content-center">
<div class="banner-content center col-md-6 align-items-center">
<img src="img/car4you.png">
<h4 class="text-white" id="w">
Wybraliśmy dla Ciebie następujące modele:
</h4>
</div>
</div>
</div>
</div>
</section>
<!-- End banner Area -->
<!-- start footer Area -->
<footer class="footer-area section-gap">
<div class="container">
<div class="row">
<div class="col-lg-2 col-md-6 col-sm-6">
<div class="single-footer-widget">
<h6>Szybkie linki</h6>
<ul>
<li><a href="https://www.autocentrum.pl/">Auto Centrum</a></li>
<li><a href="https://www.otomoto.pl/">OTOMOTO</a></li>
</ul>
</div>
</div>
<p class="mt-80 mx-auto footer-text col-lg-12">
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
Copyright &copy;
<script>document.write(new Date().getFullYear());</script> Wszelkie prawa zastrzeżone
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
</p>
</div>
</div>
<img class="footer-bottom" alt="">
</footer>
<!-- End footer Area -->
</body> </body>
</html> </html>

View File

@ -40,7 +40,7 @@ public class CarRepositoryImpl implements CustomCarRepository {
if(enginePowerTo != null) predicates.add(criteriaBuilder.lessThanOrEqualTo(car.get("engine_power"), enginePowerTo)); if(enginePowerTo != null) predicates.add(criteriaBuilder.lessThanOrEqualTo(car.get("engine_power"), enginePowerTo));
if(transmission != null && !transmission.isEmpty()) predicates.add(criteriaBuilder.like(car.get("transmission"), "%" + transmission + "%")); if(transmission != null && !transmission.isEmpty()) predicates.add(criteriaBuilder.like(car.get("transmission"), "%" + transmission + "%"));
if(fuelType != null && !fuelType.isEmpty()) predicates.add(criteriaBuilder.like(car.get("fuel"), "%" + fuelType + "%")); if(fuelType != null && !fuelType.isEmpty()) predicates.add(criteriaBuilder.like(car.get("fuel"), "%" + fuelType + "%"));
if(driveType != null && !driveType.isEmpty()) predicates.add(criteriaBuilder.like(car.get("drivetype"), "%" + driveType + "%")); if(driveType != null && !driveType.isEmpty()) predicates.add(criteriaBuilder.like(car.get("drive"), "%" + driveType + "%"));
if(seats != null) predicates.add(criteriaBuilder.equal(car.get("seats"), seats)); if(seats != null) predicates.add(criteriaBuilder.equal(car.get("seats"), seats));
if(doors != null) predicates.add(criteriaBuilder.equal(car.get("doors"), doors)); if(doors != null) predicates.add(criteriaBuilder.equal(car.get("doors"), doors));