Commit 1402915618e0da76afd50652d9c5b4f21e4e3cb7
1 parent
35b02d3f26
Exists in
master
and in
1 other branch
EMMM VEEEE SEEEE
Showing 8 changed files with 47 additions and 78 deletions Side-by-side Diff
config.js
View file @
1402915
home.html
View file @
1402915
scripts/CardGridController.js
View file @
1402915
1 | 1 | angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSocket']).controller = |
2 | 2 | function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService) { |
3 | - $scope.cards = false; | |
3 | + $scope.cards = []; | |
4 | + $scope.deck_cards = []; | |
4 | 5 | $scope.cardCols = []; // organized data |
5 | 6 | $scope.numCols = 0; |
6 | 7 | $scope.cardTable = {}; // look up table of cards, {'colNum':col, 'obj':card} |
... | ... | @@ -26,26 +27,6 @@ |
26 | 27 | }); |
27 | 28 | }; |
28 | 29 | |
29 | - $scope.pullCard = function(id) { | |
30 | - if ($scope.deck_cards[id]) return console.log('Not pulling', id, "because it's already in deck"); | |
31 | - $http.post('/api/flashcards/' + id + '/pull/'). | |
32 | - success(function(data) { | |
33 | - console.log('pulled flashcard #' + id); | |
34 | - }). | |
35 | - error(function(data) { | |
36 | - console.log('failed to pull flashcard #' + id); | |
37 | - }); | |
38 | - }; | |
39 | - $scope.unpullCard = function(id) { | |
40 | - if (!$scope.deck_cards[id]) return console.log('Not unpulling', id, "because it's not in deck"); | |
41 | - $http.post('/api/flashcards/' + id + '/unpull/'). | |
42 | - success(function(data) { | |
43 | - console.log('unpulled flashcard #' + id); | |
44 | - }). | |
45 | - error(function(data) { | |
46 | - console.log('failed to unpull flashcard #' + id); | |
47 | - }); | |
48 | - }; | |
49 | 30 | $scope.refreshLayout = function() { |
50 | 31 | numCols = Math.max(1, Math.floor(($window.innerWidth - 17) / 250)); |
51 | 32 | |
... | ... | @@ -118,7 +99,7 @@ |
118 | 99 | }; |
119 | 100 | |
120 | 101 | |
121 | - $scope.deck_cards = []; | |
102 | + | |
122 | 103 | $http.get('/api/sections/' + $scope.sectionId + '/deck/'). |
123 | 104 | success(function(data) { |
124 | 105 |
scripts/DeckController.js
View file @
1402915
... | ... | @@ -2,20 +2,8 @@ |
2 | 2 | |
3 | 3 | controller('DeckController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService) { |
4 | 4 | angular.module('flashy.CardGridController').controller.apply(this, arguments); |
5 | - | |
6 | - $scope.refreshCards = function() { | |
7 | - $http.get('/api/sections/' + $scope.sectionId + '/deck/'). | |
8 | - success(function(data) { | |
9 | - console.log(data); | |
10 | - $scope.cards = data; | |
11 | - $scope.refreshLayout(); | |
12 | - console.log('success in refresh cards...'); | |
13 | - }). | |
14 | - error(function(err) { | |
15 | - console.log('refresh fail'); | |
16 | - }); | |
17 | - }; | |
18 | - $scope.refreshCards(); | |
5 | + $scope.cards = $scope.deck_cards; | |
6 | + $scope.refreshLayout(); | |
19 | 7 | } |
20 | 8 | ); |
scripts/FeedController.js
View file @
1402915
1 | 1 | angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket', 'contenteditable']). |
2 | 2 | |
3 | - controller('FeedController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService) { | |
3 | + controller('FeedController', function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, UserService, Flashcard) { | |
4 | 4 | angular.module('flashy.CardGridController').controller.apply(this, arguments); |
5 | 5 | $scope.refreshCards = function() { |
6 | 6 | $http.get('/api/sections/' + $scope.sectionId + '/feed/'). |
7 | 7 | success(function(data) { |
8 | 8 | console.log(data); |
9 | 9 | $scope.cards = []; |
10 | - for (var i in data) { | |
11 | - console.log(data[i].id); | |
12 | - data[i].isInDeck = function(id) { | |
13 | - return $scope.cardInDeck(id); | |
14 | - }.bind(this, data[i].id); | |
15 | - data[i].unpull = function(id) { | |
16 | - $scope.unpullCard(id); | |
17 | - //$scope.deck_cards[id] = undefined; | |
18 | - }.bind(this, data[i].id); | |
19 | - data[i].pull = function(id, card) { | |
20 | - $scope.pullCard(id); | |
21 | - //$scope.deck_cards[id] = card; | |
22 | - }.bind(this, data[i].id, data[i]); | |
23 | - $scope.cards.push(data[i]); | |
24 | - } | |
10 | + for (var i in data) $scope.cards.push(new Flashcard(data[i], $scope.deck_cards)); | |
25 | 11 | $scope.refreshLayout(); |
26 | 12 | console.log('success in refresh cards...'); |
27 | 13 | }). |
scripts/FlashcardDirective.js
View file @
1402915
... | ... | @@ -11,32 +11,7 @@ |
11 | 11 | }, |
12 | 12 | link: function(scope, element) { |
13 | 13 | /* Handles width of the card */ |
14 | - scope.textPieces = []; | |
15 | - scope.flashcard.mask.sort(function(a, b) { | |
16 | - return a[0] - b[0]; | |
17 | - }); | |
18 | - var i = 0; | |
19 | - scope.flashcard.mask.forEach(function(blank) { | |
20 | - scope.textPieces.push({text: scope.flashcard.text.slice(i, blank[0])}); | |
21 | - scope.textPieces.push({text: scope.flashcard.text.slice(blank[0], blank[1]), blank: true}); | |
22 | - i = blank[1]; | |
23 | - }); | |
24 | - scope.textPieces.push({text: scope.flashcard.text.slice(i)}); | |
25 | 14 | |
26 | - /* Hides card from feed */ | |
27 | - scope.hideCard = function(flashcard) { | |
28 | - if ($state.current.name == 'feed') { | |
29 | - $http.post('/api/flashcards/' + flashcard.id + '/hide/'). | |
30 | - success(function(data) { | |
31 | - console.log('card hide success'); | |
32 | - scope.startShrink = true; | |
33 | - scope.refresh(flashcard); | |
34 | - }). | |
35 | - error(function(data) { | |
36 | - console.log('card hide FAILURE'); | |
37 | - }); | |
38 | - } | |
39 | - }; | |
40 | 15 | } |
41 | 16 | }; |
42 | 17 | } |
scripts/FlashcardFactory.js
View file @
1402915
1 | +angular.module('flashy.FlashcardFactory', ['ui.router']). | |
2 | + factory('Flashcard', function ($http) { | |
3 | + var Flashcard = function (data, deck) { | |
4 | + for (var k in data) this[k] = data[k]; | |
5 | + this.deck = deck; | |
6 | + this.textPieces = []; | |
7 | + this.mask.sort(function (a, b) { | |
8 | + return a[0] - b[0]; | |
9 | + }); | |
10 | + | |
11 | + var i = 0; | |
12 | + this.mask.forEach(function (blank) { | |
13 | + this.textPieces.push({text: this.text.slice(i, blank[0])}); | |
14 | + this.textPieces.push({text: this.text.slice(blank[0], blank[1]), blank: true}); | |
15 | + i = blank[1]; | |
16 | + }, this); | |
17 | + this.textPieces.push({text: this.text.slice(i)}); | |
18 | + }; | |
19 | + | |
20 | + Flashcard.prototype.isInDeck = function () { | |
21 | + return this.deck[this.id]; | |
22 | + }; | |
23 | + Flashcard.prototype.pull = function () { | |
24 | + if (this.deck[this.id]) return console.log('Not pulling', this.id, "because it's already in deck"); | |
25 | + return $http.post('/api/flashcards/' + this.id + '/pull/'); | |
26 | + }; | |
27 | + Flashcard.prototype.unpull = function () { | |
28 | + if (!this.deck[this.id]) return console.log('Not unpulling', this.id, "because it's not in deck"); | |
29 | + return $http.post('/api/flashcards/' + this.id + '/unpull/'); | |
30 | + }; | |
31 | + Flashcard.prototype.hide = function () { | |
32 | + return $http.post('/api/flashcards/' + this.id + '/hide/'); | |
33 | + }; | |
34 | + | |
35 | + return Flashcard; | |
36 | + }); |
templates/flashcard.html
View file @
1402915
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | ng-class="{'shrinky': startShrink}"> |
3 | 3 | <div class="valign-wrapper"> |
4 | 4 | <div class="card-content valign center-align"> |
5 | - <span ng-repeat="piece in textPieces" | |
5 | + <span ng-repeat="piece in flashcard.textPieces" | |
6 | 6 | ng-style="piece.blank ? {'opacity':'0.4', 'border-bottom': '1px solid black'} : {}">{{piece.text}}</span> |
7 | 7 | </div> |
8 | 8 | </div> |