From 20ed06e1b5a4b2f5675f96d5eeb15248d9786d00 Mon Sep 17 00:00:00 2001 From: Andrew Buss Date: Tue, 2 Jun 2015 04:45:29 -0700 Subject: [PATCH] make cardgridcontroller an actual controller; deck almost works now --- scripts/CardGridController.js | 17 +++++++---------- scripts/DeckController.js | 7 ++++--- scripts/FeedController.js | 36 ++++++++++++++++-------------------- templates/feed.html | 2 +- 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/scripts/CardGridController.js b/scripts/CardGridController.js index e7fe7b3..26a3cf1 100644 --- a/scripts/CardGridController.js +++ b/scripts/CardGridController.js @@ -1,4 +1,4 @@ -angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSocket']).controller = +angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSocket']).CardGridController = function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) { $scope.cards = []; $scope.deck = []; @@ -106,6 +106,7 @@ angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSoc for (i in col) col[i].colRank = parseInt(i); }; + $scope.hideCardFromGrid = function(card) { console.log('hiding', card); $scope.cardCols[card.colNum].splice(card.colRank, 1); @@ -113,18 +114,14 @@ angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSoc console.log($scope.cardCols); }; - $http.get('/api/sections/' + $scope.sectionId + '/deck/'). - success(function(data) { - for (i in data) $scope.deck[data[i].id] = data[i]; - console.log("got user's deck"); - }). - error(function(err) { - console.log('get deck failed'); - }); - $scope.$on('$destroy', function() { $scope.deck_ws.close(); $rootScope.currentSection = {}; $(document).off('keydown'); }); + return $http.get('/api/sections/' + $scope.sectionId + '/deck/'). + success(function(data) { + for (i in data) $scope.deck[data[i].id] = new Flashcard(data[i], $scope.deck); + console.log("got user's deck", data); + }); }; diff --git a/scripts/DeckController.js b/scripts/DeckController.js index 11cac86..a6177cd 100644 --- a/scripts/DeckController.js +++ b/scripts/DeckController.js @@ -1,8 +1,9 @@ angular.module('flashy.DeckController', ['ui.router', 'ngWebSocket']). - controller('DeckController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService) { - angular.module('flashy.CardGridController').controller.apply(this, arguments); + controller('DeckController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) { + angular.module('flashy.CardGridController').CardGridController.apply(this, arguments).then(function() { + $scope.refreshLayout(); + }); $scope.cards = $scope.deck; - $scope.refreshLayout(); } ); diff --git a/scripts/FeedController.js b/scripts/FeedController.js index 82307da..d9bd9e2 100644 --- a/scripts/FeedController.js +++ b/scripts/FeedController.js @@ -1,23 +1,6 @@ -angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket', 'contenteditable']). - - controller('FeedController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) { - angular.module('flashy.CardGridController').controller.apply(this, arguments); - - $scope.refreshCards = function() { - $http.get('/api/sections/' + $scope.sectionId + '/feed/'). - success(function(data) { - console.log(data); - $scope.cards = data.map(function(card) { - return new Flashcard(card, $scope.deck); - }); - $scope.refreshLayout().then(function() { - $timeout($scope.refreshColumnWidth).then(function() { - $scope.showGrid = true; - }); - console.log('layout done'); - }); - }); - }; +angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket', 'contenteditable']).controller('FeedController', + function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) { + angular.module('flashy.CardGridController').CardGridController.apply(this, arguments); $scope.sortAdd = function(card, array) { console.log('sort add'); @@ -180,4 +163,17 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket' $scope.$on('$destroy', function() { $scope.feed_ws.close(); }); + return $http.get('/api/sections/' + $scope.sectionId + '/feed/'). + success(function(data) { + console.log(data); + $scope.cards = data.map(function(card) { + return new Flashcard(card, $scope.deck); + }); + $scope.refreshLayout().then(function() { + $timeout($scope.refreshColumnWidth).then(function() { + $scope.showGrid = true; + }); + console.log('layout done'); + }); + }); }); diff --git a/templates/feed.html b/templates/feed.html index da2422e..6e8323e 100644 --- a/templates/feed.html +++ b/templates/feed.html @@ -5,7 +5,7 @@
-
+
-- 1.9.1