finished
This commit is contained in:
parent
f992656570
commit
a08ef5fcb0
4 changed files with 113 additions and 29 deletions
|
@ -1,7 +1,7 @@
|
|||
|
||||
// Array of products, each product is an object with different fieldset
|
||||
// A set of ingredients should be added to products
|
||||
|
||||
var filtered = [];
|
||||
var products = [
|
||||
{
|
||||
name: "broccoli",
|
||||
|
@ -89,7 +89,7 @@ var products = [
|
|||
},
|
||||
{
|
||||
name: "cheese",
|
||||
vegetarian: false,
|
||||
vegetarian: true,
|
||||
glutenFree: false,
|
||||
organic: false,
|
||||
price: 5.14,
|
||||
|
@ -154,7 +154,6 @@ function getProductImg(productName) {
|
|||
return prodVal.productImg;
|
||||
}
|
||||
|
||||
|
||||
// given restrictions provided, make a reduced list of products
|
||||
// prices should be included in this list, as well as a sort based on price
|
||||
|
||||
|
@ -184,29 +183,36 @@ function restrictListProducts(prods, restriction) {
|
|||
}
|
||||
|
||||
function filterProduct(prod, filter) {
|
||||
|
||||
let prod_filter = [];
|
||||
for(let i=0; i < prod.length; i++) {
|
||||
if ( filter === "Fruits" && prod[i].Fruits === true ) {
|
||||
prod_filter.push(prod[i].name);
|
||||
|
||||
//filteredArray = prod.find();
|
||||
var prodVal = products.find(prod1 => prod1.name === prod[i]);
|
||||
|
||||
console.log("test", prodVal);
|
||||
|
||||
if ( filter === "Fruits" && prodVal.Fruits === true ) {
|
||||
prod_filter.push(prodVal.name);
|
||||
}
|
||||
else if ( filter === "Vegetables" && prod[i].Vegetables === true ) {
|
||||
prod_filter.push(prod[i].name);
|
||||
else if ( filter === "Vegetables" && prodVal.Vegetables === true ) {
|
||||
prod_filter.push(prodVal.name);
|
||||
}
|
||||
else if ( filter === "Pantry" && prod[i].Pantry === true ) {
|
||||
prod_filter.push(prod[i].name);
|
||||
else if ( filter === "Pantry" && prodVal.Pantry === true ) {
|
||||
prod_filter.push(prodVal.name);
|
||||
}
|
||||
else if ( filter === "Dairy" && prod[i].Dairy === true) {
|
||||
prod_filter.push(prod[i].name);
|
||||
else if ( filter === "Dairy" && prodVal.Dairy === true) {
|
||||
prod_filter.push(prodVal.name);
|
||||
}
|
||||
else if ( filter === "Meat&Seafood" && prod[i].MeatandSeafood === true) {
|
||||
prod_filter.push(prod[i].name);
|
||||
else if ( filter === "Meat&Seafood" && prodVal.MeatandSeafood === true) {
|
||||
prod_filter.push(prodVal.name);
|
||||
}
|
||||
else if ( filter === "Bakery" && prod[i].Bakery === true) {
|
||||
prod_filter.push(prod[i].name);
|
||||
else if ( filter === "Bakery" && prodVal.Bakery === true) {
|
||||
prod_filter.push(prodVal.name);
|
||||
}
|
||||
else if ( filter === "" ){
|
||||
prod_filter.push(prodVal.name);
|
||||
}
|
||||
// else if ( filter === "None" ){
|
||||
// prod_filter.push(prod[i].name);
|
||||
// }
|
||||
}
|
||||
return prod_filter;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,11 @@ function openInfo(evt, tabName) {
|
|||
// it makes each product name as the label for the checkbos
|
||||
|
||||
function populateListProductChoices(slct1, slct2) {
|
||||
|
||||
var s1 = document.getElementById(slct1);
|
||||
var s2 = document.getElementById(slct2);
|
||||
|
||||
|
||||
// s2 represents the <div> in the Products tab, which shows the product list, so we first set it empty
|
||||
s2.innerHTML = "";
|
||||
s2.appendChild(document.createElement("br"));
|
||||
|
@ -34,6 +36,10 @@ function populateListProductChoices(slct1, slct2) {
|
|||
// obtain a reduced list of products based on restrictions
|
||||
var optionArray = restrictListProducts(products, s1.value);
|
||||
|
||||
//add to the filtered array
|
||||
filtered = optionArray;
|
||||
console.log("hello", filtered);
|
||||
|
||||
// for each item in the array, create a checkbox element, each containing information such as:
|
||||
// <input type="checkbox" name="product" value="Bread">
|
||||
// <label for="Bread">Bread/label><br>
|
||||
|
@ -124,13 +130,23 @@ function filterProducts(sel1, sel2) {
|
|||
var s1 = document.getElementById(sel1)
|
||||
var s2 = document.getElementById(sel2)
|
||||
|
||||
|
||||
|
||||
// s2 represents the <div> in the Products tab, which shows the product list, so we first set it empty
|
||||
s2.innerHTML = ''
|
||||
s2.appendChild(document.createElement('br'))
|
||||
s2.appendChild(document.createElement('br'))
|
||||
|
||||
|
||||
//var restrictProd = restrictListProducts(filtered, );
|
||||
|
||||
// obtain a reduced list of products based on restrictions
|
||||
var optionArray = filterProduct(products, s1.value);
|
||||
|
||||
var optionArray = filterProduct(filtered, s1.value);
|
||||
//var optionArray = filterProduct()
|
||||
|
||||
|
||||
|
||||
|
||||
// for each item in the array, create a checkbox element, each containing information such as:
|
||||
// <input type="checkbox" name="product" value="Bread">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue