From e6fb28d990fc8f517e9257d72fec25fec8fb1542 Mon Sep 17 00:00:00 2001 From: s452111 Date: Mon, 20 Jan 2020 16:20:40 +0100 Subject: [PATCH] CAR-38 --- .../src/main/client/html/js/sendingRequest.js | 115 +++++--- cars4you/src/main/client/html/search.html | 261 +++++++----------- cars4you/src/main/client/html/wynik.html | 124 +++------ .../car4you/repository/CarRepositoryImpl.java | 2 +- 4 files changed, 218 insertions(+), 284 deletions(-) diff --git a/cars4you/src/main/client/html/js/sendingRequest.js b/cars4you/src/main/client/html/js/sendingRequest.js index 0e20dce..784d5bf 100644 --- a/cars4you/src/main/client/html/js/sendingRequest.js +++ b/cars4you/src/main/client/html/js/sendingRequest.js @@ -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) { + 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) { + // + // // 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 += ''; + cars_data += '' + value.brand + ''; + cars_data += '' + value.model + ''; + cars_data += '' + value.version + ''; + cars_data += '' + value.year + ''; + cars_data += '' + value.engine_power + ''; + cars_data += '' + value.engine_capacity + ''; + cars_data += '' + value.transmission + ''; + cars_data += '' + value.drive + ''; + cars_data += '' + value.body_type + ''; + cars_data += '' + value.doors + ''; + cars_data += '' + value.seats + ''; + cars_data += '' + value.price_from + ''; + cars_data += '' + value.price_to + ''; + cars_data += '' + value.average + ''; + cars_data += '' + value.rating + ''; + cars_data += '' + value.fuel + ''; + cars_data += '' + value.fuelEconomy + ''; + cars_data += '' + value.car_pros + ''; + cars_data += '' + value.car_cons + ''; + + cars_data += ''; + + }); + $('#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; - } - }; } diff --git a/cars4you/src/main/client/html/search.html b/cars4you/src/main/client/html/search.html index da23e14..7d50d95 100644 --- a/cars4you/src/main/client/html/search.html +++ b/cars4you/src/main/client/html/search.html @@ -28,171 +28,124 @@ + + + + + + - - +
+
+ + +
- + + +
+ + + + + + + + + + + + + + + + + + + + + +
MarkaModelWersjaRok produkcjiMoc silnika [KM]Pojemność silnikaSkrzynia biegówNapędTyp autaLiczba drzwiLiczba miejscCeny odCeny doSrednioRodzaj paliwaSrednie spalanieZaletyWady
+
+
- - - - - - \ No newline at end of file diff --git a/cars4you/src/main/client/html/wynik.html b/cars4you/src/main/client/html/wynik.html index 1416cd8..91a3aff 100644 --- a/cars4you/src/main/client/html/wynik.html +++ b/cars4you/src/main/client/html/wynik.html @@ -1,99 +1,39 @@ - - + + - + + - - - - - - - - - - - - Car4You - - - - - - - - - - + + + + + + + + + Hello, world! - - - - - - - - - - +
+ + + + + + + + + + + +
#MarkaModelWersjaRok produkcjiMoc silnika [KM]
+
+ + + + + \ No newline at end of file diff --git a/cars4you/src/main/java/com/cars/car4you/repository/CarRepositoryImpl.java b/cars4you/src/main/java/com/cars/car4you/repository/CarRepositoryImpl.java index 70581f8..87d0b7d 100644 --- a/cars4you/src/main/java/com/cars/car4you/repository/CarRepositoryImpl.java +++ b/cars4you/src/main/java/com/cars/car4you/repository/CarRepositoryImpl.java @@ -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));