diff --git a/config.js b/config.js index 803f825..4b55987 100644 --- a/config.js +++ b/config.js @@ -87,7 +87,7 @@ angular.module('flashy', [ }). state('root', { resolve: auth_resolve, - url: '', + url: '/', controller: 'RootController' }). state('feed', { diff --git a/scripts/CardGridController.js b/scripts/CardGridController.js index 44dc8c8..27f8951 100644 --- a/scripts/CardGridController.js +++ b/scripts/CardGridController.js @@ -17,11 +17,6 @@ angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSoc //$scope.moveQueue = []; // queue of flashcard objects $rootScope.currentSection = $scope.section; - if (!UserService.isInSection($scope.sectionId)) { - console.log('user is not enrolled in ' + $scope.sectionId); - $state.go('addclass'); - } - $scope.refreshColumnWidth = function() { avail = $window.innerWidth - 17; width = Math.floor(avail / Math.floor(avail / 250)); diff --git a/scripts/DeckController.js b/scripts/DeckController.js index db64683..64144ea 100644 --- a/scripts/DeckController.js +++ b/scripts/DeckController.js @@ -5,7 +5,7 @@ angular.module('flashy.DeckController', ['ui.router', 'ngWebSocket']). angular.module('flashy.CardGridController').CardGridController.apply(this, arguments).then(function() { $scope.refreshLayout(); }); - $scope.cards = $scope.deck.deck; + $scope.cards = $scope.deck.cards; $scope.deckPullCallback = $scope.addCardToGrid; $scope.deckUnpullCallback = $scope.hideCardFromGrid; diff --git a/scripts/DeckFactory.js b/scripts/DeckFactory.js index db1b14e..0df388a 100644 --- a/scripts/DeckFactory.js +++ b/scripts/DeckFactory.js @@ -1,13 +1,18 @@ angular.module('flashy.DeckFactory', ['ui.router', 'flashy.FlashcardFactory', 'ngWebSocket']). - factory('Deck', function ($http, $rootScope, $websocket, Flashcard) { + factory('Deck', function ($http, $rootScope, $state, $websocket, Flashcard, UserService) { var Deck = function (sectionId, callbacks) { + if (!UserService.isInSection(sectionId)) { + console.log('user is not enrolled in ' + sectionId); + $state.go('addclass'); + } obj = this; - this.deck = []; + this.cards = []; this.section = $rootScope.SectionResource.get({sectionId: sectionId}); + this.ws = $websocket($rootScope.ws_host + '/ws/deck/' + sectionId + '?subscribe-user'); this.contains = function (id) { - return this.deck[id]; + return this.cards[id]; }; this.ws.onMessage(function (message) { @@ -15,11 +20,11 @@ angular.module('flashy.DeckFactory', ['ui.router', 'flashy.FlashcardFactory', 'n console.log('message', data); card = new Flashcard(data.flashcard); if (data.event_type == 'card_pulled') { - obj.deck[card.id] = card; + obj.cards[card.id] = card; if (callbacks.cardPullCallback) callbacks.cardPullCallback(card); } if (data.event_type == 'card_unpulled') { - obj.deck[card.id] = undefined; + obj.cards[card.id] = undefined; if (callbacks.cardUnpullCallback) callbacks.cardUnpullCallback(card); } if (data.event_type == 'card_hidden') { @@ -27,13 +32,13 @@ angular.module('flashy.DeckFactory', ['ui.router', 'flashy.FlashcardFactory', 'n } }); this.deckPromise = $http.get('/api/sections/' + sectionId + '/deck/').success(function (data) { - for (i in data) obj.deck[data[i].id] = new Flashcard(data[i], obj); + for (i in data) obj.cards[data[i].id] = new Flashcard(data[i], obj); console.log("got user's deck", data); }); this.cleanup = function () { this.ws.close(); }; - this.forEach = this.deck.forEach; + this.forEach = this.cards.forEach; }; return Deck; diff --git a/scripts/FlashcardFactory.js b/scripts/FlashcardFactory.js index f62a98c..a8cf634 100644 --- a/scripts/FlashcardFactory.js +++ b/scripts/FlashcardFactory.js @@ -1,11 +1,10 @@ angular.module('flashy.FlashcardFactory', ['ui.router']). factory('Flashcard', function ($http) { var FlashcardCache = []; - var Deck = null; var Flashcard = function (data, deck) { - if(deck) Deck = deck; if (typeof data == 'number') return FlashcardCache[data]; if (FlashcardCache[data.id]) return FlashcardCache[data.id]; + if (deck) this.deck = deck; for (var k in data) this[k] = data[k]; this.textPieces = []; this.mask.sort(function (a, b) { @@ -27,9 +26,9 @@ angular.module('flashy.FlashcardFactory', ['ui.router']). }; Flashcard.prototype.isInDeck = function () { - return !(typeof Deck.contains(this.id) === 'undefined'); + return !(typeof this.deck.contains(this.id) === 'undefined'); }; - Flashcard.prototype.pullUnpull = function() { + Flashcard.prototype.pullUnpull = function () { if (this.isInDeck()) this.unpull(); else this.pull(); }; diff --git a/scripts/RootController.js b/scripts/RootController.js index 79feab8..5961007 100644 --- a/scripts/RootController.js +++ b/scripts/RootController.js @@ -6,44 +6,16 @@ angular.module('flashy.RootController', ['ui.router', 'ngResource', 'ngSanitize' $rootScope.currentSection = {}; $rootScope.UserService = UserService; $rootScope.ws_host = window.location.origin.replace('http', 'ws'); - //UserService.getUserData().then(function(data) { - // console.log(data); - // $rootScope.user = data; - //}); - /* $('.button-collapse').sideNav({ - menuWidth: 240, // Default is 240 - edge: 'left', // Choose the horizontal origin - closeOnClick: true // Closes side-nav on clicks, useful for Angular/Meteor - } - ); */ - - /* - $('.collapsible').collapsible({ - accordion: false // A setting that changes the collapsible behavior to expandable instead of the default accordion style - }); - */ - - /* - $('#dropdown-button').dropdown({ - closeOnClick: true; - }); - */ - - /* - $('#class-list').on('click',function(){ - $('#classDropdown').toggle(); - }) - */ var postlogin = function(data) { - $scope.user = data; - //UserService.redirectToDefaultState($state); + UserService.redirectToDefaultState($state); }; if (UserService.isLoggedIn()) { postlogin(UserService.getUserData()); } else { UserService.getUserData().then(postlogin); } + var ws = new WebSocket($rootScope.ws_host + '/ws/rce/?subscribe-broadcast'); ws.onmessage = function(e) { console.log('got websocket message ' + e.data);