visits added to site page
This commit is contained in:
parent
e69a1e03f8
commit
571a65986c
@ -18,8 +18,11 @@ module.exports = {
|
||||
// if(err) throw err;
|
||||
if(err) res.render('index', { title: 'Site is not found!'});
|
||||
else {
|
||||
Visit.findBySite(site.id, function(err, visits){
|
||||
if(err) res.render('index', { title: 'Site:Visits has caused an error!'});
|
||||
console.log("Site->Controller: findBySlug queried: " + site.site);
|
||||
res.render('site', { title: site.site, site: site });
|
||||
res.render('site', { title: site.site, site: site, visits: visits });
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -21,7 +21,7 @@ con.connect(function(err) {
|
||||
});
|
||||
|
||||
con.query("CREATE TABLE sites(\
|
||||
id int NOT NULL AUTO_INCREMENT,\
|
||||
id int NOT NULL UNIQUE,\
|
||||
category varchar(255),\
|
||||
in_danger bool,\
|
||||
date_inscribed int,\
|
||||
|
@ -10,6 +10,9 @@ var arr = [];
|
||||
|
||||
val.query.row.forEach(function(site){
|
||||
var s = [];
|
||||
// Changed ID to the UNESCO unique number.
|
||||
// This is done in order to associate a visit to a site.
|
||||
s.push(site.unique_number);
|
||||
s.push(site.category);
|
||||
s.push(site.danger != '' || false);
|
||||
s.push(site.date_inscribed);
|
||||
@ -38,7 +41,7 @@ con.connect(function(err) {
|
||||
if (err) throw err;
|
||||
console.log("Connected!");
|
||||
|
||||
sql = "INSERT INTO sites (category, in_danger, date_inscribed, unesco_url, latitude, longitude, description, site, unesco_unique, img_url, states, slug) VALUES ?";
|
||||
sql = "INSERT INTO sites (id, category, in_danger, date_inscribed, unesco_url, latitude, longitude, description, site, unesco_unique, img_url, states, slug) VALUES ?";
|
||||
|
||||
con.query(sql, [arr], function(err, res){
|
||||
if (err) throw err;
|
||||
|
@ -2,14 +2,14 @@ var con = require('./db');
|
||||
|
||||
sql = "INSERT INTO visits (date, img, site_id) VALUES ?";
|
||||
val = [
|
||||
['10-15-2019','https://seanland.ca', '1'],
|
||||
['10-17-2019','https://seanland.ca', '1'],
|
||||
['01-17-2020','https://seanland.ca', '134'],
|
||||
['11-23-2019','https://seanland.ca', '15']
|
||||
['10-15-2019','https://seanland.ca', '203'],
|
||||
['10-17-2019','https://seanland.ca', '169'],
|
||||
['01-17-2020','https://seanland.ca', '520'],
|
||||
['11-23-2019','https://seanland.ca', '520']
|
||||
];
|
||||
|
||||
con.query(sql, [val], function(err, res){
|
||||
if (err) throw err;
|
||||
console.log("visits" + ": records inserted: " + res.affectedRows);
|
||||
console.log("visit records inserted: " + res.affectedRows);
|
||||
process.exit();
|
||||
});
|
||||
|
@ -1,7 +1,7 @@
|
||||
extends layout
|
||||
|
||||
block content
|
||||
h1= title
|
||||
h1(id='title')= title
|
||||
|
||||
h2= "Sites Visited: "
|
||||
a(href="/visits") #{visits.length}
|
||||
@ -13,7 +13,7 @@ block content
|
||||
h2= "Visits"
|
||||
each visit in visits
|
||||
- sitesVisited.push(visit.id);
|
||||
h3= visit.site
|
||||
h3 #[a(href="/sites/" + visit.slug) #{visit.site}]
|
||||
//- Commmand list of all the states
|
||||
h5
|
||||
- var states = visit.states.split(',')
|
||||
@ -25,7 +25,7 @@ block content
|
||||
h2= "Remaining"
|
||||
each site in sites
|
||||
if !(sitesVisited.includes(site.id))
|
||||
h3= site.site
|
||||
h3 #[a(href="/sites/" + site.slug) #{site.site}]
|
||||
//- Commmand list of all the states
|
||||
h5
|
||||
- var states = site.states.split(',')
|
||||
|
@ -9,4 +9,16 @@ block content
|
||||
h5= site.category
|
||||
.content
|
||||
p #{site.description}
|
||||
|
||||
//- - var states = visit.states.split(',')
|
||||
//- - for (var i = 0; i < states.length; i++)
|
||||
//- | #{states[i]}
|
||||
//- if (i + 1 < states.length)
|
||||
//- | ,
|
||||
|
||||
if visits
|
||||
each visit in visits
|
||||
p #{visit.date}: #{visit.img} at the site: #{visit.site_id}
|
||||
|
||||
|
||||
include footer.pug
|
||||
|
Reference in New Issue
Block a user