Skip to content

Commit

Permalink
Merge pull request #83 from arc12012/ApproveRejectTickets
Browse files Browse the repository at this point in the history
Approve reject tickets
  • Loading branch information
clj13001 committed Apr 7, 2017
2 parents a3dbda4 + f295c71 commit 70f9441
Show file tree
Hide file tree
Showing 8 changed files with 432 additions and 15 deletions.
2 changes: 1 addition & 1 deletion WebContent/html/webpages/admin.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ div.approveConfirm {
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<h4>Admin Options</h4>
<li class="option"><a href="../webpages/adminApprove.html">Approve Devices</a></li>
<li class="option"><a href="../webpages/adminApprove.jsp">Approve Devices</a></li>
<li class="option"><a href="#">Manage Admins</a></li>
<li class="option"><a href="#">Manage Devices</a></li>
</ul>
Expand Down
167 changes: 154 additions & 13 deletions WebContent/html/webpages/adminApprove.jsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<%@ page import = "database.*,entities.*" %>
<%@ 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 lang="en">
<head>
<meta charset="utf-8">
Expand All @@ -22,27 +26,22 @@
background-color: #E9EAEB;
display: inline-block;
}
div.imgContainer{
display: inline-block;
text-align: center;
}
img.device{
display: block;
}
div.deviceDescp{
display: inline-block;
width: 200px;
text-align: center;
}
button.approvebutton{
display: block;
margin: auto;
}
div.approveConfirm{
display: none;
top: 50%;
Expand All @@ -57,27 +56,169 @@
border-color: #3B3C43;
border-radius: 5px;
}
div.displayDevice{
left: 0px;
}
.form-control{
margin: auto;
text-align: center;
}
tr.entry{
cursor: pointer;
}
.table{
width: auto;
background-color: #E9EAEB;
}
tbody{
text-align: left;
}
</style>
</head>

<body>
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="navbar.html"%>
<%@ include file="navbar.html"%>
</nav>

<!-- Modal for choosing ticket action. -->
<div id="Modal" class="modal">
<div class="modal-content">
<div class="modal-head">
<span id="closeForm" class="close">&times;</span>
<h4>View Ticket Below</h4>
</div><br>
<div class="modal-body">
<!-- Where new information is added. -->
<form ACTION = "ticketAdminRedirect.jsp" METHOD = "POST">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Ticket ID</th>
<th>Requestor Name</th>
<th>Location Name</th>
<th>Device Name</th>
<th>Status</th>
<th>Return Date</th>
</tr>
</thead>
<tbody id="tablemodal">
</tbody>
</table>
<button type = "submit" name = "approve" value = "Approve" class="btn btn-primary">Approve</button>
<button type = "submit" name = "reject" value = "Reject" class="btn btn-primary">Reject</button>
<input type = "text" id = "ticketIDfield" name = "ticketid" style = "display: none;">
<input type = "text" id = "deviceIDfield" name = "deviceid" style = "display: none;">
<input type = "text" id = "locationIDfield" name = "locationid" style = "display: none;">
</form>
</div>
</div>
</div>

<div class = "displayDevice">
<h2>Admin View Approvals</h2>
<div id = "devContainer"></div>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Ticket ID</th>
<th>Requestor Name</th>
<th>Location Name</th>
<th>Device Name</th>
<th>Status</th>
<th>Return Date</th>
</tr>
</thead>
<tbody id="tablebodymain">
</tbody>
</table>
</div>

<div class = "approveConfirm" id = "approved">
<p>Approved!</p>
</div>

<script src="../javascript/admin.js"></script>
<%TicketQueries query = new TicketQueries();
Ticket[] tickets = query.getTickets();
User[] users = EmployeeQueries.getAllUsers();
Location[] locations = LocationQueries.getAllLocations();
ListedDevice[] devices = DeviceQueries.getAllDevices();
String ticketStr = Ticket.arrayToString(tickets);
String userStr = User.arrayToString(users);
String locationStr = Location.arrayToString(locations).replace("'","\\'");
String deviceStr = ListedDevice.arrayToString(devices);
%>

<script>
window.json = '<%=ticketStr%>';
var tickets = JSON.parse(window.json);
window.json = '<%=userStr%>';
var users = JSON.parse(window.json);
window.json = '<%=locationStr%>';
var locations = JSON.parse(window.json);
window.json = '<%=deviceStr%>';
var devices = JSON.parse(window.json);
populateTickets();
//adds event listeners to all table records
$("tr.entry").click(ticketAction);
//Exits modal when x is clicked.
$("#closeForm").click(closeModal);
//Event listener exits modal when esc key pressed.
window.onkeydown = function(e){if (e.keyCode == 27){closeModal();}}
//Event listener exits modal when click outside modal.
window.onclick = function(e){var modal = document.getElementById('Modal'); if(e.target == modal) {closeModal();}}
//Places all tickets from query into page
function populateTickets(){
var html = "";
for(var i = 0; i < tickets.length; i++){
var requestor = getRequestor(tickets[i].requestor);
var location = getLocation(tickets[i].location);
var device = getDevice(tickets[i].deviceID);
//NEED TO ADD IN RETURN DATE AT END BUT THAT WOULD BREAK THINGS AT THE MOMENT
html += "<tr class = 'entry' id = '" + i + "'><td>" + tickets[i].id + "</td><td>" + requestor + "</td><td>" + location + "</td><td>" + device + "</td><td>" + tickets[i].status + "</td><td>" + tickets[i].return + "</td></tr>";
}
document.getElementById("tablebodymain").innerHTML = html;
}
function getRequestor(id){
for(var i = 0; i < users.length; i++){
if(id == users[i].id)
return users[i].name;
}
}
function getLocation(id){
for(var i = 0; i < locations.length; i++){
if(id == locations[i].id)
return locations[i].name;
}
}
function getDevice(id){
for(var i = 0; i < devices.length; i++){
if(id == devices[i].id)
return devices[i].name;
}
}
function ticketAction(){
var id = this.id;
var requestor = getRequestor(tickets[id].requestor);
var location = getLocation(tickets[id].location);
var device = getDevice(tickets[id].deviceID);
var html = "<tr><td>" + tickets[id].id + "</td><td>" + requestor + "</td><td>" + location + "</td><td>" + device + "</td><td>" + tickets[id].status + "</td><td>" + tickets[id].return + "</td></tr>";
document.getElementById("tablemodal").innerHTML = html;
$("#ticketIDfield").val(tickets[id].id);
$("#deviceIDfield").val(tickets[id].deviceID);
$("#locationIDfield").val(tickets[id].location);
$("#Modal").show();
}
function closeModal(){
$("#Modal").hide();
}
</script>
</body>
</html>
53 changes: 53 additions & 0 deletions WebContent/html/webpages/ticketAdminRedirect.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<%@ page import = "database.*" %>
<%@ 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 lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">

<title>Synchrony Financial</title>

<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel = "stylesheet" type = "text/css" href = "../css/stylesheet.css">
<link rel = "shortcut icon" href = "../imgs/synchrony-financial-logo-dlpx_1.ico">
<nav class="navbar navbar-inverse navbar-fixed-top" id = "navbaruniversal">
<%@ include file="navbar.html"%>
</nav>
</head>
<body>
<h2>Redirect Page</h2>
<p>You shouldn't be seeing this page :)</p>

<%
//make instance
String ticketidstr = request.getParameter("ticketid");
String deviceidstr = request.getParameter("deviceid");
String locationidstr = request.getParameter("locationid");
int ticketid = Integer.parseInt(ticketidstr);
int deviceid = Integer.parseInt(deviceidstr);
int locationid = Integer.parseInt(locationidstr);
//add form was submitted
if(request.getParameter("approve") != null){
TicketQueries.acceptTicket(ticketid,deviceid,locationid);
}
//modify form was submitted
if(request.getParameter("reject") != null){
TicketQueries.rejectTicket(ticketid);
}
%>
<script>
window.location.replace("adminApprove.jsp");
</script>
<!-- Navbar generation. -->
</body>
</html>
25 changes: 25 additions & 0 deletions src/database/EmployeeQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,29 @@ public static User getEmployeeByID(int id) throws ClassNotFoundException, SQLExc
access.closeConnection();
return employee;
}

public static User[] getAllUsers() throws SQLException, ClassNotFoundException{
//database connect
System.getenv("VCAP_SERVICES");
MySQLAccess access = new MySQLAccess();
Statement stmt = access.getStatement();
ResultSet resultSet = stmt.executeQuery("SELECT * FROM employee");
int counter = 0;

resultSet.last();
int rows = resultSet.getRow();
resultSet.beforeFirst();

//Covers amount of rows, and 6 attributes (indices 0-5)
User[] users = new User[rows];

//iterate result set
while(resultSet.next()){
users[counter] = new User(resultSet.getInt("Employee_ID"),resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Phone_Number"));
counter++;
}

access.closeConnection();
return users;
}
}
25 changes: 25 additions & 0 deletions src/database/LocationQueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,29 @@ public static void deleteLocation(int id) throws ClassNotFoundException, SQLExce
stmt.close();
connect.close();
}

public static Location[] getAllLocations() throws SQLException, ClassNotFoundException{
//database connect
System.getenv("VCAP_SERVICES");
MySQLAccess access = new MySQLAccess();
Statement stmt = access.getStatement();
ResultSet resultSet = stmt.executeQuery("SELECT * FROM location");
int counter = 0;

resultSet.last();
int rows = resultSet.getRow();
resultSet.beforeFirst();

//Covers amount of rows, and 6 attributes (indices 0-5)
Location[] locations = new Location[rows];

//iterate result set
while(resultSet.next()){
locations[counter] = new Location(resultSet.getInt("Location_ID"),resultSet.getString("Name"),resultSet.getString("Address"),resultSet.getString("Town"),resultSet.getString("State"),resultSet.getString("Zip_Code"));
counter++;
}

access.closeConnection();
return locations;
}
}
Loading

0 comments on commit 70f9441

Please sign in to comment.