diff options
| author | ivanshen <iwshen11@gmail.com> | 2019-03-05 04:12:16 +0000 |
|---|---|---|
| committer | ivanshen <iwshen11@gmail.com> | 2019-03-05 04:12:16 +0000 |
| commit | 786d0aacd27f27875568c7a89d9e1df918fadbf3 (patch) | |
| tree | e313a040f1a44d8a3f7cfb51736f295b94d76df6 | |
| parent | c16d2af861f4ed452b2b43f087290f5c0889c34d (diff) | |
| parent | 18cfcf14ea982d3277d819b88b0dd4df96da40d0 (diff) | |
Merge branch 'qa' of github.com:csc301-winter-2019/project-team-02 into qa
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | mobile/App.js | 29 | ||||
| -rw-r--r-- | mobile/components/FormPage.js | 20 | ||||
| -rw-r--r-- | mobile/components/GreetingPage.js | 112 | ||||
| -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 | 72 | ||||
| -rw-r--r-- | web/views/map.pug | 16 |
10 files changed, 282 insertions, 72 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..acdfd5a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# SOME README diff --git a/mobile/App.js b/mobile/App.js index 7271bc2..4348381 100644 --- a/mobile/App.js +++ b/mobile/App.js @@ -1,17 +1,16 @@ import React, { Component } from 'react'; -import { Text, View } from 'react-native'; +import { Text, View, Alert, StyleSheet, Button, AppRegistry, Navigator, TouchableHighlight} from 'react-native'; +import { Ionicons } from '@expo/vector-icons'; +import { createStackNavigator, createAppContainer } from 'react-navigation'; -export default class HelloWorldApp extends Component { - //Every component needs a render() function - render() { - return ( - //<View> acts like the way <div> does in JavaScript - //style={...} stores properties about where you want the component to be placed - //and how you want it to look. It's similar to adding CSS styles to HTML elements - //when creating web pages - <View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}> - <Text>Hello world!</Text> - </View> - ); - } -} +import GreetingPage from './components/GreetingPage'; +import FormPage from './components/FormPage'; + + +const RootStack = createStackNavigator( {GreetingPage: GreetingPage, FormPage: FormPage,}, + {headerMode: 'none'}) + +const App = createAppContainer(RootStack) + +export default App; + diff --git a/mobile/components/FormPage.js b/mobile/components/FormPage.js new file mode 100644 index 0000000..9ea3dce --- /dev/null +++ b/mobile/components/FormPage.js @@ -0,0 +1,20 @@ +import React, { Component } from 'react'; +import { Text, View, Alert, StyleSheet, Button, AppRegistry, Navigator, TouchableHighlight} from 'react-native'; +import { Ionicons } from '@expo/vector-icons'; +import { createStackNavigator, createAppContainer } from 'react-navigation'; + +export default class FormPage extends Component { + render() { + return ( + <View marginTop = {50}> + <Text> + Put the form stuff here + </Text> + <Button + onPress={() => this.props.navigation.navigate('GreetingPage')} + title='Go Back' + /> + </View> + ); + } +} diff --git a/mobile/components/GreetingPage.js b/mobile/components/GreetingPage.js new file mode 100644 index 0000000..8b87474 --- /dev/null +++ b/mobile/components/GreetingPage.js @@ -0,0 +1,112 @@ +import React, { Component } from 'react'; +import { Text, View, Alert, StyleSheet, Button, AppRegistry, Navigator, TouchableHighlight} from 'react-native'; +import { Ionicons } from '@expo/vector-icons'; +import { createStackNavigator, createAppContainer } from 'react-navigation'; + +export default class GreetingPage extends Component { + //Every component needs a render() function + render() { + return ( + //<View> acts like the way <div> does in JavaScript + //style={...} stores properties about where you want the component to be placed + //and how you want it to look. It's similar to adding CSS styles to HTML elements + //when creating web pages + + <View style={styles.container}> + + <View style={styles.titleContainer}> + <Text style={styles.title}> + [Place text here!] + </Text> + </View> + + <TouchableHighlight + style={styles.first_button_container} + onPress={() => this.props.navigation.navigate('FormPage')}> + + <View style={styles.press_button}> + + <View> + <Text style={styles.current_location_title}> + Use Current Location + </Text> + </View> + + <View marginTop = {20}> + <Ionicons name="md-locate" size={40} color="white"/> + </View> + + </View> + + </TouchableHighlight> + + <TouchableHighlight + style={styles.second_button_container} + onPress={() => this.props.navigation.navigate('FormPage')}> + <View style={styles.press_button}> + + <View> + <Text style={styles.current_location_title}> + Drop Pin + </Text> + </View> + + <View marginTop = {20}> + <Ionicons name="md-pin" size={40} color="white"/> + </View> + + </View> + </TouchableHighlight> + + </View> + ); + } +} + + +const styles = StyleSheet.create( { + container: { + flex: 1, + flexDirection: 'column', + backgroundColor: '#40739e', + alignItems: 'stretch' + }, + titleContainer: { + flex: 3, + //position: 'absolute', + marginTop: 205, + //flexGrow: 1 + }, + title: { + color: '#FFF', + marginTop: 10, + textAlign: 'center', + opacity: 0.9, + fontSize: 30 + }, + current_location_title: { + color: '#FFF', + marginTop: 15, + textAlign: 'center', + opacity: 0.9, + fontSize: 20 + }, + first_button_container: { + flex: 1, + //position: 'absolute', + //marginTop: 360, + backgroundColor: '#c0392b', + flexDirection: 'row', + justifyContent: 'center', + alignItems: 'stretch' + }, + press_button: { + flexDirection: 'column', + justifyContent: 'center', + alignItems: 'center' + }, + second_button_container: { + flex: 1, + backgroundColor: '#535c68' + } +}) @@ -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') |
