Commit ba553b18ad4682c584f1ff582ebf5ad09c37dda2
1 parent
412c2c332a
Exists in
master
and in
1 other branch
start refactoring isInDeck
Showing 3 changed files with 76 additions and 64 deletions Side-by-side Diff
scripts/CardGridController.js
View file @
ba553b1
... | ... | @@ -64,8 +64,16 @@ |
64 | 64 | |
65 | 65 | $scope.deck_ws.onMessage(function(message) { |
66 | 66 | console.log('message', message); |
67 | + if (message.event_type == 'pull_card') { | |
68 | + $scope.deck_cards.push(card); | |
69 | + } | |
67 | 70 | }); |
68 | 71 | |
72 | + $scope.cardInDeck = function(id) { | |
73 | + console.log('checking whether', id, 'in deck'); | |
74 | + for (card in $scope.deck_cards) if (card.id == id) return true; | |
75 | + return false; | |
76 | + }; | |
69 | 77 | $scope.add = function(card) { |
70 | 78 | var colNum = 0; |
71 | 79 | var lowestCol = $scope.cardCols[0]; |
scripts/FlashcardDirective.js
View file @
ba553b1
1 | 1 | angular.module('flashy.FlashcardDirective', []). |
2 | 2 | |
3 | - directive('flashcard', ['$http', '$state', '$window', | |
4 | - function($http, $state, $window) { | |
5 | - return { | |
6 | - templateUrl: '/app/templates/flashcard.html', | |
7 | - restrict: 'E', | |
8 | - scope: { | |
9 | - flashcard: '=flashcardObj', // flashcard-obj in parent html | |
10 | - refresh: '&' // eval refresh in parent html | |
11 | - }, | |
12 | - link: function(scope, element) { | |
13 | - /* Handles width of the card */ | |
14 | - scope.textPieces = []; | |
15 | - scope.flashcard.mask.sort(function(a, b) { | |
16 | - return a[0] - b[0]; | |
17 | - }); | |
18 | - var i = 0; | |
19 | - scope.flashcard.mask.forEach(function(blank) { | |
20 | - scope.textPieces.push({text: scope.flashcard.text.slice(i, blank[0])}); | |
21 | - scope.textPieces.push({text: scope.flashcard.text.slice(blank[0], blank[1]), blank: true}); | |
22 | - i = blank[1]; | |
23 | - }); | |
24 | - scope.textPieces.push({text: scope.flashcard.text.slice(i)}); | |
25 | - /* Pulls card from feed into deck */ | |
26 | - scope.pullCard = function(flashcard) { | |
27 | - flashcard.is_in_deck = true; | |
28 | - $http.post('/api/flashcards/' + flashcard.id + '/pull/'). | |
29 | - success(function(data) { | |
30 | - console.log('pulled flashcard #' + flashcard.id); | |
31 | - //scope.startShrink = true; | |
32 | - //scope.refresh(flashcard); | |
33 | - }). | |
34 | - error(function(data) { | |
35 | - console.log('failed to pull flashcard #' + flashcard.id); | |
36 | - }); | |
37 | - }; | |
3 | + directive('flashcard', | |
4 | + function($http, $state, $window) { | |
5 | + return { | |
6 | + templateUrl: '/app/templates/flashcard.html', | |
7 | + restrict: 'E', | |
8 | + scope: { | |
9 | + flashcard: '=flashcardObj', // flashcard-obj in parent html | |
10 | + refresh: '&' // eval refresh in parent html | |
11 | + }, | |
12 | + link: function(scope, element) { | |
13 | + /* Handles width of the card */ | |
14 | + scope.textPieces = []; | |
15 | + scope.flashcard.mask.sort(function(a, b) { | |
16 | + return a[0] - b[0]; | |
17 | + }); | |
18 | + var i = 0; | |
19 | + scope.flashcard.mask.forEach(function(blank) { | |
20 | + scope.textPieces.push({text: scope.flashcard.text.slice(i, blank[0])}); | |
21 | + scope.textPieces.push({text: scope.flashcard.text.slice(blank[0], blank[1]), blank: true}); | |
22 | + i = blank[1]; | |
23 | + }); | |
24 | + scope.textPieces.push({text: scope.flashcard.text.slice(i)}); | |
25 | + /* Pulls card from feed into deck */ | |
26 | + scope.pullCard = function(flashcard) { | |
27 | + flashcard.is_in_deck = true; | |
28 | + $http.post('/api/flashcards/' + flashcard.id + '/pull/'). | |
29 | + success(function(data) { | |
30 | + console.log('pulled flashcard #' + flashcard.id); | |
31 | + //scope.startShrink = true; | |
32 | + //scope.refresh(flashcard); | |
33 | + }). | |
34 | + error(function(data) { | |
35 | + console.log('failed to pull flashcard #' + flashcard.id); | |
36 | + }); | |
37 | + }; | |
38 | 38 | |
39 | - /* Unpulls card from deck */ | |
40 | - scope.unpullCard = function(flashcard) { | |
41 | - console.log('unpulling card...'); | |
42 | - flashcard.is_in_deck = false; | |
43 | - $http.post('/api/flashcards/' + flashcard.id + '/unpull/'). | |
39 | + /* Unpulls card from deck */ | |
40 | + scope.unpullCard = function(flashcard) { | |
41 | + console.log('unpulling card...'); | |
42 | + flashcard.is_in_deck = false; | |
43 | + $http.post('/api/flashcards/' + flashcard.id + '/unpull/'). | |
44 | + success(function(data) { | |
45 | + console.log('card unpull success'); | |
46 | + //scope.startShrink = true; | |
47 | + //scope.refresh(flashcard); | |
48 | + }). | |
49 | + error(function(data) { | |
50 | + console.log('card unpull FAILURE'); | |
51 | + }); | |
52 | + }; | |
53 | + | |
54 | + /* Hides card from feed */ | |
55 | + scope.hideCard = function(flashcard) { | |
56 | + if ($state.current.name == 'feed') { | |
57 | + $http.post('/api/flashcards/' + flashcard.id + '/hide/'). | |
44 | 58 | success(function(data) { |
45 | - console.log('card unpull success'); | |
46 | - //scope.startShrink = true; | |
47 | - //scope.refresh(flashcard); | |
59 | + console.log('card hide success'); | |
60 | + scope.startShrink = true; | |
61 | + scope.refresh(flashcard); | |
48 | 62 | }). |
49 | 63 | error(function(data) { |
50 | - console.log('card unpull FAILURE'); | |
64 | + console.log('card hide FAILURE'); | |
51 | 65 | }); |
52 | - }; | |
53 | - | |
54 | - /* Hides card from feed */ | |
55 | - scope.hideCard = function(flashcard) { | |
56 | - if ($state.current.name == 'feed') { | |
57 | - $http.post('/api/flashcards/' + flashcard.id + '/hide/'). | |
58 | - success(function(data) { | |
59 | - console.log('card hide success'); | |
60 | - scope.startShrink = true; | |
61 | - scope.refresh(flashcard); | |
62 | - }). | |
63 | - error(function(data) { | |
64 | - console.log('card hide FAILURE'); | |
65 | - }); | |
66 | - } | |
67 | - }; | |
68 | - } | |
69 | - }; | |
70 | - }]); | |
66 | + } | |
67 | + }; | |
68 | + scope.isInDeck = function(flashcard) { | |
69 | + //$scope. | |
70 | + }; | |
71 | + } | |
72 | + }; | |
73 | + } | |
74 | +); |
templates/flashcard.html
View file @
ba553b1
... | ... | @@ -26,7 +26,7 @@ |
26 | 26 | |
27 | 27 | </div> |
28 | 28 | </div> |
29 | - <div ng-show="flashcard.is_in_deck" class="green-text" style="position:absolute; top:0px;right:0px"> | |
29 | + <div ng-show="cardInDeck(flashcard.id)" class="green-text" style="position:absolute; top:0px;right:0px"> | |
30 | 30 | <div class="center-me"><i class="mdi-action-done small"></i></div> |
31 | 31 | </div> |
32 | 32 | <div ng-show="$root.debug_flashcard" style="position:absolute; bottom:0px; right:5px;"> |