From 24e670eb1c881ca1382f48d67eb96eec71d29c1e Mon Sep 17 00:00:00 2001 From: arnaucode Date: Fri, 24 Feb 2017 01:15:56 +0100 Subject: [PATCH] map of events implemented --- www/index.html | 3 ++ www/js/app.js | 30 ++++++++++++++++ www/js/byPlace.js | 68 ++++++++++++++++++++++++++++++++++++ www/js/mapEvents.js | 59 +++++++++++++++++++++++++++++++ www/js/place.js | 51 +++++++++++++++++++++++++++ www/templates/byPlace.html | 43 +++++++++++++++++++++++ www/templates/main.html | 2 +- www/templates/mapEvents.html | 7 ++++ www/templates/menu.html | 7 ++-- www/templates/place.html | 25 +++++++++++++ 10 files changed, 292 insertions(+), 3 deletions(-) create mode 100644 www/js/byPlace.js create mode 100644 www/js/mapEvents.js create mode 100644 www/js/place.js create mode 100644 www/templates/byPlace.html create mode 100644 www/templates/mapEvents.html create mode 100644 www/templates/place.html diff --git a/www/index.html b/www/index.html index 4e1c8ab..665ccb5 100644 --- a/www/index.html +++ b/www/index.html @@ -47,11 +47,14 @@ + + + diff --git a/www/js/app.js b/www/js/app.js index 80d0a96..9b64b67 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -10,11 +10,14 @@ angular.module('app', [ 'app.menu', 'app.main', 'app.events', + 'app.mapEvents', 'app.event', 'app.alerts', 'app.savedEvents', 'app.categories', 'app.byCategory', + 'app.place', + 'app.byPlace', 'app.users', 'app.user', 'app.login', @@ -67,6 +70,15 @@ angular.module('app', [ } } }) + .state('app.mapEvents', { + url: '/mapEvents', + views: { + 'menuContent': { + templateUrl: 'templates/mapEvents.html', + controller: 'MapEventsCtrl' + } + } + }) .state('app.event', { url: '/events/:eventid', views: { @@ -112,6 +124,24 @@ angular.module('app', [ } } }) + .state('app.place', { + url: '/place', + views: { + 'menuContent': { + templateUrl: 'templates/place.html', + controller: 'PlaceCtrl' + } + } + }) + .state('app.byPlace', { + url: '/byPlace/:place', + views: { + 'menuContent': { + templateUrl: 'templates/byPlace.html', + controller: 'ByPlaceCtrl' + } + } + }) .state('app.users', { url: '/users', views: { diff --git a/www/js/byPlace.js b/www/js/byPlace.js new file mode 100644 index 0000000..dd19835 --- /dev/null +++ b/www/js/byPlace.js @@ -0,0 +1,68 @@ +angular.module('app.byPlace', ['pascalprecht.translate']) + +.controller('ByPlaceCtrl', function($scope, $http, $ionicModal, + $timeout, $ionicLoading, $filter, $stateParams) { + + $scope.category=$stateParams.categoryname; + $scope.events=[]; + $scope.page=0; + $scope.doRefresh = function() { + /* events refresh: */ + //$http.get(urlapi + 'events?page=' + $scope.page) + $http.get(urlapi + 'events/category/'+ $stateParams.categoryname) + .then(function(data){ + $scope.events=data.data; + console.log($scope.events); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + + }, function(data){ + console.log('data error'); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 }); + + }); + }; + $scope.doRefresh(); + + $scope.share = function(event){ + var message = "[" + event.title + "]" + event.description; + /*var subject = event.title; + var file= ['',''];*/ + var link = "http://duckduckgo.com"; + $cordovaSocialSharing + .share(message, link) // Share via native share sheet + .then(function(result) { + // Success! + }, function(err) { + // An error occured. Show a message to the user + }); + }; + $scope.savedEvents=[]; + $scope.$on('$ionicView.enter', function(){//per executar-ho cada cop que es carrega el view + if (localStorage.getItem("events_app_savedEvents")) { + $scope.savedEvents = JSON.parse(localStorage.getItem("events_app_savedEvents")); + } + }); + $scope.saveEvent = function(event){ + $scope.savedEvents.push(event); + localStorage.setItem("events_app_savedEvents", JSON.stringify($scope.savedEvents)); + $ionicLoading.show({ template: 'Event saved', noBackdrop: true, duration: 1000 }); + }; + $scope.unsaveEvent = function(event){ + for(var i=0; i<$scope.savedEvents.length; i++) { + if ($scope.savedEvents[i]._id === event._id){ + $scope.savedEvents.splice(i, 1); + } + } + localStorage.setItem("events_app_savedEvents", JSON.stringify($scope.savedEvents)); + $ionicLoading.show({ template: 'Event unsaved', noBackdrop: true, duration: 1000 }); + }; + $scope.isEventSaved = function(event) { + for(var i=0; i<$scope.savedEvents.length; i++) { + if ($scope.savedEvents[i]._id === event._id){ + return true; + } + } + return false; + }; +}); diff --git a/www/js/mapEvents.js b/www/js/mapEvents.js new file mode 100644 index 0000000..e460d2d --- /dev/null +++ b/www/js/mapEvents.js @@ -0,0 +1,59 @@ +angular.module('app.mapEvents', ['pascalprecht.translate', 'ui-leaflet']) + +.controller('MapEventsCtrl', function($scope, $http, $ionicModal, + $timeout, $ionicLoading, $filter, + leafletBoundsHelpers, $cordovaSocialSharing) { + + //map + $scope.center= { + lat: 0, + lng: 0, + zoom: 1 + }; + $scope.markers=[]; + $scope.tiles= { + url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", + options: { + attribution: 'OpenStreetMap contributors' + } + }; + + $scope.events=[]; + $scope.page=0; + $http.get(urlapi + 'events') + .then(function(data){ + console.log('data success events'); + console.log(data); // for browser console + //$scope.events = data.data; // for UI + $scope.events=data.data; + $scope.$broadcast('scroll.refreshComplete');//refresher stop + for(var i=0; i<$scope.events.length; i++) + { + if($scope.events[i].location) + { + var msg="" + +"

"+$scope.events[i].title + "

" + +"" + +$scope.events[i].description+"
"; + + $scope.markers.push({ + lat: Number($scope.events[i].location.geo.lat), + lng: Number($scope.events[i].location.geo.long), + message: msg + }); + $scope.center= { + lat: Number($scope.events[i].location.geo.lat), + lng: Number($scope.events[i].location.geo.long), + zoom: 12 + }; + } + } + }, function(data){ + console.log('data error'); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 }); + + }); + + +}); diff --git a/www/js/place.js b/www/js/place.js new file mode 100644 index 0000000..e105d12 --- /dev/null +++ b/www/js/place.js @@ -0,0 +1,51 @@ +angular.module('app.place', ['pascalprecht.translate', 'ui-leaflet']) + +.controller('PlaceCtrl', function($scope, $http, $ionicModal, $timeout, + $ionicLoading, $filter, leafletData, leafletBoundsHelpers) { + + $scope.center= { + lat: 0, + lng: 0, + zoom: 1 + }; + $scope.markers=new Array(); + $scope.tiles= { + url: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", + options: { + attribution: 'OpenStreetMap contributors' + } + }; + $scope.place={ + location:{ + direction:"", + geo:{ + lat:"", + long:"" + } + } + }; + $scope.getGeo = function(){ + $scope.markers=[]; + console.log($scope.place.location.direction); + $http.get('http://nominatim.openstreetmap.org/search?q=' + $scope.place.location.direction + '&format=json&limit=1') + .then(function(data) { + console.log(data); + if(data.data[0]) + { + $scope.place.location.geo.lat=data.data[0].lat; + $scope.place.location.geo.long=data.data[0].lon; + //$scope.newtravel.from.name=data.data[0].display_name; + $scope.markers.push({ + lat: Number(data.data[0].lat), + lng: Number(data.data[0].lon), + message: $scope.place.location.direction + }); + $scope.center= { + lat: Number(data.data[0].lat), + lng: Number(data.data[0].lon), + zoom: 16 + }; + } + }); + }; +}); diff --git a/www/templates/byPlace.html b/www/templates/byPlace.html new file mode 100644 index 0000000..42a5ed5 --- /dev/null +++ b/www/templates/byPlace.html @@ -0,0 +1,43 @@ + + + + + + + diff --git a/www/templates/main.html b/www/templates/main.html index be79f8e..565c47d 100644 --- a/www/templates/main.html +++ b/www/templates/main.html @@ -12,7 +12,7 @@ - + diff --git a/www/templates/mapEvents.html b/www/templates/mapEvents.html new file mode 100644 index 0000000..65bebd8 --- /dev/null +++ b/www/templates/mapEvents.html @@ -0,0 +1,7 @@ + + + + + diff --git a/www/templates/menu.html b/www/templates/menu.html index fc0b35b..19455c7 100644 --- a/www/templates/menu.html +++ b/www/templates/menu.html @@ -24,6 +24,9 @@ Events + + Map of Events + Users @@ -33,9 +36,9 @@ By Categories - + By Date diff --git a/www/templates/place.html b/www/templates/place.html new file mode 100644 index 0000000..fd87c85 --- /dev/null +++ b/www/templates/place.html @@ -0,0 +1,25 @@ + + + +
+ Get geolocation +
+ + + + +
+
+ Post new event! +
+
+
+