diff --git a/WebContent/html/javascript/return.js b/WebContent/html/javascript/return.js
index 6298caa..c3374ac 100644
--- a/WebContent/html/javascript/return.js
+++ b/WebContent/html/javascript/return.js
@@ -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()
{
@@ -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++) {
@@ -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)
- 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();
}
\ No newline at end of file
diff --git a/WebContent/html/webpages/returnPage.html b/WebContent/html/webpages/returnPage.html
index fdcda6c..2e702d5 100644
--- a/WebContent/html/webpages/returnPage.html
+++ b/WebContent/html/webpages/returnPage.html
@@ -20,6 +20,7 @@
padding: 15px;
background-color: #E9EAEB;
display: inline-block;
+ cursor: pointer;
}
div.imgContainer{
@@ -60,6 +61,17 @@
+
+
+
+ ×
+
Please Review Your Return Choices
+
+
+
+
+
+
Filter by Time Ordered
@@ -73,10 +85,25 @@
Filter by Time Ordered
Devices to Be Returned
+
+
+
+
+
+ George
+
+
+
Checked out: 2/15/2016
+
You've had this device for one day!
+
+
+
+
+
-
-
Returned
+
+
Return Here
diff --git a/src/database/MySQLAccess.java b/src/database/MySQLAccess.java
index 36a8ed9..d68d57b 100644
--- a/src/database/MySQLAccess.java
+++ b/src/database/MySQLAccess.java
@@ -2,6 +2,8 @@
import java.sql.*;
+import entities.RentedDevice;
+
public class MySQLAccess {
String[][] result = new String[20][3];
@@ -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;
}
diff --git a/src/entities/Admin.java b/src/entities/Admin.java
deleted file mode 100644
index f5d12c5..0000000
--- a/src/entities/Admin.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package entities;
-/**
- * Admins get special privileges!
- * @author conno
- *
- */
-public class Admin extends User {
-
- public Admin(int id, int location, String name) {
- super(id, location, name);
- }
-
-}
diff --git a/src/entities/Device.java b/src/entities/Device.java
deleted file mode 100644
index 197ed6c..0000000
--- a/src/entities/Device.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package entities;
-
-
-/**
- * This illustrates a device that will be requested.
- * Later will be replaced by database entity.
- * @author conno
- *
- */
-public class Device {
-private int id;
-private String type;
-private String version;
-private boolean available;
-
-/**
- * Constructor.
- * @param id
- * @param type
- * @param version
- */
- public Device(int id, String type, String version){
- this.id = id;
- this.type = type;
- this.version = version;
- this.available = true;
- }
-
- public String getType(){
- return this.type;
- }
-
- public String getVersion(){
- return this.version;
- }
-
- public boolean checkAvailabilty(){
- return this.available;
- }
-
- public void setAvailability(){
- this.available = !available;
- }
-
-}
diff --git a/src/entities/RentedDevice.java b/src/entities/RentedDevice.java
new file mode 100644
index 0000000..1517383
--- /dev/null
+++ b/src/entities/RentedDevice.java
@@ -0,0 +1,68 @@
+package entities;
+
+/**
+ * Will support querying devices a certain user has rented out.
+ * @author conno
+ *
+ */
+public class RentedDevice {
+ private String Device_ID;
+ private String Device_Name;
+ private String Device_Description;
+ private String Ticket_ID;
+ //Smartphone, tablet, etc.
+ private String Model_Type;
+ //iPhone, Galaxy S5, etc.
+ private String Hardware_Model;
+ private String Borrow_Date;
+
+ public RentedDevice(String id, String name, String desc, String ticketid, String model, String hardware, String date){
+ Device_ID = id;
+ Device_Name = name;
+ Device_Description = desc;
+ Ticket_ID = ticketid;
+ Model_Type = model;
+ Hardware_Model = hardware;
+ Borrow_Date = date;
+ }
+/**
+ * Formatting the device to fit a JSON object.
+ */
+ public String toString(){
+ StringBuilder sb = new StringBuilder();
+ String comma = ", ";
+ sb.append("{id: ").append(Device_ID).append(comma);
+ sb.append("name: \"").append(Device_Name).append(comma);
+ sb.append("description: \"").append(Device_Description).append(comma);
+ sb.append("ticket: \"").append(Ticket_ID).append(comma);
+ sb.append("model: \"").append(Model_Type).append(comma);
+ sb.append("hardware: \"").append(Hardware_Model).append(comma);
+ sb.append("checkout: \"").append(Borrow_Date);
+ sb.append("};");
+ return sb.toString();
+ }
+
+ public String getID(){
+ return Device_ID;
+ }
+
+ public String getName(){
+ return Device_Name;
+ }
+
+ public String getDesc(){
+ return Device_Description;
+ }
+
+ public String getTicketID(){
+ return Ticket_ID;
+ }
+
+ public String getModel(){
+ return Model_Type;
+ }
+
+ public String getHardware(){
+ return Hardware_Model;
+ }
+}
\ No newline at end of file
diff --git a/src/entities/User.java b/src/entities/User.java
deleted file mode 100644
index 8d7e49c..0000000
--- a/src/entities/User.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package entities;
-
-public class User {
-private int id;
-private int location;
-private String name;
-
- public User(int id, int location, String name){
- this.id = id;
- this.location = location;
- this.name = name; //later will do table lookup to determine by id
- }
-}
diff --git a/src/features/RequestHandler.java b/src/features/RequestHandler.java
deleted file mode 100644
index 590bab1..0000000
--- a/src/features/RequestHandler.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package features;
-
-import java.util.ArrayList;
-import java.util.Scanner;
-
-import entities.Device;
-
-public class RequestHandler {
-
- public void requestDevice(Scanner STDIN, Device[] db){
- System.out.println("What type of device would you like to request?\n");
- ArrayList listtypes = displayTypes(db); //displays types that can be chosen from
- System.out.print("\nChoice: ");
- String type = STDIN.nextLine().toLowerCase(); //gets user input of what they want
- System.out.print("---------------------------------------------------------------------------------------------------------\n");
- if(type.equals("cancel") || type.equals(Integer.toString(listtypes.size() + 1))) //if user wants to cancel
- return;
- while(!checkAvailability(type,db)){ //makes sure the user typed in a valid option
- System.out.print("Please choose a valid type.\nChoice: ");
- type = STDIN.nextLine().toLowerCase();
- if(type.equals("cancel") || type.equals(Integer.toString(listtypes.size()))) //if user wants to cancel
- return;
- }
- System.out.print("Type which number device you would like!\n\n");
- int cancelindex = displayDevices(type,db);
- System.out.print("\nChoice: ");
- String input = STDIN.nextLine();
- System.out.print("---------------------------------------------------------------------------------------------------------\n");
- if(input.toLowerCase().equals("cancel") || input.equals(Integer.toString(cancelindex)))
- return;
- int option = Integer.parseInt(input);
- while(option > cancelindex || option < 1){
- System.out.print("Invalid option, please choose a right one.\nChoice: ");
- if(input.toLowerCase().equals("cancel") || input.equals(Integer.toString(cancelindex)))
- return;
- option = Integer.parseInt(STDIN.nextLine());
- System.out.print("---------------------------------------------------------------------------------------------------------\n");
- }
- checkoutDevice(option, type, db);
- System.out.print("---------------------------------------------------------------------------------------------------------\n");
- }
-
- public boolean checkAvailability(String type, Device[] db){
- for(int i = 0; i < db.length; i++){
- if(db[i].getType().toLowerCase().equals(type) == true && db[i].checkAvailabilty() == true)
- return true;
- }
- return false;
- }
-
- public int displayDevices(String type, Device[] db){
- int counter = 1;
- for(int i = 0; i < db.length; i++){
- if(db[i].getType().toLowerCase().equals(type) == true && db[i].checkAvailabilty() == true){
- System.out.print(counter + ": " + db[i].getType() + " - " + db[i].getVersion() + "\n");
- counter++;
- }
- }
- System.out.print(counter + ". Cancel\n");
- return counter;
- }
-
- public void checkoutDevice(int option, String type, Device[] db){
- int counter = 1;
- for(int i = 0; i < db.length; i++){
- if(db[i].getType().toLowerCase().equals(type) == true && db[i].checkAvailabilty() == true){
- if(counter == option){
- db[i].setAvailability();
- }
- counter++;
- }
- }
- System.out.print("Congrats! You checked out the device.\n");
- }
-
- public ArrayList displayTypes(Device[] db){
- ArrayList al = new ArrayList();
- int counter = 1;
- for(int i = 0; i < db.length; i++){
- if(!al.contains(db[i].getType()) && db[i].checkAvailabilty() == true){
- al.add(db[i].getType());
- System.out.print(counter + ". " + db[i].getType() + "\n");
- counter++;
- }
- }
- System.out.println(counter + ". Cancel\n");
- return al;
- }
-
-}
diff --git a/src/features/ReturnHandler.java b/src/features/ReturnHandler.java
deleted file mode 100644
index 4d73b34..0000000
--- a/src/features/ReturnHandler.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package features;
-
-import entities.Device;
-
-public class ReturnHandler
-{
- public void returnDevice()
- {
- // Insert some sort of user verification into this system
- String user = "Maegan";
- System.out.print("Welcome " + user + "which device would you like to return");
- //Hard code devices in?
- }
-
- public boolean changeAvailability(String type, Device[] db)
- {
- return true;
-
- }
-
-
-
-}
diff --git a/src/functionality_managers/ClientManager.java b/src/functionality_managers/ClientManager.java
deleted file mode 100644
index e0e0d8a..0000000
--- a/src/functionality_managers/ClientManager.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package functionality_managers;
-
-import java.util.Scanner;
-
-import entities.Device;
-import features.RequestHandler;
-
-/**
- * This class will effectively manage any type of task a client would like to do.
- * @author conno
- *
- */
-public class ClientManager {
-
- private RequestHandler rh = new RequestHandler();
-
- public void requestDevice(Scanner STDIN, Device[] db){
- rh.requestDevice(STDIN, db);
- }
-}
diff --git a/src/functionality_managers/SystemManager.java b/src/functionality_managers/SystemManager.java
deleted file mode 100644
index c5bc8c3..0000000
--- a/src/functionality_managers/SystemManager.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package functionality_managers;
-
-import java.util.Scanner;
-
-import entities.Device;
-
-/**
- * This will manage tasks that have to generally be handled by the system.
- * @author conno
- *
- */
-public class SystemManager {
-
- private Device[] db;
-
- public SystemManager(){
- Device dev1 = new Device(0, "iPod", "iOS7");
- Device dev2 = new Device(0, "iPod", "iOS8");
- Device dev3 = new Device(0, "iPad", "iOS10");
- Device dev4 = new Device(0, "iPhone", "iOS9");
- Device dev5 = new Device(0, "iPhone", "iOS7");
-
- db = new Device[] {dev1, dev2, dev3, dev4, dev5};
- }
-
- /**
- * This will (later) return a user object based on who is logging in.
- * @param STDIN
- */
- public void loginProcess(Scanner STDIN){
- /*
- * Based on the user name we can create a user object
- * Make the return type a user
- * Use the user return so that the return handler remembers a client
- */
- System.out.print("---------------------------------------------------------------------------------------------------------\n");
- System.out.print("Welcome to the Senior Design Request System!\nPlease type in your login credentials below.\nUser: ");
- String name = STDIN.nextLine();
- System.out.print("Password: ");
- String pass = STDIN.nextLine();
- //will obviously later have a more clear cut way of login
- System.out.print("\nLog in successful!\n");
- System.out.print("---------------------------------------------------------------------------------------------------------\n");
- //return user
- }
-
- public void runMenu(Scanner STDIN, ClientManager cm){
- while(true){
- System.out.println("Welcome to the request system! Please select a menu option from below of what you'd like to do:\n\n1. Request Device\n2. Quit\n\nChoice: ");
- String option = STDIN.nextLine();
- System.out.print("---------------------------------------------------------------------------------------------------------\n");
- switch(option.toLowerCase()){
- case "request device":
- cm.requestDevice(STDIN, db);
- break;
- case "quit":
- System.out.print("Thanks for using the service.\n\n");
- return;
- case "1":
- cm.requestDevice(STDIN, db);
- break;
- case "2":
- System.out.print("Thanks for using the service.\n\n");
- return;
- }
- }
- }
-
-}