Skip to content

Commit

Permalink
Merge pull request #76 from arc12012/JcoonaBranch
Browse files Browse the repository at this point in the history
Jcoona branch
  • Loading branch information
clj13001 committed Apr 5, 2017
2 parents a588daa + 8b460df commit f93a61c
Show file tree
Hide file tree
Showing 13 changed files with 604 additions and 67 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
4 changes: 4 additions & 0 deletions WebContent/html/css/stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ input[type=number]{
width: 60%;
}

textarea{
margin: 0 auto;
}

select{
margin:0 auto;
width: 65%;
Expand Down
19 changes: 3 additions & 16 deletions WebContent/html/javascript/listing.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,24 +8,20 @@
</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);
%>

<script type=text/javascript>
//gets variables for database data
var devices = makeDeviceArray();
//get all the option buttons
//var options = document.getElementsByClassName('checkboxes');
var hardwareOptions = document.getElementsByClassName('hw-data-type');
var softwareOptions = document.getElementsByClassName('sw-data-type');
//options[0].addEventListener('click', showAll);
for(var a = 0; a < hardwareOptions.length; a++){
hardwareOptions[a].addEventListener('click', refresh);
Expand All @@ -36,7 +32,6 @@ for(var a = 0; a < softwareOptions.length; a++){
// searchbar listener
var searchbar = document.getElementsByName('searchBar');
searchbar[0].onkeyup = refresh;
showAll();
function showAll(){
var html = '';
Expand Down Expand Up @@ -85,10 +80,8 @@ function show(deviceArray){
id = '#' + id;
$(id).css({'background-color':'#1fe07f'});
}
}
}
function applyFilter() {
var filteredDevices = new Array();
var activeHOptions = [];
Expand All @@ -106,7 +99,6 @@ function applyFilter() {
for(var i = 0; i < devices.length; i++){
var hardwareMatch = false;
var softwareMatch = false;
for(var j = 0; j < activeHOptions.length; j++) {
if (activeHOptions[j] == devices[i].hardware){
hardwareMatch = true;
Expand All @@ -124,11 +116,9 @@ function applyFilter() {
if(othermatch) hardwareMatch = true;
}
}
if (activeHOptions.length == 0) {
hardwareMatch = true;
}
for(var j = 0; j < activeSOptions.length; j++) {
if (activeSOptions[j] == devices[i].manufacturer){
softwareMatch = true;
Expand All @@ -146,7 +136,6 @@ function applyFilter() {
if(othermatch) softwareMatch = true;
}
}
if (activeSOptions.length == 0) {
softwareMatch = true;
}
Expand All @@ -157,7 +146,6 @@ function applyFilter() {
}
return filteredDevices;
}
function fuzzyFilter(deviceList) {
var searchText = document.getElementsByName('searchBar')[0].value;
var options = {
Expand All @@ -183,7 +171,6 @@ function fuzzyFilter(deviceList) {
manufacturer:fuzzyResults[i].original.manufacturer,
};
}
return results;
}
function makeDeviceArray(){
Expand Down
33 changes: 8 additions & 25 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,25 +8,19 @@
</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);
%>

<script type=text/javascript>
//gets variables for database data
var devices = makeDeviceArray();
//get all the option buttons
var hardwareOptions = document.getElementsByClassName('hw-data-type');
var softwareOptions = document.getElementsByClassName('sw-data-type');
function ajaxFunction(){
var request;
try {
Expand Down Expand Up @@ -56,7 +50,6 @@ function ajaxFunction(){
}
}
//add event listeners to the options in the left sidebar
for(var a = 0; a < hardwareOptions.length; a++){
hardwareOptions[a].addEventListener('click', refresh);
Expand All @@ -67,18 +60,15 @@ for(var a = 0; a < softwareOptions.length; a++){
// searchbar listener
var searchbar = document.getElementsByName('searchBar');
searchbar[0].onkeyup = refresh;
function refresh() {
show(fuzzyFilter(filter(devices)));
}
//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');
var html = '';
for (var i = 0; i < deviceArray.length; i++) {
html += '<div class = "deviceContainer"><div class = "imgContainer"><img src="../imgs/my-icons-collection-devices/png/' + deviceArray[i].hardware + '.png" class = "device">' + deviceArray[i].name + '</div><div class = "deviceDescp"><p>' + deviceArray[i].description + '</p><button class = "requestbutton" id = "button' + (i+1) + '" type="button">Order device</button></div></div><br><br>'
html += '<div class = "deviceContainer"><div class = "imgContainer"><img src="../imgs/my-icons-collection-devices/png/' + deviceArray[i].hardware + '.png" onerror="this.src=\'../imgs/synchrony-financial-logo-dlpx_1.png\';" class = "device">' + deviceArray[i].name + '</div><div class = "deviceDescp"><p>' + deviceArray[i].description + '</p><button class = "requestbutton" id = "button' + (deviceArray[i].id) + '" type="button">Order device</button></div></div><br><br>'
}
if(html.localeCompare("")==0)
Expand All @@ -93,8 +83,6 @@ function show(deviceArray){
requestbuttons[i].addEventListener('click',addToCart);
}
}
function filter(deviceArray) {
var filteredArray = new Array();
var activeHOptions = [];
Expand Down Expand Up @@ -158,7 +146,6 @@ function filter(deviceArray) {
}
return filteredArray;
}
function fuzzyFilter(deviceArray) {
var searchText = document.getElementsByName('searchBar')[0].value;
var options = {
Expand All @@ -184,15 +171,14 @@ function fuzzyFilter(deviceArray) {
manufacturer:fuzzyResults[i].original.manufacturer,
};
}
return results;
}
function addToCart(){
var id = this.getAttribute('id');
id = parseInt(id.replace(/[^0-9\.]/g,''),10); //this gets just the numerical value from the id!
id = id.replace(/[^0-9\.]/g,'');
if(!inCart(id)){ //if not in the cart
var cart = getCartItems(); //this is an array
id = parseInt(id,10); //this gets just the numerical value from the id!
cart.push(devices[id - 1]); //push to bottom of cart
localStorage.setItem('cart', JSON.stringify(cart));
$('#added').fadeIn(1000);
Expand All @@ -205,32 +191,29 @@ function addToCart(){
$('#already').fadeOut(1000);
}
}
function inCart(id){
var cart = getCartItems();
if(cart.length == 0) //if nothing's in the cart
return 0;
else{ //something is in the cart
for(var i = 0; i < cart.length; i++){
if(cart[i] === id)
if(id.localeCompare(cart[i].id) == 0)
return 1;
}
}
return 0;
}
function getCartItems(){
//initiate array for them
var cart = new Array;
//get them from local storage
//get them from local age
var cart_str = localStorage.getItem('cart');
//if there is at least one object already we need to convert it from JSON to string
if (cart_str !== null && cart_str !== "") {
cart = JSON.parse(cart_str);
}
return cart;
}
function makeDeviceArray(){
window.json = '<%=deviceString%>';
return JSON.parse(window.json);
Expand Down
Loading

0 comments on commit f93a61c

Please sign in to comment.