diff --git a/functions/views/404.ejs b/functions/views/404.ejs index 5b13ff1..30390a8 100644 --- a/functions/views/404.ejs +++ b/functions/views/404.ejs @@ -51,7 +51,7 @@
- img + img Extras diff --git a/functions/views/css/style.css b/functions/views/css/style.css index 00d2e39..552220e 100644 --- a/functions/views/css/style.css +++ b/functions/views/css/style.css @@ -215,7 +215,8 @@ footer a { height: 35px; float: left; padding-left: 7%; - padding-right: 20px; + margin-right: 20px; + cursor: pointer; /*left: 5%;*/ } diff --git a/functions/views/js/fdb.js b/functions/views/js/fdb.js index 35a7d17..be99920 100644 --- a/functions/views/js/fdb.js +++ b/functions/views/js/fdb.js @@ -320,6 +320,10 @@ function addShippingAddress(){ }) } +function search(keywords){ + window.location.replace('search?search='+keywords) +} + try { var addressField = document.getElementById("shippingaddressinput") @@ -337,4 +341,21 @@ try { } }) } +catch(error) {console.log(error)} + + +try { + var searchField = document.getElementById("sfield") + searchField.addEventListener("keyup", function(event) { + if (event.keyCode === 13) { + event.preventDefault() + if (searchField.value == ""){ + searchField.blur() + } + else { + search(searchField.value) + } + } + }) +} catch(error) {console.log(error)} \ No newline at end of file diff --git a/functions/views/my-product.ejs b/functions/views/my-product.ejs index 3bd0ef1..51ae691 100644 --- a/functions/views/my-product.ejs +++ b/functions/views/my-product.ejs @@ -51,7 +51,7 @@
- img + img Extras diff --git a/functions/views/my-products.ejs b/functions/views/my-products.ejs index c094291..b235fff 100644 --- a/functions/views/my-products.ejs +++ b/functions/views/my-products.ejs @@ -52,7 +52,7 @@
- img + img Extras diff --git a/functions/views/product.ejs b/functions/views/product.ejs index 3219c0b..5817704 100644 --- a/functions/views/product.ejs +++ b/functions/views/product.ejs @@ -51,7 +51,7 @@
- img + img Extras diff --git a/functions/views/search.ejs b/functions/views/search.ejs new file mode 100644 index 0000000..3ee9837 --- /dev/null +++ b/functions/views/search.ejs @@ -0,0 +1,109 @@ + + + + + + + GG Prototype + + + + + + + + + + + + + + +
+
+ + + +
+ img + + + Extras +
+ +
+ +
+

Search results:

+
+ <% var keys = Object.keys(products) %> + <% keys.forEach(function(key){ %> +
+ ')} title="<%= products[key].img %>" alt="img" src="media/var.png"> +
+

<%= products[key].name%>

+

+

+

Β£ <%= products[key].price%>

+
+
+ <% }) %> + +
+
+ + +
+
+ +
+ + + + + + \ No newline at end of file diff --git a/server.js b/server.js index d148787..a1f6f29 100644 --- a/server.js +++ b/server.js @@ -47,10 +47,51 @@ function homePage(request, responce) { if (request.query.itemAdded == "true") { x = 'block' } + console.log(data) responce.render('home.ejs', {products: data, message: x}) }) } +app.get('/search', function(request, responce){ + var dbRef = database.ref("/products") + if (request.query.search) { + let sQuery = request.query.search.toLowerCase() + dbRef.orderByChild("status").equalTo("on-sale").once('value', function(snapshot){ + var data = { + 'x': {desc: '',holder: '',id: 999,img: '',location: '',name: 'Nothing found 😒',owner: '',price: '',public: '',stock: ''}, + } + if (snapshot.val()) { + data = snapshot.val() + var sResults = [{desc: '',holder: '',id: 999,img: '',location: '',name: 'Nothing found 😒',owner: '',price: '',public: '',stock: ''}] + + var keys = Object.keys(data) + + keys.forEach(key => { + if (data[key].name.toLowerCase().includes(sQuery) || data[key].desc.toLowerCase().includes(sQuery)) { + sResults[key] = data[key] + console.log(sResults) + } + }) + if (Object.keys(sResults).length > 1) { + delete sResults[0] + } + console.log(sResults) + responce.render('search.ejs', {products: sResults}) + } + else {responce.render('search.ejs', {products: data})} + }) + } + else { + dbRef.orderByChild("status").equalTo("on-sale").once('value', function(snapshot){ + var data = { + 'x': {desc: '',holder: '',id: 999,img: '',location: '',name: 'Nothing found 😒',owner: '',price: '',public: '',stock: ''}, + } + if (snapshot.val()) {data = snapshot.val()} + responce.render('search.ejs', {products: data}) + }) + } +}) + app.get('/additmpage', function(request, responce){ responce.render('add-item.ejs') })