Commit 180aa08bb854a7122ebeee09dc578ae172eaa77d

Authored by Andrew Buss
1 parent bf0941f00c

hide now working

Showing 4 changed files with 23 additions and 17 deletions Side-by-side Diff

scripts/CardGridController.js View file @ 180aa08
1 1 angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSocket']).controller =
2   - function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService) {
  2 + function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) {
3 3 $scope.cards = [];
4 4 $scope.deck = [];
5 5 $scope.cardCols = []; // organized data
6 6  
... ... @@ -38,11 +38,10 @@
38 38 var cols = [];
39 39 for (i = 0; i < $scope.numCols; i++) cols.push([]);
40 40 $scope.cards.forEach(function(card, i) {
41   - cols[i % $scope.numCols].push(card);
42   - $scope.cardTable[card.id] = {'colNum': (i % $scope.numCols), 'obj': card};
43   - card.isInDeck();
  41 + card.colNum = i % $scope.numCols;
  42 + cols[card.colNum].push(card);
44 43 });
45   - // wait until the next digest cycle to update cardCols
  44 + for (i in cols) $scope.updateColRanks(cols[i]);
46 45 console.log(cols);
47 46 $timeout(function() {
48 47 $scope.cardCols = cols;
49 48  
50 49  
51 50  
... ... @@ -62,15 +61,16 @@
62 61 $scope.deck_ws.onMessage(function(message) {
63 62 data = JSON.parse(message.data);
64 63 console.log('message', data);
  64 + card = new Flashcard(data.flashcard.id);
65 65 if (data.event_type == 'card_pulled') {
66   - card = data.flashcard;
67   - console.log('pulling', card);
68 66 $scope.deck[card.id] = card;
69 67 }
70 68 if (data.event_type == 'card_unpulled') {
71   - card = data.flashcard;
72 69 $scope.deck[card.id] = undefined;
73 70 }
  71 + if (data.event_type == 'card_hidden') {
  72 + $scope.hideCardFromGrid(card);
  73 + }
74 74 });
75 75  
76 76 $scope.cardInDeck = function(id) {
77 77  
78 78  
... ... @@ -98,11 +98,18 @@
98 98 $timeout($scope.refreshColumnWidth);
99 99 };
100 100  
  101 + $scope.updateColRanks = function(col) {
  102 + for (i in col)
  103 + col[i].colRank = i;
  104 + };
  105 + $scope.hideCardFromGrid = function(card) {
  106 + console.log('hiding', card);
  107 + $scope.cardCols[card.colNum].splice(card.colRank, 1);
  108 + $scope.updateColRanks($scope.cardCols[card.colNum]);
  109 + };
101 110  
102   -
103 111 $http.get('/api/sections/' + $scope.sectionId + '/deck/').
104 112 success(function(data) {
105   -
106 113 for (i in data) $scope.deck[data[i].id] = data[i];
107 114 console.log("got user's deck");
108 115 }).
scripts/FeedController.js View file @ 180aa08
... ... @@ -27,8 +27,7 @@
27 27 });
28 28 };
29 29  
30   - $scope.updateCardScore = function(flashcard) {
31   - card = new Flashcard(flashcard.id);
  30 + $scope.updateCardScore = function(card) {
32 31 console.log('old score', card.score);
33 32 card.score = flashcard.score;
34 33 console.log('new score', card.score);
35 34  
... ... @@ -42,9 +41,10 @@
42 41 data = JSON.parse(e.data);
43 42 console.log('message', data);
44 43 if (data.event_type == 'new_card') {
45   - $scope.addCardToGrid(new Flashcard(data.flashcard, $scope.deck));
  44 + $scope.addCardToGrid(new Flashcard(data.flashcard), $scope.deck);
46 45 } else if (data.event_type == 'score_change') {
47   - $scope.updateCardScore(data.flashcard);
  46 + card = new Flashcard(data.flashcard.id);
  47 + $scope.updateCardScore(new Flashcard(data.flashcard.id));
48 48 }
49 49 });
50 50  
scripts/SettingsController.js View file @ 180aa08
... ... @@ -20,7 +20,7 @@
20 20 };
21 21  
22 22 function sendRegistrationId(registrationId, callback) {
23   - console.log('registration id: '+ registrationId);
  23 + console.log('registration id: ' + registrationId);
24 24 $http.post('/api/subscribe/', JSON.stringify({
25 25 'registration_id': registrationId
26 26 }));
templates/flashcard.html View file @ 180aa08
... ... @@ -19,8 +19,7 @@
19 19 <div class="left-box">
20 20 <div class="center-me"><i class="mdi-action-info-outline small"></i></div>
21 21 </div>
22   - <div class="right-box" ng-click="
23   - hideCard(flashcard)">
  22 + <div class="right-box" ng-click="flashcard.hide()">
24 23 <div class="center-me"><i class="mdi-action-delete small"></i></div>
25 24 </div>
26 25