Commit cf476b03e519eab86a15b6171c7f1dc6ac4603f4
1 parent
7a53b3daec
Exists in
master
and in
1 other branch
properly check whether a user can go straight to a class
Showing 3 changed files with 30 additions and 29 deletions Side-by-side Diff
config.js
View file @
cf476b0
... | ... | @@ -60,7 +60,7 @@ |
60 | 60 | console.log('no auth required for', $rootScope.nextState.name); |
61 | 61 | return UserService.getUserData(); |
62 | 62 | } |
63 | - console.log('resolving user before continuing for ' + $state.name); | |
63 | + console.log('resolving user before continuing to ' + $rootScope.nextState.name); | |
64 | 64 | var redirectAsNeeded = function() { |
65 | 65 | if (!UserService.isLoggedIn()) { |
66 | 66 | console.log(UserService.getUserData()); |
scripts/FeedController.js
View file @
cf476b0
1 | 1 | angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket', 'contenteditable']). |
2 | 2 | |
3 | - controller('FeedController', function ($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService) { | |
3 | + controller('FeedController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService) { | |
4 | 4 | angular.module('flashy.CardGridController').controller.apply(this, arguments); |
5 | 5 | console.log('Hello from feed'); |
6 | 6 | |
7 | - $scope.refreshCards = function () { | |
7 | + $scope.refreshCards = function() { | |
8 | 8 | $http.get('/api/sections/' + $scope.sectionId + '/feed/'). |
9 | - success(function (data) { | |
9 | + success(function(data) { | |
10 | 10 | console.log(data); |
11 | 11 | $scope.cards = data; |
12 | 12 | $scope.refreshLayout(); |
13 | 13 | console.log('success in refresh cards...'); |
14 | 14 | }). |
15 | - error(function (err) { | |
15 | + error(function(err) { | |
16 | 16 | console.log('refresh fail'); |
17 | 17 | console.log(err); |
18 | 18 | }); |
19 | 19 | }; |
20 | 20 | |
21 | - $scope.sortAdd = function (card, array) { | |
21 | + $scope.sortAdd = function(card, array) { | |
22 | 22 | console.log('sort add'); |
23 | - array.forEach(function (ele, i, ary) { | |
23 | + array.forEach(function(ele, i, ary) { | |
24 | 24 | if (ele.score <= card.score) { |
25 | 25 | ary.splice(i, 0, card); |
26 | 26 | return; |
... | ... | @@ -28,7 +28,7 @@ |
28 | 28 | }); |
29 | 29 | }; |
30 | 30 | |
31 | - $scope.hide = function (card) { | |
31 | + $scope.hide = function(card) { | |
32 | 32 | console.log('hiding card'); |
33 | 33 | var found = -1; |
34 | 34 | col = $scope.cardTable[card.id].colNum; |
... | ... | @@ -43,7 +43,7 @@ |
43 | 43 | return -1; |
44 | 44 | }; |
45 | 45 | |
46 | - $scope.update = function (id, new_score) { | |
46 | + $scope.update = function(id, new_score) { | |
47 | 47 | card = $scope.cardTable[id].obj; |
48 | 48 | if (Math.abs(new_score - card.score) < .0001) { |
49 | 49 | console.log('score same, no update required'); |
50 | 50 | |
... | ... | @@ -65,11 +65,11 @@ |
65 | 65 | }; |
66 | 66 | |
67 | 67 | $scope.feed_ws = $websocket($scope.ws_host + '/ws/feed/' + $scope.sectionId + '?subscribe-broadcast'); |
68 | - $scope.feed_ws.onOpen(function () { | |
68 | + $scope.feed_ws.onOpen(function() { | |
69 | 69 | console.log('deck ws open'); |
70 | 70 | }); |
71 | 71 | |
72 | - $scope.feed_ws.onMessage(function (e) { | |
72 | + $scope.feed_ws.onMessage(function(e) { | |
73 | 73 | data = JSON.parse(e.data); |
74 | 74 | console.log('got websocket message ' + e.data); |
75 | 75 | console.log(data); |
... | ... | @@ -80,7 +80,7 @@ |
80 | 80 | } |
81 | 81 | }); |
82 | 82 | |
83 | - $scope.pushCard = function () { | |
83 | + $scope.pushCard = function() { | |
84 | 84 | var myCard = { |
85 | 85 | // we can't trim this string because it'd mess up the blanks. Something to fix. |
86 | 86 | 'text': $('#new-card-input').text(), |
87 | 87 | |
... | ... | @@ -92,13 +92,13 @@ |
92 | 92 | return closeNewCard(); |
93 | 93 | } |
94 | 94 | $http.post('/api/flashcards/', myCard). |
95 | - success(function (data) { | |
95 | + success(function(data) { | |
96 | 96 | console.log('flashcard pushed: ' + myCard.text); |
97 | 97 | if (!UserService.hasVerifiedEmail()) { |
98 | 98 | Materialize.toast("<p>Thanks for contributing! However, others won't see your card until you verify your email address<p>", 4000); |
99 | 99 | } |
100 | 100 | }). |
101 | - error(function (error) { | |
101 | + error(function(error) { | |
102 | 102 | console.log('something went wrong pushing a card!'); |
103 | 103 | }); |
104 | 104 | return $scope.closeNewCardModal(); |
105 | 105 | |
... | ... | @@ -115,13 +115,13 @@ |
115 | 115 | opacity: 0, // Opacity of modal background |
116 | 116 | in_duration: 300, // Transition in duration |
117 | 117 | out_duration: 200, // Transition out duration |
118 | - ready: function () { | |
118 | + ready: function() { | |
119 | 119 | $('#new-card-input').focus(); |
120 | 120 | document.execCommand('selectAll', false, null); |
121 | 121 | } |
122 | 122 | }; |
123 | 123 | |
124 | - $(document).keydown(function (e) { | |
124 | + $(document).keydown(function(e) { | |
125 | 125 | var keyed = e.which; |
126 | 126 | if (keyed == 67 && listenForC) { // "c" for compose |
127 | 127 | $scope.openNewCardModal(); |
128 | 128 | |
... | ... | @@ -132,13 +132,13 @@ |
132 | 132 | } |
133 | 133 | }); |
134 | 134 | |
135 | - $scope.openNewCardModal = function () { | |
135 | + $scope.openNewCardModal = function() { | |
136 | 136 | $('#newCard').openModal(modal_options); |
137 | 137 | listenForC = false; |
138 | 138 | $('#new-card-input').html('Write a flashcard!'); |
139 | 139 | }; |
140 | 140 | |
141 | - $scope.closeNewCardModal = function () { | |
141 | + $scope.closeNewCardModal = function() { | |
142 | 142 | listenForC = true; |
143 | 143 | $('#new-card-input').html('').blur(); |
144 | 144 | $('#newCard').closeModal(modal_options); |
... | ... | @@ -147,7 +147,7 @@ |
147 | 147 | $('.tooltipped').tooltip({delay: 50}); |
148 | 148 | // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered |
149 | 149 | $('.modal-trigger').leanModal(modal_options); |
150 | - $('#new-card-input').on('keydown', function (e) { | |
150 | + $('#new-card-input').on('keydown', function(e) { | |
151 | 151 | if (e.which == 13) { |
152 | 152 | e.preventDefault(); |
153 | 153 | $scope.pushCard(); |
154 | 154 | |
155 | 155 | |
... | ... | @@ -157,17 +157,17 @@ |
157 | 157 | |
158 | 158 | } |
159 | 159 | }); |
160 | - $('button#blank-selected').click(function () { | |
160 | + $('button#blank-selected').click(function() { | |
161 | 161 | console.log(window.getSelection()); |
162 | 162 | document.execCommand('bold'); |
163 | 163 | }); |
164 | 164 | $scope.refreshCards(); |
165 | 165 | $scope.newCardBlanks = []; |
166 | - $scope.refreshNewCardInput = function () { | |
166 | + $scope.refreshNewCardInput = function() { | |
167 | 167 | $scope.newCardText = $('#new-card-input').text(); |
168 | 168 | $scope.submit_enabled = $scope.newCardText.length >= 5 && $scope.newCardText.length <= 160; |
169 | 169 | var i = 0; |
170 | - $('#new-card-input')[0].childNodes.forEach(function (node) { | |
170 | + $('#new-card-input')[0].childNodes.forEach(function(node) { | |
171 | 171 | if (typeof node.data == 'undefined') { |
172 | 172 | console.log('undefined node'); |
173 | 173 | } |
174 | 174 | |
... | ... | @@ -189,12 +189,12 @@ |
189 | 189 | i += node.data.length; |
190 | 190 | } |
191 | 191 | }); |
192 | - $scope.newCardBlanks.sort(function (a, b) { | |
192 | + $scope.newCardBlanks.sort(function(a, b) { | |
193 | 193 | return a[0] - b[0]; |
194 | 194 | }); |
195 | 195 | var i = 0; |
196 | 196 | newtext = ''; |
197 | - $scope.newCardBlanks.forEach(function (blank) { | |
197 | + $scope.newCardBlanks.forEach(function(blank) { | |
198 | 198 | newtext += $scope.newCardText.slice(i, blank[0]); |
199 | 199 | newtext += '<b>' + $scope.newCardText.slice(blank[0], blank[1]) + '</b>'; |
200 | 200 | i = blank[1]; |
201 | 201 | |
... | ... | @@ -202,15 +202,15 @@ |
202 | 202 | newtext += $scope.newCardText.slice(i); |
203 | 203 | //$scope.newCardFormattedText = newtext; |
204 | 204 | }; |
205 | - $scope.shuffleCards = function () { | |
206 | - $timeout(function () { | |
207 | - (function (o) { | |
205 | + $scope.shuffleCards = function() { | |
206 | + $timeout(function() { | |
207 | + (function(o) { | |
208 | 208 | for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); |
209 | 209 | return o; |
210 | 210 | })($scope.cardCols[0]); |
211 | 211 | }); |
212 | 212 | }; |
213 | - $scope.$on('$destroy', function () { | |
213 | + $scope.$on('$destroy', function() { | |
214 | 214 | $scope.feed_ws.close(); |
215 | 215 | }); |
216 | 216 | }); |
scripts/UserService.js
View file @
cf476b0
... | ... | @@ -75,7 +75,8 @@ |
75 | 75 | }; |
76 | 76 | this.authorizedFor = function(state, stateParams) { |
77 | 77 | if (['feed', 'deck', 'cardlist'].indexOf(state.name) >= 0) { |
78 | - if (_user.sectionIdList.indexOf(stateParams.sectionId) < 0) { | |
78 | + console.log('checking whether', stateParams, 'in', _user.sectionIdList); | |
79 | + if (_user.sectionIdList.indexOf(parseInt(stateParams.sectionId)) < 0) { | |
79 | 80 | return false; |
80 | 81 | } |
81 | 82 | } |