Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maps #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Maps #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .bowerrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"directory": "www/lib"
"directory": "www/lib",
"strict-ssl": false,
"https-proxy": ""
}
8 changes: 8 additions & 0 deletions www/css/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
/* Empty. Add your own CSS if you like */
.scroll {
height: 100%;
}

#map {
width: 100%;
height: 100%;
}
11 changes: 11 additions & 0 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,30 @@

<!-- compiled css output -->
<link href="css/ionic.app.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">

<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>

<script src="http://maps.google.com/maps/api/js?key=AIzaSyAgwAnjh2fZrYqzokGyqvsLo-OD3dyTjbc"></script>


</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic Maps</h1>
</ion-header-bar>
<ion-nav-view></ion-nav-view>
</ion-pane>
</body>
</html>
22 changes: 6 additions & 16 deletions www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <body> 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() {
Expand All @@ -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');
})
152 changes: 37 additions & 115 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
@@ -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');
};


Expand All @@ -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();
});
}
});
};
})

;
16 changes: 2 additions & 14 deletions www/views/home.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
<ion-view class="home-view">
<ion-nav-title>
<span>Facebook Login Example</span>
</ion-nav-title>
<ion-view>
<ion-content>
<div class="row">
<div class="col">
<h3 class="welcome-message">Hi {{user.name}}</h3>
<p class="welcome-message">You have logged in with Facebook</p>
<img ng-src="{{user.picture}}">
<a class="button button-assertive button-block button-outline" ng-click="showLogOutMenu()">
Log Out
</a>
</div>
</div>
<div id="map" data-tap-disabled="true"></div>
</ion-content>
</ion-view>