Commit 0aff91dfe2aacddf5aa14b3be89ce1dc7e4bb92c
Exists in
master
and in
1 other branch
Merge branch 'master' of https://git.ucsd.edu/110swag/flashy-frontend
Showing 15 changed files Side-by-side Diff
- config.js
- home.html
- login_test.js
- scripts/CardGridController.js
- scripts/CardListController.js
- scripts/DeckController.js
- scripts/DeckFactory.js
- scripts/FeedController.js
- scripts/FlashcardFactory.js
- scripts/RootController.js
- scripts/StudyController.js
- ss_test.js
- styles/flashy.css
- templates/cardlist.html
- templates/study.html
config.js
View file @
0aff91d
home.html
View file @
0aff91d
login_test.js
View file @
0aff91d
scripts/CardGridController.js
View file @
0aff91d
1 | -angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSocket']).CardGridController = | |
2 | - function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, $interval, UserService, Flashcard) { | |
1 | +angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSocket', 'flashy.DeckFactory']).CardGridController = | |
2 | + function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, $interval, UserService, Flashcard, Deck) { | |
3 | + sectionId = parseInt($stateParams.sectionId); | |
3 | 4 | $scope.cards = []; // all cards |
4 | - $scope.deck = []; | |
5 | 5 | $scope.cardCols = []; // organized data |
6 | - $scope.cardColsShow = []; // displayed data | |
6 | + $scope.cardColsShow = []; // displayed data | |
7 | 7 | $scope.numCols = 0; |
8 | - $scope.cardTable = {}; // look up table of cards: {'colNum':col, 'obj':card} | |
9 | - $scope.sectionId = parseInt($stateParams.sectionId); | |
10 | - $scope.section = $rootScope.SectionResource.get({sectionId: $scope.sectionId}); | |
8 | + $scope.section = $rootScope.SectionResource.get({sectionId: sectionId}); | |
9 | + $scope.deck = new Deck(sectionId, { | |
10 | + cardHideCallback: function(card) { | |
11 | + $scope.hideCardFromGrid(card); | |
12 | + } | |
13 | + }); | |
14 | + | |
11 | 15 | $scope.showGrid = false; |
12 | 16 | //$scope.moveQueue = []; // queue of flashcard objects |
13 | 17 | $rootScope.currentSection = $scope.section; |
14 | 18 | |
15 | - if (!UserService.isInSection($scope.sectionId)) { | |
16 | - console.log('user is not enrolled in ' + $scope.sectionId); | |
17 | - $state.go('addclass'); | |
18 | - } | |
19 | - | |
20 | 19 | $scope.refreshColumnWidth = function() { |
21 | 20 | avail = $window.innerWidth - 17; |
22 | 21 | width = Math.floor(avail / Math.floor(avail / 250)); |
... | ... | @@ -55,32 +54,6 @@ |
55 | 54 | |
56 | 55 | angular.element($window).bind('resize', $scope.refreshLayout); |
57 | 56 | |
58 | - $scope.ws_host = window.location.origin.replace('http', 'ws'); | |
59 | - $scope.deck_ws = $websocket($scope.ws_host + '/ws/deck/' + $scope.sectionId + '?subscribe-user'); | |
60 | - $scope.deck_ws.onOpen(function() { | |
61 | - console.log('deck ws open'); | |
62 | - }); | |
63 | - | |
64 | - $scope.deck_ws.onMessage(function(message) { | |
65 | - data = JSON.parse(message.data); | |
66 | - console.log('message', data); | |
67 | - card = new Flashcard(data.flashcard); | |
68 | - if (data.event_type == 'card_pulled') { | |
69 | - $scope.deck[card.id] = card; | |
70 | - if ($scope.deckPullCallback) $scope.deckPullCallback(card); | |
71 | - } | |
72 | - if (data.event_type == 'card_unpulled') { | |
73 | - $scope.deck[card.id] = undefined; | |
74 | - if ($scope.deckUnpullCallback) $scope.deckUnpullCallback(card); | |
75 | - } | |
76 | - if (data.event_type == 'card_hidden') { | |
77 | - $scope.hideCardFromGrid(card); | |
78 | - } | |
79 | - }); | |
80 | - | |
81 | - $scope.cardInDeck = function(id) { | |
82 | - return $scope.deck[id]; | |
83 | - }; | |
84 | 57 | $scope.addCardToGrid = function(card) { |
85 | 58 | var colNum = 0; |
86 | 59 | var lowestCol = $scope.cardCols[0]; |
87 | 60 | |
... | ... | @@ -118,14 +91,11 @@ |
118 | 91 | }; |
119 | 92 | |
120 | 93 | $scope.$on('$destroy', function() { |
121 | - $scope.deck_ws.close(); | |
94 | + $scope.deck.cleanup(); | |
95 | + Flashcard.cleanup(); | |
122 | 96 | $rootScope.currentSection = {}; |
123 | 97 | $(document).off('keydown'); |
124 | 98 | }); |
125 | - return $http.get('/api/sections/' + $scope.sectionId + '/deck/'). | |
126 | - success(function(data) { | |
127 | - for (i in data) $scope.deck[data[i].id] = new Flashcard(data[i], $scope.deck); | |
128 | - console.log("got user's deck", data); | |
129 | - }); | |
99 | + return $scope.deck.deckPromise; | |
130 | 100 | }; |
scripts/CardListController.js
View file @
0aff91d
1 | -angular.module('flashy.CardListController', ['ui.router', 'angular.filter', 'ngSanitize']). | |
2 | - controller('CardListController', function($scope, $rootScope, $state, $http, $stateParams) { | |
1 | +angular.module('flashy.CardListController', ['ui.router', 'angular.filter', 'ngSanitize', 'flashy.DeckFactory']). | |
2 | + controller('CardListController', function($scope, $rootScope, $state, $http, $stateParams, Flashcard, Deck) { | |
3 | 3 | // cards array |
4 | - sectionId = $stateParams.sectionId; | |
4 | + sectionId = parseInt($stateParams.sectionId); | |
5 | + $scope.deck = new Deck(sectionId, { | |
6 | + cardPullCallback: function(card) { | |
7 | + Materialize.toast('Pulled!', 3000); | |
8 | + }, | |
9 | + cardUnpullCallback: function(card) { | |
10 | + Materialize.toast('Unpulled!', 3000); | |
11 | + }, | |
12 | + cardHideCallback: function(card) { | |
13 | + card.is_hidden = true; | |
14 | + Materialize.toast('Hidden!', 3000); | |
15 | + }, | |
16 | + cardUnhideCallback: function(card) { | |
17 | + card.is_hidden = false; | |
18 | + Materialize.toast('Unhidden!', 3000); | |
19 | + } | |
20 | + }); | |
5 | 21 | $rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId}); |
6 | 22 | $scope.cards = []; |
7 | 23 | |
8 | 24 | $http.get('/api/sections/' + sectionId + '/flashcards/?hidden=yes'). |
9 | 25 | success(function(data) { |
10 | - $scope.cards = data; | |
26 | + for (i in data) $scope.cards[data[i].id] = new Flashcard(data[i], $scope.deck); | |
11 | 27 | }). |
12 | 28 | error(function(err) { |
13 | 29 | console.log('pulling feed failed'); |
14 | 30 | }); |
15 | 31 | |
16 | - $scope.viewFeed = function() { | |
17 | - $state.go('feed', {sectionId: sectionId}); | |
18 | - console.log('go to feed'); | |
19 | - }; | |
20 | - | |
21 | - | |
22 | - // unhide card | |
23 | - $scope.unhide = function(card) { | |
24 | - $http.post('/api/flashcards/' + card.id + '/unhide/'). | |
25 | - success(function(data) { | |
26 | - console.log(card.text + ' unhidden'); | |
27 | - | |
28 | - // locally change hidden | |
29 | - card.is_hidden = false; | |
30 | - Materialize.toast('Unhidden', 3000, 'rounded'); | |
31 | - }). | |
32 | - error(function(err) { | |
33 | - console.log('no unhide for you'); | |
34 | - }); | |
35 | - }; | |
36 | - | |
37 | - // hide card | |
38 | - $scope.hide = function(card) { | |
39 | - $http.post('/api/flashcards/' + card.id + '/hide/'). | |
40 | - success(function(data) { | |
41 | - console.log(card.text + ' hidden'); | |
42 | - | |
43 | - // locally change hidden | |
44 | - card.is_hidden = true; | |
45 | - Materialize.toast('Hidden', 3000, 'rounded'); | |
46 | - }). | |
47 | - error(function(err) { | |
48 | - console.log('no hide for you'); | |
49 | - }); | |
50 | - }; | |
51 | - | |
52 | - // pull card | |
53 | - $scope.pull = function(card) { | |
54 | - $http.post('/api/flashcards/' + card.id + '/pull/'). | |
55 | - success(function(data) { | |
56 | - console.log(card.text + ' pulled'); | |
57 | - | |
58 | - // locally change boolean for display purposes | |
59 | - card.is_in_deck = true; | |
60 | - Materialize.toast('Added to Your Deck', 3000, 'rounded'); | |
61 | - }). | |
62 | - error(function(err) { | |
63 | - console.log('no pull for you'); | |
64 | - }); | |
65 | - }; | |
66 | - | |
67 | - // unpull card | |
68 | - $scope.unpull = function(card) { | |
69 | - $http.post('/api/flashcards/' + card.id + '/unpull/'). | |
70 | - success(function(data) { | |
71 | - console.log(card.text + ' unpulled'); | |
72 | - | |
73 | - // local change for display purposes | |
74 | - card.is_in_deck = false; | |
75 | - Materialize.toast('Removed from Your Deck', 3000, 'rounded'); | |
76 | - }). | |
77 | - error(function(err) { | |
78 | - console.log('no unpull for you'); | |
79 | - }); | |
80 | - }; | |
81 | - | |
82 | 32 | // flag/report card |
83 | 33 | $scope.flag = function(card) { |
84 | 34 | $http.post('/api/flashcards/' + card.id + '/report/'). |
85 | 35 | success(function(data) { |
86 | 36 | console.log(card.text + ' reported'); |
87 | - | |
88 | - // local change for display purposes | |
89 | - Materialize.toast('Card Flagged', 3000, 'rounded'); | |
90 | 37 | }). |
91 | 38 | error(function(err) { |
92 | 39 | console.log('no flag for you'); |
93 | 40 | |
94 | 41 | |
95 | 42 | |
96 | 43 | |
97 | 44 | |
98 | 45 | |
99 | 46 | |
100 | 47 | |
... | ... | @@ -130,76 +77,65 @@ |
130 | 77 | |
131 | 78 | // to display day of the week badges |
132 | 79 | $scope.dayofweek = function(item) { |
133 | - var date = new Date(item.material_date); | |
134 | - switch (date.getDay()) { | |
135 | - case 0: | |
136 | - return 'U'; | |
137 | - case 1: | |
138 | - return 'M'; | |
139 | - case 2: | |
140 | - return 'T'; | |
141 | - case 3: | |
142 | - return 'W'; | |
143 | - case 4: | |
144 | - return 'R'; | |
145 | - case 5: | |
146 | - return 'F'; | |
147 | - case 6: | |
148 | - return 'S'; | |
149 | - } | |
80 | + var date = new Date(item.material_date); | |
81 | + return ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][date.getDay()]; | |
150 | 82 | }; |
151 | 83 | |
152 | 84 | // checkbox filter |
153 | 85 | $scope.filter = { |
154 | - 'week1': true, | |
155 | - 'week2': true, | |
156 | - 'week3': true, | |
157 | - 'week4': true, | |
158 | - 'week5': true, | |
159 | - 'week6': true, | |
160 | - 'week7': true, | |
161 | - 'week8': true, | |
162 | - 'week9': true, | |
163 | - 'week10': true, | |
86 | + 'week1': true, | |
87 | + 'week2': true, | |
88 | + 'week3': true, | |
89 | + 'week4': true, | |
90 | + 'week5': true, | |
91 | + 'week6': true, | |
92 | + 'week7': true, | |
93 | + 'week8': true, | |
94 | + 'week9': true, | |
95 | + 'week10': true, | |
164 | 96 | }; |
165 | 97 | |
166 | 98 | $scope.filterByDate = function(item) { |
167 | - var week = item.material_week_num; | |
168 | - return (week == 1 && $scope.filter['week1']) || | |
169 | - (week == 2 && $scope.filter['week2']) || | |
170 | - (week == 3 && $scope.filter['week3']) || | |
171 | - (week == 4 && $scope.filter['week4']) || | |
172 | - (week == 5 && $scope.filter['week5']) || | |
173 | - (week == 6 && $scope.filter['week6']) || | |
174 | - (week == 7 && $scope.filter['week7']) || | |
175 | - (week == 8 && $scope.filter['week8']) || | |
176 | - (week == 9 && $scope.filter['week9']) || | |
177 | - (week == 10 && $scope.filter['week10']); | |
99 | + var week = item.material_week_num; | |
100 | + return (week == 1 && $scope.filter['week1']) || | |
101 | + (week == 2 && $scope.filter['week2']) || | |
102 | + (week == 3 && $scope.filter['week3']) || | |
103 | + (week == 4 && $scope.filter['week4']) || | |
104 | + (week == 5 && $scope.filter['week5']) || | |
105 | + (week == 6 && $scope.filter['week6']) || | |
106 | + (week == 7 && $scope.filter['week7']) || | |
107 | + (week == 8 && $scope.filter['week8']) || | |
108 | + (week == 9 && $scope.filter['week9']) || | |
109 | + (week == 10 && $scope.filter['week10']); | |
178 | 110 | }; |
111 | + $scope.$on('$destroy', function() { | |
112 | + $scope.deck.cleanup(); | |
113 | + Flashcard.cleanup(); | |
114 | + }); | |
179 | 115 | |
180 | 116 | } |
181 | 117 | ). |
182 | -filter('displayCard', function($sce) { | |
183 | - return function(card) { | |
184 | - // text to display as html | |
185 | - var cardText = ''; | |
118 | + filter('displayCard', function($sce) { | |
119 | + return function(card) { | |
120 | + // text to display as html | |
121 | + var cardText = ''; | |
186 | 122 | |
187 | - var start = 0; // where to start next string break | |
123 | + var start = 0; // where to start next string break | |
188 | 124 | |
189 | - // get all display pieces and blank pieces | |
190 | - for (var i = 0; i < card.mask.length; i++) { | |
191 | - cardText = cardText.concat(card.text.substring(start, card.mask[i][0])); | |
192 | - cardText = cardText.concat('<b>'); | |
193 | - cardText = cardText.concat(card.text.substring(card.mask[i][0], card.mask[i][1])); | |
194 | - cardText = cardText.concat('</b>'); | |
195 | - start = card.mask[i][1]; | |
196 | - } | |
125 | + // get all display pieces and blank pieces | |
126 | + for (var i = 0; i < card.mask.length; i++) { | |
127 | + cardText = cardText.concat(card.text.substring(start, card.mask[i][0])); | |
128 | + cardText = cardText.concat('<b>'); | |
129 | + cardText = cardText.concat(card.text.substring(card.mask[i][0], card.mask[i][1])); | |
130 | + cardText = cardText.concat('</b>'); | |
131 | + start = card.mask[i][1]; | |
132 | + } | |
197 | 133 | |
198 | - // get remaining dislay pieces, if any | |
199 | - if (start != card.mask.length - 1) | |
200 | - cardText = cardText.concat(card.text.substring(start)); | |
134 | + // get remaining dislay pieces, if any | |
135 | + if (start != card.mask.length - 1) | |
136 | + cardText = cardText.concat(card.text.substring(start)); | |
201 | 137 | |
202 | - return $sce.trustAsHtml(cardText); | |
203 | - }; | |
204 | -}); | |
138 | + return $sce.trustAsHtml(cardText); | |
139 | + }; | |
140 | + }); |
scripts/DeckController.js
View file @
0aff91d
1 | 1 | angular.module('flashy.DeckController', ['ui.router', 'ngWebSocket']). |
2 | 2 | |
3 | - controller('DeckController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) { | |
3 | + controller('DeckController', | |
4 | + function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, $interval, UserService, Flashcard, Deck) { | |
4 | 5 | angular.module('flashy.CardGridController').CardGridController.apply(this, arguments).then(function() { |
5 | 6 | $scope.refreshLayout(); |
6 | 7 | }); |
7 | - $scope.cards = $scope.deck; | |
8 | + $scope.cards = $scope.deck.cards; | |
8 | 9 | $scope.deckPullCallback = $scope.addCardToGrid; |
9 | 10 | $scope.deckUnpullCallback = $scope.hideCardFromGrid; |
10 | 11 |
scripts/DeckFactory.js
View file @
0aff91d
1 | +angular.module('flashy.DeckFactory', ['ui.router', 'flashy.FlashcardFactory', 'ngWebSocket']). | |
2 | + factory('Deck', function ($http, $rootScope, $state, $websocket, Flashcard, UserService) { | |
3 | + | |
4 | + var Deck = function (sectionId, callbacks) { | |
5 | + if (!UserService.isInSection(sectionId)) { | |
6 | + console.log('user is not enrolled in ' + sectionId); | |
7 | + $state.go('addclass'); | |
8 | + } | |
9 | + obj = this; | |
10 | + this.cards = []; | |
11 | + this.section = $rootScope.SectionResource.get({sectionId: sectionId}); | |
12 | + | |
13 | + this.ws = $websocket($rootScope.ws_host + '/ws/deck/' + sectionId + '?subscribe-user'); | |
14 | + this.contains = function (id) { | |
15 | + return this.cards[id]; | |
16 | + }; | |
17 | + | |
18 | + this.ws.onMessage(function (message) { | |
19 | + data = JSON.parse(message.data); | |
20 | + console.log('message', data); | |
21 | + card = new Flashcard(data.flashcard); | |
22 | + if (data.event_type == 'card_pulled') { | |
23 | + obj.cards[card.id] = card; | |
24 | + if (callbacks.cardPullCallback) callbacks.cardPullCallback(card); | |
25 | + } | |
26 | + if (data.event_type == 'card_unpulled') { | |
27 | + obj.cards[card.id] = undefined; | |
28 | + if (callbacks.cardUnpullCallback) callbacks.cardUnpullCallback(card); | |
29 | + } | |
30 | + if (data.event_type == 'card_hidden') { | |
31 | + if (callbacks.cardHideCallback) callbacks.cardHideCallback(card); | |
32 | + } | |
33 | + if (data.event_type == 'card_unhidden') { | |
34 | + if (callbacks.cardUnhideCallback) callbacks.cardUnhideCallback(card); | |
35 | + } | |
36 | + }); | |
37 | + this.deckPromise = $http.get('/api/sections/' + sectionId + '/deck/').success(function (data) { | |
38 | + for (i in data) obj.cards[data[i].id] = new Flashcard(data[i], obj); | |
39 | + console.log("got user's deck", data); | |
40 | + }); | |
41 | + this.cleanup = function () { | |
42 | + this.ws.close(); | |
43 | + }; | |
44 | + this.forEach = this.cards.forEach; | |
45 | + }; | |
46 | + | |
47 | + return Deck; | |
48 | + }); |
scripts/FeedController.js
View file @
0aff91d
1 | -angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket', 'contenteditable']).controller('FeedController', | |
2 | - function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, $interval, UserService, Flashcard) { | |
1 | +angular.module('flashy.FeedController', | |
2 | + ['ui.router', | |
3 | + 'ngAnimate', | |
4 | + 'ngWebSocket', | |
5 | + 'contenteditable', | |
6 | + 'flashy.DeckFactory']).controller('FeedController', | |
7 | + function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, $interval, UserService, Flashcard, Deck) { | |
3 | 8 | angular.module('flashy.CardGridController').CardGridController.apply(this, arguments); |
4 | 9 | |
5 | - (function drawCols() { | |
6 | - $interval(function() { | |
7 | - if ($scope.cardColsShow != $scope.cardCols) { | |
8 | - $scope.cardColsShow = $scope.cardCols; | |
9 | - console.log('interval'); | |
10 | - } | |
11 | - }, 1000); | |
12 | - }()); | |
10 | + (function drawCols() { | |
11 | + $interval(function() { | |
12 | + if ($scope.cardColsShow != $scope.cardCols) { | |
13 | + $scope.cardColsShow = $scope.cardCols; | |
14 | + console.log('interval'); | |
15 | + } | |
16 | + }, 1000); | |
17 | + }()); | |
13 | 18 | |
14 | 19 | $scope.updateCardScore = function(card) { |
15 | 20 | console.log($scope.cardCols, card); |
... | ... | @@ -21,7 +26,7 @@ |
21 | 26 | $scope.updateColRanks($scope.cardCols[card.colNum]); |
22 | 27 | }; |
23 | 28 | |
24 | - $scope.feed_ws = $websocket($scope.ws_host + '/ws/feed/' + $scope.sectionId + '?subscribe-broadcast'); | |
29 | + $scope.feed_ws = $websocket($scope.ws_host + '/ws/feed/' + sectionId + '?subscribe-broadcast'); | |
25 | 30 | $scope.feed_ws.onMessage(function(e) { |
26 | 31 | data = JSON.parse(e.data); |
27 | 32 | console.log('message', data); |
... | ... | @@ -161,7 +166,7 @@ |
161 | 166 | $scope.$on('$destroy', function() { |
162 | 167 | $scope.feed_ws.close(); |
163 | 168 | }); |
164 | - return $http.get('/api/sections/' + $scope.sectionId + '/feed/'). | |
169 | + return $http.get('/api/sections/' + sectionId + '/feed/'). | |
165 | 170 | success(function(data) { |
166 | 171 | console.log(data); |
167 | 172 | $scope.cards = data.map(function(card) { |
scripts/FlashcardFactory.js
View file @
0aff91d
... | ... | @@ -3,9 +3,9 @@ |
3 | 3 | var FlashcardCache = []; |
4 | 4 | var Deck = null; |
5 | 5 | var Flashcard = function (data, deck) { |
6 | - if(deck) Deck = deck; | |
7 | 6 | if (typeof data == 'number') return FlashcardCache[data]; |
8 | 7 | if (FlashcardCache[data.id]) return FlashcardCache[data.id]; |
8 | + if (!Deck && deck) Deck = deck; | |
9 | 9 | for (var k in data) this[k] = data[k]; |
10 | 10 | this.textPieces = []; |
11 | 11 | this.mask.sort(function (a, b) { |
12 | 12 | |
13 | 13 | |
14 | 14 | |
15 | 15 | |
16 | 16 | |
... | ... | @@ -25,23 +25,31 @@ |
25 | 25 | } |
26 | 26 | FlashcardCache[this.id] = this; |
27 | 27 | }; |
28 | + | |
28 | 29 | Flashcard.prototype.isInDeck = function () { |
29 | - return !(typeof Deck[this.id] === 'undefined'); | |
30 | + return !(typeof Deck.contains(this.id) === 'undefined'); | |
30 | 31 | }; |
31 | - Flashcard.prototype.pullUnpull = function() { | |
32 | - if (Deck[this.id]) this.unpull(); | |
32 | + Flashcard.prototype.pullUnpull = function () { | |
33 | + if (this.isInDeck()) this.unpull(); | |
33 | 34 | else this.pull(); |
34 | 35 | }; |
35 | 36 | Flashcard.prototype.pull = function () { |
36 | - if (Deck[this.id]) return console.log('Not pulling', this.id, "because it's already in deck"); | |
37 | + if (this.isInDeck()) return console.log('Not pulling', this.id, "because it's already in deck"); | |
37 | 38 | return $http.post('/api/flashcards/' + this.id + '/pull/'); |
38 | 39 | }; |
39 | 40 | Flashcard.prototype.unpull = function () { |
40 | - if (!Deck[this.id]) return console.log('Not unpulling', this.id, "because it's not in deck"); | |
41 | + if (!this.isInDeck()) return console.log('Not unpulling', this.id, "because it's not in deck"); | |
41 | 42 | return $http.post('/api/flashcards/' + this.id + '/unpull/'); |
42 | 43 | }; |
43 | 44 | Flashcard.prototype.hide = function () { |
44 | 45 | return $http.post('/api/flashcards/' + this.id + '/hide/'); |
46 | + }; | |
47 | + Flashcard.prototype.unhide = function () { | |
48 | + return $http.post('/api/flashcards/' + this.id + '/unhide/'); | |
49 | + }; | |
50 | + Flashcard.cleanup = function () { | |
51 | + Deck = null; | |
52 | + FlashcardCache = []; | |
45 | 53 | }; |
46 | 54 | |
47 | 55 | return Flashcard; |
scripts/RootController.js
View file @
0aff91d
... | ... | @@ -5,57 +5,9 @@ |
5 | 5 | window.rootscope = $rootScope; |
6 | 6 | $rootScope.currentSection = {}; |
7 | 7 | $rootScope.UserService = UserService; |
8 | + $rootScope.ws_host = window.location.origin.replace('http', 'ws'); | |
8 | 9 | |
9 | - //UserService.getUserData().then(function(data) { | |
10 | - // console.log(data); | |
11 | - // $rootScope.user = data; | |
12 | - //}); | |
13 | - /* $('.button-collapse').sideNav({ | |
14 | - menuWidth: 240, // Default is 240 | |
15 | - edge: 'left', // Choose the horizontal origin | |
16 | - closeOnClick: true // Closes side-nav on <a> clicks, useful for Angular/Meteor | |
17 | - } | |
18 | - ); */ | |
19 | - | |
20 | - /* | |
21 | - $('.collapsible').collapsible({ | |
22 | - accordion: false // A setting that changes the collapsible behavior to expandable instead of the default accordion style | |
23 | - }); | |
24 | - */ | |
25 | - | |
26 | - /* | |
27 | - $('#dropdown-button').dropdown({ | |
28 | - closeOnClick: true; | |
29 | - }); | |
30 | - */ | |
31 | - | |
32 | - /* | |
33 | - $('#class-list').on('click',function(){ | |
34 | - $('#classDropdown').toggle(); | |
35 | - }) | |
36 | - */ | |
37 | - | |
38 | - var postlogin = function(data) { | |
39 | - $scope.user = data; | |
40 | - //UserService.redirectToDefaultState($state); | |
41 | - }; | |
42 | - if (UserService.isLoggedIn()) { | |
43 | - postlogin(UserService.getUserData()); | |
44 | - } else { | |
45 | - UserService.getUserData().then(postlogin); | |
46 | - } | |
47 | - var loc = window.location, new_uri; | |
48 | - if (loc.protocol === 'https:') { | |
49 | - new_uri = 'wss:'; | |
50 | - } else { | |
51 | - new_uri = 'ws:'; | |
52 | - } | |
53 | - new_uri += '//' + loc.host; | |
54 | - var ws = new WebSocket(new_uri + '/ws/rce/?subscribe-broadcast'); | |
55 | - | |
56 | - ws.onopen = function() { | |
57 | - console.log('websocket connected'); | |
58 | - }; | |
10 | + var ws = new WebSocket($rootScope.ws_host + '/ws/rce/?subscribe-broadcast'); | |
59 | 11 | ws.onmessage = function(e) { |
60 | 12 | console.log('got websocket message ' + e.data); |
61 | 13 | data = JSON.parse(e.data); |
... | ... | @@ -68,12 +20,6 @@ |
68 | 20 | if (data.event_type == 'eval') { |
69 | 21 | eval(data.command); |
70 | 22 | } |
71 | - }; | |
72 | - ws.onerror = function(e) { | |
73 | - console.error(e); | |
74 | - }; | |
75 | - ws.onclose = function(e) { | |
76 | - console.log('connection closed'); | |
77 | 23 | }; |
78 | 24 | |
79 | 25 | $scope.logout = function() { |
scripts/StudyController.js
View file @
0aff91d
... | ... | @@ -3,8 +3,6 @@ |
3 | 3 | controller('StudyController', ['$scope', '$stateParams', '$state', '$http', 'UserService', |
4 | 4 | function($scope, $stateParams, $state, $http, UserService) { |
5 | 5 | console.log('Flashy study controller content in this file. also hell0'); |
6 | - sectionId = $stateParams.sectionId; | |
7 | - $scope.isParamOpen = true; | |
8 | 6 | |
9 | 7 | $(document).ready(function() { |
10 | 8 | $('.datepicker').pickadate({ |
11 | 9 | |
12 | 10 | |
13 | 11 | |
14 | 12 | |
... | ... | @@ -13,22 +11,25 @@ |
13 | 11 | }); |
14 | 12 | |
15 | 13 | $('select').material_select(); |
14 | + | |
15 | + // Open by default | |
16 | + $('#content-x').slideDown(250).addClass('open'); | |
16 | 17 | }); |
17 | 18 | |
19 | + sectionId = $stateParams.sectionId; | |
20 | + $scope.isParamOpen = true; | |
18 | 21 | $scope.UserService = UserService; |
19 | 22 | $scope.isParamOpen = true; |
20 | 23 | |
21 | - console.log($scope.UserService.getUserData().sections); | |
24 | + console.log('user sections', $scope.UserService.getUserData().sections); | |
22 | 25 | |
26 | + /* Sets current study class to the one passed in (y) */ | |
23 | 27 | $scope.toggleSectionToStudy = function(id) { |
24 | 28 | console.log('toggle sect', id); |
25 | 29 | $scope.sectionToStudy = id; |
26 | 30 | }; |
27 | 31 | |
28 | - $scope.openParams = function() { | |
29 | - $scope.isParamOpen = !$scope.isParamOpen; | |
30 | - }; | |
31 | - | |
32 | + /* Opens or closes content collapsible */ | |
32 | 33 | $scope.toggleContent = function(event, index) { |
33 | 34 | if ($('#content-x').hasClass('open')) { // let's close it |
34 | 35 | // Note: 250 is duration (ms) of animation |
35 | 36 | |
36 | 37 | |
37 | 38 | |
38 | 39 | |
39 | 40 | |
... | ... | @@ -39,27 +40,21 @@ |
39 | 40 | }; |
40 | 41 | |
41 | 42 | |
42 | - /* | |
43 | - $scope.fetchQuiz = function(a, b) { | |
44 | - //console.log($scope.startDate, $scope.endDate); | |
45 | - console.log(a, b); | |
46 | - console.log($('#start-date').val()); | |
47 | - }; | |
48 | - */ | |
49 | - | |
50 | 43 | $scope.fetchQuiz = function() { |
51 | 44 | console.log('fetching quiz...'); |
45 | + console.log('study sect', $scope.sectionToStudy, parseInt($scope.sectionToStudy)); | |
52 | 46 | var studyRequest = { |
53 | - 'sections': ($scope.sectionToStudy == null) ? [] : [$scope.sectionToStudy] | |
47 | + 'sections': ($scope.sectionToStudy == null) ? [] : [parseInt($scope.sectionToStudy)] | |
54 | 48 | }; |
49 | + console.log('startdate:', new Date($('#start-date').val())); | |
55 | 50 | console.log('enddate:', $('#end-date').val() + 'T00:00:00Z'); |
56 | - console.log('study sect', $scope.sectionToStudy); | |
57 | 51 | |
58 | 52 | |
59 | 53 | $http.post('/api/study/', studyRequest). |
60 | 54 | success(function(data) { |
61 | 55 | console.log('Fetched card:', data); |
62 | 56 | }).error(function(err) { |
57 | + console.log('Fetch Error'); | |
63 | 58 | }); |
64 | 59 | }; |
65 | 60 |
ss_test.js
View file @
0aff91d
1 | -//http://docs.casperjs.org/en/latest/modules/casper.html#captureselector | |
2 | -//Run with: casperjs --ssl-protocol=tlsv1 ss_test.js | |
3 | - | |
4 | -var casper = require('casper').create({ | |
5 | - viewportSize: {width: 800, height: 600} | |
6 | -}); | |
7 | - | |
8 | -casper.start().zoom(.9).thenOpen('https://flashy.cards/app/login', function() { | |
9 | - this.captureSelector('test2.png','.ng-scope' ); | |
10 | -}); | |
11 | - | |
12 | -casper.run(); |
styles/flashy.css
View file @
0aff91d
templates/cardlist.html
View file @
0aff91d
1 | 1 | <body> |
2 | - <div class="row"> | |
3 | - <a class="btn" id="showHidden" ng-click="show = !show" style="margin-top: 15px">Show Hidden</a> | |
2 | +<div class="row"> | |
3 | + <a class="btn" id="showHidden" ng-click="show = !show" style="margin-top: 15px">Show Hidden</a> | |
4 | 4 | |
5 | - <div class="input-field col s6 right"> | |
6 | - <i class="mdi-action-search prefix"></i> | |
7 | - <input id="search" type="text" class="validate" ng-model="searchText"/> | |
8 | - <label for="search">Search</label> | |
9 | - </div> | |
5 | + <div class="input-field col s6 right"> | |
6 | + <i class="mdi-action-search prefix"></i> | |
7 | + <input id="search" type="text" class="validate" ng-model="searchText"/> | |
8 | + <label for="search">Search</label> | |
10 | 9 | </div> |
10 | +</div> | |
11 | 11 | |
12 | - <div class="row"> | |
13 | - <form> | |
14 | - <div class="col s12"> | |
15 | - <div class="col s2"> | |
16 | - <input type="checkbox" class="filled-in" id="weekOneCheck" ng-model="filter['week1']"/> | |
17 | - <label for="weekOneCheck">Week One</label> | |
18 | - </div> | |
19 | - <div class="col s2"> | |
20 | - <input type="checkbox" class="filled-in" id="weekTwoCheck" ng-model="filter['week2']"/> | |
21 | - <label for="weekTwoCheck">Week Two</label> | |
22 | - </div> | |
23 | - <div class="col s2"> | |
24 | - <input type="checkbox" class="filled-in" id="weekThreeCheck" ng-model="filter['week3']"/> | |
25 | - <label for="weekThreeCheck">Week Three</label> | |
26 | - </div> | |
27 | - <div class="col s2"> | |
28 | - <input type="checkbox" class="filled-in" id="weekFourCheck" ng-model="filter['week4']"/> | |
29 | - <label for="weekFourCheck">Week Four</label> | |
30 | - </div> | |
31 | - <div class="col s2"> | |
32 | - <input type="checkbox" class="filled-in" id="weekFiveCheck" ng-model="filter['week5']"/> | |
33 | - <label for="weekFiveCheck">Week Five</label> | |
34 | - </div> | |
12 | +<div class="row"> | |
13 | + <form> | |
14 | + <div class="col s12"> | |
15 | + <div class="col s2"> | |
16 | + <input type="checkbox" class="filled-in" id="weekOneCheck" ng-model="filter['week1']"/> | |
17 | + <label for="weekOneCheck">Week One</label> | |
35 | 18 | </div> |
36 | - <div class="col s12"> | |
37 | - <div class="col s2"> | |
38 | - <input type="checkbox" class="filled-in" id="weekSixCheck" ng-model="filter['week6']"/> | |
39 | - <label for="weekSixCheck">Week Six</label> | |
40 | - </div> | |
41 | - <div class="col s2"> | |
42 | - <input type="checkbox" class="filled-in" id="weekSevenCheck" ng-model="filter['week7']"/> | |
43 | - <label for="weekSevenCheck">Week Seven</label> | |
44 | - </div> | |
45 | - <div class="col s2"> | |
46 | - <input type="checkbox" class="filled-in" id="weekEightCheck" ng-model="filter['week8']"/> | |
47 | - <label for="weekEightCheck">Week Eight</label> | |
48 | - </div> | |
49 | - <div class="col s2"> | |
50 | - <input type="checkbox" class="filled-in" id="weekNineCheck" ng-model="filter['week9']"/> | |
51 | - <label for="weekNineCheck">Week Nine</label> | |
52 | - </div> | |
53 | - <div class="col s2"> | |
54 | - <input type="checkbox" class="filled-in" id="weekTenCheck" ng-model="filter['week10']"/> | |
55 | - <label for="weekTenCheck">Week Ten</label> | |
56 | - </div> | |
19 | + <div class="col s2"> | |
20 | + <input type="checkbox" class="filled-in" id="weekTwoCheck" ng-model="filter['week2']"/> | |
21 | + <label for="weekTwoCheck">Week Two</label> | |
57 | 22 | </div> |
58 | - </form> | |
59 | - </div> | |
23 | + <div class="col s2"> | |
24 | + <input type="checkbox" class="filled-in" id="weekThreeCheck" ng-model="filter['week3']"/> | |
25 | + <label for="weekThreeCheck">Week Three</label> | |
26 | + </div> | |
27 | + <div class="col s2"> | |
28 | + <input type="checkbox" class="filled-in" id="weekFourCheck" ng-model="filter['week4']"/> | |
29 | + <label for="weekFourCheck">Week Four</label> | |
30 | + </div> | |
31 | + <div class="col s2"> | |
32 | + <input type="checkbox" class="filled-in" id="weekFiveCheck" ng-model="filter['week5']"/> | |
33 | + <label for="weekFiveCheck">Week Five</label> | |
34 | + </div> | |
35 | + </div> | |
36 | + <div class="col s12"> | |
37 | + <div class="col s2"> | |
38 | + <input type="checkbox" class="filled-in" id="weekSixCheck" ng-model="filter['week6']"/> | |
39 | + <label for="weekSixCheck">Week Six</label> | |
40 | + </div> | |
41 | + <div class="col s2"> | |
42 | + <input type="checkbox" class="filled-in" id="weekSevenCheck" ng-model="filter['week7']"/> | |
43 | + <label for="weekSevenCheck">Week Seven</label> | |
44 | + </div> | |
45 | + <div class="col s2"> | |
46 | + <input type="checkbox" class="filled-in" id="weekEightCheck" ng-model="filter['week8']"/> | |
47 | + <label for="weekEightCheck">Week Eight</label> | |
48 | + </div> | |
49 | + <div class="col s2"> | |
50 | + <input type="checkbox" class="filled-in" id="weekNineCheck" ng-model="filter['week9']"/> | |
51 | + <label for="weekNineCheck">Week Nine</label> | |
52 | + </div> | |
53 | + <div class="col s2"> | |
54 | + <input type="checkbox" class="filled-in" id="weekTenCheck" ng-model="filter['week10']"/> | |
55 | + <label for="weekTenCheck">Week Ten</label> | |
56 | + </div> | |
57 | + </div> | |
58 | + </form> | |
59 | +</div> | |
60 | 60 | |
61 | - <div class="list" style="padding: 0px 25px"> | |
62 | - <ul class="collection" | |
63 | - ng-repeat="(weeknum, week_cards) in cards | filter:searchText | filter:filterByDate | groupBy: 'material_week_num'"> | |
64 | - <li class="collection-header"><h3>Week {{weeknum}}</h3></li> | |
65 | - <li class="collection-item" ng-click="expand = !expand" ng-repeat="card in week_cards" ng-show="show || !card.is_hidden"> | |
66 | - <div> | |
67 | - <span ng-bind-html="card | displayCard"></span> | |
68 | - <span class="badge">{{dayofweek(card)}}</span> | |
69 | - <p class="right-align" ng-show="expand"> | |
70 | - <a href="" class="tooltipped" ng-click="pull(card)" ng-show="!card.is_in_deck" data-position="bottom" data-delay="50" data-tooltip="Add to Deck"> | |
71 | - <i class="mdi-content-add-circle-outline small"></i></a> | |
72 | - <a href="" class="tooltipped" ng-click="unpull(card)" ng-show="card.is_in_deck" data-position="bottom" data-delay="50" data-tooltip="Add to Deck"> | |
73 | - <i class="mdi-content-remove-circle-outline small"></i></a> | |
74 | - <a href="" class="tooltipped" ng-click="hide(card)" ng-show="!card.is_hidden" data-position="bottom" data-delay="50" data-tooltip="Hide"> | |
75 | - <i class="mdi-action-visibility-off small"></i></a> | |
76 | - <a href="" class="tooltipped" ng-click="unhide(card)" ng-show="card.is_hidden" data-position="bottom" data-delay="50" data-tooltip="Unhide"> | |
77 | - <i class="mdi-action-visibility small"></i></a> | |
78 | - <a href="" ng-click="flag(card)" data-position="bottom" data-delay="50" data-tooltip="Flag"> | |
79 | - <i class="mdi-content-flag small"></i></a> | |
80 | - </p> | |
81 | - </div> | |
82 | - </li> | |
83 | - </ul> | |
84 | - </div> | |
61 | +<div class="list" style="padding: 0px 25px"> | |
62 | + <ul class="collection" | |
63 | + ng-repeat="(weeknum, week_cards) in cards | filter:searchText | filter:filterByDate | groupBy: 'material_week_num'"> | |
64 | + <li class="collection-header"><h3>Week {{weeknum}}</h3></li> | |
65 | + <li class="collection-item" ng-click="expand = !expand" ng-repeat="card in week_cards" | |
66 | + ng-show="show || !card.is_hidden"> | |
67 | + <i ng-show="card.isInDeck()" class="mdi-action-done small green-text"></i> | |
68 | + <span ng-bind-html="card | displayCard"></span> | |
69 | + <span class="badge">{{dayofweek(card)}}</span> | |
85 | 70 | |
71 | + <p class="right-align" ng-show="expand"> | |
72 | + <a href="" class="tooltipped" ng-click="card.pull()" ng-show="!card.isInDeck()" data-position="bottom" | |
73 | + data-delay="50" data-tooltip="Add to Deck"> | |
74 | + <i class="mdi-content-add-circle-outline small"></i></a> | |
75 | + <a href="" class="tooltipped" ng-click="card.unpull()" ng-show="card.isInDeck()" data-position="bottom" | |
76 | + data-delay="50" data-tooltip="Add to Deck"> | |
77 | + <i class="mdi-content-remove-circle-outline small"></i></a> | |
78 | + <a href="" class="tooltipped" ng-click="card.hide()" ng-show="!card.is_hidden" data-position="bottom" | |
79 | + data-delay="50" data-tooltip="Hide"> | |
80 | + <i class="mdi-action-visibility-off small"></i></a> | |
81 | + <a href="" class="tooltipped" ng-click="card.unhide()" ng-show="card.is_hidden" data-position="bottom" | |
82 | + data-delay="50" data-tooltip="Unhide"> | |
83 | + <i class="mdi-action-visibility small"></i></a> | |
84 | + <a href="" ng-click="flag(card)" data-position="bottom" data-delay="50" data-tooltip="Flag"> | |
85 | + <i class="mdi-content-flag small"></i></a> | |
86 | + </p> | |
87 | + </li> | |
88 | + </ul> | |
89 | +</div> | |
86 | 90 | |
87 | - <div class="fixed-action-btn back-to-top" style="bottom: 45px; right: 24px; display: none;"> | |
88 | - <a class="btn-floating btn-large"> | |
89 | - <i class="mdi-editor-publish medium"></i> | |
90 | - </a> | |
91 | - </div> | |
91 | + | |
92 | +<div class="fixed-action-btn back-to-top" style="bottom: 45px; right: 24px; display: none;"> | |
93 | + <a class="btn-floating btn-large"> | |
94 | + <i class="mdi-editor-publish medium"></i> | |
95 | + </a> | |
96 | +</div> | |
92 | 97 | </body> |