changing ui.router version

This commit is contained in:
Jon Lambson 2017-08-10 11:36:59 -06:00
parent fa5568d9cb
commit 3abdf1a606
4 changed files with 41 additions and 49 deletions

View File

@ -7,21 +7,16 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
$stateProvider
.state('splash-page', {
url: '/splash-page',
data: {
'requiresLogin': false
},
data: { 'requiresLogin': false },
params: {
'toState': 'launchpad-home', // default state to proceed to after login
'toParams': {}
},
url: '/splash-page',
templateUrl: '/templates/splash-page.html',
})
.state('app',{
url: '/launchpad-',
data: {
'requiresLogin': true
},
views: {
'header': {
templateUrl: '/templates/partials/header.html',
@ -37,13 +32,15 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
'notifications': {
templateUrl: '/templates/partials/notifications.html'
}
},
data: { 'requiresLogin': true },
params: {
'toState': '',
'toParams': {}
}
})
.state('app.home', {
url: 'home',
data: {
'requiresLogin': true
},
views: {
'content@': {
templateUrl: 'templates/home.html',
@ -54,9 +51,6 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
})
.state('app.bolt', {
url: 'bolt',
data: {
'requiresLogin': true
},
views: {
'content@': {
templateUrl: 'templates/bolt.html',
@ -131,18 +125,30 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
}
}
});
}])
.run(['$rootScope', '$state', 'Auth', function($rootScope, $state, Auth) {
}]);
app.run(['$rootScope', '$state', 'Auth', function($rootScope, $state, Auth) {
// Change title based on the `data` object in routes
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
console.log('things');
// var requiresLogin = toState.data.requiresLogin;
//
// if (requiresLogin && !LoginService.check()) {
// event.preventDefault();
// $state.go('splash-page', {'toState': toState.name, 'toParams': toParams});
// }
});
console.log('toState', toState);
console.log('toParams', toParams);
console.log('fromState', fromState);
console.log('fromParams', fromParams);
var requiresLogin = toState.data.requiresLogin;
if (requiresLogin && !Auth.isLoggedIn()) {
event.preventDefault();
$state.go('splash-page', {'toState': toState.name, 'toParams': toParams});
} else {
// if ($state.params.toState === undefined && $state.params.toParams === undefined) {
// console.log('set a route');
// }
console.log('TOSTATE: ',$state.params.toState);
console.log('TOPARAMS: ',$state.params.toParams);
// $state.go($state.params.toState, $state.params.toParams);
}
});
}]);

View File

@ -1,19 +1,16 @@
app.controller('HomeController', ['$scope', 'Auth', 'localStorageService', '$location', function ($scope, Auth, localStorageService, $location) {
app.controller('HomeController', ['$scope', 'Auth', 'localStorageService', '$location', '$rootScope', function ($scope, Auth, localStorageService, $location, $rootScope) {
var vm = this;
vm.signOut = function () {
localStorageService.remove('userAuth');
$location.path('/splash-page');
}
};
function userAuth() {
return JSON.parse(localStorageService.get('userAuth'));
}
$scope.$watch(Auth.isLoggedIn, function (value, oldValue) {
if (!value && !oldValue) {
$location.path('/splash-page');
}
}, true);
}]);

View File

@ -1,18 +1,14 @@
app.controller('SignInController', ['$scope', 'Auth', '$location', 'localStorageService', function ($scope, Auth, $location, localStorageService) {
app.controller('SignInController', ['$scope', 'Auth', '$location', 'localStorageService', '$rootScope', function ($scope, Auth, $location, localStorageService, $rootScope) {
var vm = this;
vm.signIn = function () {
vm.signIn = function () {
var userInfo = {
email: vm.userAuthEmail
};
Auth.setUser(userInfo);
var userAuthenticated = function() {
return localStorageService.set('userAuth', JSON.stringify(userInfo));
}();
$location.path('/launchpad-home');
};
}]);

File diff suppressed because one or more lines are too long