Skip to content

Commit

Permalink
#3 #4 Geolocation from browser, show users on the map
Browse files Browse the repository at this point in the history
  • Loading branch information
simison committed Oct 10, 2014
1 parent 1985ed7 commit 42c0b74
Show file tree
Hide file tree
Showing 19 changed files with 394 additions and 184 deletions.
53 changes: 36 additions & 17 deletions app/controllers/offers.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ function fuzzyLocation(location) {


/**
* Create a Offer
* Create (or update if exists) a Offer
*/
exports.create = function(req, res) {
console.log('->offer.create');

var offer = new Offer(req.body);
offer.user = req.user;

Expand Down Expand Up @@ -98,42 +96,64 @@ exports.create = function(req, res) {
};


/**
* Update a Offer
*/
exports.update = function(req, res) {
console.log('->offer.read');

};

/**
* Delete an Offer
*/
exports.delete = function(req, res) {
console.log('->offer.delete');

};

/**
* List of Offers
*/
exports.list = function(req, res) {
console.log('->offer.list');
Offer.find( {
$or: [
{ status: 'yes' },
{ status: 'maybe' }
],
locationFuzzy: {
$geoWithin: {
$box: [
[Number(req.query.northEastLng), Number(req.query.northEastLat)],
[Number(req.query.southWestLng), Number(req.query.southWestLat)]
]
}
}
},
'locationFuzzy status user'
)
.exec(function(err, offers) {
if (err) {
return res.status(400).send({
message: errorHandler.getErrorMessage(err)
});
} else {

/*
* Could return something like this here already (so no need to refactor at frontend):
*
* lat: marker.locationFuzzy[0],
* lng: marker.locationFuzzy[1],
* user: marker.user,
* icon: $scope.icons[marker.status]
*/
res.jsonp(offers);
}
});
};


/**
* Show the current Offer
*/
exports.read = function(req, res) {
console.log('->offer.read');
res.jsonp(req.offer);
};


// Offer reading middleware
exports.offerByUserID = function(req, res, next, userId) {
console.log('->offer.offerByUserID: ' + userId);

Offer.findOne({
user: userId
})
Expand Down Expand Up @@ -174,7 +194,6 @@ exports.offerByUserID = function(req, res, next, userId) {
* Offer authorization middleware
*/
exports.hasAuthorization = function(req, res, next) {
console.log('->offer.hasAuthorization');
if (req.offer.user.id !== req.user.id) {
return res.status(403).send('User is not authorized');
}
Expand Down
2 changes: 1 addition & 1 deletion app/routes/offers.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function(app) {

app.route('/offers/:userId')
.get(users.requiresLogin, offers.read)
.put(users.requiresLogin, offers.hasAuthorization, offers.update)
//.put(users.requiresLogin, offers.hasAuthorization, offers.update)
.delete(users.requiresLogin, offers.hasAuthorization, offers.delete);

// Finish by binding the middleware
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"select2": "~3.4.5",
"selectize": "~0.8.5",
"angular-leaflet-directive": "~0.7.8",
"leaflet.markercluster": "~0.4.0"
"leaflet.markercluster": "~0.4.0",
"ngGeolocation": "~0.0.4"
}
}
1 change: 1 addition & 0 deletions config/env/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = {
'public/lib/leaflet/dist/leaflet-src.js',
'public/lib/leaflet.markercluster/dist/leaflet.markercluster.js',
'public/lib/angular-leaflet-directive/dist/angular-leaflet-directive.js',
'public/lib/ngGeolocation/ngGeolocation.js',
]
},
less: [
Expand Down
3 changes: 2 additions & 1 deletion public/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var ApplicationConfiguration = (function() {
'angularMoment',
'angular-medium-editor',
'perfect_scrollbar',
'leaflet-directive'
'leaflet-directive',
'ngGeolocation'
];

// Add a new vertical module
Expand Down
10 changes: 8 additions & 2 deletions public/modules/core/controllers/header.client.controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('core').controller('HeaderController', ['$scope', '$log', '$filter', 'Authentication', 'Menus', 'Socket',
function($scope, $log, $filter, Authentication, Menus, Socket) {
angular.module('core').controller('HeaderController', ['$scope', '$log', '$filter', '$geolocation', 'Authentication', 'Menus', 'Socket',
function($scope, $log, $filter, $geolocation, Authentication, Menus, Socket) {

// @todo: show info popup when this happens
Socket.on('reconnect', function () {
Expand All @@ -12,6 +12,12 @@ angular.module('core').controller('HeaderController', ['$scope', '$log', '$filte
$log.log('Attempting to re-connect to the server');
});

// Makes it faster for other controllers to load this if we get it already now
// @todo: should this be at some MainController?
$scope.position = $geolocation.getCurrentPosition({
timeout: 60000 // 1min
});

$scope.authentication = Authentication;
$scope.isCollapsed = false;
$scope.isHidden = false;
Expand Down
Binary file added public/modules/core/img/map/marker-icon-maybe.png
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/modules/core/img/map/marker-icon-yes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/modules/core/img/map/marker-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/modules/core/img/map/marker-shadow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/modules/core/less/panels.less
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@
&.panel-disabled {
opacity: 0.4;
}
&.panel-loading {
&, * {
color: lighten(@gray-lighter, 2%) !important;
}
}
}
2 changes: 1 addition & 1 deletion public/modules/messages/config/messages.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ angular.module('messages').run(['Menus',
function(Menus) {
// Set top bar menu items
// This menu has only icon and no text label
Menus.addMenuItem('topuserbar', '', 'messages', 'messages', 'messages', null, null, 0, 'comments fa-lg');
Menus.addMenuItem('topuserbar', '', 'messages', 'messages', '/messages', null, null, 0, 'comments fa-lg');
}
]);
25 changes: 19 additions & 6 deletions public/modules/offers/controllers/add-offer.client.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@
/*global jQuery:false */


angular.module('offers').controller('AddOfferController', ['$scope', '$http', '$timeout', '$state', '$stateParams', 'Offers', 'Authentication',
function($scope, $http, $timeout, $state, $stateParams, Offers, Authentication) {
angular.module('offers').controller('AddOfferController', ['$scope', '$rootScope', '$http', '$timeout', '$state', '$stateParams', '$geolocation', 'Offers', 'Authentication',
function($scope, $rootScope, $http, $timeout, $state, $stateParams, $geolocation, Offers, Authentication) {

$scope.authentication = Authentication;

$scope.isLoading = true;
$scope.isLoading = false;

$scope.offer = false;

$scope.position = $geolocation.getCurrentPosition({
timeout: 60000 // 1min
});

// Leaflet
angular.extend($scope, {
center: {
// Default to Europe
lat: $scope.offer ? $scope.offer.location[0] : 48.6908333333,
lng: $scope.offer ? $scope.offer.location[1] : 9.14055555556,
zoom: $scope.offer ? 16 : 4
lat: 48.6908333333,
lng: 9.14055555556,
zoom: 4
},
layers: {
baselayers: {
Expand Down Expand Up @@ -65,6 +69,15 @@ angular.module('offers').controller('AddOfferController', ['$scope', '$http', '$
else {
offer.maxGuests = 1;
offer.status = 'yes';

// Center map to user's location
$scope.position.then(function(position){
if(position.coords.latitude && position.coords.longitude) {
$scope.center.lat = position.coords.latitude;
$scope.center.lng = position.coords.longitude;
$scope.center.zoom = 13;
}
});
}

// Determine new status from URL, overrides previous status
Expand Down
8 changes: 4 additions & 4 deletions public/modules/offers/views/view-offers.client.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<div ng-show="offer.status !== 'no'">
<div ng-show="offer.description" ng-bind-html="offer.description | trustedHtml"></div>
<p class="offer-restrictions">
<em ng-show="offer.maxGuests > 1">At most {{offer.maxGuests}} guests</em>
<em ng-show="offer.maxGuests === 1">At most one guest</em>
<em ng-show="offer.maxGuests === 0">Zero guests</em>
<small ng-show="offer.description && user._id === profile.id" class="pull-right"><a ui-sref="offer" class="text-muted">edit</a></small>
<small ng-show="offer.maxGuests > 1">At most {{offer.maxGuests}} guests.</small>
<small ng-show="offer.maxGuests === 1">At most one guest.</small>
<small ng-show="offer.maxGuests === 0">Zero guests.</small>
</p>
<small ng-show="offer.description && user._id === profile.id" class="pull-right"><a ui-sref="offer" class="text-muted">edit</a></small>
</div>
<!-- /Hosting: yes | maybe -->

Expand Down
3 changes: 2 additions & 1 deletion public/modules/search/config/search.client.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
angular.module('search').run(['Menus',
function(Menus) {
// Set top bar menu items
Menus.addMenuItem('topbar', 'Search', 'search', 'search');
Menus.addMenuItem('topbar', 'Search', 'search', 'search', '/search', null, null, 0, 'search fa-lg');

}
]);
Loading

0 comments on commit 42c0b74

Please sign in to comment.