Commit 5673511eb31342e4e53ddaf9d416a1680b759f44
1 parent
0dfc725862
Exists in
master
and in
1 other branch
more feed refactoring; bugfixes
Showing 7 changed files with 35 additions and 30 deletions Side-by-side Diff
config.js
View file @
5673511
scripts/CardGridController.js
View file @
5673511
... | ... | @@ -7,6 +7,7 @@ |
7 | 7 | $scope.cardTable = {}; // look up table of cards, {'colNum':col, 'obj':card} |
8 | 8 | $scope.sectionId = parseInt($stateParams.sectionId); |
9 | 9 | $scope.section = $rootScope.SectionResource.get({sectionId: $scope.sectionId}); |
10 | + $scope.showGrid = false; | |
10 | 11 | $rootScope.currentSection = $scope.section; |
11 | 12 | |
12 | 13 | if (!UserService.isInSection($scope.sectionId)) { |
... | ... | @@ -43,7 +44,7 @@ |
43 | 44 | }); |
44 | 45 | for (i in cols) $scope.updateColRanks(cols[i]); |
45 | 46 | console.log(cols); |
46 | - $timeout(function() { | |
47 | + return $timeout(function() { | |
47 | 48 | $scope.cardCols = cols; |
48 | 49 | $timeout($scope.refreshColumnWidth); |
49 | 50 | }); |
... | ... | @@ -94,7 +95,8 @@ |
94 | 95 | console.log(card); |
95 | 96 | $scope.cards.push(data); |
96 | 97 | lowestCol.unshift(card); |
97 | - $scope.cardTable[card.id] = {'colNum': lowestColNum, 'obj': card}; | |
98 | + card.colNum = lowestColNum; | |
99 | + $scope.updateColRanks(lowestCol); | |
98 | 100 | $timeout($scope.refreshColumnWidth); |
99 | 101 | |
100 | 102 | }; |
scripts/FeedController.js
View file @
5673511
... | ... | @@ -2,18 +2,20 @@ |
2 | 2 | |
3 | 3 | controller('FeedController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) { |
4 | 4 | angular.module('flashy.CardGridController').controller.apply(this, arguments); |
5 | + | |
5 | 6 | $scope.refreshCards = function() { |
6 | 7 | $http.get('/api/sections/' + $scope.sectionId + '/feed/'). |
7 | 8 | success(function(data) { |
8 | 9 | console.log(data); |
9 | - $scope.cards = []; | |
10 | - for (var i in data) $scope.cards.push(new Flashcard(data[i], $scope.deck)); | |
11 | - $scope.refreshLayout(); | |
12 | - console.log('success in refresh cards...'); | |
13 | - }). | |
14 | - error(function(err) { | |
15 | - console.log('refresh fail'); | |
16 | - console.log(err); | |
10 | + $scope.cards = data.map(function(card) { | |
11 | + return new Flashcard(card, $scope.deck); | |
12 | + }); | |
13 | + $scope.refreshLayout().then(function() { | |
14 | + $timeout($scope.refreshColumnWidth).then(function() { | |
15 | + $scope.showGrid = true; | |
16 | + }); | |
17 | + console.log('layout done'); | |
18 | + }); | |
17 | 19 | }); |
18 | 20 | }; |
19 | 21 | |
... | ... | @@ -28,6 +30,9 @@ |
28 | 30 | }; |
29 | 31 | |
30 | 32 | $scope.updateCardScore = function(card) { |
33 | + console.log($scope.cardCols, card); | |
34 | + // if no colNum is attached, then this doesn't exist on the feed yet | |
35 | + if (!card.colNum) return; | |
31 | 36 | $scope.cardCols[card.colNum].sort(function(a, b) { |
32 | 37 | return b.score - a.score; |
33 | 38 | }); |
34 | 39 | |
... | ... | @@ -38,9 +43,9 @@ |
38 | 43 | data = JSON.parse(e.data); |
39 | 44 | console.log('message', data); |
40 | 45 | if (data.event_type == 'new_card') { |
41 | - $scope.addCardToGrid(new Flashcard(data.flashcard), $scope.deck); | |
46 | + $scope.addCardToGrid(new Flashcard(data.flashcard, $scope.deck)); | |
42 | 47 | } else if (data.event_type == 'score_change') { |
43 | - card = new Flashcard(data.flashcard.id); | |
48 | + card = new Flashcard(data.flashcard); | |
44 | 49 | card.score = data.flashcard.score; |
45 | 50 | $scope.updateCardScore(card); |
46 | 51 | } |
... | ... | @@ -63,9 +68,6 @@ |
63 | 68 | if (!UserService.hasVerifiedEmail()) { |
64 | 69 | Materialize.toast("<p>Thanks for contributing! However, others won't see your card until you verify your email address<p>", 4000); |
65 | 70 | } |
66 | - }). | |
67 | - error(function(error) { | |
68 | - console.log('something went wrong pushing a card!'); | |
69 | 71 | }); |
70 | 72 | return $scope.closeNewCardModal(); |
71 | 73 | }; |
... | ... | @@ -137,9 +139,6 @@ |
137 | 139 | var i = 0; |
138 | 140 | $scope.newCardBlanks = []; |
139 | 141 | $('#new-card-input')[0].childNodes.forEach(function(node) { |
140 | - if (typeof node.data == 'undefined') { | |
141 | - console.log('undefined node'); | |
142 | - } | |
143 | 142 | node = $(node)[0]; |
144 | 143 | if (node.tagName == 'B') { |
145 | 144 | var text = $(node).text(); |
... | ... | @@ -151,7 +150,6 @@ |
151 | 150 | if (leftspaces != text.length) $scope.newCardBlanks.push([i + leftspaces, i + text.length - rightspaces]); |
152 | 151 | i += text.length; |
153 | 152 | } else if (!node.data) { |
154 | - console.log('weird node', node); | |
155 | 153 | i += $(node).text().length; |
156 | 154 | } else { |
157 | 155 | i += node.data.length; |
... | ... | @@ -162,7 +160,6 @@ |
162 | 160 | }); |
163 | 161 | i = 0; |
164 | 162 | newtext = ''; |
165 | - console.log($scope.newCardBlanks); | |
166 | 163 | $scope.newCardBlanks.forEach(function(blank) { |
167 | 164 | newtext += $scope.newCardText.slice(i, blank[0]); |
168 | 165 | newtext += '<b>' + $scope.newCardText.slice(blank[0], blank[1]) + '</b>'; |
scripts/FlashcardFactory.js
View file @
5673511
1 | 1 | angular.module('flashy.FlashcardFactory', ['ui.router']). |
2 | 2 | factory('Flashcard', function ($http) { |
3 | 3 | var FlashcardCache = []; |
4 | + var Deck = null; | |
4 | 5 | var Flashcard = function (data, deck) { |
6 | + if(deck) Deck = deck; | |
5 | 7 | if (typeof data == 'number') return FlashcardCache[data]; |
8 | + if (FlashcardCache[data.id]) return FlashcardCache[data.id]; | |
6 | 9 | for (var k in data) this[k] = data[k]; |
7 | - this.deck = deck; | |
8 | 10 | this.textPieces = []; |
9 | 11 | this.mask.sort(function (a, b) { |
10 | 12 | return a[0] - b[0]; |
11 | 13 | |
12 | 14 | |
... | ... | @@ -24,14 +26,14 @@ |
24 | 26 | FlashcardCache[this.id] = this; |
25 | 27 | }; |
26 | 28 | Flashcard.prototype.isInDeck = function () { |
27 | - return !(typeof this.deck[this.id] === 'undefined'); | |
29 | + return !(typeof Deck[this.id] === 'undefined'); | |
28 | 30 | }; |
29 | 31 | Flashcard.prototype.pull = function () { |
30 | - if (this.deck[this.id]) return console.log('Not pulling', this.id, "because it's already in deck"); | |
32 | + if (Deck[this.id]) return console.log('Not pulling', this.id, "because it's already in deck"); | |
31 | 33 | return $http.post('/api/flashcards/' + this.id + '/pull/'); |
32 | 34 | }; |
33 | 35 | Flashcard.prototype.unpull = function () { |
34 | - if (!this.deck[this.id]) return console.log('Not unpulling', this.id, "because it's not in deck"); | |
36 | + if (!Deck[this.id]) return console.log('Not unpulling', this.id, "because it's not in deck"); | |
35 | 37 | return $http.post('/api/flashcards/' + this.id + '/unpull/'); |
36 | 38 | }; |
37 | 39 | Flashcard.prototype.hide = function () { |
styles/flashy.css
View file @
5673511
templates/feed.html
View file @
5673511
1 | 1 | <div class="row"> |
2 | - <h2 ng-cloak ng-show="cards.length == 0">No cards. Be the first one to add a card!</h2> | |
2 | + <h2 ng-cloak ng-show="showGrid && cards.length == 0">No cards. Be the first one to add a card!</h2> | |
3 | 3 | |
4 | - <div class="progress center-align" style="margin: 70px auto auto;width:50%;" ng-if="cards === false"> | |
4 | + <div class="progress center-align" style="margin: 70px auto auto;width:50%;" ng-if="!cardCols.length || !showGrid"> | |
5 | 5 | <div class="indeterminate"></div> |
6 | 6 | </div> |
7 | 7 | |
8 | - <div class="cardColumn" ng-repeat="col in cardCols"> | |
8 | + <div class="cardColumn" ng-repeat="col in cardCols" > | |
9 | 9 | <div class="repeated-card" ng-repeat="card in col"> |
10 | 10 | <flashcard flashcard-obj="card"/> |
11 | 11 | </div> |
templates/flashcard.html
View file @
5673511
... | ... | @@ -6,8 +6,8 @@ |
6 | 6 | <!--ng-style="piece.blank ? {'opacity':'0.4', 'border-bottom': '1px solid black'} : {}">{{piece.text}}</span>--> |
7 | 7 | </div> |
8 | 8 | </div> |
9 | - <div class="card-overlay"> | |
10 | - <div class="top-box no-user-select" ng-hide="flashcard.isInDeck()" | |
9 | + <div class="card-overlay" > | |
10 | + <div class="top-box no-user-select" ng-show="!flashcard.isInDeck()" | |
11 | 11 | ng-click="flashcard.pull()"> |
12 | 12 | <div class="center-me"><i class="mdi-content-add-circle-outline medium"></i></div> |
13 | 13 | </div> |