From 96a533009ea7f66544a3ffa02cce5e41f1956393 Mon Sep 17 00:00:00 2001 From: Aaron Altounian Date: Thu, 11 Apr 2019 18:50:02 -0500 Subject: [PATCH 01/23] initial commit, display products, handle click for details of product --- public/index.html | 19 +++++++++++++++++-- public/index.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ public/products.js | 1 + public/style.css | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 public/style.css diff --git a/public/index.html b/public/index.html index 138da963..a178c150 100644 --- a/public/index.html +++ b/public/index.html @@ -5,10 +5,25 @@ My Store - + - +
+ Home + +

Awesome Store

+
+ + + +
+ +
+ + \ No newline at end of file diff --git a/public/index.js b/public/index.js index e69de29b..28a8ece1 100644 --- a/public/index.js +++ b/public/index.js @@ -0,0 +1,46 @@ +'use strict' +console.log(products); + +// variables to store the divs used to display information: +const list = document.getElementById('list'); +const item = document.getElementById('itemContainer'); +const results = document.getElementById('searchResults'); + +// function to reset the divs on click event: +const resetDivs = () => { + list.innerHTML = ''; + item.innerHTML = ''; + searchResults.innerHTML = ''; +} + +// function to display all products on page load or when 'home' link is clicked: +const displayProducts = () => { + resetDivs(); + products.map( (value, index) => { + list.innerHTML += `
  • ${value.name}
  • ` + }) +} + +displayProducts(); + +// function to display details about a product when clicked: +const focusProduct = (index) => { + resetDivs(); + item.innerHTML = products[index].name; +} + + + +let searchBox = document.getElementById('searchBox'); +let searchButton = document.getElementById('searchButton'); + +searchButton.onclick = function() { + let regex = new RegExp(searchBox.value); + if( searchBox.value.length === 0 ) alert('You must type in something to search!'); + console.log(regex); + for( let product of products ) { + if( product.name.match(regex) ) { + console.log('works'); + } + } +} \ No newline at end of file diff --git a/public/products.js b/public/products.js index 4f07bb51..5562cdbf 100644 --- a/public/products.js +++ b/public/products.js @@ -219,3 +219,4 @@ const products = [{ } ] }]; + diff --git a/public/style.css b/public/style.css new file mode 100644 index 00000000..230f97f7 --- /dev/null +++ b/public/style.css @@ -0,0 +1,38 @@ +body { + font-family: Georgia, 'Times New Roman', Times, serif +} + +header { + position: static; + top: 0; + height: 40px; + background-color: #e6e6e6; + border-bottom: 2px solid black; + display: flex; + align-items: center; + justify-content: space-between; + padding: 0 20px; +} + +li { + margin: 10px 0 0 0; + list-style-type: none; +} + +a, button { + cursor: pointer; +} + +a:hover { + color: blue; +} + +input { + width: 400px; +} + +.product { + width: 600px; + margin: auto; + border: 1px solid red; +} \ No newline at end of file From 105aa7289c2536b1a5f7b53c91c20d4632cb6e21 Mon Sep 17 00:00:00 2001 From: Aaron Altounian Date: Thu, 11 Apr 2019 19:35:25 -0500 Subject: [PATCH 02/23] did some minor stuff --- public/index.html | 2 +- public/index.js | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/public/index.html b/public/index.html index a178c150..657fd203 100644 --- a/public/index.html +++ b/public/index.html @@ -9,7 +9,7 @@
    - Home + Home
    diff --git a/public/search.js b/public/search.js index e5c299d0..9906e204 100644 --- a/public/search.js +++ b/public/search.js @@ -22,4 +22,9 @@ const search = function() { // clear the search field: // searchBox.value = ''; +} + +const clearSearch = () => { + searchBox.value = ''; + displayProducts(products); } \ No newline at end of file From 33a74e38951345a20fa7e99eaaffdcc82ca6987f Mon Sep 17 00:00:00 2001 From: Aaron Altounian Date: Tue, 16 Apr 2019 20:56:30 -0500 Subject: [PATCH 12/23] some minor changes, started to try & get addToCart working better --- public/cart.js | 9 +++++++-- public/display-products.js | 16 ++++++++++++++++ public/index.html | 1 + public/index.js | 16 ---------------- public/search.js | 6 ++++-- 5 files changed, 28 insertions(+), 20 deletions(-) create mode 100644 public/display-products.js diff --git a/public/cart.js b/public/cart.js index 9bea218b..d7457399 100644 --- a/public/cart.js +++ b/public/cart.js @@ -5,8 +5,13 @@ const updateQty = () => { } // function to add item to cart: -const addToCart = (index) => { - cart.push(products[index]) +const addToCart = (index, itemQty) => { + // let toAdd = { + // 'product': products[index], + // 'qty': itemQty; + // } + // cart.push(toAdd); + cart.push(products[index]); updateQty(); } diff --git a/public/display-products.js b/public/display-products.js new file mode 100644 index 00000000..6d5501c9 --- /dev/null +++ b/public/display-products.js @@ -0,0 +1,16 @@ +// function to display all products: +const displayProducts = (products) => { + reset(); + // map the products array and generate html for each position: + products.map( (value) => { + // instead of using index from the map function for ID's, use the '_id' property for each item minus 1. + // this returns the index of the item within the original products array, even when different arrays are passed through (e.g. a search results array) + let index = value._id - 1; + + // manipulate DOM to list out products: + list.innerHTML += `
  • + + ${value.name} +
  • ` + }) +} \ No newline at end of file diff --git a/public/index.html b/public/index.html index a342df24..1642ef67 100644 --- a/public/index.html +++ b/public/index.html @@ -44,6 +44,7 @@

    A Store

    + diff --git a/public/index.js b/public/index.js index d4b0ebd9..70fb6769 100644 --- a/public/index.js +++ b/public/index.js @@ -1,22 +1,6 @@ 'use strict' let cart = []; -// function to display all products on page load or when 'home' link is clicked: -const displayProducts = (products) => { - reset(); - // map the products array and generate html for each position: - products.map( (value) => { - // instead of using index from the map function for ID's, use the '_id' property for each item minus 1. - // this returns the index of the item within the original products array, even when different arrays are passed through (e.g. a search results array) - let index = value._id - 1; - - // manipulate DOM to list out products: - list.innerHTML += `
  • - - ${value.name} -
  • ` - }) -} displayProducts(products); updateQty(); diff --git a/public/search.js b/public/search.js index 9906e204..93af99ef 100644 --- a/public/search.js +++ b/public/search.js @@ -25,6 +25,8 @@ const search = function() { } const clearSearch = () => { - searchBox.value = ''; - displayProducts(products); + if(searchBox.value) { + searchBox.value = ''; + displayProducts(products); + } } \ No newline at end of file From f5ad9dc8802505920c940ba2d22d0bf13faaeb0a Mon Sep 17 00:00:00 2001 From: Aaron Altounian Date: Tue, 16 Apr 2019 21:03:39 -0500 Subject: [PATCH 13/23] added dropdown box for QTY in product focus --- public/focus-product.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/public/focus-product.js b/public/focus-product.js index 6835967f..07948246 100644 --- a/public/focus-product.js +++ b/public/focus-product.js @@ -10,10 +10,18 @@ const focusProduct = (index) => { imgUrl, } = products[index]; + let options; + function selectOptions() { + for(let i = 1; i <= 10; i++) { + options += `