angular.module('homepage').
run(function($rootScope, $state, $timeout, Authentication) {
$rootScope.isVisible = {
loading: false
};
$rootScope.currentRoute = {
name: ''
};
$rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams) {
$rootScope.isVisible.loading = true;
if (toState.name == 'login' && Authentication.isAuthenticated()) {
// User is authenticated
$rootScope.currentRoute.name = "home";
$state.transitionTo("home");
event.preventDefault();
}
else if (toState.authenticate && !Authentication.isAuthenticated()) {
// User isn’t authenticated
$rootScope.currentRoute.name = "login";
$state.transitionTo("login");
event.preventDefault();
}
else if (!toState.authenticate) {
$rootScope.currentRoute.name = toState.name;
}
});
$rootScope.$on("$viewContentLoaded", function () {
$timeout(function () {
$rootScope.isVisible.loading = false;
}, 1000);
});
}).
config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/start');
$stateProvider.
// INDEX STATES ========================================
state('start', {
url: '/start',
templateUrl: '../../html/partials/partial-index.html',
authenticate: false
}).
// LOGIN ROUTES ========================================
state('login', {
url: '/login',
templateUrl: '../../html/partials/partial-login.html',
authenticate: false
}).
state('signup', {
url: '/signup',
templateUrl: '../../html/partials/partial-signup.html',
authenticate: false
}).
state('register', {
url: '/register',
templateUrl: '../../html/partials/partial-register.html',
authenticate: false
}).
state('comment', {
url: '/comment',
templateUrl: '../../html/partials/partial-comment.html',
authenticate: false
}).
// HOME PAGE AND MULTIPLE NAMED VIEWS ====================
state('home', {
url: '/home',
controller: 'HomeController',
templateUrl: '../../html/partials/partial-home.html',
authenticate: true
}).
state('demo', {
url: '/demo',
controller: 'DemoController',
templateUrl: '../../html/partials/partial-demo.html',
authenticate: false
}).
// NOTES ROUTES ========================================
state('notes', {
url: '/notes',
templateUrl: '../../html/partials/partial-notes.html',
authenticate: false
}).
// LIST ROUTES ========================================
state('list', {
url: '/list',
templateUrl: '../../html/partials/partial-list.html',
authenticate: false
}).
// CALENDAR ROUTES ====================================
state('calendar', {
url: '/calendar',
templateUrl: '../../html/partials/partial-calendar.html',
authenticate: false
}).
// CONTACTS ROUTES ====================================
state('contacts', {
url: '/contacts',
templateUrl: '../../html/partials/partial-contacts.html',
authenticate: false
}).
// HABIT ROUTES ====================================
state('habits', {
url: '/habits',
templateUrl: '../../html/partials/partial-habits.html',
authenticate: false
}).
// FITNESS ROUTES ===================================
state('fitness', {
url: '/fitness',
templateUrl: '../../html/partials/partial-fitness.html',
authenticate: false
}).
// FINANCE ROUTES ===================================
state('finance', {
url: '/finance',
templateUrl: '../../html/partials/partial-finance.html',
authenticate: true
}).
// PLACES ROUTES ====================================
state('places', {
url: '/places',
templateUrl: '../../html/partials/partial-places.html',
authenticate: false
}).
// ACTIVITY ROUTES ==================================
state('activity', {
url: '/activity',
templateUrl: '../../html/partials/partial-activity.html',
authenticate: false
});
});