mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2025-09-10 08:27:20 +00:00
@@ -1,18 +1,18 @@
|
||||
// ReviewCard.js
|
||||
|
||||
class ReviewCard extends HTMLElement {
|
||||
// Called once when document.createElement('review-card') is called, or
|
||||
// the element is written into the DOM directly as <review-card>
|
||||
constructor() {
|
||||
super();
|
||||
// Called once when document.createElement('review-card') is called, or
|
||||
// the element is written into the DOM directly as <review-card>
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
|
||||
let shadowEl = this.attachShadow({mode:'open'});
|
||||
let shadowEl = this.attachShadow({mode:"open"});
|
||||
|
||||
let articleEl = document.createElement('article');
|
||||
let articleEl = document.createElement("article");
|
||||
|
||||
let styleEl = document.createElement('style');
|
||||
styleEl.textContent = `
|
||||
let styleEl = document.createElement("style");
|
||||
styleEl.textContent = `
|
||||
* {
|
||||
font-family: sans-serif;
|
||||
margin: 0;
|
||||
@@ -82,17 +82,17 @@ class ReviewCard extends HTMLElement {
|
||||
font-size: 12px;
|
||||
}
|
||||
`;
|
||||
articleEl.append(styleEl);
|
||||
shadowEl.append(articleEl);
|
||||
this.shadowEl = shadowEl;
|
||||
//attach event listener to each recipe-card
|
||||
this.addEventListener('click', (event) => {
|
||||
console.log(event.target);
|
||||
console.log(event.target.data);
|
||||
//Option 1: sending current data to second html page using localStorage (could also just store index)
|
||||
sessionStorage.setItem('current', JSON.stringify(event.target.data));
|
||||
window.location.assign("./ReviewDetails.html");
|
||||
/*
|
||||
articleEl.append(styleEl);
|
||||
shadowEl.append(articleEl);
|
||||
this.shadowEl = shadowEl;
|
||||
//attach event listener to each recipe-card
|
||||
this.addEventListener("click", (event) => {
|
||||
console.log(event.target);
|
||||
console.log(event.target.data);
|
||||
//Option 1: sending current data to second html page using localStorage (could also just store index)
|
||||
sessionStorage.setItem("current", JSON.stringify(event.target.data));
|
||||
window.location.assign("./ReviewDetails.html");
|
||||
/*
|
||||
//Option 2: sending current data to second html page using string query w/ url (currently not storing value)
|
||||
let reviewFields = window.location.search.slice(1).split("&");
|
||||
for(let i = 0; i < reviewFields.length; i++) {
|
||||
@@ -103,10 +103,10 @@ class ReviewCard extends HTMLElement {
|
||||
console.log(value);
|
||||
// What you want to do with name and value...
|
||||
}*/
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Called when the .data property is set on this element.
|
||||
*
|
||||
* For Example:
|
||||
@@ -125,29 +125,29 @@ class ReviewCard extends HTMLElement {
|
||||
* "tags": string array
|
||||
* }
|
||||
*/
|
||||
set data(data) {
|
||||
// If nothing was passed in, return
|
||||
if (!data) return;
|
||||
set data(data) {
|
||||
// If nothing was passed in, return
|
||||
if (!data) return;
|
||||
|
||||
// Select the <article> we added to the Shadow DOM in the constructor
|
||||
let articleEl = this.shadowEl.querySelector('article');
|
||||
// Select the <article> we added to the Shadow DOM in the constructor
|
||||
let articleEl = this.shadowEl.querySelector("article");
|
||||
|
||||
// setting the article elements for the review card
|
||||
// setting the article elements for the review card
|
||||
|
||||
//image setup
|
||||
let mealImg = document.createElement('img');
|
||||
mealImg.setAttribute('id', 'a-mealImg');
|
||||
mealImg.setAttribute('src',data['mealImg']);
|
||||
mealImg.setAttribute('alt',data['imgAlt']);
|
||||
//image setup
|
||||
let mealImg = document.createElement("img");
|
||||
mealImg.setAttribute("id", "a-mealImg");
|
||||
mealImg.setAttribute("src",data["mealImg"]);
|
||||
mealImg.setAttribute("alt",data["imgAlt"]);
|
||||
|
||||
//meal name setup
|
||||
let mealLabel = document.createElement('label');
|
||||
mealLabel.setAttribute('id', 'a-mealName');
|
||||
mealLabel.setAttribute('class','meal-name');
|
||||
mealLabel.innerHTML = data['mealName'];
|
||||
//meal name setup
|
||||
let mealLabel = document.createElement("label");
|
||||
mealLabel.setAttribute("id", "a-mealName");
|
||||
mealLabel.setAttribute("class","meal-name");
|
||||
mealLabel.innerHTML = data["mealName"];
|
||||
|
||||
//restaurant name setup
|
||||
/*
|
||||
//restaurant name setup
|
||||
/*
|
||||
//review page link
|
||||
//giving it functionality to save the review card's info to session storage for loading the review page
|
||||
let reviewLink = document.createElement('a');
|
||||
@@ -167,53 +167,53 @@ class ReviewCard extends HTMLElement {
|
||||
sessionStorage.setItem('currReview', JSON.stringify(currReview));
|
||||
});
|
||||
*/
|
||||
let restaurantLabel = document.createElement('label');
|
||||
restaurantLabel.setAttribute('id', 'a-restaurant');
|
||||
restaurantLabel.setAttribute('class','restaurant-name');
|
||||
restaurantLabel.innerHTML = data['restaurant'];
|
||||
let restaurantLabel = document.createElement("label");
|
||||
restaurantLabel.setAttribute("id", "a-restaurant");
|
||||
restaurantLabel.setAttribute("class","restaurant-name");
|
||||
restaurantLabel.innerHTML = data["restaurant"];
|
||||
|
||||
//comment section setup (display set to none)
|
||||
let comments = document.createElement('p');
|
||||
comments.setAttribute('id', 'a-comments');
|
||||
comments.style.display = 'none';
|
||||
comments.innerText = data['comments'];
|
||||
//comment section setup (display set to none)
|
||||
let comments = document.createElement("p");
|
||||
comments.setAttribute("id", "a-comments");
|
||||
comments.style.display = "none";
|
||||
comments.innerText = data["comments"];
|
||||
|
||||
//other info: rating
|
||||
let ratingDiv = document.createElement('div');
|
||||
ratingDiv.setAttribute('class', 'rating');
|
||||
let starsImg = document.createElement('img');
|
||||
starsImg.setAttribute('id', 'a-rating');
|
||||
starsImg.setAttribute('src', './source/assets/images/icons/'+data['rating']+'-star.svg');
|
||||
starsImg.setAttribute('alt', data['rating'] +' stars');
|
||||
starsImg.setAttribute('num', data['rating']);
|
||||
ratingDiv.append(starsImg);
|
||||
//other info: rating
|
||||
let ratingDiv = document.createElement("div");
|
||||
ratingDiv.setAttribute("class", "rating");
|
||||
let starsImg = document.createElement("img");
|
||||
starsImg.setAttribute("id", "a-rating");
|
||||
starsImg.setAttribute("src", "./source/assets/images/icons/"+data["rating"]+"-star.svg");
|
||||
starsImg.setAttribute("alt", data["rating"] +" stars");
|
||||
starsImg.setAttribute("num", data["rating"]);
|
||||
ratingDiv.append(starsImg);
|
||||
|
||||
//added tags
|
||||
let tagContainer = document.createElement('div');
|
||||
tagContainer.setAttribute('class', 'tag-container');
|
||||
tagContainer.setAttribute('id', 'a-tags');
|
||||
tagContainer.setAttribute('list', data['tags']);
|
||||
if(data['tags']){
|
||||
for (let i = 0; i < data['tags'].length; i++) {
|
||||
let newTag = document.createElement('label');
|
||||
newTag.setAttribute('class','tag');
|
||||
newTag.innerHTML = data['tags'][i] + " ";
|
||||
tagContainer.append(newTag);
|
||||
}
|
||||
}
|
||||
//added tags
|
||||
let tagContainer = document.createElement("div");
|
||||
tagContainer.setAttribute("class", "tag-container");
|
||||
tagContainer.setAttribute("id", "a-tags");
|
||||
tagContainer.setAttribute("list", data["tags"]);
|
||||
if(data["tags"]){
|
||||
for (let i = 0; i < data["tags"].length; i++) {
|
||||
let newTag = document.createElement("label");
|
||||
newTag.setAttribute("class","tag");
|
||||
newTag.innerHTML = data["tags"][i] + " ";
|
||||
tagContainer.append(newTag);
|
||||
}
|
||||
}
|
||||
|
||||
articleEl.append(mealImg);
|
||||
articleEl.append(mealLabel);
|
||||
//articleEl.append(reviewLink)
|
||||
articleEl.append(restaurantLabel);
|
||||
articleEl.append(ratingDiv);
|
||||
articleEl.append(tagContainer);
|
||||
articleEl.append(comments);
|
||||
articleEl.append(mealImg);
|
||||
articleEl.append(mealLabel);
|
||||
//articleEl.append(reviewLink)
|
||||
articleEl.append(restaurantLabel);
|
||||
articleEl.append(ratingDiv);
|
||||
articleEl.append(tagContainer);
|
||||
articleEl.append(comments);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Called when getting the .data property of this element.
|
||||
*
|
||||
* For Example:
|
||||
@@ -232,39 +232,39 @@ class ReviewCard extends HTMLElement {
|
||||
* "tags": string array
|
||||
* }
|
||||
*/
|
||||
get data() {
|
||||
get data() {
|
||||
|
||||
let dataContainer = {};
|
||||
let dataContainer = {};
|
||||
|
||||
// getting the article elements for the review card
|
||||
// getting the article elements for the review card
|
||||
|
||||
//get image
|
||||
let mealImg = this.shadowEl.getElementById('a-mealImg');
|
||||
dataContainer['mealImg'] = mealImg.getAttribute('src');
|
||||
dataContainer['imgAlt'] = mealImg.getAttribute('alt');
|
||||
//get image
|
||||
let mealImg = this.shadowEl.getElementById("a-mealImg");
|
||||
dataContainer["mealImg"] = mealImg.getAttribute("src");
|
||||
dataContainer["imgAlt"] = mealImg.getAttribute("alt");
|
||||
|
||||
//get meal name
|
||||
let mealLabel = this.shadowEl.getElementById('a-mealName');
|
||||
dataContainer['mealName'] = mealLabel.innerHTML;
|
||||
//get meal name
|
||||
let mealLabel = this.shadowEl.getElementById("a-mealName");
|
||||
dataContainer["mealName"] = mealLabel.innerHTML;
|
||||
|
||||
//get comment section
|
||||
let comments = this.shadowEl.getElementById('a-comments');
|
||||
console.log(comments);
|
||||
dataContainer['comments'] = comments.innerText;
|
||||
//get comment section
|
||||
let comments = this.shadowEl.getElementById("a-comments");
|
||||
console.log(comments);
|
||||
dataContainer["comments"] = comments.innerText;
|
||||
|
||||
//get other info: rating
|
||||
let starsImg = this.shadowEl.getElementById('a-rating');
|
||||
dataContainer['rating'] = starsImg.getAttribute('num');
|
||||
//get other info: rating
|
||||
let starsImg = this.shadowEl.getElementById("a-rating");
|
||||
dataContainer["rating"] = starsImg.getAttribute("num");
|
||||
|
||||
//get restaurant name
|
||||
let restaurantLabel = this.shadowEl.getElementById('a-restaurant');
|
||||
dataContainer['restaurant'] = restaurantLabel.innerHTML;
|
||||
//get restaurant name
|
||||
let restaurantLabel = this.shadowEl.getElementById("a-restaurant");
|
||||
dataContainer["restaurant"] = restaurantLabel.innerHTML;
|
||||
|
||||
//get tags
|
||||
let tagContainer = this.shadowEl.getElementById('a-tags');
|
||||
dataContainer['tags'] = tagContainer.getAttribute('list').split(",");
|
||||
//get tags
|
||||
let tagContainer = this.shadowEl.getElementById("a-tags");
|
||||
dataContainer["tags"] = tagContainer.getAttribute("list").split(",");
|
||||
|
||||
return dataContainer;
|
||||
}
|
||||
return dataContainer;
|
||||
}
|
||||
}
|
||||
customElements.define('review-card', ReviewCard);
|
||||
customElements.define("review-card", ReviewCard);
|
||||
|
Reference in New Issue
Block a user