Skip to content

Commit

Permalink
asp project
Browse files Browse the repository at this point in the history
  • Loading branch information
babatech committed Nov 4, 2016
1 parent 98fe300 commit 675c791
Show file tree
Hide file tree
Showing 23 changed files with 755 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
*/node_modules
.idea
85 changes: 85 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
var express = require('express');
var socket_io = require('socket.io');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var sanitizer = require('sanitizer');
var googleMapsClient = require('@google/maps').createClient({
key: 'AIzaSyCPRT3eQNIcTUgj5mSHT5AA6qJ_NG3MCj4'
});
outputarr = [];

var routes = require('./routes/index');
var users = require('./routes/users');

var app = express();

// socket.io
var io = socket_io();
app.io = io;

// view engine setup

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

Expand Down Expand Up @@ -56,5 +67,79 @@ app.use(function(err, req, res, next) {
});
});

io.on('connection', function(socket){
console.log('new user connected');

socket.on('data', function(data){
// limit chars
data.message = data.message.substring(0,200);

// sanitaze html
data.message = sanitizer.escape(data.message);

io.emit('data', data);
console.log('message:' + data.message);
});
socket.on('user-position', function(data){

// sanitaze html
data.lat = sanitizer.escape(data.lat);
data.lng = sanitizer.escape(data.lng);
getnearbyPlaces(data);
//io.emit('nearbyplaces', outputarr);
console.log(outputarr);
console.log('location:' + data.lat +":"+ data.lng);
});

socket.on('disconnect', function(){
console.log('user disconnected');
});
});
// Geocode an address.
/*googleMapsClient.geocode({
address: '1600 Amphitheatre Parkway, Mountain View, CA'
}, function(err, response) {
if (!err) {
console.log(response.json.results);
}
});*/

function getnearbyPlaces(position,type) {
outputarr = [];
googleMapsClient.placesNearby({
location: [position.lat, position.lng],
opennow: true,
radius: 3000,
type: 'museum'
}, function(err, response) {
if (!err) {
processnearbyplace(response.json.results);
io.emit('nearbyplaces', outputarr);
}
});

//console.log(outputarr);
}

function processnearbyplace(result){

for (var i = 0; i < result.length; i++) {
var obj = result[i];
temp = {
id: sanitizer.escape(obj['id']),
place_id: sanitizer.escape(obj['place_id']),
title: sanitizer.escape(obj['name']),
geometry: sanitizer.escape(obj['geometry']['location']),
lat:sanitizer.escape(obj['geometry']['location']['lat']),
lan: sanitizer.escape(obj['geometry']['location']['lng']),
icon: sanitizer.escape(obj['icon'])
};

//console.log(temp);
outputarr.push(temp);


}
}

module.exports = app;
8 changes: 8 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ app.set('port', port);

var server = http.createServer(app);


/**
* Socket.io
*/

var io = app.io
io.attach(server);

/**
* Listen on provided port, on all network interfaces.
*/
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"express": "~4.13.4",
"jade": "~1.11.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0"
"serve-favicon": "~2.3.0",
"socket.io": "^1.3.6",
"sanitizer": "^0.1.3",
"@google/maps": "^0.3.0"
}
}
6 changes: 6 additions & 0 deletions public/css/bootstrap-theme.min.css

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions public/css/bootstrap.min.css

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions public/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
body { padding-top: 60px; }
.dropdown-login{
min-width: 250px;
}

#map {
height: 100%;
width: 100%;
min-height: 300px;

margin: 0 auto;
}

.full-width {
width: 100%;

margin: 0 auto;
}

.full-height {

height: 100%;
}
Empty file added public/css/style.styl
Empty file.
Binary file added public/fonts/glyphicons-halflings-regular.eot
Binary file not shown.
288 changes: 288 additions & 0 deletions public/fonts/glyphicons-halflings-regular.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/fonts/glyphicons-halflings-regular.ttf
Binary file not shown.
Binary file added public/fonts/glyphicons-halflings-regular.woff
Binary file not shown.
Binary file added public/fonts/glyphicons-halflings-regular.woff2
Binary file not shown.
Binary file added public/images/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions public/scripts/bootstrap.min.js

Large diffs are not rendered by default.

199 changes: 199 additions & 0 deletions public/scripts/globle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/**
* Created by shahab on 10/7/2016.
*/


// initialize the library with the API key
FB.init({ appId:'524562497683320' });

// fetch the status on load
FB.getLoginStatus(handleSessionResponse);

$('.btn-login-facebook').bind('click', function() {
FB.login(handleSessionResponse);
});

/*
$('#logout').bind('click', function() {
FB.logout(handleSessionResponse);
});*/

// handle a session response from any of the auth related calls
function handleSessionResponse() {
FB.api('/me', function(response) {
console.log(response);
$('#user-info').html(response.id + ' - ' + response.name);
});
}



var socket = io();
var map;
var pos;
var placeService;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: {lat: 0, lng: 0}
});
placeService = new google.maps.places.PlacesService(map);
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};

map.setCenter(pos);
map.setZoom(12);
//searchNearbyAttarctions(pos);
socket.emit('user-position', pos);
}, function() {
handleLocationError(true, infoWindow, map.getCenter());
});
} else {
handleLocationError(false, infoWindow, map.getCenter());
}
}

function handleLocationError(browserHasGeolocation, infoWindow, pos) {
infoWindow.setPosition(pos);
infoWindow.setContent(browserHasGeolocation ?
'Error: The Geolocation service failed.' :
'Error: Your browser doesn\'t support geolocation.');
}

$(document).ready(function(){
initMap();
var lastSend = 0;
$("#send-message").submit(function(event) {
if(pos==null) return false;

event.preventDefault();
});

});

socket.on('nearbyplaces', function(data){

for (var i = 0; i < data.length; i++) {

var place = data[i];
var latLng = new google.maps.LatLng(place.lat, place.lng);
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: latLng,
map: map,
title: place.title,
icon: place.icon
});
}

});
socket.on('data', function(data){
var infoWindow = new google.maps.InfoWindow({map: map});
var position = data.pos;
var message = data.message;

message = message.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig, "<a target='_blank' href='$1'>$1</a>");

infoWindow.setPosition(position);
infoWindow.setContent(message);

setTimeout(function(){
infoWindow.close();
}, 5000);
});
function searchNearbyAttarctions(position) {
var latLng = new google.maps.LatLng(position.lat, position.lng);
placeService.nearbySearch({
location: latLng,
radius: 2000,
type: ['night_club']
}, processNearbyAttarctions);
placeService.nearbySearch({
location: latLng,
radius: 2000,
type: ['museum']
}, processNearbyAttarctions);
placeService.nearbySearch({
location: latLng,
radius: 2000,
type: ['zoo']
}, processNearbyAttarctions);
placeService.nearbySearch({
location: latLng,
radius: 2000,
type: ['aquarium']
}, processNearbyAttarctions);
placeService.nearbySearch({
location: latLng,
radius: 2000,
type: ['amusement_park']
}, processNearbyAttarctions);
placeService.nearbySearch({
location: latLng,
radius: 2000,
type: ['art_gallery']
}, processNearbyAttarctions);

}

function processNearbyAttarctions(results, status) {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
createMarker(results[i]);
}
}
}

function createMarker(place) {
makePanel(place);
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location/*,
icon:place.icon*/
});

google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}

function makePanel(place) {
//console.log(place);
var newpanel = document.createElement("div");
newpanel.className="panel panel-default";
newpanel.id=place.id;

var newpanelbody = document.createElement("div");
newpanelbody.className="panel-body";

var newpanelbodyrow = document.createElement("div");
newpanelbodyrow.className="row";

var newpanelbodycolimage = document.createElement("div");
newpanelbodycolimage.className="col-sm-4";
newpanelbodycolimage.innerHTML='<img class="img-responsive" src="'+place.icon+'" alt="'+place.name+'" />';

var newpanelbodycoldes = document.createElement("div");
newpanelbodycoldes.className="col-sm-6";
newpanelbodycoldes.innerHTML='<p><strong>'+place.name+'</strong></br>'+place.name+'</p>';

newpanelbodyrow.appendChild(newpanelbodycolimage);
newpanelbodyrow.appendChild(newpanelbodycoldes);


newpanelbody.appendChild(newpanelbodyrow);
newpanel.appendChild(newpanelbody);

addPanel(newpanel);

}

function addPanel(newpanel) {
$(newpanel).insertAfter(".add-after-panel");
}
8 changes: 0 additions & 8 deletions public/stylesheets/style.css

This file was deleted.

15 changes: 14 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
var express = require('express');
var router = express.Router();
var header = [];
header["sitetitle"] = false;

var user = [];




/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
header["title"] = 'yo this is home';
res.render('index', { header: header,user: user,title: 'khlo tari' });
});
/* GET about page. */
router.get('/about', function(req, res, next) {
header["title"] = 'About Us';
res.render('about', { header: header });
});

module.exports = router;
Loading

0 comments on commit 675c791

Please sign in to comment.