Skip to content

Commit

Permalink
Device Settings Page Now Works.
Browse files Browse the repository at this point in the history
  • Loading branch information
clj13001 committed Apr 1, 2017
1 parent 9c166a8 commit f397ee9
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 109 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="C:/Users/conno/opt/pivotal/pivotal-tc-server-standard-3.2.1.RELEASE/tomcat-7.0.72.A.RELEASE/lib/servlet-api.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
1 change: 1 addition & 0 deletions .settings/org.eclipse.wst.common.project.facet.core.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Cloud Foundry"/>
<secondary-runtime name="Apache Tomcat v8.0"/>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.8"/>
<installed facet="wst.jsdt.web" version="1.0"/>
Expand Down
5 changes: 2 additions & 3 deletions WebContent/html/javascript/listing.jsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%@ page import = "database.MySQLAccess,entities.Device" %>
<%@ page import = "database.MySQLAccess,entities.Device,database.DeviceQueries" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
Expand All @@ -8,8 +8,7 @@
</head>
<body>
<%
MySQLAccess myaccess = new MySQLAccess();
Device[] mydevices = myaccess.getAllDevices();
Device[] mydevices = DeviceQueries.getAllDevices();
//string representation of array.
String deviceString = Device.arrayToString(mydevices);
Expand Down
40 changes: 4 additions & 36 deletions WebContent/html/javascript/request.jsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%@ page import = "database.*,entities.ListedDevice" %>
<%@ page import = "database.*,entities.Device" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
Expand All @@ -8,10 +8,10 @@
</head>
<body>
<%
ListedDevice[] mydevices = DeviceQueries.getAllDevices();
Device[] mydevices = DeviceQueries.getAllDevices();
//string representation of array.
String deviceString = ListedDevice.arrayToString(mydevices);
String deviceString = Device.arrayToString(mydevices);
//out.println(description);
//out.println(hardware);
Expand All @@ -26,37 +26,6 @@ var devices = makeDeviceArray();
var hardwareOptions = document.getElementsByClassName('hw-data-type');
var softwareOptions = document.getElementsByClassName('sw-data-type');
function ajaxFunction(){
var request;
try {
request = new XMLHttpRequest();
}
catch(e){
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try {
request = new ActiveXObject(Microsoft.XMLHTTP);
} catch(e) {
alert("Something is wrong with your browser");
return false;
}
}
}
request.onreadystatechange = function(){
if(request.readyState == 4){
var display = document.getElementById('ajaxDiv');
display.innerHTML = request.responseText;
}
}
}
//add event listeners to the options in the left sidebar
for(var a = 0; a < hardwareOptions.length; a++){
hardwareOptions[a].addEventListener('click', show);
Expand Down Expand Up @@ -115,8 +84,7 @@ function show(){
}
if(hardwareMatch == true && softwareMatch == true){
//if((hw_type.localeCompare(devices[i].hardware) == 0 && sw_type.localeCompare(devices[i].software) == 0) && !isUnavailable(i)){
if(hardwareMatch == true && softwareMatch == true && devices[i].status.localeCompare("Available") == 0){
html += '<div class = "deviceContainer"><div class = "imgContainer"><img src="../imgs/my-icons-collection-devices/png/' + devices[i].hardware + '.png" class = "device">' + devices[i].name + '</div><div class = "deviceDescp"><p>' + devices[i].description + '</p><button class = "requestbutton" id = "button' + (i+1) + '" type="button">Order device</button></div></div><br><br>'
}
}
Expand Down
36 changes: 27 additions & 9 deletions WebContent/html/webpages/adminDeviceSettings.jsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%@ page import = "database.MySQLAccess,entities.Device" %>
<%@ page import = "database.*,entities.Device" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Expand Down Expand Up @@ -68,10 +68,11 @@
</style>
<!-- Header -->
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="navbar.html"%>
</nav>
</head>
<body>
<!-- Sidebar -->
<!-- Side bar -->
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<h4>Admin Options</h4>
Expand All @@ -86,7 +87,7 @@
<div class="modal-content">
<div class="modal-head">
<span id="closeAddForm" class="close">&times;</span>
<h4>Add a New Device Below<h4>
<h4>Add a New Device Below</h4>
</div><br>
<div class="modal-body">
<!-- Where new information is added. -->
Expand All @@ -99,6 +100,11 @@
<label for="addDesc">Description</label>
<textarea style = "width: 200px;" name = "description" class="form-control" rows = "5" id="addDesc" placeholder="Description"></textarea>
</div>
<div class = "form-group">
<label for="addAvailability">Availability *</label>
<select required style = "width 190px;" name = "status" class="form-control" id="addAvailability">
</select>
</div>
<div class = "form-group">
<label for="addMAC">MAC Address</label>
<input style = "width: 150px;" name = "MAC" class="form-control" id="addMAC" placeholder="MAC Address">
Expand Down Expand Up @@ -136,7 +142,7 @@
<div class="modal-content">
<div class="modal-head">
<span id="closeModifyForm" class="close">&times;</span>
<h4>Modify Device Below<h4>
<h4>Modify Device Below</h4>
</div><br>
<div class="modal-body">
<!-- Where information is modified. -->
Expand All @@ -149,6 +155,11 @@
<label for="modifyDesc">Description</label>
<textarea style = "width: 200px;" name = "description" class="form-control" rows = "5" id="modifyDesc" placeholder="Description"></textarea>
</div>
<div class = "form-group">
<label for="modifyAvailability">Availability *</label>
<select required style = "width 190px;" name = "status" class="form-control" id="modifyAvailability">
</select>
</div>
<div class = "form-group">
<label for="modifyMAC">MAC Address</label>
<input style = "width: 150px;" name = "MAC" class="form-control" id="modifyMAC" placeholder="MAC Address">
Expand Down Expand Up @@ -191,6 +202,7 @@
<tr>
<th>Name</th>
<th class = "column">Description</th>
<th>Availability</th>
<th>MAC Address</th>
<th>Manufacturer</th>
<th>Hardware Type</th>
Expand All @@ -205,10 +217,8 @@
<button id ="add" class="btn btn-primary">Add Device</button>
</div>
<%
//database connection
MySQLAccess myaccess = new MySQLAccess();
//database query
Device[] devices = myaccess.getAllDevices();
Device[] devices = DeviceQueries.getAllDevices();
//string representation of array.
String deviceString = Device.arrayToString(devices);
deviceString = deviceString.replace("'","\\'");
Expand All @@ -220,6 +230,7 @@ deviceString = deviceString.replace("'","\\'");
var devices = makeDeviceArray();
var manufacturers = new Array;
var hardwares = new Array;
var availabilities = new Array;
//Populate locations into table!
populateDevices();
Expand All @@ -238,25 +249,32 @@ window.onclick = function(e){var add = document.getElementById('addModal'); var
//set up options in modals
var manuHTML = '<option value="" disabled selected>Choose Manufacturer</option>';
var hardwareHTML = '<option value="" disabled selected>Choose Hardware</option>';
var availabilityHTML = '<option value="" disable selected>Choose Availability</option>';
for(var i = 0; i < manufacturers.length; i++)
manuHTML += '<option value="' + manufacturers[i] + '">' + manufacturers[i] + '</option>';
for(var i = 0; i < hardwares.length; i++)
hardwareHTML += '<option value="' + hardwares[i] + '">' + hardwares[i] + '</option>';
for(var i = 0; i < availabilities.length; i++)
availabilityHTML += '<option value="' + availabilities[i] + '">' + availabilities[i] + '</option>';
document.getElementById('addManu').innerHTML = manuHTML;
document.getElementById('addHardware').innerHTML = hardwareHTML;
document.getElementById('addAvailability').innerHTML = availabilityHTML;
document.getElementById('modifyManu').innerHTML = manuHTML;
document.getElementById('modifyHardware').innerHTML = hardwareHTML;
document.getElementById('modifyAvailability').innerHTML = availabilityHTML;
//Places all locations from query into page
function populateDevices(){
var html = "";
for(var i = 0; i < devices.length; i++){
html += "<tr class = 'entry' id = '" + devices[i].id + "'><td>" + devices[i].name + "</td><td>" + devices[i].description + "</td><td>" + devices[i].mac + "</td><td>" + devices[i].manufacturer + "</td><td>" + devices[i].hardware + "</td><td>" + devices[i].model + "</td><td>" + devices[i].serial + "</td><td>" + devices[i].nfc + "</td></tr>";
html += "<tr class = 'entry' id = '" + devices[i].id + "'><td>" + devices[i].name + "</td><td>" + devices[i].description + "</td><td>" + devices[i].status + "</td><td>" + devices[i].mac + "</td><td>" + devices[i].manufacturer + "</td><td>" + devices[i].hardware + "</td><td>" + devices[i].model + "</td><td>" + devices[i].serial + "</td><td>" + devices[i].nfc + "</td></tr>";
if(findInArray(devices[i].manufacturer,manufacturers) == false){
manufacturers.push(devices[i].manufacturer);
}
if(findInArray(devices[i].hardware,hardwares) == false)
hardwares.push(devices[i].hardware);
if(findInArray(devices[i].status,availabilities) == false)
availabilities.push(devices[i].status);
}
document.getElementById("tablebodymain").innerHTML = html;
}
Expand Down Expand Up @@ -286,6 +304,7 @@ function modifyModal(){
}
$("#modifyName").val(devices[i].name.replace(/&quot;/g,"\""));
$("#modifyDesc").val(devices[i].description.replace(/&quot;/g,"\""));
$("#modifyAvailability").val(devices[i].status);
$("#modifyMAC").val(devices[i].mac);
$("#modifyManu").val(devices[i].manufacturer.replace(/&quot;/g,"\""));
$("#modifyHardware").val(devices[i].hardware.replace(/&quot;/g,"\""));
Expand All @@ -312,6 +331,5 @@ function findInArray(string,array){
</script>
<!-- Navbar generation. -->
<script src = "../javascript/navbar.js"></script>
</body>
</html>
23 changes: 12 additions & 11 deletions WebContent/html/webpages/deviceRedirect.jsp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%@ page import = "database.MySQLAccess,entities.Device" %>
<%@ page import = "database.*,entities.Device" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -31,16 +31,17 @@
MySQLAccess myaccess = new MySQLAccess();
String name = request.getParameter("name").replace("\"","\\\"");
String description = request.getParameter("description").replace("\"","\\\"");
String status = request.getParameter("status");
String mac = request.getParameter("MAC");
String manufacturer = request.getParameter("manu").replace("\"","\\\"");
String hardware = request.getParameter("hardware").replace("\"","\\\"");
String model = request.getParameter("model").replace("\"","\\\"");
String serial = request.getParameter("serial");
String nfc = request.getParameter("NFC");
int nfc = Integer.parseInt(request.getParameter("NFC"));
//add form was submitted
if(request.getParameter("add") != null){
Device device = new Device(name,description,mac,manufacturer,hardware,model,serial,nfc);
myaccess.addDevice(device);
Device device = new Device(name,1,description,hardware,model,manufacturer,status,mac,serial,nfc);
DeviceQueries.addDevice(device);
}
//modify form was submitted
Expand All @@ -49,20 +50,20 @@ if(request.getParameter("modify") != null){
String strID = request.getParameter("id");
//turn to int for constructor
int id = Integer.parseInt(strID);
Device device = new Device(name,id,description,mac,manufacturer,hardware,model,serial,nfc);
myaccess.modifyDevice(device);
Device device = new Device(name,id,description,hardware,model,manufacturer,status,mac,serial,nfc);
DeviceQueries.modifyDevice(device);
}
/*
//delete form was submitted
if(request.getParameter("delete") != null){
String strID = request.getParameter("id");
int id = Integer.parseInt(strID);
myaccess.deleteLocation(id);
DeviceQueries.deleteDevice(id);
}
*/
%>
<script>
window.location.replace("adminLocation.jsp");
window.location.replace("adminDeviceSettings.jsp");
</script>
<!-- Navbar generation. -->
<script src = "../javascript/navbar.js"></script>
Expand Down
Loading

0 comments on commit f397ee9

Please sign in to comment.