changing ui.router version
This commit is contained in:
parent
fa5568d9cb
commit
3abdf1a606
52
js/app.js
52
js/app.js
|
@ -7,21 +7,16 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
|
||||||
|
|
||||||
$stateProvider
|
$stateProvider
|
||||||
.state('splash-page', {
|
.state('splash-page', {
|
||||||
url: '/splash-page',
|
data: { 'requiresLogin': false },
|
||||||
data: {
|
|
||||||
'requiresLogin': false
|
|
||||||
},
|
|
||||||
params: {
|
params: {
|
||||||
'toState': 'launchpad-home', // default state to proceed to after login
|
'toState': 'launchpad-home', // default state to proceed to after login
|
||||||
'toParams': {}
|
'toParams': {}
|
||||||
},
|
},
|
||||||
|
url: '/splash-page',
|
||||||
templateUrl: '/templates/splash-page.html',
|
templateUrl: '/templates/splash-page.html',
|
||||||
})
|
})
|
||||||
.state('app',{
|
.state('app',{
|
||||||
url: '/launchpad-',
|
url: '/launchpad-',
|
||||||
data: {
|
|
||||||
'requiresLogin': true
|
|
||||||
},
|
|
||||||
views: {
|
views: {
|
||||||
'header': {
|
'header': {
|
||||||
templateUrl: '/templates/partials/header.html',
|
templateUrl: '/templates/partials/header.html',
|
||||||
|
@ -37,13 +32,15 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
|
||||||
'notifications': {
|
'notifications': {
|
||||||
templateUrl: '/templates/partials/notifications.html'
|
templateUrl: '/templates/partials/notifications.html'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
data: { 'requiresLogin': true },
|
||||||
|
params: {
|
||||||
|
'toState': '',
|
||||||
|
'toParams': {}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.state('app.home', {
|
.state('app.home', {
|
||||||
url: 'home',
|
url: 'home',
|
||||||
data: {
|
|
||||||
'requiresLogin': true
|
|
||||||
},
|
|
||||||
views: {
|
views: {
|
||||||
'content@': {
|
'content@': {
|
||||||
templateUrl: 'templates/home.html',
|
templateUrl: 'templates/home.html',
|
||||||
|
@ -54,9 +51,6 @@ app.config(['$stateProvider', '$urlRouterProvider', 'localStorageServiceProvider
|
||||||
})
|
})
|
||||||
.state('app.bolt', {
|
.state('app.bolt', {
|
||||||
url: 'bolt',
|
url: 'bolt',
|
||||||
data: {
|
|
||||||
'requiresLogin': true
|
|
||||||
},
|
|
||||||
views: {
|
views: {
|
||||||
'content@': {
|
'content@': {
|
||||||
templateUrl: 'templates/bolt.html',
|
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
|
// Change title based on the `data` object in routes
|
||||||
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
|
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
|
||||||
console.log('things');
|
console.log('toState', toState);
|
||||||
// var requiresLogin = toState.data.requiresLogin;
|
console.log('toParams', toParams);
|
||||||
//
|
console.log('fromState', fromState);
|
||||||
// if (requiresLogin && !LoginService.check()) {
|
console.log('fromParams', fromParams);
|
||||||
// event.preventDefault();
|
|
||||||
// $state.go('splash-page', {'toState': toState.name, 'toParams': toParams});
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -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;
|
var vm = this;
|
||||||
|
|
||||||
vm.signOut = function () {
|
vm.signOut = function () {
|
||||||
localStorageService.remove('userAuth');
|
localStorageService.remove('userAuth');
|
||||||
$location.path('/splash-page');
|
$location.path('/splash-page');
|
||||||
}
|
};
|
||||||
|
|
||||||
function userAuth() {
|
function userAuth() {
|
||||||
return JSON.parse(localStorageService.get('userAuth'));
|
return JSON.parse(localStorageService.get('userAuth'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.$watch(Auth.isLoggedIn, function (value, oldValue) {
|
|
||||||
if (!value && !oldValue) {
|
|
||||||
$location.path('/splash-page');
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -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;
|
var vm = this;
|
||||||
vm.signIn = function () {
|
|
||||||
|
|
||||||
|
vm.signIn = function () {
|
||||||
var userInfo = {
|
var userInfo = {
|
||||||
email: vm.userAuthEmail
|
email: vm.userAuthEmail
|
||||||
};
|
};
|
||||||
|
|
||||||
Auth.setUser(userInfo);
|
Auth.setUser(userInfo);
|
||||||
|
|
||||||
var userAuthenticated = function() {
|
var userAuthenticated = function() {
|
||||||
return localStorageService.set('userAuth', JSON.stringify(userInfo));
|
return localStorageService.set('userAuth', JSON.stringify(userInfo));
|
||||||
}();
|
}();
|
||||||
|
|
||||||
$location.path('/launchpad-home');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue