From a6f921740d1ca8e9f32abdf247843de1385f271e Mon Sep 17 00:00:00 2001 From: John Costa Date: Mon, 17 Apr 2017 19:48:25 -0400 Subject: [PATCH 1/4] temporary fix for some issues --- WebContent/html/javascript/listing.jsp | 4 ++-- WebContent/html/javascript/request.jsp | 22 +++++++++++++++++++++- WebContent/html/javascript/statistics.jsp | 18 +++++++++--------- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/WebContent/html/javascript/listing.jsp b/WebContent/html/javascript/listing.jsp index ff995e1..99e3733 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 += '
' + deviceArray[i].name + '

' + deviceArray[i].description + '



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

' + deviceArray[i].description + '



' } 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 6e050fe..21f9d45 100644 --- a/WebContent/html/javascript/request.jsp +++ b/WebContent/html/javascript/request.jsp @@ -28,12 +28,32 @@ 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; 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'); @@ -41,7 +61,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..dc510ba 100644 --- a/WebContent/html/javascript/statistics.jsp +++ b/WebContent/html/javascript/statistics.jsp @@ -36,20 +36,20 @@ function displayData() { //data for info section availableDevices = statistics[0].count; loanDevices = statistics[1].count; + unavailDevices = statistics[2].count; + + //old categories //lostDevices = statistics[2].count; //returnDevices = statistics[6].count; //umbrella divisions //pendingDevices = statistics[0].count; - unavailDevices = statistics[2].count; - html += '
Total Devices: '+ totalDevices + '
Available Devices: ' + availableDevices + '
Loaned Devices: ' + loanDevices + - '
Returning Devices: ' + returnDevices + - '
Lost Devices: ' + lostDevices + - '
' + '
Permanent Devices: ' + unavailDevices + + ''; // Load the Visualization API and the corechart package. google.charts.load('current', {'packages':['corechart']}); @@ -65,10 +65,10 @@ function displayData() { // Create the data table. var data = new google.visualization.DataTable(); data.addColumn('string', 'Status'); - data.addColumn('number', 'Count'); - data.addRows([['Available Devices', availableDevices],['Unavailable Devices',unavailDevices], - ['Loaned Devices',loanDevices]]); - + data.addColumn('number', 'Count'); + for (var i = 0; i Date: Thu, 20 Apr 2017 22:25:27 -0400 Subject: [PATCH 2/4] fixed statistics page, added a chart and made map work, still a few bugs --- .classpath | 6 +- WebContent/html/javascript/statistics.jsp | 121 ++++++++++++++++++-- WebContent/html/webpages/statisticsPage.jsp | 43 +------ src/database/StatisticsQueries.java | 48 +++++++- src/entities/Statistics.java | 15 ++- 5 files changed, 175 insertions(+), 58 deletions(-) diff --git a/.classpath b/.classpath index 7ac7040..0295c16 100644 --- a/.classpath +++ b/.classpath @@ -37,10 +37,6 @@ - - - - - + diff --git a/WebContent/html/javascript/statistics.jsp b/WebContent/html/javascript/statistics.jsp index dc510ba..737c3dc 100644 --- a/WebContent/html/javascript/statistics.jsp +++ b/WebContent/html/javascript/statistics.jsp @@ -8,18 +8,30 @@ 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); %> + \ No newline at end of file diff --git a/WebContent/html/webpages/statisticsPage.jsp b/WebContent/html/webpages/statisticsPage.jsp index dfb2309..79645de 100644 --- a/WebContent/html/webpages/statisticsPage.jsp +++ b/WebContent/html/webpages/statisticsPage.jsp @@ -65,42 +65,6 @@

Distribution of Devices Nationwide

- diff --git a/WebContent/html/webpages/statisticsPage.jsp b/WebContent/html/webpages/statisticsPage.jsp index 79645de..f6cdf5c 100644 --- a/WebContent/html/webpages/statisticsPage.jsp +++ b/WebContent/html/webpages/statisticsPage.jsp @@ -75,9 +75,13 @@


-
-
+
+


+
+
+

+
diff --git a/src/database/StatisticsQueries.java b/src/database/StatisticsQueries.java index 5ddd565..476a2d1 100644 --- a/src/database/StatisticsQueries.java +++ b/src/database/StatisticsQueries.java @@ -24,7 +24,7 @@ public static Statistics[] getStatistics() throws ClassNotFoundException, SQLExc Statistics[] statusDevice = new Statistics[rows]; //iterate result set while(resultSet.next()){ - statusDevice[counter] = new Statistics(resultSet.getString("Status"), null, resultSet.getInt("count(*)"), null, null); + statusDevice[counter] = new Statistics(resultSet.getString("Status"), null, null, resultSet.getInt("count(*)"), null, null); counter++; } stmt.close(); @@ -47,7 +47,7 @@ public static Statistics[] getLocations() throws ClassNotFoundException, SQLExce Statistics[] locations = new Statistics[rows]; //iterate result set while(resultSet.next()){ - locations[counter] = new Statistics(null, null, 0, resultSet.getString("Latitude"), resultSet.getString("Longitude")); + locations[counter] = new Statistics(null, null, null, 0, resultSet.getString("Latitude"), resultSet.getString("Longitude")); counter++; } stmt.close(); @@ -71,7 +71,7 @@ public static Statistics[] getDeviceTypes() throws ClassNotFoundException, SQLEx Statistics[] typeDevice = new Statistics[rows]; //iterate result set while(resultSet.next()){ - typeDevice[counter] = new Statistics(null, resultSet.getString("Hardware"), resultSet.getInt("count(*)"), null, null); + typeDevice[counter] = new Statistics(null, resultSet.getString("Hardware"), null, resultSet.getInt("count(*)"), null, null); counter++; } stmt.close(); @@ -79,4 +79,29 @@ public static Statistics[] getDeviceTypes() throws ClassNotFoundException, SQLEx 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 6c0e99a..0666042 100644 --- a/src/entities/Statistics.java +++ b/src/entities/Statistics.java @@ -3,13 +3,15 @@ public class Statistics { private String _status; private String _type; + private String _manu; private int _count; private String _latitude; private String _longitude; - public Statistics(String status,String type, int count, String latitude, 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; @@ -24,6 +26,7 @@ public String toString(){ String comma = ", "; sb.append("{\"status\": \"").append(_status).append("\"").append(comma); 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("\"");