diff --git a/.bowerrc b/.bowerrc index e28246d..570b109 100644 --- a/.bowerrc +++ b/.bowerrc @@ -1,3 +1,5 @@ { - "directory": "www/lib" + "directory": "www/lib", + "strict-ssl": false, + "https-proxy": "" } diff --git a/www/css/style.css b/www/css/style.css index fa22927..0573127 100644 --- a/www/css/style.css +++ b/www/css/style.css @@ -1 +1,9 @@ /* Empty. Add your own CSS if you like */ +.scroll { + height: 100%; +} + +#map { + width: 100%; + height: 100%; +} diff --git a/www/index.html b/www/index.html index 1979a4b..1ad1465 100644 --- a/www/index.html +++ b/www/index.html @@ -8,19 +8,30 @@ + + + + + + + + +

Ionic Maps

+
+
diff --git a/www/js/app.js b/www/js/app.js index 57ae272..b7c046d 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -3,7 +3,7 @@ // angular.module is a global place for creating, registering and retrieving Angular modules // 'starter' is the name of this angular module example (also set in a attribute in index.html) // the 2nd parameter is an array of 'requires' -angular.module('starter', ['ionic', 'controllers', 'services']) +angular.module('starter', ['ionic', 'controllers', 'services', 'ngCordova']) .run(function($ionicPlatform) { $ionicPlatform.ready(function() { @@ -27,25 +27,15 @@ angular.module('starter', ['ionic', 'controllers', 'services']) controller: 'WelcomeCtrl' }) - .state('app', { - url: "/app", - abstract: true, - templateUrl: "views/sidemenu.html", - controller: 'AppCtrl' - }) - - .state('app.home', { + .state('home', { url: "/home", - views: { - 'menuContent': { - templateUrl: "views/home.html", - controller: 'HomeCtrl' - } - } + abstract: false, + templateUrl: "views/home.html", + controller: 'HomeCtrl' }) ; // if none of the above states are matched, use this as the fallback - $urlRouterProvider.otherwise('/welcome'); + $urlRouterProvider.otherwise('home'); }) diff --git a/www/js/controllers.js b/www/js/controllers.js index 8a2daba..92e7fcc 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -1,34 +1,11 @@ angular.module('controllers', []) - .controller('WelcomeCtrl', function($scope, $state, $q, UserService, $ionicLoading) { //This is the success callback from the login method var fbLoginSuccess = function(response) { - if (!response.authResponse){ - fbLoginError("Cannot find the authResponse"); - return; - } - var authResponse = response.authResponse; - - getFacebookProfileInfo(authResponse) - .then(function(profileInfo) { - //for the purpose of this example I will store user data on local storage - UserService.setUser({ - authResponse: authResponse, - userID: profileInfo.id, - name: profileInfo.name, - email: profileInfo.email, - picture : "http://graph.facebook.com/" + authResponse.userID + "/picture?type=large" - }); - - $ionicLoading.hide(); - $state.go('app.home'); - - }, function(fail){ - //fail get profile info - console.log('profile info fail', fail); - }); + console.log(authResponse); + $state.go('app.home'); }; @@ -38,111 +15,56 @@ angular.module('controllers', []) $ionicLoading.hide(); }; - //this method is to get the user profile info from the facebook api - var getFacebookProfileInfo = function (authResponse) { - var info = $q.defer(); - - facebookConnectPlugin.api('/me?fields=email,name&access_token=' + authResponse.accessToken, null, - function (response) { - console.log(response); - info.resolve(response); - }, - function (response) { - console.log(response); - info.reject(response); - } - ); - return info.promise; - }; - //This method is executed when the user press the "Login with facebook" button $scope.facebookSignIn = function() { + console.log("login called") facebookConnectPlugin.getLoginStatus(function(success){ + console.log(success) if(success.status === 'connected'){ - // the user is logged in and has authenticated your app, and response.authResponse supplies - // the user's ID, a valid access token, a signed request, and the time the access token - // and signed request each expire - console.log('getLoginStatus', success.status); - - //check if we have our user saved - var user = UserService.getUser('facebook'); - - if(!user.userID) - { - getFacebookProfileInfo(success.authResponse) - .then(function(profileInfo) { - - //for the purpose of this example I will store user data on local storage - UserService.setUser({ - authResponse: success.authResponse, - userID: profileInfo.id, - name: profileInfo.name, - email: profileInfo.email, - picture : "http://graph.facebook.com/" + success.authResponse.userID + "/picture?type=large" - }); - - $state.go('app.home'); - - }, function(fail){ - //fail get profile info - console.log('profile info fail', fail); - }); - }else{ - $state.go('app.home'); - } - + console.log('getLoginStatus', success.status); + $state.go('app.home'); } else { - //if (success.status === 'not_authorized') the user is logged in to Facebook, but has not authenticated your app - //else The person is not logged into Facebook, so we're not sure if they are logged into this app or not. - console.log('getLoginStatus', success.status); - - $ionicLoading.show({ - template: 'Logging in...' - }); - - //ask the permissions you need. You can learn more about FB permissions here: https://developers.facebook.com/docs/facebook-login/permissions/v2.4 - facebookConnectPlugin.login(['email', 'public_profile'], fbLoginSuccess, fbLoginError); + console.log('getLoginStatus', success.status); + facebookConnectPlugin.login([], fbLoginSuccess, fbLoginError); } }); }; + + //auto login + /*facebookConnectPlugin.getLoginStatus(function(success){ + console.log(success) + if(success.status === 'connected'){ + console.log('getLoginStatus', success.status); + $state.go('app.home'); + } else { + console.log('getLoginStatus', success.status); + facebookConnectPlugin.login([], fbLoginSuccess, fbLoginError); + } + });*/ + }) +.controller('HomeCtrl', function($scope, UserService, $ionicActionSheet, $state, $ionicLoading, $cordovaGeolocation){ + var options = {timeout: 10000, enableHighAccuracy: true}; -.controller('AppCtrl', function($scope){ + $cordovaGeolocation.getCurrentPosition(options).then(function(position){ -}) + var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); + + var mapOptions = { + center: latLng, + zoom: 15, + mapTypeId: google.maps.MapTypeId.ROADMAP + }; + + $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions); + + }, function(error){ + console.log("Could not get location"); + }); -.controller('HomeCtrl', function($scope, UserService, $ionicActionSheet, $state, $ionicLoading){ - - $scope.user = UserService.getUser(); - - $scope.showLogOutMenu = function() { - var hideSheet = $ionicActionSheet.show({ - destructiveText: 'Logout', - titleText: 'Are you sure you want to logout? This app is awsome so I recommend you to stay.', - cancelText: 'Cancel', - cancel: function() {}, - buttonClicked: function(index) { - return true; - }, - destructiveButtonClicked: function(){ - $ionicLoading.show({ - template: 'Logging out...' - }); - - //facebook logout - facebookConnectPlugin.logout(function(){ - $ionicLoading.hide(); - $state.go('welcome'); - }, - function(fail){ - $ionicLoading.hide(); - }); - } - }); - }; }) ; diff --git a/www/views/home.html b/www/views/home.html index 30169ae..ca5a95b 100644 --- a/www/views/home.html +++ b/www/views/home.html @@ -1,17 +1,5 @@ - - - Facebook Login Example - + -
-
-

Hi {{user.name}}

-

You have logged in with Facebook

- - - Log Out - -
-
+