diff options
| author | Kumar Damani <damani.kumar@gmail.com> | 2019-03-04 23:44:03 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-03-04 23:44:03 +0000 |
| commit | 4c0c485c37eaa5dda07c31947d4d11e18448f943 (patch) | |
| tree | e4691429ed02491fba13de2a1e5b5102b19ccd77 | |
| parent | 76214c83dc52d4dca6e5043fe374da57a54f9738 (diff) | |
| parent | 5dd172866ff87842db07e563b3cb77cc3c2577a8 (diff) | |
Merge pull request #20 from csc301-winter-2019/feat7-qa-merging
Feat7 qa merging
| -rw-r--r-- | web/app.js | 24 | ||||
| -rw-r--r-- | web/models/mockpoints.js | 32 | ||||
| -rw-r--r-- | web/models/points.js | 32 | ||||
| -rw-r--r-- | web/public/javascripts/map.js | 16 | ||||
| -rw-r--r-- | web/routes/index.js | 34 | ||||
| -rw-r--r-- | web/views/map.pug | 16 |
6 files changed, 104 insertions, 50 deletions
@@ -23,24 +23,24 @@ app.use(express.static(path.join(__dirname, 'public'))); var env = process.env.NODE_ENV || 'development'; var uri; if (env === 'development') { - uri = 'mongodb://localhost:27017/helpthehome' - // use for small testing only if really necessary - // uri = 'mongodb+srv://development:dreamteam@cluster0-krnr4.mongodb.net/helpthehome?retryWrites=true' + uri = 'mongodb://localhost:27017/helpthehome' + // use for small testing only if really necessary + // uri = 'mongodb+srv://development:dreamteam@cluster0-krnr4.mongodb.net/helpthehome?retryWrites=true' } else if (env === 'qa') { - uri = process.env.MONGODB_URI + uri = process.env.MONGODB_URI } else if (env === 'production') { - uri = '' + uri = '' } // Mongoose connection to MongoDB mongoose.connect(uri, { useNewUrlParser: true }, function (error) { - if (error) { - console.log(error); - console.log("App was not able to connect to the mongo server!"); - console.log("... double check that the mongo server is running locally"); - } else { - console.log(`connected to ${uri}`); - } + if (error) { + console.log(error); + console.log("App was not able to connect to the mongo server!"); + console.log("... double check that the mongo server is running locally"); + } else { + console.log(`connected to ${uri}`); + } }); app.use('/', indexRouter); diff --git a/web/models/mockpoints.js b/web/models/mockpoints.js new file mode 100644 index 0000000..ff5e771 --- /dev/null +++ b/web/models/mockpoints.js @@ -0,0 +1,32 @@ +var mongoose = require('mongoose'); + +// Mongoose Schema definition +var Schema = mongoose.Schema; +var dumbJsonSchema = new Schema({ + type: String, + coordinates: Array, + ageRange: String, + clothingDescription: String, + isInjured: Boolean, + reasonForHelp: String +}); + +// Mongoose Model definition +var dumbJson = mongoose.model('dumbJstring', dumbJsonSchema, 'dumbpointscollection'); + +// this function gets ALL the points from the db +// returns the entire document without modifications +exports.get_points = function(callback) { + dumbJson.find({}).exec(function(err, docs) { + if (err) callback(err, null); + callback(null, docs); + }); +} + +// this function stores A user report into the db +exports.save_request = function(data, callback) { + dumbJson.create(data, function(err, result) { + if (err) callback(err, null); + callback(null, result); + }); +} diff --git a/web/models/points.js b/web/models/points.js new file mode 100644 index 0000000..3a07c82 --- /dev/null +++ b/web/models/points.js @@ -0,0 +1,32 @@ +var mongoose = require('mongoose'); + +// Mongoose Schema definition +var Schema = mongoose.Schema; +var JsonSchema = new Schema({ + type: String, + coordinates: Array, + ageRange: String, + clothingDescription: String, + isInjured: Boolean, + reasonForHelp: String +}); + +// Mongoose Model definition +var Json = mongoose.model('Jstring', JsonSchema, 'pointscollection'); + +// this function gets ALL the points from the db +// returns the entire document without modifications +exports.get_points = function(callback) { + Json.find({}).exec(function(err, docs) { + if (err) callback(err, null); + callback(null, docs); + }); +} + +// this function stores A user report into the db +exports.save_request = function(data, callback) { + Json.create(data, function(err, result) { + if (err) callback(err, null); + callback(null, result); + }); +} diff --git a/web/public/javascripts/map.js b/web/public/javascripts/map.js index 5e5a303..190307d 100644 --- a/web/public/javascripts/map.js +++ b/web/public/javascripts/map.js @@ -12,10 +12,12 @@ L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}{r} ext: 'png' }).addTo(map); -// Create point feature for somewhere downtown -var myDataPoint = L.marker([43.6529, -79.3849]).addTo(map); - -// Bind popup to Data Point object -myDataPoint.bindPopup("<h3>City Hall (not really)</h3><p>Toronto, ON<br>Information about city hall.</p>"); - -map.setZoom(13); +L.geoJson(points, { + pointToLayer: function (feature, latlng) { + //return L.circleMarker(latlng); + return L.marker(latlng); + } +}).bindPopup(function (layer) { + // layer.feature.geometry gives you access to all the fields + return "<p>" + JSON.stringify(layer.feature.geometry) + "</p>"; +}).addTo(map) diff --git a/web/routes/index.js b/web/routes/index.js index 32a5890..b2d0796 100644 --- a/web/routes/index.js +++ b/web/routes/index.js @@ -1,36 +1,24 @@ var express = require('express'); var router = express.Router(); -// Mongoose import -var mongoose = require('mongoose'); -// Mongoose Schema definition -var Schema = mongoose.Schema; - -var JsonSchema = new Schema({ - name: String, - type: Schema.Types.Mixed, - coordinates: Array, - ageRange: String, - clothingDescription: String, - isInjured: Boolean, - reasonForHelp: String -}); - -// Mongoose Model definition -var Json = mongoose.model('Jstring', JsonSchema, 'pointscollection'); +var Mockpoints = require('../models/mockpoints'); +var Points = require('../models/points'); /* GET home page. */ router.get('/', function(req, res, next) { // for now just redirect to /map - //res.render('index', { title: 'Welcome' }); res.redirect('/map'); }); /* GET Map page. */ router.get('/map', function(req,res) { - // send the view lat, and long. city center - res.render('map', { - lat : 43.654127, - lng : -79.383370 + // load the map with all the points + // Mockpoints.get_points(function(err, points){ + Points.get_points(function(err, points){ + res.render('map', { + lat : 43.665234, + lng : -79.383370, + points: points + }); }); }); @@ -43,7 +31,7 @@ router.post('/mobilerequest', function(req, res) { 'ageRange': req.body.ageRange, 'clothingDescription': req.body.clothingDescription } - Json.create(data, function(err, result) { + Points.save_request(data, function(err, result) { if (err) { console.log(`err inserting mobile request into db: ${err}`); res.status(500).send({ error: "boo:(" }); diff --git a/web/views/map.pug b/web/views/map.pug index b7781fa..725c8a8 100644 --- a/web/views/map.pug +++ b/web/views/map.pug @@ -1,11 +1,11 @@ extends layout.pug block content - #sidebar - h1 This is a sidebar - #map - - script(type='text/javascript'). - var map = L.map('map').setView([#{lat},#{lng}], 15); - script(src='/javascripts/map.js') - + #sidebar + h1 This is a sidebar + #map + script(type='text/javascript'). + var map = L.map('map').setView([#{lat},#{lng}], 13); + var points = !{JSON.stringify(points)}; + console.log(points); + script(src='/javascripts/map.js') |
