Commit 8fa323ef66e4a4bec2d39cf2848b15548eaf598c

Authored by Andrew Buss
1 parent 0b8a1b6050

more on userservice. conditionally display sidebar

Showing 9 changed files with 73 additions and 70 deletions Inline Diff

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',
'ngCookies']). 14 14 'ngCookies']).
config(['$stateProvider', '$urlRouterProvider', '$httpProvider', 15 15 config(['$stateProvider', '$urlRouterProvider', '$httpProvider',
'$locationProvider', 16 16 '$locationProvider',
function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { 17 17 function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) {
'use strict'; 18 18 'use strict';
$httpProvider.defaults.withCredentials = true; 19 19 $httpProvider.defaults.withCredentials = true;
$httpProvider.defaults.xsrfCookieName = 'csrftoken'; 20 20 $httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; 21 21 $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
$locationProvider.html5Mode(true); 22 22 $locationProvider.html5Mode(true);
$urlRouterProvider.otherwise('/home'); 23 23 $urlRouterProvider.otherwise('/home');
var auth_resolve = { 24 24 var auth_resolve = {
authorize: ['$q', 'UserService', 25 25 authorize: ['$q', 'UserService',
function($q, UserService) { 26 26 function($q, UserService) {
console.log('resolving user before continuing'); 27 27 console.log('resolving user before continuing');
return UserService.getUserData(); 28 28 return UserService.getUserData();
} 29 29 }
] 30 30 ]
}; 31 31 };
$stateProvider. 32 32 $stateProvider.
state('login', { 33 33 state('login', {
url: '/login', 34 34 url: '/login',
templateUrl: 'templates/login.html', 35 35 templateUrl: 'templates/login.html',
controller: 'LoginController' 36 36 controller: 'LoginController'
}). 37 37 }).
state('logout', { 38 38 state('logout', {
resolve: auth_resolve, 39 39 resolve: auth_resolve,
url: '/logout', 40 40 url: '/logout',
templateUrl: 'templates/logout.html', 41 41 templateUrl: 'templates/logout.html',
controller: 'LogoutController' 42 42 controller: 'LogoutController'
}). 43 43 }).
state('root', { 44 44 state('root', {
resolve: auth_resolve, 45 45 resolve: auth_resolve,
url: '/', 46 46 url: '/',
templateUrl: 'templates/root.html', 47 47 templateUrl: 'templates/root.html',
controller: 'RootController' 48 48 controller: 'RootController'
}). 49 49 }).
state('feed', { 50 50 state('feed', {
resolve: auth_resolve, 51 51 resolve: auth_resolve,
url: '/feed', 52 52 url: '/feed/{sectionId}',
templateUrl: 'templates/feed.html', 53 53 templateUrl: 'templates/feed.html',
controller: 'FeedController' 54 54 controller: 'FeedController'
}). 55 55 }).
state('addclass', { 56 56 state('addclass', {
resolve: auth_resolve, 57 57 resolve: auth_resolve,
url: '/addclass', 58 58 url: '/addclass',
templateUrl: 'templates/addclass.html', 59 59 templateUrl: 'templates/addclass.html',
controller: 'ClassAddController' 60 60 controller: 'ClassAddController'
}). 61 61 }).
state('deck', { 62 62 state('deck', {
resolve: auth_resolve, 63 63 resolve: auth_resolve,
url: '/deck', 64 64 url: '/deck',
templateUrl: 'templates/deck.html', 65 65 templateUrl: 'templates/deck.html',
controller: 'DeckController' 66 66 controller: 'DeckController'
}). 67 67 }).
state('study', { 68 68 state('study', {
resolve: auth_resolve, 69 69 resolve: auth_resolve,
url: '/study', 70 70 url: '/study',
templateUrl: 'templates/study.html', 71 71 templateUrl: 'templates/study.html',
controller: 'StudyController' 72 72 controller: 'StudyController'
}). 73 73 }).
state('flashcard', { 74 74 state('flashcard', {
resolve: auth_resolve, 75 75 resolve: auth_resolve,
url: '/flashcard', 76 76 url: '/flashcard',
templateUrl: 'templates/flashcard.html', 77 77 templateUrl: 'templates/flashcard.html',
controller: 'FlashcardController' 78 78 controller: 'FlashcardController'
}). 79 79 }).
state('requestpasswordreset', { 80 80 state('requestpasswordreset', {
resolve: auth_resolve, 81
url: '/requestpasswordreset', 82 81 url: '/requestpasswordreset',
templateUrl: 'templates/requestpasswordreset.html', 83 82 templateUrl: 'templates/requestpasswordreset.html',
controller: 'RequestResetController' 84 83 controller: 'RequestResetController'
}). 85 84 }).
state('resetpassword', { 86 85 state('resetpassword', {
resolve: auth_resolve, 87
url: '/resetpassword/{uid}/{token}', 88 86 url: '/resetpassword/{uid}/{token}',
templateUrl: 'templates/resetpassword.html', 89 87 templateUrl: 'templates/resetpassword.html',
controller: 'ResetPasswordController' 90 88 controller: 'ResetPasswordController'
}). 91 89 }).
state('verifyemail', { 92 90 state('verifyemail', {
resolve: auth_resolve, 93 91 resolve: auth_resolve,
url: '/verifyemail/{key}', 94 92 url: '/verifyemail/{key}',
templateUrl: 'templates/verifyemail.html', 95 93 templateUrl: 'templates/verifyemail.html',
controller: 'VerifyEmailController' 96 94 controller: 'VerifyEmailController'
}); 97 95 });
}]).run(['$rootScope', '$state', '$stateParams', '$location', 'UserService', 98 96 }]).run(['$rootScope', '$state', '$stateParams', '$location', 'UserService',
function($rootScope, $state, $stateParams, $location, UserService) { 99 97 function($rootScope, $state, $stateParams, $location, UserService) {
$rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) { 100 98 $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) {
if (UserService.isLoggedIn()) return console.log('no login required; going straight to ' + toState.name); 101 99 if (UserService.isLoggedIn()) return console.log('no login required; going straight to ' + toState.name);
if (toState.name == 'login') return; 102 100 if (toState.name == 'login') return console.log('we are going to login anyway; just let it happen :)');
if (!UserService.isUserResolved()) return; 103 101 if (!UserService.isUserResolved()) return console.log('user not yet resolved; hold off');
$rootScope.returnToState = toState; 104 102 $rootScope.returnToState = toState;
$rootScope.returnToStateParams = toStateParams; 105 103 $rootScope.returnToStateParams = toStateParams;
console.log('going to ' + toState.name + ' after login'); 106 104 console.log('going to ' + toState.name + ' after login');
$state.go('login'); 107 105 $state.go('login');
}); 108 106 });
$rootScope.$on('$routeChangeError', function() { 109 107 $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
console.log('failed to change routes'); 110 108 console.log('failed to change state: ' + error);
109 $state.go('login');
}); 111 110 });
} 112 111 }
]); 113 112 ]);
114 113
.angucomplete-dropdown { 1 1 .angucomplete-dropdown {
border-color: #ececec; 2 2 border-color: #ececec;
border-width: 1px; 3 3 border-width: 1px;
border-style: solid; 4 4 border-style: solid;
border-radius: 2px; 5 5 border-radius: 2px;
/*width: 250px;*/ 6 6 /*width: 250px;*/
padding: 6px; 7 7 padding: 6px;
cursor: pointer; 8 8 cursor: pointer;
z-index: 9999; 9 9 z-index: 9999;
position: absolute; 10 10 position: absolute;
/*top: 32px; 11 11 /*top: 32px;
left: 0px; 12 12 left: 0px;
*/ 13 13 */
margin-top: -6px; 14 14 margin-top: -6px;
background-color: #ffffff; 15 15 background-color: #ffffff;
} 16 16 }
17 17
.angucomplete-description { 18 18 .angucomplete-description {
font-size: 14px; 19 19 font-size: 14px;
} 20 20 }
21 21
.angucomplete-row { 22 22 .angucomplete-row {
padding: 5px; 23 23 padding: 5px;
color: #000000; 24 24 color: #000000;
margin-bottom: 4px; 25 25 margin-bottom: 4px;
clear: both; 26 26 clear: both;
} 27 27 }
28 28
.angucomplete-selected-row { 29 29 .angucomplete-selected-row {
background-color: #aaaaff; 30 30 background-color: #aaaaff;
} 31 31 }
32 32
.container .row { 33 33 .container .row {
margin-left: 0; 34 34 margin-left: 0;
margin-right: 0; 35 35 margin-right: 0;
} 36 36 }
37 37
ul.side-nav.fixed li { 38 38 ul.side-nav.fixed li {
/*line-height: 30px;*/ 39 39 /*line-height: 30px;*/
/*font-weight:700;*/ 40 40 /*font-weight:700;*/
font-size:24px; 41 41 font-size:24px;
} 42 42 }
43 43
ul.side-nav.fixed li a { 44 44 ul.side-nav.fixed li a {
/*line-height: 30px;*/ 45 45 /*line-height: 30px;*/
/*font-weight:700;*/ 46 46 /*font-weight:700;*/
font-size:24px; 47 47 font-size:24px;
} 48 48 }
49 49
50 50
ul.side-nav.fixed li ul li { 51 51 ul.side-nav.fixed li ul li {
/*line-height: 30px;*/ 52 52 /*line-height: 30px;*/
/*font-weight:700;*/ 53 53 /*font-weight:700;*/
margin-left:20px; 54 54 margin-left:20px;
} 55 55 }
56 56
ul.side-nav.fixed li a { 57 57 ul.side-nav.fixed li a {
/*line-height: 30px;*/ 58 58 /*line-height: 30px;*/
/*font-weight:700;*/ 59 59 /*font-weight:700;*/
font-size:24px; 60 60 font-size:24px;
} 61 61 }
62 62
63
#logo-container{ 64
height:110px; 65
} 66
/* Flashcard directive css */ 67 63 /* Flashcard directive css */
.card.fixed-size { 68 64 .card.fixed-size {
height: calc(3 * 5vw); 69 65 height: calc(3 * 5vw);
min-height: calc(3 * 50px); 70 66 min-height: calc(3 * 50px);
min-width: calc(5 * 50px); 71 67 min-width: calc(5 * 50px);
width: calc(5 * 5vw); 72 68 width: calc(5 * 5vw);
} 73 69 }
74 70
.card-overlay { 75 71 .card-overlay {
/* display: none; */ 76 72 /* display: none; */
height: calc(3 * 5vw); 77 73 height: calc(3 * 5vw);
left: 0; 78 74 left: 0;
min-height: calc(3 * 50px); 79 75 min-height: calc(3 * 50px);
min-width: calc(5 * 50px); 80 76 min-width: calc(5 * 50px);
position: absolute; 81 77 position: absolute;
top: 0; 82 78 top: 0;
width: calc(5 * 5vw); 83 79 width: calc(5 * 5vw);
} 84 80 }
85 81
.card-overlay i { 86 82 .card-overlay i {
color: #FFF; 87 83 color: #FFF;
} 88 84 }
89 85
.card:hover .card-overlay { 90 86 .card:hover .card-overlay {
display: block; 91 87 display: block;
} 92 88 }
93 89
.top-box { 94 90 .top-box {
background-color: rgba(50, 50, 90, 0.5); 95 91 background-color: rgba(50, 50, 90, 0.5);
height: 50%; 96 92 height: 50%;
position: relative; 97 93 position: relative;
width: 100%; 98 94 width: 100%;
} 99 95 }
100 96
.bottom-box { 101 97 .bottom-box {
height: 50%; 102 98 height: 50%;
position: relative; 103 99 position: relative;
width: 100%; 104 100 width: 100%;
} 105 101 }
106 102
.left-box { 107 103 .left-box {
background-color: rgba(90, 50, 190, 0.5); 108 104 background-color: rgba(90, 50, 190, 0.5);
float: left; 109 105 float: left;
position: relative; 110 106 position: relative;
width: 50%; 111 107 width: 50%;
} 112 108 }
113 109
.right-box { 114 110 .right-box {
background-color: rgba(190, 50, 90, 0.5); 115 111 background-color: rgba(190, 50, 90, 0.5);
float: right; 116 112 float: right;
width: 50%; 117 113 width: 50%;
} 118 114 }
119 115
.center-me { 120 116 .center-me {
margin: 0 auto; 121 117 margin: 0 auto;
} 122 118 }
123 119
.container { 124 120 .container {
margin-left: 250px; 125 121 margin-left: 250px;
/*position: relative; 126 122 /*position: relative;
width: 600px; 127 123 width: 600px;
height: 80px;*/ 128 124 height: 80px;*/
} 129 125 }
130 126
.modal.bottom-sheet { 131 127 .modal.bottom-sheet {
width: 40%; 132 128 width: 40%;
margin-left: auto; 133 129 margin-left: auto;
margin-right: auto; 134 130 margin-right: auto;
} 135 131 }
136 132
/* label color */ 137 133 /* label color */
.input-field label { 138 134 .input-field label {
color: #673ab7; 139 135 color: #673ab7;
} 140 136 }
141 137
/* label focus color */ 142 138 /* label focus color */
.input-field input[type]:focus + label { 143 139 .input-field input[type]:focus + label {
color: #b388ff; 144 140 color: #b388ff;
} 145 141 }
146 142
/* label underline focus color */ 147 143 /* label underline focus color */
.input-field input[type]:focus { 148 144 .input-field input[type]:focus {
border-bottom: 1px solid #b388ff; 149 145 border-bottom: 1px solid #b388ff;
box-shadow: 0 1px 0 0 #b388ff; 150 146 box-shadow: 0 1px 0 0 #b388ff;
} 151 147 }
152 148
/* valid color */ 153 149 /* valid color */
.input-field input[type].valid { 154 150 .input-field input[type].valid {
border-bottom: 1px solid #673ab7; 155 151 border-bottom: 1px solid #673ab7;
box-shadow: 0 1px 0 0 #673ab7; 156 152 box-shadow: 0 1px 0 0 #673ab7;
} 157 153 }
158 154
/* invalid color */ 159 155 /* invalid color */
.input-field input[type].invalid { 160 156 .input-field input[type].invalid {
border-bottom: 1px solid #673ab7; 161 157 border-bottom: 1px solid #673ab7;
box-shadow: 0 1px 0 0 #673ab7; 162 158 box-shadow: 0 1px 0 0 #673ab7;
} 163 159 }
164 160
/* icon prefix focus color */ 165 161 /* icon prefix focus color */
<!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>
<link type="text/css" rel="stylesheet" href="styles/materialize.min.css" 5 5 <link type="text/css" rel="stylesheet" href="styles/materialize.min.css"
media="screen,projection"/> 6 6 media="screen,projection"/>
<!--<link rel="stylesheet" href="styles/bootstrap-3.3.4-dist/css/bootstrap.css"/>--> 7 7 <!--<link rel="stylesheet" href="styles/bootstrap-3.3.4-dist/css/bootstrap.css"/>-->
<link rel="stylesheet" 8 8 <link rel="stylesheet"
href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.css"> 9 9 href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.css">
10 10
<link rel="stylesheet" href="flashy.css"/> 11 11 <link rel="stylesheet" href="flashy.css"/>
</head> 12 12 </head>
13 13
<body ng-controller="RootController"> 14 14 <body ng-controller="RootController">
15 15
<ul id="slide-out" class="side-nav fixed"> 16 16 <ul id="slide-out" ng-show="isLoggedIn" class="side-nav fixed">
<li class="logo"><a href="//flashy.cards/" id="logo-container"> 17 17 <li class="logo"><a href="//flashy.cards/" id="logo-container">
<h1>Flashy</h1> 18 18 <h1>Flashy</h1>
</a></li> 19 19 </a></li>
<li class="bold"> 20 20 <li class="bold">
<a>Classes</a> 21 21 <a>Classes</a>
<!--<a ui-sref="addclass"><i class="mdi-content-add"></i></a>--> 22 22 <!--<a ui-sref="addclass"><i class="mdi-content-add"></i></a>-->
</li> 23 23 </li>
<li> 24 24 <li>
<ul> 25 25 <ul>
<li ui-sref="feed">WRONG 123</li> 26 26 <li ui-sref="feed">WRONG 123</li>
<li ui-sref="feed/4567">CSE 1337</li> 27 27 <li ui-sref="feed(4567)">CSE 1337</li>
<li ui-sref="feed/1242">MATH 20Z</li> 28 28 <li ui-sref="feed(1242)">MATH 20Z</li>
<li ui-sref="feed/2842">BILD 99</li> 29 29 <li ui-sref="feed(2842)">BILD 99</li>
</ul> 30 30 </ul>
</li> 31 31 </li>
<li class="bold"><a ui-sref="addclass">Add Class</a></li> 32 32 <li class="bold"><a ui-sref="addclass">Add Class</a></li>
<li class="bold"><a ui-sref="feed">Feed</a></li> 33 33 <li class="bold"><a ui-sref="feed">Feed</a></li>
<li class="bold"><a ui-sref="deck">Deck</a></li> 34 34 <li class="bold"><a ui-sref="deck">Deck</a></li>
<li class="bold"><a ui-sref="logout">Logout</a></li> 35 35 <li class="bold"><a ui-sref="logout">Logout</a></li>
</ul> 36 36 </ul>
37 37
38 38
<div class="container" ui-view></div> 39 39 <div class="container" ui-view></div>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script> 40 40 <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> 41 41 <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> 42 42 <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> 43 43 <script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="scripts/materialize.min.js"></script> 44 44 <script type="text/javascript" src="scripts/materialize.min.js"></script>
<script type="text/javascript" src="scripts/jquery.collapsible.js"></script> 45 45 <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> 46 46 <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> 47 47 <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> 48 48 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script>
49 49
<script src="config.js"></script> 50 50 <script src="config.js"></script>
51 51
<!-- Controllers --> 52 52 <!-- Controllers -->
<script src="scripts/FeedController.js"></script> 53 53 <script src="scripts/FeedController.js"></script>
<script src="scripts/RootController.js"></script> 54 54 <script src="scripts/RootController.js"></script>
<script src="scripts/LoginController.js"></script> 55 55 <script src="scripts/LoginController.js"></script>
<script src="scripts/LogoutController.js"></script> 56 56 <script src="scripts/LogoutController.js"></script>
<script src="scripts/DeckController.js"></script> 57 57 <script src="scripts/DeckController.js"></script>
<script src="scripts/RequestResetController.js"></script> 58 58 <script src="scripts/RequestResetController.js"></script>
<script src="scripts/ClassAddController.js"></script> 59 59 <script src="scripts/ClassAddController.js"></script>
<script src="scripts/StudyController.js"></script> 60 60 <script src="scripts/StudyController.js"></script>
<script src="scripts/VerifyEmailController.js"></script> 61 61 <script src="scripts/VerifyEmailController.js"></script>
<!--<script src="scripts/SidebarController.js"></script>--> 62 62 <!--<script src="scripts/SidebarController.js"></script>-->
63 63
<!-- Services --> 64 64 <!-- Services -->
<script src="scripts/UserService.js"></script> 65 65 <script src="scripts/UserService.js"></script>
66 66
<!-- Directives --> 67 67 <!-- Directives -->
<script src="scripts/FlashcardDirective.js"></script> 68 68 <script src="scripts/FlashcardDirective.js"></script>
69 69
<!-- Other --> 70 70 <!-- Other -->
<!--<script src="scripts/StudyController.js"></script>--> 71 71 <!--<script src="scripts/StudyController.js"></script>-->
scripts/FeedController.js View file @ 8fa323e
angular.module('flashy.FeedController', ['ui.router']). 1 1 angular.module('flashy.FeedController', ['ui.router']).
2 2
controller('FeedController', ['$scope', '$state', '$http', function($scope, $state, $http) { 3 3 controller('FeedController', ['$scope', '$stateParams', '$state', '$http', function($scope, $stateParams, $state, $http) {
console.log('Hello from feed'); 4 4 console.log('Hello from feed');
5 5 sectionId = $stateParams.sectionId;
$scope.cards = []; 6 6 $scope.cards = [];
7 7
8 $scope.cards[0] = {'id': 1, 'title': 'title1', 'content': 'abc'};
9 $scope.cards[1] = {'id': 2, 'title': 'title2', 'content': 'xyz'};
10 $scope.cards[2] = {'id': 2, 'title': 'title3', 'content': 'qwe'};
8 11
$scope.cards[0] = { 'id': 1, 'title': 'title1', 'content': 'abc' }; 9 12 $http.get('/api/sections/' + sectionId + '/flashcards/').
$scope.cards[1] = { 'id': 2, 'title': 'title2', 'content': 'xyz' }; 10 13 success(function(data) {
$scope.cards[2] = { 'id': 2, 'title': 'title3', 'content': 'qwe' }; 11 14 for (var i = 0; i < data.length; i++) {
15 cards.push({'title': data[i].title, 'content': data[i].content});
16 }
17 }).
18 error(function(err) {
19 console.log('no');
20 });
12 21
$http.get('/api/sections/{pk}/flashcards'). 13
success(function(data) { 14
for (var i = 0; i < data.length; i++) { 15
cards.push({ 'title': data[i].title, 'content': data[i].content }); 16
} 17
}). 18
error(function(err) { 19
console.log('no'); 20
}); 21
22
$scope.viewDeck = function() { 23 22 $scope.viewDeck = function() {
$state.go('deck'); 24 23 $state.go('deck');
console.log('go to deck'); 25 24 console.log('go to deck');
}; 26 25 };
27 26
$scope.pullCard = function(card) { 28 27 $scope.pullCard = function(card) {
var index = $scope.cards.indexOf(card); 29 28 var index = $scope.cards.indexOf(card);
30 29
console.log($scope.cards[index]); 31 30 console.log($scope.cards[index]);
}; 32 31 };
33 32
$scope.pushCard = function() { 34 33 $scope.pushCard = function() {
console.log('make! card content:' + $scope.text); 35 34 console.log('make! card content:' + $scope.text);
var pushed = new Date(Date.now()); 36 35 var pushed = new Date(Date.now());
console.log(pushed.toString()); 37 36 console.log(pushed.toString());
38 37
// attempt to make card :( 39 38 // attempt to make card :(
$http.post('/api/flashcards/', {'text': $scope.text, 'pushed': pushed, 'mask': []}). 40 39 $http.post('/api/flashcards/', {'text': $scope.text, 'pushed': pushed, 'mask': []}).
success(function(data) { 41 40 success(function(data) {
console.log('No way, really?'); 42 41 console.log('No way, really?');
}). 43 42 }).
error(function(error) { 44 43 error(function(error) {
console.log('haha, n00b'); 45 44 console.log('haha, n00b');
}); 46 45 });
47 46
$scope.text = ''; 48 47 $scope.text = '';
}; 49 48 };
50 49
$scope.flashcard = 'hi i am a flashcard. I need to be really long and awesome I ain\'t know how long I am right now. Is it good enough now?????????? Howz about now???'; 51 50 $scope.flashcard = 'hi i am a flashcard. I need to be really long and awesome I ain\'t ' +
51 'know how long I am right now. Is it good enough now?????????? Howz about now???';
$scope.text = ''; 52 52 $scope.text = '';
53 53
$(document).ready(function() { 54 54 $(document).ready(function() {
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered 55 55 // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
$('.modal-trigger').leanModal({ 56 56 $('.modal-trigger').leanModal({
dismissible: true, // Modal can be dismissed by clicking outside of the modal 57 57 dismissible: true, // Modal can be dismissed by clicking outside of the modal
opacity: 0, // Opacity of modal background 58 58 opacity: 0, // Opacity of modal background
in_duration: 300, // Transition in duration 59 59 in_duration: 300, // Transition in duration
out_duration: 200, // Transition out duration 60 60 out_duration: 200, // Transition out duration
/*ready: function() { alert('Ready'); }, // Callback for Modal open 61 61 /*ready: function() { alert('Ready'); }, // Callback for Modal open
complete: function() { alert('Closed'); } // Callback for Modal close*/ 62 62 complete: function() { alert('Closed'); } // Callback for Modal close*/
} 63 63 }
); 64 64 );
}); 65 65 });
66 66
}]); 67 67 }]);
68 68
scripts/RequestResetController.js View file @ 8fa323e
angular.module('flashy.RequestResetController', ['ui.router']) 1 1 angular.module('flashy.RequestResetController', ['ui.router'])
2 2
.controller('RequestResetController', ['$scope', '$state', '$http', 3 3 .controller('RequestResetController', ['$scope', '$state', '$http',
function($scope, $state, $http) { 4 4 function($scope, $state, $http) {
'use strict'; 5 5 'use strict';
$scope.success = false; 6 6 $scope.success = false;
$scope.error = false; 7 7 $scope.error = false;
$scope.resetPass = function(email) { 8 8 $scope.resetPass = function(email) {
$http.post('/api/request_password_reset', JSON.stringify({ 9 9 $http.post('/api/request_password_reset/', JSON.stringify({
'email': email 10 10 'email': email
})) 11 11 }))
.success(function(data) { 12 12 .success(function(data) {
$scope.success = true; 13 13 $scope.success = true;
//$state.go('requestresetsuccess'); 14 14 //$state.go('requestresetsuccess');
console.log('SUCCESS'); 15 15 console.log('SUCCESS');
console.log(data); 16 16 console.log(data);
}) 17 17 })
.error(function(data, status, header, config) { 18 18 .error(function(data, status, header, config) {
if (data.email) { 19 19 if (data.email) {
$scope.error = true; 20 20 $scope.error = true;
} 21 21 }
console.log('ERROR'); 22 22 console.log('ERROR');
console.log(data); 23 23 console.log(data);
}); 24 24 });
}; 25 25 };
$scope.cancelReset = function() { 26 26 $scope.cancelReset = function() {
$state.go('login'); 27 27 $state.go('login');
}; 28 28 };
} 29 29 }
]); 30 30 ]);
scripts/ResetPasswordController.js View file @ 8fa323e
angular.module('flashy.ResetPasswordController', ['ui.router']). 1 1 angular.module('flashy.ResetPasswordController', ['ui.router']).
2 2
controller('ResetPasswordController', ['$scope', '$state', '$http', '$timeout', 3 3 controller('ResetPasswordController', ['$scope', '$state', '$http', '$timeout',
function($scope, $state, $http, $timeout) { 4 4 function($scope, $state, $http, $timeout) {
'use strict'; 5 5 'use strict';
var url = document.location.href.split('/'); 6 6 var url = document.location.href.split('/');
var token = url[url.length - 1]; 7 7 var token = url[url.length - 1];
var uid = url[url.length - 2]; 8 8 var uid = url[url.length - 2];
$scope.error = false; 9 9 $scope.error = false;
$scope.success = false; 10 10 $scope.success = false;
$scope.mismatch = false; 11 11 $scope.mismatch = false;
$scope.unacceptable = false; 12 12 $scope.unacceptable = false;
/*if(token == 'resetpassword') { 13 13 /*if(token == 'resetpassword') {
$state.go('login'); 14 14 $state.go('login');
}*/ 15 15 }*/
console.log('RESETTING'); 16 16 console.log('RESETTING');
$scope.confirmResetPass = function() { 17 17 $scope.confirmResetPass = function() {
if ($scope.newPassword.length < 8) { 18 18 if ($scope.newPassword.length < 8) {
$scope.unacceptable = true; 19 19 $scope.unacceptable = true;
return; 20 20 return;
} 21 21 }
if ($scope.newPassword != $scope.confirmPassword) { 22 22 if ($scope.newPassword != $scope.confirmPassword) {
$scope.mismatch = true; 23 23 $scope.mismatch = true;
$scope.confirmPassword.$setPristine(); 24 24 $scope.confirmPassword.$setPristine();
console.log('mismatch'); 25 25 console.log('mismatch');
return; 26 26 return;
} 27 27 }
$http.post('/api/reset_password', JSON.stringify({ 28 28 $http.post('/api/reset_password/', JSON.stringify({
'uid': uid, 29 29 'uid': uid,
'token': token, 30 30 'token': token,
'new_password': $scope.newPassword 31 31 'new_password': $scope.newPassword
})) 32 32 }))
.success(function(data) { 33 33 .success(function(data) {
$scope.error = false; 34 34 $scope.error = false;
$scope.success = true; 35 35 $scope.success = true;
//$state.go('resetpasssuccess'); 36 36 //$state.go('resetpasssuccess');
$timeout(function($state) { 37 37 $timeout(function($state) {
$state.go('login'); 38 38 $state.go('login');
}, 1000); 39 39 }, 1000);
console.log(data); 40 40 console.log(data);
}) 41 41 })
.error(function(data, status, header, config) { 42 42 .error(function(data, status, header, config) {
$scope.error = true; 43 43 $scope.error = true;
$scope.success = false; 44 44 $scope.success = false;
$scope.mismatch = false; 45 45 $scope.mismatch = false;
$scope.unacceptable = false; 46 46 $scope.unacceptable = false;
console.log(data); 47 47 console.log(data);
}); 48 48 });
}; 49 49 };
$scope.cancelReset = function() { 50 50 $scope.cancelReset = function() {
$state.go('login'); 51 51 $state.go('login');
}; 52 52 };
} 53 53 }
]); 54 54 ]);
scripts/RootController.js View file @ 8fa323e
angular.module('flashy.RootController', ['ui.router']). 1 1 angular.module('flashy.RootController', ['ui.router']).
2 2
controller('RootController', ['$rootScope', '$scope', '$state', 'UserService', function($rootScope, $scope, $state, UserService) { 3 3 controller('RootController', ['$rootScope', '$scope', '$state', 'UserService', function($rootScope, $scope, $state, UserService) {
//UserService.getUserData(); 4 4 //UserService.getUserData();
//$('#top').collapsible('accordion'); 5 5 //$('#top').collapsible('accordion');
if (UserService.isLoggedIn()) $state.go('login'); 6 6 if (UserService.isLoggedIn()) $state.go('login');
else $state.go('addclass'); 7 7 else $state.go('addclass');
8 $rootScope.isLoggedIn = false;
scripts/UserService.js View file @ 8fa323e
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 _user = undefined;
this.getUserData = function() { 4 4 this.getUserData = function() {
var deferred = $q.defer(); 5 5 var deferred = $q.defer();
if (angular.isDefined(_user)) { 6 6 if (angular.isDefined(_user)) {
console.log('user is already defined: ' + _user); 7 7 console.log('user is already defined: ' + _user);
if (!_user) deferred.reject(_user); 8 8 if (!_user) {
deferred.resolve(_user); 9 9 console.log('rejecting deferred');
10 deferred.reject(_user);
11 } else {
12 $rootScope.isLoggedIn = true;
13 deferred.resolve(_user);
14 }
return deferred.promise; 10 15 return deferred.promise;
} 11 16 }
$http.get('/api/me/').success(function(data) { 12 17 $http.get('/api/me/').success(function(data) {
console.log('user is logged in!'); 13 18 console.log('user is logged in!');
_user = data; 14 19 _user = data;
20 $rootScope.isLoggedIn = true;
deferred.resolve(data); 15 21 deferred.resolve(data);
}).error(function(data) { 16 22 }).error(function(data) {
23 console.log('not logged in yet: ' + data.detail);
deferred.reject('error getting own data'); 17 24 deferred.reject('error getting own data');
_user = false; 18 25 _user = false;
console.log(data); 19
}); 20 26 });
return deferred.promise; 21 27 return deferred.promise;
}; 22 28 };
this.setUserData = function(data) { 23 29 this.setUserData = function(data) {
_user = data; 24 30 _user = data;
}; 25 31 };
this.isUserResolved = function() { 26 32 this.isUserResolved = function() {
return angular.isDefined(_user); 27 33 return angular.isDefined(_user);
}; 28 34 };
this.logout = function() { 29 35 this.logout = function() {
36 $rootScope.isLoggedIn = false;
_user = undefined; 30 37 _user = undefined;
}; 31 38 };
this.isLoggedIn = function() { 32 39 this.isLoggedIn = function() {
rv = this.isUserResolved() && _user; 33 40 rv = this.isUserResolved() && _user;
console.log('is user logged in? ' + rv); 34 41 console.log('is user logged in? ' + rv);
return rv; 35 42 return rv;
}; 36 43 };
}); 37 44 });
38 45
scripts/VerifyEmailController.js View file @ 8fa323e
angular.module('flashy.VerifyEmailController', ['ui.router']) 1 1 angular.module('flashy.VerifyEmailController', ['ui.router'])
2 2
.controller('VerifyEmailController', ['$scope', '$state', '$http', '$timeout', 3 3 .controller('VerifyEmailController', ['$scope', '$state', '$http', '$timeout',
function($scope, $state, $http, $timeout) { 4 4 function($scope, $state, $http, $timeout) {
'use strict'; 5 5 'use strict';
var url = document.location.href.split('/'); 6 6 var url = document.location.href.split('/');
var key = url[url.length - 1]; 7 7 var key = url[url.length - 1];
$scope.success = false; 8 8 $scope.success = false;
$scope.error = false; 9 9 $scope.error = false;
10 10
$http.patch('/api/me', JSON.stringify({ 11 11 $http.patch('/api/me/', JSON.stringify({
'confirmation_key': key 12 12 'confirmation_key': key
})) 13 13 }))
.success(function(data) { 14 14 .success(function(data) {
$scope.success = true; 15 15 $scope.success = true;
console.log('SUCCESS'); 16 16 console.log('SUCCESS');
console.log(data); 17 17 console.log(data);
$timeout(function($state) { 18 18 $timeout(function($state) {
$state.go('feed'); 19 19 $state.go('feed');
}, 2000); 20 20 }, 2000);
}) 21 21 })
.error(function(data, status, header, config) { 22 22 .error(function(data, status, header, config) {
$scope.error = true; 23 23 $scope.error = true;
console.log('ERROR'); 24 24 console.log('ERROR');
console.log(data); 25 25 console.log(data);
}); 26 26 });
} 27 27 }
]); 28 28 ]);
29 29