From 2c43d0be2b8d5ba3a9c4dd931ca7c7699cb3d4c7 Mon Sep 17 00:00:00 2001 From: John Costa Date: Sun, 5 Mar 2017 22:14:27 -0500 Subject: [PATCH] the listing page filtering works, shoutouts to adam for the help --- WebContent/html/javascript/listing.jsp | 78 +++++++++++-------- .../javascript/{request.js => request.jsp} | 77 +++++++----------- WebContent/html/webpages/listingPage.jsp | 35 +++++---- src/database/MySQLAccess.java | 2 +- src/entities/ListedDevice.java | 7 +- 5 files changed, 101 insertions(+), 98 deletions(-) rename WebContent/html/javascript/{request.js => request.jsp} (77%) diff --git a/WebContent/html/javascript/listing.jsp b/WebContent/html/javascript/listing.jsp index 58a50b1..9ff0462 100644 --- a/WebContent/html/javascript/listing.jsp +++ b/WebContent/html/javascript/listing.jsp @@ -24,11 +24,16 @@ String deviceString = ListedDevice.arrayToString(mydevices); var devices = makeDeviceArray(); //get all the option buttons -var options = document.getElementsByClassName('option'); +//var options = document.getElementsByClassName('checkboxes'); +var hardwareOptions = document.getElementsByClassName('hw-data-type'); +var softwareOptions = document.getElementsByClassName('sw-data-type'); -options[0].addEventListener('click', showAll); -for(var a = 1; a < options.length; a++){ - options[a].addEventListener('click', show); +//options[0].addEventListener('click', showAll); +for(var a = 0; a < hardwareOptions.length; a++){ + hardwareOptions[a].addEventListener('click', show); +} +for(var a = 0; a < softwareOptions.length; a++){ + softwareOptions[a].addEventListener('click', show); } showAll(); function showAll(){ @@ -56,8 +61,44 @@ function showAll(){ function show(){ var type = this.getAttribute('data-type'); var html = ''; + var activeHOptions = []; + var activeSOptions = []; + for(var i = 0; i < hardwareOptions.length; i++) { + if (hardwareOptions[i].checked == true) { + activeHOptions.push(hardwareOptions[i].getAttribute("data-type")); + } + } + for(var i = 0; i < softwareOptions.length; i++) { + if (softwareOptions[i].checked == true) { + activeSOptions.push(softwareOptions[i].getAttribute("data-type")); + } + } for(var i = 0; i < devices.length; i++){ - if(type.localeCompare(devices[i].hardware) == 0 || type.localeCompare(devices[i].model) == 0){ + var hardwareMatch = false; + var softwareMatch = false; + + for(var j = 0; j < activeHOptions.length; j++) { + if (activeHOptions[j] == devices[i].hardware){ + hardwareMatch = true; + } + } + + if (activeHOptions.length == 0) { + hardwareMatch = true; + } + + for(var j = 0; j < activeSOptions.length; j++) { + if (activeSOptions[j] == devices[i].manufacturer){ + softwareMatch = true; + } + } + + if (activeSOptions.length == 0) { + softwareMatch = true; + } + + + if(hardwareMatch == true && softwareMatch == true){ html += '
' + devices[i].name + '

' + devices[i].description + '



' } } @@ -78,33 +119,6 @@ function show(){ } } } - //Generates html and writes to 'devContainer' div in JSP - function populateDeviceList(){ - //begin empty html - var htmlString=""; - //iterate returned devices - for (var i = 0; i < devices.length; i++) { - //get device values - var id = devices[i].id; - var name = devices[i].name; - var hardware = devices[i].hardware; - var checkout = devices[i].checkout; - //HTML representation in divs - htmlString+="
"; - htmlString+=""; - htmlString+="
"; - htmlString+=name; - htmlString+="

Checked out: " - htmlString+=checkout; - htmlString+="



"; - } - //Handles if no devices are returned - if(i==0) htmlString+="Couldn't find any devices to show."; - //Place html in body - document.getElementById("devContainer").innerHTML = htmlString; - } function makeDeviceArray(){ window.json = '<%=deviceString%>'; diff --git a/WebContent/html/javascript/request.js b/WebContent/html/javascript/request.jsp similarity index 77% rename from WebContent/html/javascript/request.js rename to WebContent/html/javascript/request.jsp index 62ebde9..8b03631 100644 --- a/WebContent/html/javascript/request.js +++ b/WebContent/html/javascript/request.jsp @@ -1,3 +1,28 @@ +<%@ page import = "database.MySQLAccess,entities.ListedDevice" %> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Insert title here + + +<% +MySQLAccess myaccess = new MySQLAccess(); +ListedDevice[] mydevices = myaccess.getAllDevices(); + +//string representation of array. +String deviceString = ListedDevice.arrayToString(mydevices); +//out.println(description); +//out.println(hardware); + +%> + + + + \ No newline at end of file diff --git a/WebContent/html/webpages/listingPage.jsp b/WebContent/html/webpages/listingPage.jsp index a5b1633..c7ec3f2 100644 --- a/WebContent/html/webpages/listingPage.jsp +++ b/WebContent/html/webpages/listingPage.jsp @@ -53,20 +53,27 @@ + + +
+ +

Device Dictionary

diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java index 085193a..ff0059e 100644 --- a/src/database/MySQLAccess.java +++ b/src/database/MySQLAccess.java @@ -73,7 +73,7 @@ public ListedDevice[] getAllDevices() throws SQLException, ClassNotFoundExceptio //iterate result set while(resultSet.next()){ - devices[counter] = new ListedDevice(resultSet.getString("Device_Name"),resultSet.getString("Device_ID"),resultSet.getString("Device_Description"),resultSet.getString("Hardware"), resultSet.getString("Model"),resultSet.getString("Status")); + devices[counter] = new ListedDevice(resultSet.getString("Device_Name"),resultSet.getString("Device_ID"),resultSet.getString("Device_Description"),resultSet.getString("Hardware"), resultSet.getString("Model"), resultSet.getString("Manufacturer"), resultSet.getString("Status")); counter++; } diff --git a/src/entities/ListedDevice.java b/src/entities/ListedDevice.java index b4301ef..2be3fd5 100644 --- a/src/entities/ListedDevice.java +++ b/src/entities/ListedDevice.java @@ -10,13 +10,15 @@ public class ListedDevice { private String Device_Description; private String Hardware; private String Model; + private String Manu; private String Status; - public ListedDevice(String name, String id, String desc, String hardware, String model, String available) { + public ListedDevice(String name, String id, String desc, String hardware, String model, String manufacturer, String available) { Device_ID = id; Device_Name = name; Device_Description = desc; Hardware = hardware; Model = model; + Manu = manufacturer; Status = available; } /** @@ -31,7 +33,8 @@ public String toString(){ sb.append("\"description\": \"").append(Device_Description).append("\"").append(comma); sb.append("\"hardware\": \"").append(Hardware).append("\"").append(comma); sb.append("\"status\": \"").append(Status).append("\"").append(comma); - sb.append("\"model\": \"").append(Model).append("\""); + sb.append("\"model\": \"").append(Model).append("\"").append(comma); + sb.append("\"manufacturer\": \"").append(Manu).append("\""); sb.append("}"); return sb.toString(); }