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 fuel_type = document.getElementById('fuel_type');
let seats = document.getElementsByClassName('seats')[0];
let seats = document.getElementsByClassName('seats');
let doors = document.getElementById('doors');
let maximum_price = document.getElementById('maximum_price');
let max_years_old = document.getElementById('max_years_old');
@ -11,60 +12,100 @@
let gearbox = document.getElementById('gearbox');
let drive_type = document.getElementById('drive_type');
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";
var params = [];
if(fuel_type.value != -1){
params.push("fuel_type="+fuel_type.options[fuel_type.value].text);
if (fuel_type.value != -1) {
params.push("fuel_type=" + fuel_type.options[fuel_type.value].text);
}
if(seats.value > 0){
params.push("seats="+seats.value);
if (seats.value > 0) {
params.push("seats=" + seats.value);
}
if(doors.value != -1){
params.push("doors="+doors.options[doors.value].text);
if (doors.value != -1) {
params.push("doors=" + doors.options[doors.value].text);
}
if(maximum_price.value > 0){
params.push("maximum_price="+maximum_price.value);
if (maximum_price.value > 0) {
params.push("maximum_price=" + maximum_price.value);
}
if(max_years_old.value > 0){
params.push("max_years_old="+max_years_old.value);
if (max_years_old.value > 0) {
params.push("max_years_old=" + max_years_old.value);
}
if(engine_power_from.value > 0){
params.push("engine_power_from="+engine_power_from.value);
if (engine_power_from.value > 0) {
params.push("engine_power_from=" + engine_power_from.value);
}
if(engine_power_to.value > 0){
params.push("engine_power_to="+engine_power_to.value);
if (engine_power_to.value > 0) {
params.push("engine_power_to=" + engine_power_to.value);
}
if(body_type.value != -1){
params.push("body_type="+body_type.value);
if (body_type.value != -1) {
params.push("body_type=" + body_type.value);
}
if(gearbox.value != -1){
params.push("gearbox="+gearbox.value);
if (gearbox.value != -1) {
params.push("gearbox=" + gearbox.value);
}
if(drive_type.value != -1){
params.push("drive_type="+drive_type.value);
if (drive_type.value != -1) {
params.push("drive_type=" + drive_type.value);
}
var buff = "";
if(params.length>0){
if (params.length > 0) {
buff += "?";
for (var i = 0, len = params.length; i < len; i++) {
buff += params[i];
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);
request.open("GET", url+buff, true);
request.setRequestHeader("Content-Type", "text/html");
request.send();
request.onreadystatechange = function () {
if (request.readyState === 4 && request.status === 200) {
// request.open("GET", url + buff, true);
// request.setRequestHeader("Content-Type", "text/html");
// request.send();
// request.onreadystatechange = function () {
// 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,96 +28,69 @@
<link rel="stylesheet" href="css/animate.min.css">
<link rel="stylesheet" href="css/jquery-ui.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>
<body>
<header id="header">
<div class="main-menu">
<div class="row align-items-center d-flex">
<a href="index.html"><img src="img/car4you.png" alt="" title="" width="100px" /></a>
<nav id="nav-menu-container">
<ul class="nav-menu">
<li class="menu-active"><a href="index.html">Strona główna</a></li>
<li><a href="opis.html">O nas</a></li>
<li><a href="ankieta.html">Rekomendacja</a></li>
</ul>
</nav><!-- #nav-menu-container -->
</div>
</div>
</header>
<!-- start banner Area -->
<section class="banner-area relative" id="home">
<div class="text-center">
<div class="overlay overlay-bg"></div>
<div class="row fullscreen d-flex justify-content-between">
<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="container-fluid">
<form class="col">
<div class="form-row">
<div class="form-group">
Typ paliwa:
<div class="default-select">
<select id="fuel_type">
<label for="fuel_type">Typ paliwa</label>
<select class="form-control" 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 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">
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">
<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">
<div class="default-select">
Budżet:
<input id="maximum_price">
</input>
<label for="max_years_old"> Maksymalny wiek pojazdu </label>
<input class="form-control" type="text" id="max_years_old">
</div>
</div>
<div class="form-row">
<div class="form-group">
<div class="default-select">
Maksymalny wiek pojazdu:
<input id="max_years_old">
</input>
</div>
<label for="engine_power_from">Moc silnika (od) </label>
<input class="form-control" type="text" id="engine_power_from">
</div>
<div class="form-group">
<div class="default-select">
Moc od:
<input id="engine_power_from">
</input>
</div>
<label for="engine_power_to">Moc silnika (do) </label>
<input class="form-control" type="text" id="engine_power_to">
</div>
<div class="form-group">
<div class="default-select">
Moc do:
<input id="engine_power_to">
</input>
</div>
</div>
<div class="form-group">
<div class="default-select">
Typ nadwozia:
<select id="body_type">
<div class="form-group ">
<label for="body_type">Typ nadwozia </label>
<select class="form-control" id="body_type">
<option value="-1">Dowolny</option>
<option value="hetchback">Hetchback</option>
<option value="SUV">SUV</option>
@ -125,23 +98,19 @@
<option value="sedan">Sedan</option>
</select>
</div>
</div>
<div class="form-group">
<div class="default-select">
Skrzynia biegów:
<select id="gearbox">
<label for="gearbox">Skrzynia biegów </label>
<select class="form-control" 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">
<label for="drive_type"> Rodzaj napędu </label>
<select class="form-control" id="drive_type">
<option value="-1">Dowolny</option>
<option value="przednie">Na przednie koła</option>
<option value="tylnie">Na tylnie koła</option>
@ -149,50 +118,34 @@
</select>
</div>
</div>
<button type="button" class="btn btn-warning" onclick="sendGetRequest()">Rekomenduj auta!</button>
<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 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>
</div>
</div>
</section>
</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>
</html>

View File

@ -1,99 +1,39 @@
<!DOCTYPE html>
<html lang="zxx" class="no-js">
<!doctype html>
<html lang="en">
<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">
<!-- 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">
<!--
CSS
============================================= -->
<link rel="stylesheet" href="css/linearicons.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/magnific-popup.css">
<link rel="stylesheet" href="css/nice-select.css">
<link rel="stylesheet" href="css/animate.min.css">
<link rel="stylesheet" href="css/jquery-ui.css">
<link rel="stylesheet" href="css/main.css">
<!-- 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">
<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">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.js"></script>
<title>Hello, world!</title>
</head>
<body>
<header id="header">
<div class="container main-menu">
<div class="row align-items-center justify-content-between d-flex ">
<a href="index.html"><img src="img/car4you.png" alt="" title="" width="100px" /></a>
<nav id="nav-menu-container">
<ul class="nav-menu">
<li class="menu-active"><a href="index.html">Strona główna</a></li>
<li><a href="opis.html">O nas</a></li>
<li><a href="ankieta.html">Rekomendacja</a></li>
<li><a href="lista.html">Galeria</a></li>
</ul>
</nav><!-- #nav-menu-container -->
</div>
</div>
</header><!-- #header -->
<!-- start banner Area -->
<section class="banner-area" id="home">
<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 -->
<div class="container">
<table class="table" id="table" data-toggle="table">
<thead>
<tr>
<th scope="col">#</th>
<th data-field="brand" >Marka</th>
<th data-field="model" scope="col">Model</th>
<th data-field="version" scope="col">Wersja</th>
<th data-field="year" scope="col">Rok produkcji</th>
<th data-field="engine_power" scope="col">Moc silnika [KM]</th>
</tr>
</thead>
</table>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<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>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
</body>
</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(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(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(doors != null) predicates.add(criteriaBuilder.equal(car.get("doors"), doors));