Commit 5132f0e87c4dbda56df7c3cc9f9f0235bc539037
1 parent
c7a3eac3f4
Exists in
master
and in
1 other branch
clean up user service binding!
Showing 4 changed files with 43 additions and 59 deletions Inline Diff
config.js
View file @
5132f0e
angular.module('flashy', [ | 1 | 1 | angular.module('flashy', [ | |
'flashy.LogoutController', | 2 | 2 | 'flashy.LogoutController', | |
'flashy.LoginController', | 3 | 3 | 'flashy.LoginController', | |
'flashy.RootController', | 4 | 4 | 'flashy.RootController', | |
'flashy.FeedController', | 5 | 5 | 'flashy.FeedController', | |
'flashy.DeckController', | 6 | 6 | 'flashy.DeckController', | |
'flashy.ClassAddController', | 7 | 7 | 'flashy.ClassAddController', | |
'flashy.RequestResetController', | 8 | 8 | 'flashy.RequestResetController', | |
'flashy.StudyController', | 9 | 9 | 'flashy.StudyController', | |
'flashy.UserService', | 10 | 10 | 'flashy.UserService', | |
'flashy.FlashcardDirective', | 11 | 11 | 'flashy.FlashcardDirective', | |
'flashy.ResetPasswordController', | 12 | 12 | 'flashy.ResetPasswordController', | |
'flashy.VerifyEmailController', | 13 | 13 | 'flashy.VerifyEmailController', | |
'flashy.CardListController', | 14 | 14 | 'flashy.CardListController', | |
'ngCookies']). | 15 | 15 | 'ngCookies']). | |
config(function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { | 16 | 16 | config(function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { | |
'use strict'; | 17 | 17 | 'use strict'; | |
$httpProvider.defaults.withCredentials = true; | 18 | 18 | $httpProvider.defaults.withCredentials = true; | |
$httpProvider.defaults.xsrfCookieName = 'csrftoken'; | 19 | 19 | $httpProvider.defaults.xsrfCookieName = 'csrftoken'; | |
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; | 20 | 20 | $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; | |
21 | 21 | |||
var arrayMethods = Object.getOwnPropertyNames(Array.prototype); | 22 | 22 | var arrayMethods = Object.getOwnPropertyNames(Array.prototype); | |
arrayMethods.forEach(attachArrayMethodsToNodeList); | 23 | 23 | arrayMethods.forEach(attachArrayMethodsToNodeList); | |
function attachArrayMethodsToNodeList(methodName) { | 24 | 24 | function attachArrayMethodsToNodeList(methodName) { | |
if (methodName !== 'length') { | 25 | 25 | if (methodName !== 'length') { | |
NodeList.prototype[methodName] = Array.prototype[methodName]; | 26 | 26 | NodeList.prototype[methodName] = Array.prototype[methodName]; | |
} | 27 | 27 | } | |
}; | 28 | 28 | }; | |
29 | 29 | |||
$httpProvider.interceptors.push(function($q) { | 30 | 30 | $httpProvider.interceptors.push(function($q) { | |
return { | 31 | 31 | return { | |
'responseError': function(rejection) { | 32 | 32 | 'responseError': function(rejection) { | |
if (rejection.status >= 500) { | 33 | 33 | if (rejection.status >= 500) { | |
console.log('got error'); | 34 | 34 | console.log('got error'); | |
console.log(rejection); | 35 | 35 | console.log(rejection); | |
$('body').html('<div class="card">Sorry, the server is not serving requests properly. Try again later</div>'); | 36 | 36 | $('body').html('<div class="card">Sorry, the server is not serving requests properly. Try again later</div>'); | |
} | 37 | 37 | } | |
return $q.reject(rejection); | 38 | 38 | return $q.reject(rejection); | |
} | 39 | 39 | } | |
}; | 40 | 40 | }; | |
}); | 41 | 41 | }); | |
$locationProvider.html5Mode(true); | 42 | 42 | $locationProvider.html5Mode(true); | |
$urlRouterProvider.otherwise('/login'); | 43 | 43 | $urlRouterProvider.otherwise('/login'); | |
var auth_resolve = { | 44 | 44 | var auth_resolve = { | |
authorize: function($q, UserService) { | 45 | 45 | authorize: function($q, UserService) { | |
console.log('resolving user before continuing'); | 46 | 46 | console.log('resolving user before continuing'); | |
return UserService.getUserData(); | 47 | 47 | return UserService.getUserData(); | |
} | 48 | 48 | } | |
}; | 49 | 49 | }; | |
$stateProvider. | 50 | 50 | $stateProvider. | |
state('login', { | 51 | 51 | state('login', { | |
url: '/login', | 52 | 52 | url: '/login', | |
templateUrl: 'templates/login.html', | 53 | 53 | templateUrl: 'templates/login.html', | |
controller: 'LoginController' | 54 | 54 | controller: 'LoginController' | |
}). | 55 | 55 | }). | |
state('logout', { | 56 | 56 | state('logout', { | |
resolve: auth_resolve, | 57 | 57 | resolve: auth_resolve, | |
url: '/logout', | 58 | 58 | url: '/logout', | |
templateUrl: 'templates/logout.html', | 59 | 59 | templateUrl: 'templates/logout.html', | |
controller: 'LogoutController' | 60 | 60 | controller: 'LogoutController' | |
}). | 61 | 61 | }). | |
state('root', { | 62 | 62 | state('root', { | |
resolve: auth_resolve, | 63 | 63 | resolve: auth_resolve, | |
url: '', | 64 | 64 | url: '', | |
templateUrl: 'templates/root.html', | 65 | 65 | templateUrl: 'templates/root.html', | |
controller: 'RootController' | 66 | 66 | controller: 'RootController' | |
}). | 67 | 67 | }). | |
state('feed', { | 68 | 68 | state('feed', { | |
resolve: auth_resolve, | 69 | 69 | resolve: auth_resolve, | |
url: '/feed/{sectionId}', | 70 | 70 | url: '/feed/{sectionId}', | |
templateUrl: 'templates/feed.html', | 71 | 71 | templateUrl: 'templates/feed.html', | |
controller: 'FeedController' | 72 | 72 | controller: 'FeedController' | |
}). | 73 | 73 | }). | |
state('cardlist', { | 74 | 74 | state('cardlist', { | |
resolve: auth_resolve, | 75 | 75 | resolve: auth_resolve, | |
url: '/cards/{sectionId}', | 76 | 76 | url: '/cards/{sectionId}', | |
templateUrl: 'templates/cardlist.html', | 77 | 77 | templateUrl: 'templates/cardlist.html', | |
controller: 'CardListController' | 78 | 78 | controller: 'CardListController' | |
}). | 79 | 79 | }). | |
state('addclass', { | 80 | 80 | state('addclass', { | |
resolve: auth_resolve, | 81 | 81 | resolve: auth_resolve, | |
url: '/addclass', | 82 | 82 | url: '/addclass', | |
templateUrl: 'templates/addclass.html', | 83 | 83 | templateUrl: 'templates/addclass.html', | |
controller: 'ClassAddController' | 84 | 84 | controller: 'ClassAddController' | |
}). | 85 | 85 | }). | |
state('deck', { | 86 | 86 | state('deck', { | |
resolve: auth_resolve, | 87 | 87 | resolve: auth_resolve, | |
url: '/deck/{sectionId}', | 88 | 88 | url: '/deck/{sectionId}', | |
templateUrl: 'templates/deck.html', | 89 | 89 | templateUrl: 'templates/deck.html', | |
controller: 'DeckController' | 90 | 90 | controller: 'DeckController' | |
}). | 91 | 91 | }). | |
state('study', { | 92 | 92 | state('study', { | |
resolve: auth_resolve, | 93 | 93 | resolve: auth_resolve, | |
url: '/study', | 94 | 94 | url: '/study', | |
templateUrl: 'templates/study.html', | 95 | 95 | templateUrl: 'templates/study.html', | |
controller: 'StudyController' | 96 | 96 | controller: 'StudyController' | |
}). | 97 | 97 | }). | |
state('flashcard', { | 98 | 98 | state('flashcard', { | |
resolve: auth_resolve, | 99 | 99 | resolve: auth_resolve, | |
url: '/flashcard', | 100 | 100 | url: '/flashcard', | |
templateUrl: 'templates/flashcard.html', | 101 | 101 | templateUrl: 'templates/flashcard.html', | |
controller: 'FlashcardController' | 102 | 102 | controller: 'FlashcardController' | |
}). | 103 | 103 | }). | |
state('requestpasswordreset', { | 104 | 104 | state('requestpasswordreset', { | |
url: '/requestpasswordreset', | 105 | 105 | url: '/requestpasswordreset', | |
templateUrl: 'templates/requestpasswordreset.html', | 106 | 106 | templateUrl: 'templates/requestpasswordreset.html', | |
controller: 'RequestResetController' | 107 | 107 | controller: 'RequestResetController' | |
}). | 108 | 108 | }). | |
state('resetpassword', { | 109 | 109 | state('resetpassword', { | |
url: '/resetpassword/{uid}/{token}', | 110 | 110 | url: '/resetpassword/{uid}/{token}', | |
templateUrl: 'templates/resetpassword.html', | 111 | 111 | templateUrl: 'templates/resetpassword.html', | |
controller: 'ResetPasswordController' | 112 | 112 | controller: 'ResetPasswordController' | |
}). | 113 | 113 | }). | |
state('verifyemail', { | 114 | 114 | state('verifyemail', { | |
resolve: auth_resolve, | 115 | 115 | resolve: auth_resolve, | |
url: '/verifyemail/{key}', | 116 | 116 | url: '/verifyemail/{key}', | |
templateUrl: 'templates/verifyemail.html', | 117 | 117 | templateUrl: 'templates/verifyemail.html', | |
controller: 'VerifyEmailController' | 118 | 118 | controller: 'VerifyEmailController' | |
}); | 119 | 119 | }); | |
}). | 120 | 120 | }). | |
run(function($rootScope, $state, $stateParams, $location, UserService) { | 121 | 121 | run(function($rootScope, $state, $stateParams, $location, UserService) { | |
$rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) { | 122 | 122 | $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) { | |
if (toState.name == 'login') { | 123 | 123 | if (toState.name == 'login') { | |
if (UserService.isLoggedIn()) return console.log('already logged in') + $state.go('addclass'); | 124 | 124 | if (UserService.isLoggedIn()) return console.log('already logged in') + $state.go('addclass'); | |
else return console.log('we are going to login anyway'); | 125 | 125 | else return console.log('we are going to login anyway'); | |
} | 126 | 126 | } | |
if (UserService.isLoggedIn()) return console.log('no login required; going straight to ' + toState.name); | 127 | 127 | if (UserService.isLoggedIn()) return console.log('no login required; going straight to ' + toState.name); | |
128 | ||||
if (!UserService.isUserResolved()) return console.log('user not yet resolved; hold off'); | 129 | |||
$rootScope.returnToState = toState; | 130 | 128 | $rootScope.returnToState = toState; | |
$rootScope.returnToStateParams = toStateParams; | 131 | 129 | $rootScope.returnToStateParams = toStateParams; | |
console.log('going to ' + toState.name + ' after login'); | 132 | 130 | console.log('going to ' + toState.name + ' after login'); | |
131 | event.preventDefault(); | |||
132 | $state.go('login'); | |||
133 | 133 | |||
}); | 134 | 134 | }); | |
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | 135 | 135 | $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { |
home.html
View file @
5132f0e
<!DOCTYPE html> | 1 | 1 | <!DOCTYPE html> | |
<html ng-app="flashy"> | 2 | 2 | <html ng-app="flashy"> | |
<base href="/app/"> | 3 | 3 | <base href="/app/"> | |
<head> | 4 | 4 | <head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> | 5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> | |
<link rel="stylesheet" | 6 | 6 | <link rel="stylesheet" | |
href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.css"> | 7 | 7 | href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.css"> | |
8 | 8 | |||
<link rel="stylesheet" href="styles/flashier.css"/> | 9 | 9 | <link rel="stylesheet" href="styles/flashier.css"/> | |
<link rel="stylesheet" href="styles/flashy.css"/> | 10 | 10 | <link rel="stylesheet" href="styles/flashy.css"/> | |
<link href='https://fonts.googleapis.com/css?family=Titillium+Web:200,200italic,300,600,400,900,700,400italic,700italic,300italic,600italic' | 11 | 11 | <link href='https://fonts.googleapis.com/css?family=Titillium+Web:200,200italic,300,600,400,900,700,400italic,700italic,300italic,600italic' | |
rel='stylesheet' type='text/css'> | 12 | 12 | rel='stylesheet' type='text/css'> | |
<title>Flashy</title> | 13 | 13 | <title>Flashy</title> | |
</head> | 14 | 14 | </head> | |
<body ng-controller="RootController"> | 15 | 15 | <body ng-controller="RootController"> | |
<header> | 16 | 16 | <header> | |
<nav> | 17 | 17 | <nav> | |
<div class="nav-wrapper"> | 18 | 18 | <div class="nav-wrapper"> | |
<a href="#" data-activates="mobile-demo" class="left button-collapse hide-on-med-and-up"><i | 19 | 19 | <a ng-show="user" href="#" data-activates="mobile-demo" class="left button-collapse hide-on-med-and-up"><i | |
class="mdi-navigation-menu"></i></a> | 20 | 20 | class="mdi-navigation-menu"></i></a> | |
<ul ng-show="currentSection.id && isLoggedIn" class="left hide-on-small-and-down"> | 21 | 21 | <ul ng-show="currentSection.id && UserService.isLoggedIn()" class="left hide-on-small-and-down"> | |
<li ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})" class="tooltipped" | 22 | 22 | <li ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})" class="tooltipped" | |
data-position="bottom" | 23 | 23 | data-position="bottom" | |
data-delay="50" data-tooltip="Feed"><i | 24 | 24 | data-delay="50" data-tooltip="Feed"><i | |
class="mdi-action-view-module"></i></a></li> | 25 | 25 | class="mdi-action-view-module"></i></a></li> | |
<li ui-sref-active="active"><a ui-sref="deck({sectionId:currentSection.id})" class="tooltipped" | 26 | 26 | <li ui-sref-active="active"><a ui-sref="deck({sectionId:currentSection.id})" class="tooltipped" | |
data-position="bottom" | 27 | 27 | data-position="bottom" | |
data-delay="50" data-tooltip="Deck"><i | 28 | 28 | data-delay="50" data-tooltip="Deck"><i | |
class="mdi-action-view-carousel"></i></a></li> | 29 | 29 | class="mdi-action-view-carousel"></i></a></li> | |
<li ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})" class="tooltipped" | 30 | 30 | <li ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})" class="tooltipped" | |
data-position="bottom" | 31 | 31 | data-position="bottom" | |
data-delay="50" data-tooltip="Card List"><i | 32 | 32 | data-delay="50" data-tooltip="Card List"><i | |
class="mdi-action-view-list"></i></a></li> | 33 | 33 | class="mdi-action-view-list"></i></a></li> | |
</ul> | 34 | 34 | </ul> | |
<a href="#" class="brand-logo center">Flashy</a> | 35 | 35 | <a href="#" class="brand-logo center">Flashy</a> | |
36 | 36 | |||
<ul ng-show="isLoggedIn" id="nav-mobile" class="right hide-on-small-and-down"> | 37 | 37 | <ul ng-show="UserService.isLoggedIn()" id="nav-mobile" class="right hide-on-small-and-down"> | |
<!-- User's classes dropdown --> | 38 | 38 | <!-- User's classes dropdown --> | |
<ul id="dropdown1" class="dropdown-content"> | 39 | 39 | <ul id="dropdown1" class="dropdown-content"> | |
<li ui-sref-active="active" ng-repeat="section in sections"> | 40 | 40 | <li ui-sref-active="active" ng-repeat="section in UserService.getUserData().sections"> | |
<a class="class bold" ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | 41 | 41 | <a class="class bold" ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | |
</li> | 42 | 42 | </li> | |
<li class="divider"></li> | 43 | 43 | <li class="divider"></li> | |
<li><a ui-sref="addclass">Add Class</a></li> | 44 | 44 | <li><a ui-sref="addclass">Add Class</a></li> | |
</ul> | 45 | 45 | </ul> | |
<li><a class="dropdown-button ng-cloak" href="#!" data-activates="dropdown1">{{currentSection.id?currentSection.short_name:"Classes"}}<i | 46 | 46 | <li><a class="dropdown-button ng-cloak" href="#!" data-activates="dropdown1">{{currentSection.id?currentSection.short_name:"Classes"}}<i | |
class="mdi-navigation-arrow-drop-down right"></i></a></li> | 47 | 47 | class="mdi-navigation-arrow-drop-down right"></i></a></li> | |
<li><a ui-sref="study">Study</a></li> | 48 | 48 | <li><a ui-sref="study">Study</a></li> | |
<li><a ui-sref="logout">Logout</a></li> | 49 | 49 | <li><a ui-sref="logout">Logout</a></li> | |
</ul> | 50 | 50 | </ul> | |
51 | 51 | |||
<!-- Slide-in side-nav for small screens --> | 52 | 52 | <!-- Slide-in side-nav for small screens --> | |
<ul class="side-nav" id="mobile-demo"> | 53 | 53 | <ul ng-show="currentSection.id && UserService.isLoggedIn()" class="side-nav" id="mobile-demo"> | |
<ul ng-show="currentSection.id && isLoggedIn"> | 54 | 54 | <li ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})" class="tooltipped" | |
<li ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})" class="tooltipped" | 55 | 55 | ><i | |
><i | 56 | 56 | class="mdi-action-view-module left"></i>Feed</a></li> | |
class="mdi-action-view-module left"></i>Feed</a></li> | 57 | 57 | <li ui-sref-active="active"><a ui-sref="deck({sectionId:currentSection.id})" class="tooltipped" | |
<li ui-sref-active="active"><a ui-sref="deck({sectionId:currentSection.id})" class="tooltipped" | 58 | 58 | ><i | |
><i | 59 | 59 | class="mdi-action-view-carousel left"></i>Deck</a></li> | |
class="mdi-action-view-carousel left"></i>Deck</a></li> | 60 | 60 | <li ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})" class="tooltipped" | |
<li ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})" class="tooltipped" | 61 | 61 | ><i | |
><i | 62 | 62 | class="mdi-action-view-list left"></i>Card List</a> | |
class="mdi-action-view-list left"></i>Card List</a> | 63 | 63 | </li> | |
</li> | 64 | 64 | <hr> | |
<hr> | 65 | |||
</ul> | 66 | |||
67 | 65 | |||
<!-- Collapsible menu for all the User's classes --> | 68 | 66 | <!-- Collapsible menu for all the User's classes --> | |
<ul class="collapsible" data-collapsible="accordion"> | 69 | 67 | <ul class="collapsible" data-collapsible="accordion"> | |
<li class="bold"> | 70 | 68 | <li class="bold"> | |
<a class="collapsible-header black-text"> | 71 | 69 | <a class="collapsible-header black-text"> | |
Classes<i | 72 | 70 | Classes<i | |
class="mdi-navigation-arrow-drop-down right"></i> | 73 | 71 | class="mdi-navigation-arrow-drop-down right"></i> | |
</a> | 74 | 72 | </a> | |
</li> | 75 | 73 | </li> | |
<div class="collapsible-body" style="display: block"> | 76 | 74 | <div class="collapsible-body" style="display: block"> | |
<ul> | 77 | 75 | <ul> | |
<li ui-sref-active="active" ng-repeat="section in sections"> | 78 | 76 | <li ui-sref-active="active" ng-repeat="section in sections"> | |
<a class="class bold" ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | 79 | 77 | <a class="class bold" ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | |
</li> | 80 | 78 | </li> | |
<hr> | 81 | 79 | <hr> | |
<li><a ui-sref="addclass"><i class="tiny mdi-content-add"> Add Class</i></a></li> | 82 | 80 | <li><a ui-sref="addclass"><i class="tiny mdi-content-add"> Add Class</i></a></li> | |
</ul> | 83 | 81 | </ul> | |
</div> | 84 | 82 | </div> | |
</ul> | 85 | 83 | </ul> | |
<li><a ui-sref="study">Study</a></li> | 86 | 84 | <li><a ui-sref="study">Study</a></li> | |
<li><a ui-sref="logout">Logout</a></li> | 87 | 85 | <li><a ui-sref="logout">Logout</a></li> | |
</ul> | 88 | 86 | </ul> | |
</div> | 89 | 87 | </div> | |
</nav> | 90 | 88 | </nav> | |
91 | 89 | |||
</header> | 92 | 90 | </header> | |
93 | 91 | |||
94 | 92 | |||
<!-- Menu Bar --> | 95 | 93 | <!-- Menu Bar --> | |
<main ui-view></main> | 96 | 94 | <main ui-view></main> | |
<footer class="page-footer"> | 97 | 95 | <footer class="page-footer"> | |
<div class="footer-copyright"> | 98 | 96 | <div class="footer-copyright"> | |
<div class="container"> | 99 | 97 | <div class="container"> | |
Concerns? Contact us by <a class="grey-text text-lighten-4" href="mailto:halp@flashy.cards">email</a>! | 100 | 98 | Concerns? Contact us by <a class="grey-text text-lighten-4" href="mailto:halp@flashy.cards">email</a>! | |
</div> | 101 | 99 | </div> | |
</div> | 102 | 100 | </div> | |
</footer> | 103 | 101 | </footer> | |
</body> | 104 | 102 | </body> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script> | 105 | 103 | <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.14/angular-ui-router.js"></script> | 106 | 104 | <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.14/angular-ui-router.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-cookies.js"></script> | 107 | 105 | <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-cookies.js"></script> | |
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script> | 108 | 106 | <script src="//code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script type="text/javascript" src="scripts/materialize.js"></script> | 109 | 107 | <script type="text/javascript" src="scripts/materialize.js"></script> | |
<script type="text/javascript" src="scripts/jquery.collapsible.js"></script> | 110 | 108 | <script type="text/javascript" src="scripts/jquery.collapsible.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.js"></script> | 111 | 109 | <script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script> | 112 | 110 | <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script> | 113 | 111 | <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-resource.min.js"></script> | 114 | 112 | <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-resource.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.4/angular-filter.js"></script> | 115 | 113 | <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.4/angular-filter.js"></script> | |
116 | 114 | |||
117 | 115 | |||
<script src="config.js"></script> | 118 | 116 | <script src="config.js"></script> | |
119 | 117 | |||
<!-- Controllers --> | 120 | 118 | <!-- Controllers --> | |
<script src="scripts/FeedController.js"></script> | 121 | 119 | <script src="scripts/FeedController.js"></script> | |
<script src="scripts/RootController.js"></script> | 122 | 120 | <script src="scripts/RootController.js"></script> | |
<script src="scripts/LoginController.js"></script> | 123 | 121 | <script src="scripts/LoginController.js"></script> | |
<script src="scripts/LogoutController.js"></script> | 124 | 122 | <script src="scripts/LogoutController.js"></script> | |
<script src="scripts/DeckController.js"></script> | 125 | 123 | <script src="scripts/DeckController.js"></script> | |
<script src="scripts/RequestResetController.js"></script> | 126 | 124 | <script src="scripts/RequestResetController.js"></script> | |
<script src="scripts/ClassAddController.js"></script> | 127 | 125 | <script src="scripts/ClassAddController.js"></script> | |
<script src="scripts/StudyController.js"></script> | 128 | 126 | <script src="scripts/StudyController.js"></script> | |
<script src="scripts/ResetPasswordController.js"></script> | 129 | 127 | <script src="scripts/ResetPasswordController.js"></script> | |
<script src="scripts/CardListController.js"></script> | 130 | 128 | <script src="scripts/CardListController.js"></script> | |
<script src="scripts/VerifyEmailController.js"></script> | 131 | 129 | <script src="scripts/VerifyEmailController.js"></script> | |
<!--<script src="scripts/SidebarController.js"></script>--> | 132 | 130 | <!--<script src="scripts/SidebarController.js"></script>--> | |
133 | 131 | |||
<!-- Services --> | 134 | 132 | <!-- Services --> | |
<script src="scripts/UserService.js"></script> | 135 | 133 | <script src="scripts/UserService.js"></script> | |
136 | 134 | |||
<!-- Directives --> | 137 | 135 | <!-- Directives --> | |
<script src="scripts/FlashcardDirective.js"></script> | 138 | 136 | <script src="scripts/FlashcardDirective.js"></script> | |
139 | 137 | |||
<!-- Other --> | 140 | 138 | <!-- Other --> | |
<!--<script src="scripts/StudyController.js"></script>--> | 141 | 139 | <!--<script src="scripts/StudyController.js"></script>--> | |
142 | 140 | |||
143 | 141 | |||
</html> | 144 | 142 | </html> | |
145 | 143 |
scripts/RootController.js
View file @
5132f0e
angular.module('flashy.RootController', ['ui.router', 'ngResource']). | 1 | 1 | angular.module('flashy.RootController', ['ui.router', 'ngResource']). | |
2 | 2 | |||
controller('RootController', function($rootScope, $resource, $scope, $state, UserService) { | 3 | 3 | controller('RootController', function($rootScope, $resource, $scope, $state, UserService) { | |
$rootScope.SectionResource = $resource('/api/sections/:sectionId/'); | 4 | 4 | $rootScope.SectionResource = $resource('/api/sections/:sectionId/'); | |
window.rootscope = $rootScope; | 5 | 5 | window.rootscope = $rootScope; | |
$rootScope.isLoggedIn = false; | 6 | 6 | window.userservice = UserService; | |
$rootScope.currentSection = {}; | 7 | 7 | $rootScope.currentSection = {}; | |
8 | $scope.UserService = UserService; | |||
UserService.getUserData().then(function(data) { | 8 | 9 | UserService.getUserData().then(function(data) { | |
console.log(data); | 9 | 10 | $scope.user = data; | |
$rootScope.user = data; | 10 | |||
}); | 11 | 11 | }); | |
12 | //UserService.getUserData().then(function(data) { | |||
13 | // console.log(data); | |||
14 | // $rootScope.user = data; | |||
15 | //}); | |||
$('.button-collapse').sideNav({ | 12 | 16 | $('.button-collapse').sideNav({ | |
menuWidth: 240, // Default is 240 | 13 | 17 | menuWidth: 240, // Default is 240 | |
edge: 'left', // Choose the horizontal origin | 14 | 18 | edge: 'left', // Choose the horizontal origin | |
closeOnClick: true // Closes side-nav on <a> clicks, useful for Angular/Meteor | 15 | 19 | closeOnClick: true // Closes side-nav on <a> clicks, useful for Angular/Meteor | |
} | 16 | 20 | } | |
); | 17 | 21 | ); | |
}); | 18 | 22 | }); | |
19 | 23 |
scripts/UserService.js
View file @
5132f0e
angular.module('flashy.UserService', ['ui.router']). | 1 | 1 | angular.module('flashy.UserService', ['ui.router']). | |
service('UserService', function($rootScope, $http, $q) { | 2 | 2 | service('UserService', function($rootScope, $http, $q) { | |
var _user = undefined; | 3 | 3 | var deferred = $q.defer(); | |
$rootScope.sections = []; | 4 | 4 | ||
this.getUserData = function(refresh) { | 5 | 5 | $http.get('/api/me/').success(function(data) { | |
var deferred = $q.defer(); | 6 | 6 | console.log('user is logged in!'); | |
if (angular.isDefined(_user)) { | 7 | 7 | _user = data; | |
console.log('user is already defined: ' + _user); | 8 | 8 | deferred.resolve(data); | |
if (!_user) { | 9 | 9 | }).error(function(data) { | |
console.log('rejecting deferred'); | 10 | 10 | console.log(data); | |
deferred.reject(_user); | 11 | 11 | console.log('not logged in yet: ' + data.detail); | |
} else { | 12 | 12 | deferred.resolve({}); | |
$rootScope.isLoggedIn = true; | 13 | 13 | }); | |
$rootScope.sections = _user.sections; | 14 | 14 | ||
deferred.resolve(_user); | 15 | 15 | var _user = deferred.promise; | |
} | 16 | 16 | ||
return deferred.promise; | 17 | 17 | this.getUserData = function() { | |
} | 18 | 18 | return _user; | |
$http.get('/api/me/').success(function(data) { | 19 | |||
console.log('user is logged in!'); | 20 | |||
_user = data; | 21 | |||
$rootScope.isLoggedIn = true; | 22 | |||
$rootScope.sections = _user.sections; | 23 | |||
deferred.resolve(data); | 24 | |||
}).error(function(data) { | 25 | |||
console.log(data); | 26 | |||
console.log('not logged in yet: ' + data.detail); | 27 | |||
deferred.reject('error getting own data'); | 28 | |||
_user = false; | 29 | |||
}); | 30 | |||
return deferred.promise; | 31 | |||
}; | 32 | 19 | }; | |
this.setUserData = function(data) { | 33 | 20 | this.setUserData = function(data) { | |
_user = data; | 34 | 21 | _user = data; | |
}; | 35 | 22 | }; | |
this.isUserResolved = function() { | 36 | |||
return angular.isDefined(_user); | 37 | |||
}; | 38 | |||
this.logout = function() { | 39 | 23 | this.logout = function() { | |
$rootScope.isLoggedIn = false; | 40 | 24 | _user = {}; | |
_user = undefined; | 41 | |||
}; | 42 | 25 | }; | |
this.isLoggedIn = function() { | 43 | 26 | this.isLoggedIn = function() { | |
rv = this.isUserResolved() && _user; | 44 | 27 | rv = angular.isDefined(_user.email); | |
console.log('is user logged in? ' + rv); | 45 | |||
return rv; | 46 | 28 | return rv; | |
}; | 47 | 29 | }; | |
}); | 48 | 30 | }); | |
49 | 31 | |||