From 884e613247c9d02fe3902c9320b1ce2ee6cbc43e Mon Sep 17 00:00:00 2001 From: John Costa Date: Fri, 3 Mar 2017 01:05:14 -0500 Subject: [PATCH 1/3] availability done, most local code removed --- WebContent/html/javascript/listing.jsp | 296 ++++++++++--------------- src/database/MySQLAccess.java | 2 +- src/entities/ListedDevice.java | 8 +- 3 files changed, 122 insertions(+), 184 deletions(-) diff --git a/WebContent/html/javascript/listing.jsp b/WebContent/html/javascript/listing.jsp index b9b2c73..58a50b1 100644 --- a/WebContent/html/javascript/listing.jsp +++ b/WebContent/html/javascript/listing.jsp @@ -1,183 +1,115 @@ -<%@ 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); - -%> - - - +<%@ 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/src/database/MySQLAccess.java b/src/database/MySQLAccess.java index 404d095..085193a 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_Description"),resultSet.getString("Hardware"),resultSet.getString("Model")); + 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")); counter++; } diff --git a/src/entities/ListedDevice.java b/src/entities/ListedDevice.java index 77877dc..b4301ef 100644 --- a/src/entities/ListedDevice.java +++ b/src/entities/ListedDevice.java @@ -6,14 +6,18 @@ */ public class ListedDevice { private String Device_Name; + private String Device_ID; private String Device_Description; private String Hardware; private String Model; - public ListedDevice(String name, String desc, String hardware, String model) { + private String Status; + public ListedDevice(String name, String id, String desc, String hardware, String model, String available) { + Device_ID = id; Device_Name = name; Device_Description = desc; Hardware = hardware; Model = model; + Status = available; } /** * Formatting the device to fit a JSON object. @@ -23,8 +27,10 @@ public String toString(){ StringBuilder sb = new StringBuilder(); String comma = ", "; sb.append("{\"name\": \"").append(Device_Name).append("\"").append(comma); + sb.append("\"id\": \"").append(Device_ID).append("\"").append(comma); 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("}"); return sb.toString(); From 2c43d0be2b8d5ba3a9c4dd931ca7c7699cb3d4c7 Mon Sep 17 00:00:00 2001 From: John Costa Date: Sun, 5 Mar 2017 22:14:27 -0500 Subject: [PATCH 2/3] 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(); } From cf6a423b3030302803eb69a94fc9793a15246ce6 Mon Sep 17 00:00:00 2001 From: John Costa Date: Thu, 23 Mar 2017 14:39:10 -0400 Subject: [PATCH 3/3] request page done, localstorage issue fixed --- WebContent/html/javascript/listing.jsp | 5 +- WebContent/html/javascript/navbar.js | 2 +- WebContent/html/javascript/request.jsp | 115 +++++++++++------- WebContent/html/webpages/index.html | 2 +- .../{requestPage.html => requestPage.jsp} | 26 ++-- 5 files changed, 86 insertions(+), 64 deletions(-) rename WebContent/html/webpages/{requestPage.html => requestPage.jsp} (75%) diff --git a/WebContent/html/javascript/listing.jsp b/WebContent/html/javascript/listing.jsp index 9ff0462..64ca8fc 100644 --- a/WebContent/html/javascript/listing.jsp +++ b/WebContent/html/javascript/listing.jsp @@ -1,6 +1,5 @@ <%@ page import = "database.MySQLAccess,entities.ListedDevice" %> -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> @@ -99,7 +98,7 @@ function show(){ if(hardwareMatch == true && softwareMatch == true){ - html += '
' + devices[i].name + '

' + devices[i].description + '



' + html += '
' + devices[i].name + '

' + devices[i].description + '



' } } document.getElementById('devContainer').innerHTML = html; diff --git a/WebContent/html/javascript/navbar.js b/WebContent/html/javascript/navbar.js index 3e706ea..ba46607 100644 --- a/WebContent/html/javascript/navbar.js +++ b/WebContent/html/javascript/navbar.js @@ -1 +1 @@ -document.getElementById('navbaruniversal').innerHTML = '' +document.getElementById('navbaruniversal').innerHTML = '' diff --git a/WebContent/html/javascript/request.jsp b/WebContent/html/javascript/request.jsp index 8b03631..b1cca96 100644 --- a/WebContent/html/javascript/request.jsp +++ b/WebContent/html/javascript/request.jsp @@ -1,6 +1,5 @@ <%@ page import = "database.MySQLAccess,entities.ListedDevice" %> -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> @@ -60,37 +59,80 @@ function ajaxFunction(){ } //add event listeners to the options in the left sidebar -for(var a = 0; a < options.length; a++){ - options[a].addEventListener('click', show); +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); } //when an option is selected, show a new list of devices based on what the user asked for function show(){ - currentFilter = readFilter(); - selectedDevices = getDevices(currentFilter); //when connor is done with the database library getDevices should be redirected there - + //currentFilter = readFilter(); + //selectedDevices = getDevices(currentFilter); //when connor is done with the database library getDevices should be redirected there - + var type = this.getAttribute('data-type'); var html = ''; - - //iterate through the hardcoded device DB and select all the ones that match the selected option - for(var i = 0; i < devices.length; i++){ - if((hw_type.localeCompare(devices[i].hardware) == 0 && sw_type.localeCompare(devices[i].software) == 0) && !isUnavailable(i)){ - html += '
' + devices[i].name + '

' + devices[i].description + '



' + 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")); + } + } + if(activeHOptions.length == 0 && activeSOptions.length == 0){ + document.getElementById('devContainer').innerHTML = "

Choose an option to the left to begin requesting!

"; + } + else{ + //iterate through the hardcoded device DB and select all the ones that match the selected option + for(var i = 0; i < devices.length; i++){ + var hardwareMatch = false; + var softwareMatch = false; - if(html.localeCompare("")==0) - html += "

There are no devices with the search criteria: " + this.textContent + "

"; - - //add to HTML page - document.getElementById('devContainer').innerHTML = html; - - //now we need to add event listeners to all the request buttons - var requestbuttons = document.getElementsByClassName('requestbutton'); - for(var i = 0; i < requestbuttons.length; i++){ - requestbuttons[i].addEventListener('click',addToCart); + 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){ + //if((hw_type.localeCompare(devices[i].hardware) == 0 && sw_type.localeCompare(devices[i].software) == 0) && !isUnavailable(i)){ + html += '
' + devices[i].name + '

' + devices[i].description + '



' + } + } + + if(html.localeCompare("")==0) + html += "

There are no devices with the search criteria: " + this.textContent + "

"; + + //add to HTML page + document.getElementById('devContainer').innerHTML = html; + + //now we need to add event listeners to all the request buttons + var requestbuttons = document.getElementsByClassName('requestbutton'); + for(var i = 0; i < requestbuttons.length; i++){ + requestbuttons[i].addEventListener('click',addToCart); + } } } @@ -98,7 +140,6 @@ function readFilter() { //Constrcts a filter object for use in the database library that corresponds to the checked optionsin the sidebar var hw_type; var sw_type; - } function addToCart(){ @@ -106,7 +147,7 @@ function addToCart(){ id = parseInt(id.replace(/[^0-9\.]/g,''),10); //this gets just the numerical value from the id! if(!inCart(id)){ //if not in the cart var cart = getCartItems(); //this is an array - cart.push(id); //push to bottom of cart + cart.push(devices[id - 1]); //push to bottom of cart localStorage.setItem('cart', JSON.stringify(cart)); $('#added').fadeIn(1000); $('#added').fadeIn(1000); @@ -144,28 +185,10 @@ function getCartItems(){ return cart; } -function getUnavailableItems(){ - var unavailable = new Array; - var unavailable_str = localStorage.getItem('unavailable'); - if(unavailable_str !== "" && unavailable_str !== null){ - unavailable = JSON.parse(unavailable_str); - } - return unavailable; -} - -function isUnavailable(id){ - var unavailable = getUnavailableItems(); - if(unavailable.length == 0) - return 0; - else{ - for(var i = 0; i < unavailable.length; i++){ - if(unavailable[i] == (id+1)) - return 1; - } - } - return 0; +function makeDeviceArray(){ + window.json = '<%=deviceString%>'; + return JSON.parse(window.json); } - //this code allows a message to appear that indicates that the item was successfully placed in the shopping cart. diff --git a/WebContent/html/webpages/index.html b/WebContent/html/webpages/index.html index 5f5a100..20bd2a7 100644 --- a/WebContent/html/webpages/index.html +++ b/WebContent/html/webpages/index.html @@ -47,7 +47,7 @@