Skip to content

Commit

Permalink
Catching up with last weeks updates
Browse files Browse the repository at this point in the history
  • Loading branch information
clj13001 committed Feb 21, 2017
1 parent e4b62fd commit a04ef03
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 384 deletions.
204 changes: 95 additions & 109 deletions WebContent/html/javascript/return.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,104 @@
/*<%@ page import = "database.MySQLAccess" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>*/

//Code that will obtain the devices a certain user is trying to access
//<%
/*MySQLAccess myaccess = new MySQLAccess();
Connection connect = myaccess.connectDB();
NEED USER ID FROM COOKIE?
String userID =
RentedDevice[] mydevices = myaccess.getUserDevices(connect, userID);
int numDevices = mydevices.length;
*/
//%>

var dev1 = {
id: 1,
name:"George",
hardware:"iphone",
checkout: new Date("11/11/2016"),
};

var dev2 = {
id: 2,
name:"Greyson",
hardware:"iphone",
checkout: new Date("8/10/2016"),
};

var dev3 = {
id: 3,
name:"Linkin Park",
hardware:"ipad",
checkout: new Date("8/20/2016"),
};

var dev4 = {
id: 4,
name:"Abercrombie",
hardware:"ipad",
checkout: new Date("11/3/2016"),
};

var dev5 = {
id: 5,
name:"Hulk",
hardware:"computerStick",
checkout: new Date("4/28/2016"),
};

var dev6 = {
id: 6,
name:"Captain America",
hardware:"computerStick",
checkout: new Date("10/22/2016"),
};

var devices = [dev1, dev2, dev3, dev4, dev5, dev6];
//This array corresponds to the hardcoded inventory in request.js. The description has been replaced with a
//checkout date, because I imagine that is more the kind of info to pull from the database for this page.
//IDs, names and hardware are the same.
var devices = makeDeviceArray();
//This will be the array of ids that are checked off
var toReturn = []

//Adds event listener to each mennu option
var options = document.getElementsByClassName('option');
for (var i = options.length - 1; i >= 0; i--) {
options[i].addEventListener('click',filterDeviceList);
}

//This calls on the filter function, which by default displays ALL DEVICES! You can later filter by take out period!
//populateDeviceList(null);

//Test data
$('div[data-num="1"]').click(fireCheck);
$('input[data-num="1"]').click(selectBox);
$('#returnbutton').click(returnDevice);
$('#closeOrderForm').click(hidePopup);

//This should make the device array of retrieved devices
function makeDeviceArray(){
var devices = [];
//loop constraint
/*<%
window.numDevices = <=numDevices>;
%>
//iterate all devices we retrieved
for(var i = 0; i < window.numDevices; i++){
//get JSON text from each object
<%
window.json = "<=mydevices[i].toString()>";
%>
//push to array!
devices.push(JSON.parse(window.json));
}*/
return devices;
}

populateDeviceList(null);
//This makes a corresponding checkbox get set off, and then changes box color
function fireCheck(){
//get device id
var id = this.getAttribute('data-num');
//create jquery strings
var query = 'input[data-num="'+id+'"]';
var query2 = 'div[data-num="'+id+'"]';
//check to see if checkbox is checked
var checked = $(query).prop('checked');
//if so...
if(checked === true){
//uncheck box
$(query).prop('checked',false);
//lighten background color
$(query2).css("background-color","#E9EAEB");
//remove from toReturn array
toReturn.splice(toReturn.indexOf(id),1)
}
//if box is unchecked...
else{
//check it off
$(query).prop('checked',true);
//make background darker
$(query2).css("background-color","#C2C3C4");
//add to toReturned array
toReturn.push(id);
}
}

//behaves similarly to above, minus the forced checking
//and if statement reversed
function selectBox(){
var id = this.getAttribute('data-num');
var query = 'input[data-num="'+id+'"]';
var query2 = 'div[data-num="'+id+'"]';
var checked = $(query).prop('checked');
if(checked === false){
$(query2).css("background-color","#E9EAEB");
toReturn.splice(toReturn.indexOf(id),1)
}
else{
$(query2).css("background-color","#C2C3C4");
toReturn.push(id);
}
}

function filterDeviceList()
{
Expand Down Expand Up @@ -96,7 +142,7 @@ function filterDeviceList()
function populateDeviceList(filter)
//generates html and writes to 'devContainer' div in returnPage.html
{
var devicesToList = getCheckedOutDevices(null,filter);
var devicesToList = devices;
var htmlString="";
var i;
for (i = 0; i < devicesToList.length; i++) {
Expand Down Expand Up @@ -142,70 +188,10 @@ function populateDeviceList(filter)

function returnDevice()
{
var id = this.getAttribute('id');
id = parseInt(id.replace(/[^0-9\.]/g,''), 10);
if(isUnavailable(id))
{
var unavailable = getUnavailableIDs();
unavailable.splice(unavailable.indexOf(id),1);
localStorage.setItem('unavailable',JSON.stringify(unavailable));
$('#return').fadeIn(1000);
$('#return').fadeIn(1000);
$('#return').fadeOut(1000);
}
else
alert("That's already marked available. Something may have gone wrong.");
populateDeviceList();
$('#orderInfoModal').show();
}

function getCheckedOutDevices(user, filter)
//Eventually this will return information about all devices checked out by *user*
//Right now there is only one user, and the function just returns IDs of all checked out devicess.
//'Filter' is passed as a two-element array representing a range of milliseconds.
//If the checkout date for a device falls within that range, then it will be included in the results.
//The filter may be null. If so, all checked out devices will be returned.
{
var unavailable = getUnavailableIDs();
var checkedDevices = new Array();
for (var i = 0; i < unavailable.length; i++) {
for (var j = 0; j < devices.length; j++) {
if(unavailable[i] == devices[j].id)
{
if(filter!=null)
{
var checkedOutMillis = devices[j].checkout.getTime();
if(filter[0]<checkedOutMillis && filter[1]>checkedOutMillis)
checkedDevices.push(devices[j]);
}
else
checkedDevices.push(devices[j]);
break;
}
}
}
return checkedDevices;
}

function isUnavailable(id){
var unavailable = getUnavailableIDs();
if(unavailable.length == 0)
return 0;
else{
for(var i = 0; i < unavailable.length; i++){
if(unavailable[i] == (id))
return 1;
}
}
return 0;
}
function getUnavailableIDs()
//Identical to the function in request.js: just reads the 'unavailable' array in local storage.
//Will need to be changed (or may be obsolete) when we get a database
{
var unavailable = new Array;
var unavailable_str = localStorage.getItem('unavailable');
if(unavailable_str !== "" && unavailable_str !== null){
unavailable = JSON.parse(unavailable_str);
}
return unavailable;
//called when clicking x on the modal
function hidePopup(){
$('#orderInfoModal').hide();
}
31 changes: 29 additions & 2 deletions WebContent/html/webpages/returnPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
padding: 15px;
background-color: #E9EAEB;
display: inline-block;
cursor: pointer;
}

div.imgContainer{
Expand Down Expand Up @@ -60,6 +61,17 @@
</nav>
</head>
<body>
<div id="orderInfoModal" class="modal">
<div class="modal-content">
<div class="modal-head">
<span id="closeOrderForm" class="close">&times;</span>
<h4>Please Review Your Return Choices</h4>
</div>
<div class="modal-body">
<button>Continue</button>
</div>
</div>
</div>
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<h4>Filter by Time Ordered</h4>
Expand All @@ -73,10 +85,25 @@ <h4>Filter by Time Ordered</h4>
<div class="displayDevice">
<h2>Devices to Be Returned</h2>
<div id = "devContainer">
<input type = "checkbox" data-num = "1"/>
<div class= "deviceContainer" data-num = "1">
<div>
<div class="imgContainer">
<img src="../imgs/iphone.png" class="device">
George
</div>
<div class="deviceInfo">
<p>Checked out: 2/15/2016</p>
<p>You've had this device for one day!</p>
</div>
</div>
</div>
<br><br>
</div>
<button id ="returnbutton">Return</button>
</div>
<div class="returnConfirm" id="return">
<p>Returned</p>
<div style = "display: inline-block">
<h2>Return Here</h2>
</div>
<script src="../javascript/return.js" href></script>
<script src = "../javascript/navbar.js"></script>
Expand Down
23 changes: 23 additions & 0 deletions src/database/MySQLAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.sql.*;

import entities.RentedDevice;

public class MySQLAccess {

String[][] result = new String[20][3];
Expand All @@ -27,6 +29,27 @@ public void connectDB() throws SQLException, ClassNotFoundException {
}
}

public RentedDevice[] getUserDevices(Connection connect, String userID) throws SQLException, ClassNotFoundException{
//Not sure how to get cookie information (if that is how we choose to accomplish this...) ? But this should be a passed parameter
Statement stmt = connect.createStatement();
ResultSet countset = stmt.executeQuery("SELECT COUNT(*) FROM devices WHERE Renter = " + userID);
//number of devices obtained
int rows = countset.getInt(1);
ResultSet resultSet = connect.createStatement().executeQuery("SELECT Device_ID, Device_Name, Device_Description, Ticket_ID, Model_Type, Hardware_Model, Borrow_Date FROM devices WHERE Renter = " + userID);
int counter = 0;

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

//iterate result set
while(resultSet.next()){
devices[counter] = new RentedDevice(resultSet.getInt("Device_ID") + "",resultSet.getString("Device_Name"),resultSet.getString("Device_Description"),resultSet.getInt("Ticket_ID") + "",resultSet.getString("Model_Type"),resultSet.getString("Hardware_Model"),resultSet.getString("Borrow_Date"));
counter++;
}

return devices;
}

public String[][] getResult(){
return result;
}
Expand Down
13 changes: 0 additions & 13 deletions src/entities/Admin.java

This file was deleted.

45 changes: 0 additions & 45 deletions src/entities/Device.java

This file was deleted.

Loading

0 comments on commit a04ef03

Please sign in to comment.