aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorKumar Damani <damani.kumar@gmail.com>2019-03-05 20:49:57 +0000
committerGitHub <noreply@github.com>2019-03-05 20:49:57 +0000
commit97ae21bf83fb04526269442e2fa3954d99d18665 (patch)
tree4ef4ed4b8e9a079b504c7c31e5f5932bbe459f05 /web
parentc16d2af861f4ed452b2b43f087290f5c0889c34d (diff)
parenta08006f89b4252c5edd2d88938ba4e68010b1bd3 (diff)
Merge pull request #22 from csc301-winter-2019/feat7-qa-merging
Feat7 qa merging
Diffstat (limited to 'web')
-rw-r--r--web/app.js24
-rw-r--r--web/models/mockpoints.js32
-rw-r--r--web/models/points.js32
-rw-r--r--web/public/javascripts/map.js16
-rw-r--r--web/routes/index.js72
-rw-r--r--web/views/map.pug16
6 files changed, 135 insertions, 57 deletions
diff --git a/web/app.js b/web/app.js
index ab7aed4..f0ae3a5 100644
--- a/web/app.js
+++ b/web/app.js
@@ -3,6 +3,7 @@ var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
+var mongoose = require('mongoose');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
@@ -19,6 +20,29 @@ app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
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'
+} else if (env === 'qa') {
+ uri = process.env.MONGODB_URI
+} else if (env === 'production') {
+ 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}`);
+ }
+});
+
app.use('/', indexRouter);
app.use('/users', usersRouter);
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 df579fc..b2d0796 100644
--- a/web/routes/index.js
+++ b/web/routes/index.js
@@ -1,56 +1,44 @@
var express = require('express');
var router = express.Router();
-
-// Mongoose import
-var mongoose = require('mongoose');
-
-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'
-} else if (env === 'qa') {
- uri = process.env.MONGODB_URI
-} else if (env === 'production') {
- 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}`);
- }
-});
-
-// Mongoose Schema definition
-var Schema = mongoose.Schema;
-var JsonSchema = new Schema({
- name: String,
- type: Schema.Types.Mixed,
- coordinates: Array
-});
-
-// 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
+ });
+ });
+});
+
+router.post('/mobilerequest', function(req, res) {
+ var data = {
+ 'coordinates': req.body.coordinates,
+ 'type': req.body.type,
+ 'isInjured': req.body.isInjured,
+ 'reasonForHelp': req.body.reasonForHelp,
+ 'ageRange': req.body.ageRange,
+ 'clothingDescription': req.body.clothingDescription
+ }
+ Points.save_request(data, function(err, result) {
+ if (err) {
+ console.log(`err inserting mobile request into db: ${err}`);
+ res.status(500).send({ error: "boo:(" });
+ } else {
+ console.log(result);
+ res.status(200).send({'status': 'success', 'data': data});
+ }
});
});
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')