Commit 43f34fa03541dffeff3aded4a43c48fd307c92ff

Authored by Andrew Buss
1 parent b06f64922c

more refactoring; root view now redirects to default state

Showing 6 changed files with 19 additions and 48 deletions Side-by-side Diff

... ... @@ -87,7 +87,7 @@
87 87 }).
88 88 state('root', {
89 89 resolve: auth_resolve,
90   - url: '',
  90 + url: '/',
91 91 controller: 'RootController'
92 92 }).
93 93 state('feed', {
scripts/CardGridController.js View file @ 43f34fa
... ... @@ -17,11 +17,6 @@
17 17 //$scope.moveQueue = []; // queue of flashcard objects
18 18 $rootScope.currentSection = $scope.section;
19 19  
20   - if (!UserService.isInSection($scope.sectionId)) {
21   - console.log('user is not enrolled in ' + $scope.sectionId);
22   - $state.go('addclass');
23   - }
24   -
25 20 $scope.refreshColumnWidth = function() {
26 21 avail = $window.innerWidth - 17;
27 22 width = Math.floor(avail / Math.floor(avail / 250));
scripts/DeckController.js View file @ 43f34fa
... ... @@ -5,7 +5,7 @@
5 5 angular.module('flashy.CardGridController').CardGridController.apply(this, arguments).then(function() {
6 6 $scope.refreshLayout();
7 7 });
8   - $scope.cards = $scope.deck.deck;
  8 + $scope.cards = $scope.deck.cards;
9 9 $scope.deckPullCallback = $scope.addCardToGrid;
10 10 $scope.deckUnpullCallback = $scope.hideCardFromGrid;
11 11  
scripts/DeckFactory.js View file @ 43f34fa
1 1 angular.module('flashy.DeckFactory', ['ui.router', 'flashy.FlashcardFactory', 'ngWebSocket']).
2   - factory('Deck', function ($http, $rootScope, $websocket, Flashcard) {
  2 + factory('Deck', function ($http, $rootScope, $state, $websocket, Flashcard, UserService) {
3 3  
4 4 var Deck = function (sectionId, callbacks) {
  5 + if (!UserService.isInSection(sectionId)) {
  6 + console.log('user is not enrolled in ' + sectionId);
  7 + $state.go('addclass');
  8 + }
5 9 obj = this;
6   - this.deck = [];
  10 + this.cards = [];
7 11 this.section = $rootScope.SectionResource.get({sectionId: sectionId});
  12 +
8 13 this.ws = $websocket($rootScope.ws_host + '/ws/deck/' + sectionId + '?subscribe-user');
9 14 this.contains = function (id) {
10   - return this.deck[id];
  15 + return this.cards[id];
11 16 };
12 17  
13 18 this.ws.onMessage(function (message) {
14 19  
... ... @@ -15,11 +20,11 @@
15 20 console.log('message', data);
16 21 card = new Flashcard(data.flashcard);
17 22 if (data.event_type == 'card_pulled') {
18   - obj.deck[card.id] = card;
  23 + obj.cards[card.id] = card;
19 24 if (callbacks.cardPullCallback) callbacks.cardPullCallback(card);
20 25 }
21 26 if (data.event_type == 'card_unpulled') {
22   - obj.deck[card.id] = undefined;
  27 + obj.cards[card.id] = undefined;
23 28 if (callbacks.cardUnpullCallback) callbacks.cardUnpullCallback(card);
24 29 }
25 30 if (data.event_type == 'card_hidden') {
26 31  
... ... @@ -27,13 +32,13 @@
27 32 }
28 33 });
29 34 this.deckPromise = $http.get('/api/sections/' + sectionId + '/deck/').success(function (data) {
30   - for (i in data) obj.deck[data[i].id] = new Flashcard(data[i], obj);
  35 + for (i in data) obj.cards[data[i].id] = new Flashcard(data[i], obj);
31 36 console.log("got user's deck", data);
32 37 });
33 38 this.cleanup = function () {
34 39 this.ws.close();
35 40 };
36   - this.forEach = this.deck.forEach;
  41 + this.forEach = this.cards.forEach;
37 42 };
38 43  
39 44 return Deck;
scripts/FlashcardFactory.js View file @ 43f34fa
1 1 angular.module('flashy.FlashcardFactory', ['ui.router']).
2 2 factory('Flashcard', function ($http) {
3 3 var FlashcardCache = [];
4   - var Deck = null;
5 4 var Flashcard = function (data, deck) {
6   - if(deck) Deck = deck;
7 5 if (typeof data == 'number') return FlashcardCache[data];
8 6 if (FlashcardCache[data.id]) return FlashcardCache[data.id];
  7 + if (deck) this.deck = deck;
9 8 for (var k in data) this[k] = data[k];
10 9 this.textPieces = [];
11 10 this.mask.sort(function (a, b) {
12 11  
... ... @@ -27,9 +26,9 @@
27 26 };
28 27  
29 28 Flashcard.prototype.isInDeck = function () {
30   - return !(typeof Deck.contains(this.id) === 'undefined');
  29 + return !(typeof this.deck.contains(this.id) === 'undefined');
31 30 };
32   - Flashcard.prototype.pullUnpull = function() {
  31 + Flashcard.prototype.pullUnpull = function () {
33 32 if (this.isInDeck()) this.unpull();
34 33 else this.pull();
35 34 };
scripts/RootController.js View file @ 43f34fa
... ... @@ -6,44 +6,16 @@
6 6 $rootScope.currentSection = {};
7 7 $rootScope.UserService = UserService;
8 8 $rootScope.ws_host = window.location.origin.replace('http', 'ws');
9   - //UserService.getUserData().then(function(data) {
10   - // console.log(data);
11   - // $rootScope.user = data;
12   - //});
13   - /* $('.button-collapse').sideNav({
14   - menuWidth: 240, // Default is 240
15   - edge: 'left', // Choose the horizontal origin
16   - closeOnClick: true // Closes side-nav on <a> clicks, useful for Angular/Meteor
17   - }
18   - ); */
19 9  
20   - /*
21   - $('.collapsible').collapsible({
22   - accordion: false // A setting that changes the collapsible behavior to expandable instead of the default accordion style
23   - });
24   - */
25   -
26   - /*
27   - $('#dropdown-button').dropdown({
28   - closeOnClick: true;
29   - });
30   - */
31   -
32   - /*
33   - $('#class-list').on('click',function(){
34   - $('#classDropdown').toggle();
35   - })
36   - */
37   -
38 10 var postlogin = function(data) {
39   - $scope.user = data;
40   - //UserService.redirectToDefaultState($state);
  11 + UserService.redirectToDefaultState($state);
41 12 };
42 13 if (UserService.isLoggedIn()) {
43 14 postlogin(UserService.getUserData());
44 15 } else {
45 16 UserService.getUserData().then(postlogin);
46 17 }
  18 +
47 19 var ws = new WebSocket($rootScope.ws_host + '/ws/rce/?subscribe-broadcast');
48 20 ws.onmessage = function(e) {
49 21 console.log('got websocket message ' + e.data);