Commit 20ed06e1b5a4b2f5675f96d5eeb15248d9786d00

Authored by Andrew Buss
1 parent 0adf8f867a

make cardgridcontroller an actual controller; deck almost works now

Showing 4 changed files with 28 additions and 34 deletions Side-by-side Diff

scripts/CardGridController.js View file @ 20ed06e
1   -angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSocket']).controller =
  1 +angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSocket']).CardGridController =
2 2 function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) {
3 3 $scope.cards = [];
4 4 $scope.deck = [];
... ... @@ -106,6 +106,7 @@
106 106 for (i in col)
107 107 col[i].colRank = parseInt(i);
108 108 };
  109 +
109 110 $scope.hideCardFromGrid = function(card) {
110 111 console.log('hiding', card);
111 112 $scope.cardCols[card.colNum].splice(card.colRank, 1);
112 113  
... ... @@ -113,19 +114,15 @@
113 114 console.log($scope.cardCols);
114 115 };
115 116  
116   - $http.get('/api/sections/' + $scope.sectionId + '/deck/').
117   - success(function(data) {
118   - for (i in data) $scope.deck[data[i].id] = data[i];
119   - console.log("got user's deck");
120   - }).
121   - error(function(err) {
122   - console.log('get deck failed');
123   - });
124   -
125 117 $scope.$on('$destroy', function() {
126 118 $scope.deck_ws.close();
127 119 $rootScope.currentSection = {};
128 120 $(document).off('keydown');
129 121 });
  122 + return $http.get('/api/sections/' + $scope.sectionId + '/deck/').
  123 + success(function(data) {
  124 + for (i in data) $scope.deck[data[i].id] = new Flashcard(data[i], $scope.deck);
  125 + console.log("got user's deck", data);
  126 + });
130 127 };
scripts/DeckController.js View file @ 20ed06e
1 1 angular.module('flashy.DeckController', ['ui.router', 'ngWebSocket']).
2 2  
3   - controller('DeckController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService) {
4   - angular.module('flashy.CardGridController').controller.apply(this, arguments);
  3 + controller('DeckController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) {
  4 + angular.module('flashy.CardGridController').CardGridController.apply(this, arguments).then(function() {
  5 + $scope.refreshLayout();
  6 + });
5 7 $scope.cards = $scope.deck;
6   - $scope.refreshLayout();
7 8 }
8 9 );
scripts/FeedController.js View file @ 20ed06e
1   -angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket', 'contenteditable']).
  1 +angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket', 'contenteditable']).controller('FeedController',
  2 + function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) {
  3 + angular.module('flashy.CardGridController').CardGridController.apply(this, arguments);
2 4  
3   - controller('FeedController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) {
4   - angular.module('flashy.CardGridController').controller.apply(this, arguments);
5   -
6   - $scope.refreshCards = function() {
7   - $http.get('/api/sections/' + $scope.sectionId + '/feed/').
8   - success(function(data) {
9   - console.log(data);
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   - });
19   - });
20   - };
21   -
22 5 $scope.sortAdd = function(card, array) {
23 6 console.log('sort add');
24 7 array.forEach(function(ele, i, ary) {
... ... @@ -180,5 +163,18 @@
180 163 $scope.$on('$destroy', function() {
181 164 $scope.feed_ws.close();
182 165 });
  166 + return $http.get('/api/sections/' + $scope.sectionId + '/feed/').
  167 + success(function(data) {
  168 + console.log(data);
  169 + $scope.cards = data.map(function(card) {
  170 + return new Flashcard(card, $scope.deck);
  171 + });
  172 + $scope.refreshLayout().then(function() {
  173 + $timeout($scope.refreshColumnWidth).then(function() {
  174 + $scope.showGrid = true;
  175 + });
  176 + console.log('layout done');
  177 + });
  178 + });
183 179 });
templates/feed.html View file @ 20ed06e
... ... @@ -5,7 +5,7 @@
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>