From 01a2599c7b07be671587c5a71b42f645d17c0384 Mon Sep 17 00:00:00 2001 From: Sandesh <sguru003@campus.goldsmiths.ac.uk> Date: Wed, 12 Apr 2023 02:42:41 +0100 Subject: [PATCH] fixed a bug with listing --- public/main.css | 53 ++++++++++++++++--------------------------- routes/main.js | 19 ++++++++++------ views/about.ejs | 1 + views/correct.ejs | 20 ++++++++++++++-- views/index.ejs | 3 ++- views/itemlist.ejs | 15 +++++++++++- views/itemlisted.ejs | 20 ++++++++-------- views/listingdone.ejs | 12 ++++++++++ views/login.ejs | 4 ++-- 9 files changed, 91 insertions(+), 56 deletions(-) create mode 100644 views/listingdone.ejs diff --git a/public/main.css b/public/main.css index 7f43f7d..1649886 100644 --- a/public/main.css +++ b/public/main.css @@ -141,6 +141,23 @@ p{ font-size: 15px; background-color: #89a53a; padding: 15px 40px; + +} + +#hero a:link { + text-decoration: none; +} + +#hero a:visited { + text-decoration: none; +} + +#hero a:hover { + text-decoration: none; +} + +#hero a:active { + text-decoration: none; } @@ -229,7 +246,7 @@ p{ #items .pro{ width: 13%; min-width: 250px; - padding: 0px 12px; + padding: 20px 12px; border: 1px solid #d4cadf; border-radius: 25px; cursor: pointer; @@ -249,7 +266,7 @@ p{ } -#items .pro .des{ +#items .pro.des{ text-align: start; padding: 10px 0; } @@ -260,38 +277,6 @@ p{ } -#items .pro2{ - width: 13%; - min-width: 250px; - padding: 0px 12px; - border: 1px solid #d4cadf; - border-radius: 25px; - cursor: pointer; - box-shadow: 20px 20px 30px rgb(0, 0,0,0.02 ); - transition: 0.2s ease; - position: relative; -} - -#items .pro:hover{ - box-shadow: 20px 20px 30px rgb(0, 0,0,0.06 ); - -} - -#items .pro .listing{ - width: 100%; - border-radius: 20px; - -} - -#items .pro .des{ - text-align: start; - padding: 10px 0; -} - -#items .pro.des.spam{ - color: #606063; - font-size: 12px; -} diff --git a/routes/main.js b/routes/main.js index 2dc3a31..7c6869e 100644 --- a/routes/main.js +++ b/routes/main.js @@ -39,6 +39,10 @@ module.exports = function(app, shopData) { res.render('itemlist.ejs', shopData) }); + app.get('/listingdone',function(req,res){ + res.render('/listingdone.ejs', shopData) + }); + app.get('/search-result',[check('name').isEmpty()],function (req, res) { @@ -54,7 +58,7 @@ module.exports = function(app, shopData) { if (err) { res.redirect('./'); } - let newData = Object.assign({}, shopData, {availableItem:result}); + let newData = Object.assign({}, shopData, {listingAdded:result}); console.log(newData) res.render("itemlisted.ejs", newData) }); @@ -72,30 +76,31 @@ module.exports = function(app, shopData) { username = req.session.userId; image =req.file.buffer.toString("base64"); - let sqlquery ="INSERT INTO items (title,name,price,info,condi,img,username) VALUES(?,?,?,?,?,?,?)"; + let sqlquery ="INSERT INTO items(title,name,price,info,condi,img,username) VALUES(?,?,?,?,?,?,?)"; let newListing = [req.sanitize(title),req.sanitize(product), req.sanitize(price),req.sanitize(info), - req.sanitize(condition),req.sanitize(image),username] + req.sanitize(condition),image,username] db.query(sqlquery, newListing,(err, result) => { if (err){ return console.error(err.message); } else{ - let newData = Object.assign({}, shopData, {listingAdded: result}); - res.render("itemlisted.ejs", newData) + + let newData = Object.assign({}, shopData, {listingAdded: newListing}); + res.render("listingdone.ejs", newData) } }); - }); app.get('/itemlisted',function(req,res){ + let sqlquery = "SELECT * FROM items"; // query database to get all the books // execute sql query - db.query(sqlquery, (err, result) => { + db.query(sqlquery,(err, result) => { if (err) { res.redirect('./'); } diff --git a/views/about.ejs b/views/about.ejs index eaa9f60..aace69b 100644 --- a/views/about.ejs +++ b/views/about.ejs @@ -12,6 +12,7 @@ <div> <ul id="navbar"> <li><a href="about">About </a></li> + <li><a href="itemlisted">Explore</a></li> <li><a href="search">Search </a></li> <li><a href="itemlist">List </a></li> <li><a href="register">Register </a></li> diff --git a/views/correct.ejs b/views/correct.ejs index 6cd81cf..170309c 100644 --- a/views/correct.ejs +++ b/views/correct.ejs @@ -6,8 +6,24 @@ <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css"/> </head> <body> + <section id = "header"> + <a href="/."> <img src = "/public/logo.png" class ="logo" alt = ""> </a> + <div> + <ul id="navbar"> + <li><a href="about">About </a></li> + <li><a href="/itemlisted">Explore</a></li> + <li><a href="search">Search </a></li> + <li><a href="itemlist">List </a></li> + <li><a href="register">Register </a></li> + <li><a href="login">Login</a></li> + <li><a href="logout">Logout</a></li> + </ul> + </div> + </section> + + <h1> <%=shopName%></h1> - <p>Correct Password</p> - <p><a href="/">Home Page</a></p> + <h3>Correct Password</h3> + <h3><a href="/">Home Page</a></h3> </body> </html> \ No newline at end of file diff --git a/views/index.ejs b/views/index.ejs index 6c901b7..6cd5521 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -12,6 +12,7 @@ <div> <ul id="navbar"> <li><a href="about">About </a></li> + <li><a href="/itemlisted">Explore</a></li> <li><a href="search">Search </a></li> <li><a href="itemlist">List </a></li> <li><a href="register">Register </a></li> @@ -30,7 +31,7 @@ <p> For a more sustainable future</p> - <button> Explore now</button> + <a href="/itemlisted" class="a"><button> Explore now</button></a> </section> diff --git a/views/itemlist.ejs b/views/itemlist.ejs index 3ecb1c4..2a2b611 100644 --- a/views/itemlist.ejs +++ b/views/itemlist.ejs @@ -5,10 +5,23 @@ <link rel="stylesheet" type="text/css" href="main.css" /> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css"/> </head> + <section id = "header"> + <a href="/."> <img src = "/public/logo.png" class ="logo" alt = ""> </a> + <div> + <ul id="navbar"> + <li><a href="about">About </a></li> + <li><a href="itemlisted">Explore</a></li> + <li><a href="search">Search </a></li> + <li><a href="itemlist">List </a></li> + <li><a href="logout">Logout</a></li> + </ul> + </div> +</section> + <body> <h1>List on <%=shopName%></h1> - <form method ="POST" enctype="multipart/form-data" action = "photoDB"> + <form method ="POST" enctype="multipart/form-data" action = "/photoDB"> <input type = "text" placeholder="Title of product" name = "title"> <input type = "text" placeholder="Name of product" name = "name"> <input type = "text" placeholder="Cost of shipping" name = "price"> diff --git a/views/itemlisted.ejs b/views/itemlisted.ejs index 7334486..1c4817f 100644 --- a/views/itemlisted.ejs +++ b/views/itemlisted.ejs @@ -12,6 +12,7 @@ <div> <ul id="navbar"> <li><a href="about">About </a></li> + <li><a href="itemlisted">Explore</a></li> <li><a href="search">Search </a></li> <li><a href="itemlist">List </a></li> <li><a href="logout">Logout</a></li> @@ -19,21 +20,21 @@ </div> </section> - <section id = "items" class="section-p2"> - <%listingAdded.forEach(function(list){%> + <section id = "items"> + <% listingAdded.forEach(function(list){%> <div class = "pro-container"> <div class = "pro"> - <img alt=" Embedded Image" src = "data:image/png;base64,<%=list.img%>" class="listing"> + <img alt= "Embedded Image" src = "data:image/png;base64,<%=list.img%>" class="listing"> <div class = "des"> - <span><%=list.username%></span> - <h5><%=list.title%></h5> - <h5><%=list.condi%></h5> - <h4><%=list.price%></h4> + <span>Listed by: <%=list.username%></span> + <h5> <%=list.title%> </h5> + <h5> Condition of item: <%=list.condi%></h5> + <h4> Shipping: £ <%=list.price%></h4> </div> <a href="#"> <i class="fa-sharp fa-solid fa-cart-shopping fa-beat"></i></i></i></a> + </div> </div> - </div> - <% })%> + <%})%> </section> @@ -49,6 +50,7 @@ + </body> diff --git a/views/listingdone.ejs b/views/listingdone.ejs new file mode 100644 index 0000000..f8371d9 --- /dev/null +++ b/views/listingdone.ejs @@ -0,0 +1,12 @@ +<!doctype html> +<html lang="en"> + <head> + <title> You have added a new listing on <%=shopName%></title> + <!-- Linking my CSS --> + <link rel="stylesheet" type="text/css" href="main.css" /> + </head> + <body> + <h1>You have successfully added a new listing on <%=shopName%></h1> + </body> + <p><a href="/">home page</a></p> +</html> \ No newline at end of file diff --git a/views/login.ejs b/views/login.ejs index 194aa64..b850d2a 100644 --- a/views/login.ejs +++ b/views/login.ejs @@ -21,8 +21,8 @@ <h2>Login for <%=shopName%></h2> <form method="POST" action="/loggedin"> - <p>Username: <input id="username" type="username" name="username" value="" /></p> - <p>Password: <input id="password" type="password" name="password" value="" /></p> + <h3>Username: <input id="username" type="username" name="username" value="" /></h3> + <h4>Password: <input id="password" type="password" name="password" value="" /></h4> <input type="submit" value="login" /> </form> -- GitLab