diff --git a/.classpath b/.classpath index 7ac7040..0295c16 100644 --- a/.classpath +++ b/.classpath @@ -37,10 +37,6 @@ - - - - - + diff --git a/WebContent/html/javascript/listing.jsp b/WebContent/html/javascript/listing.jsp index ff995e1..2b6d939 100644 --- a/WebContent/html/javascript/listing.jsp +++ b/WebContent/html/javascript/listing.jsp @@ -38,7 +38,7 @@ function showAll(){ var part1 = "nhpup.popup('"; var part2 = "');" for(var i = 0; i < devices.length; i++){ - html += '
' + devices[i].name + '

' + devices[i].description + '



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

' + devices[i].description + '



'; } document.getElementById('devContainer').innerHTML = html; var anchors = document.getElementsByClassName('availableAnchor'); @@ -67,7 +67,7 @@ function show(deviceArray){ var part2 = "');" for (var i = 0; i < deviceArray.length; i++) { - html += '

' + html += '

' } document.getElementById('devContainer').innerHTML = html; var anchors = document.getElementsByClassName('availableAnchor'); diff --git a/WebContent/html/javascript/request.jsp b/WebContent/html/javascript/request.jsp index daffd7d..e1e8f4c 100644 --- a/WebContent/html/javascript/request.jsp +++ b/WebContent/html/javascript/request.jsp @@ -29,6 +29,7 @@ for(var a = 0; a < hardwareOptions.length; a++){ for(var a = 0; a < softwareOptions.length; a++){ softwareOptions[a].addEventListener('click', refresh); } +showAll(); // searchbar listener var searchbar = document.getElementsByName('searchBar'); searchbar[0].onkeyup = refresh; @@ -37,6 +38,25 @@ show(devices); function refresh() { show(fuzzyFilter(filter(devices))); } + +function showAll(){ + var html = ''; + var part1 = "nhpup.popup('"; + var part2 = "');" + for(var i = 0; i < devices.length; i++){ + html += '
' + devices[i].name + '

' + devices[i].description + '



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

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

"; + + document.getElementById('devContainer').innerHTML = html; + + var requestbuttons = document.getElementsByClassName('requestbutton'); + for(var i = 0; i < requestbuttons.length; i++) { + requestbuttons[i].addEventListener('click',addToCart); + } +} //when an option is selected, show a new list of devices based on what the user asked for function show(deviceArray){ // var type = this.getAttribute('data-type'); @@ -44,7 +64,7 @@ function show(deviceArray){ var part1 = "nhpup.popup('"; var part2 = "');" for (var i = 0; i < deviceArray.length; i++) { - html += '
' + deviceArray[i].name + '

' + deviceArray[i].description + '



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

' + deviceArray[i].description + '



' } if(html.localeCompare("")==0) diff --git a/WebContent/html/javascript/statistics.jsp b/WebContent/html/javascript/statistics.jsp index c5de328..47bd52f 100644 --- a/WebContent/html/javascript/statistics.jsp +++ b/WebContent/html/javascript/statistics.jsp @@ -8,18 +8,34 @@ Insert title here - <% +<% +//statistics for status Statistics[] genStatistics = StatisticsQueries.getStatistics(); String statString = Statistics.arrayToString(genStatistics); +//location queries for map +Statistics[] genLocations = StatisticsQueries.getLocations(); +String locString = Statistics.arrayToString(genLocations); +//device type queries +Statistics[] genTypes = StatisticsQueries.getDeviceTypes(); +String typeString = Statistics.arrayToString(genTypes); +// device manufacturer queries +Statistics[] genManu = StatisticsQueries.getDeviceManu(); +String manuString = Statistics.arrayToString(genManu); %> + \ No newline at end of file diff --git a/WebContent/html/webpages/returnPage.jsp b/WebContent/html/webpages/returnPage.jsp index 14aef23..8d5e862 100644 --- a/WebContent/html/webpages/returnPage.jsp +++ b/WebContent/html/webpages/returnPage.jsp @@ -219,11 +219,12 @@ function populateDeviceList(){ var hardware = devices[i].hardware; var checkout = devices[i].checkout; var manufacturer = devices[i].manufacturer; + var model = devices[i].model; var part1 = "nhpup.popup('"; var part2 = "');" //HTML representation in divs - htmlString+=''; + htmlString+=''; htmlString+="
"; htmlString+=""; htmlString+="
Distribution of Devices Nationwide
- - - +

Device Availability Statistics

-
-
-
-
-
-
-
- <%@ include file="../javascript/statistics.jsp" %> - - \ No newline at end of file +
+
+
+

+
+
+

+
+
+

+
+
+
+
+ <%@ include file="../javascript/statistics.jsp" %> + + diff --git a/WebContent/html/webpages/userLogin.jsp b/WebContent/html/webpages/userLogin.jsp index 8710b0b..16b9910 100644 --- a/WebContent/html/webpages/userLogin.jsp +++ b/WebContent/html/webpages/userLogin.jsp @@ -1,126 +1,126 @@ -<%@ page import = "database.*,entities.Location" %> -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" -pageEncoding="ISO-8859-1"%> -<%@ page import = "java.sql.*" %> - - - - - - - - - - Innovation Hub - - - - - - - - - - -
- - - - -<% -Cookie userCookie,newCookie; - -int ssoNum = Integer.parseInt(request.getParameter("username")); - -Class.forName("com.mysql.jdbc.Driver"); -String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317"; -String user = "b372dfe7409692"; -String password = "74f6e317"; -Connection connection; -Statement stmt; -for(;;){ - try{ - connection = DriverManager.getConnection(database, user, password); - break; - } - catch(SQLException e){ - Thread.sleep(1); - } -} -for(;;){ - try{ - stmt = connection.createStatement(); - break; - } - catch(SQLException e){ - Thread.sleep(1); - } -} -ResultSet result; -result = stmt.executeQuery("select * FROM employee where Employee_ID='" + ssoNum + "'"); - -if (result.next()){ - request.getSession(); - session.setAttribute("ssoNum", ssoNum); - newCookie = new Cookie("name",result.getString("Name")); - stmt.close(); - connection.close(); - newCookie.setMaxAge(30*60); - newCookie.setPath("/"); - response.addCookie(newCookie); - userCookie = new Cookie("ssoNum", Integer.toString(ssoNum)); - userCookie.setMaxAge(30*60); - userCookie.setPath("/"); - response.addCookie(userCookie); - response.sendRedirect("index.jsp"); -} -connection.close(); -stmt.close(); -String locations = Location.arrayToString(LocationQueries.getLocations(ssoNum)); -%> - - + + + + + + + + + + + + +<% +Cookie userCookie,newCookie; + +int ssoNum = Integer.parseInt(request.getParameter("username")); + +Class.forName("com.mysql.jdbc.Driver"); +String database = "jdbc:mysql://us-cdbr-iron-east-04.cleardb.net/ad_15a989204c2ff8a?user=b372dfe7409692&password=74f6e317"; +String user = "b372dfe7409692"; +String password = "74f6e317"; +Connection connection; +Statement stmt; +for(;;){ + try{ + connection = DriverManager.getConnection(database, user, password); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } +} +for(;;){ + try{ + stmt = connection.createStatement(); + break; + } + catch(SQLException e){ + Thread.sleep(1); + } +} +ResultSet result; +result = stmt.executeQuery("select * FROM employee where Employee_ID='" + ssoNum + "'"); + +if (result.next()){ + request.getSession(); + session.setAttribute("ssoNum", ssoNum); + newCookie = new Cookie("name",result.getString("Name")); + stmt.close(); + connection.close(); + newCookie.setMaxAge(30*60); + newCookie.setPath("/"); + response.addCookie(newCookie); + userCookie = new Cookie("ssoNum", Integer.toString(ssoNum)); + userCookie.setMaxAge(30*60); + userCookie.setPath("/"); + response.addCookie(userCookie); + response.sendRedirect("index.jsp"); +} +connection.close(); +stmt.close(); +String locations = Location.arrayToString(LocationQueries.getLocations(ssoNum)); +%> + + \ No newline at end of file diff --git a/src/database/StatisticsQueries.java b/src/database/StatisticsQueries.java index b373d58..171bea4 100644 --- a/src/database/StatisticsQueries.java +++ b/src/database/StatisticsQueries.java @@ -43,7 +43,7 @@ public static Statistics[] getStatistics() Statistics[] statusDevice = new Statistics[rows]; //iterate result set while(resultSet.next()){ - statusDevice[counter] = new Statistics(resultSet.getString("Status"), resultSet.getInt("count(*)")); + statusDevice[counter] = new Statistics(resultSet.getString("Status"), null, null, resultSet.getInt("count(*)"), null, null); counter++; } stmt.close(); @@ -51,5 +51,76 @@ public static Statistics[] getStatistics() return statusDevice; } + public static Statistics[] getLocations() throws ClassNotFoundException, SQLException { + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection = DriverManager.getConnection(database, user, password); + Statement stmt = connection.createStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT Latitude, Longitude from devices JOIN location WHERE devices.Location = location.Location_ID AND Employee_Flag = 0"); + int counter = 0; + + resultSet.last(); + int rows = resultSet.getRow(); + resultSet.beforeFirst(); + + Statistics[] locations = new Statistics[rows]; + //iterate result set + while(resultSet.next()){ + locations[counter] = new Statistics(null, null, null, 0, resultSet.getString("Latitude"), resultSet.getString("Longitude")); + counter++; + } + stmt.close(); + connection.close(); + return locations; + } + + public static Statistics[] getDeviceTypes() throws ClassNotFoundException, SQLException { + //database connect + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection = DriverManager.getConnection(database, user, password); + Statement stmt = connection.createStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT Hardware, count(*) FROM devices GROUP BY Hardware"); + int counter = 0; + + resultSet.last(); + int rows = resultSet.getRow(); + resultSet.beforeFirst(); + + Statistics[] typeDevice = new Statistics[rows]; + //iterate result set + while(resultSet.next()){ + typeDevice[counter] = new Statistics(null, resultSet.getString("Hardware"), null, resultSet.getInt("count(*)"), null, null); + counter++; + } + stmt.close(); + connection.close(); + return typeDevice; + + } + + public static Statistics[] getDeviceManu() throws ClassNotFoundException, SQLException { + //database connect + System.getenv("VCAP_SERVICES"); + Class.forName("com.mysql.jdbc.Driver"); + Connection connection = DriverManager.getConnection(database, user, password); + Statement stmt = connection.createStatement(); + ResultSet resultSet = stmt.executeQuery("SELECT Manufacturer, count(*) FROM devices GROUP BY Manufacturer"); + int counter = 0; + resultSet.last(); + int rows = resultSet.getRow(); + resultSet.beforeFirst(); + + Statistics[] manuType = new Statistics[rows]; + //iterate result set + while(resultSet.next()){ + manuType[counter] = new Statistics(null, null, resultSet.getString("Manufacturer"), resultSet.getInt("count(*)"), null, null); + counter++; + } + stmt.close(); + connection.close(); + return manuType; + + } } diff --git a/src/entities/Statistics.java b/src/entities/Statistics.java index 9be1ef5..0666042 100644 --- a/src/entities/Statistics.java +++ b/src/entities/Statistics.java @@ -2,10 +2,19 @@ public class Statistics { private String _status; + private String _type; + private String _manu; private int _count; - public Statistics(String status,int count) { + private String _latitude; + private String _longitude; + + public Statistics(String status,String type, String manu, int count, String latitude, String longitude) { _status = status; + _type = type; + _manu = manu; _count = count; + _latitude = latitude; + _longitude = longitude; } /** @@ -16,11 +25,16 @@ public String toString(){ StringBuilder sb = new StringBuilder(); String comma = ", "; sb.append("{\"status\": \"").append(_status).append("\"").append(comma); - sb.append("\"count\": ").append(_count); + sb.append("\"type\": \"").append(_type).append("\"").append(comma); + sb.append("\"manu\": \"").append(_manu).append("\"").append(comma); + sb.append("\"count\": ").append(_count).append(comma); + sb.append("\"lat\": \"").append(_latitude).append("\"").append(comma); + sb.append("\"lng\": \"").append(_longitude).append("\""); sb.append("}"); return sb.toString(); } + /** * This is a static function which will turn a Listed Statistics array into its proper string. (modification) * @author - Connor