Commit 7cf67e5616aa5ca55642b7f4f56af534c25ddd1a
1 parent
5c6363eb7e
Exists in
master
and in
1 other branch
merge proper
Showing 1 changed file with 42 additions and 60 deletions Side-by-side Diff
scripts/FeedController.js
View file @
7cf67e5
... | ... | @@ -8,11 +8,11 @@ |
8 | 8 | return $state.go('addclass'); |
9 | 9 | } |
10 | 10 | $rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId}); |
11 | - $rootScope.debug_flashcard = false; | |
11 | + $rootScope.debug_flashcard = false; | |
12 | 12 | $scope.cards = false; |
13 | 13 | $scope.cardCols = []; // organized data |
14 | 14 | $scope.numCols = 0; |
15 | - $scope.cardTable = {}; // look up table of cards, {'colNum':col, 'obj':card} | |
15 | + $scope.cardTable = {}; // look up table of cards, {'colNum':col, 'obj':card} | |
16 | 16 | |
17 | 17 | function calculate_cols() { |
18 | 18 | var avail = $window.innerWidth - 17; |
... | ... | @@ -43,7 +43,7 @@ |
43 | 43 | for (i = 0; i < $scope.numCols; i++) cols.push([]); |
44 | 44 | $scope.cards.forEach(function(card, i) { |
45 | 45 | cols[i % $scope.numCols].push(card); |
46 | - $scope.cardTable[card.id] = {'colNum': (i % $scope.numCols), 'obj': card}; | |
46 | + $scope.cardTable[card.id] = {'colNum': (i % $scope.numCols), 'obj': card}; | |
47 | 47 | }); |
48 | 48 | // wait until the next digest cycle to update cardCols |
49 | 49 | |
50 | 50 | |
... | ... | @@ -73,14 +73,14 @@ |
73 | 73 | $scope.add = function(card) { |
74 | 74 | var colNum = 0; |
75 | 75 | var lowestCol = $scope.cardCols[0]; |
76 | - var lowestColNum = 0; | |
76 | + var lowestColNum = 0; | |
77 | 77 | while (colNum < $scope.numCols) { |
78 | 78 | if ($scope.cardCols[colNum].length == 0) { |
79 | 79 | lowestCol = $scope.cardCols[colNum]; |
80 | 80 | break; |
81 | 81 | } else if ($scope.cardCols[colNum].length < lowestCol.length) { |
82 | 82 | lowestCol = $scope.cardCols[colNum]; |
83 | - lowestColNum = colNum; | |
83 | + lowestColNum = colNum; | |
84 | 84 | lowestColLen = $scope.cardCols[colNum].length; |
85 | 85 | } |
86 | 86 | colNum++; |
87 | 87 | |
88 | 88 | |
89 | 89 | |
90 | 90 | |
... | ... | @@ -89,68 +89,50 @@ |
89 | 89 | $scope.cards.push(data); |
90 | 90 | $timeout(function() { |
91 | 91 | lowestCol.unshift(card); |
92 | - $scope.cardTable[card.id] = {'colNum': lowestColNum, 'obj': card}; | |
92 | + $scope.cardTable[card.id] = {'colNum': lowestColNum, 'obj': card}; | |
93 | 93 | $timeout($scope.refreshColumnWidth); |
94 | 94 | }); |
95 | 95 | }; |
96 | 96 | |
97 | - $scope.sortAdd = function(card, array) { | |
98 | - console.log('sort add'); | |
99 | - array.forEach(function(ele, i, ary) { | |
100 | - if (ele.score <= card.score) { | |
101 | - ary.splice(i, 0, card); | |
102 | - return; | |
103 | - } | |
104 | - }); | |
105 | - }; | |
97 | + $scope.sortAdd = function(card, array) { | |
98 | + console.log('sort add'); | |
99 | + array.forEach(function(ele, i, ary) { | |
100 | + if (ele.score <= card.score) { | |
101 | + ary.splice(i, 0, card); | |
102 | + return; | |
103 | + } | |
104 | + }); | |
105 | + }; | |
106 | 106 | |
107 | 107 | $scope.hide = function(card) { |
108 | 108 | console.log('hiding card'); |
109 | 109 | var found = -1; |
110 | - col = $scope.cardTable[card.id].colNum; | |
111 | - found = $scope.cardCols[col].indexOf(card); | |
112 | - if (found != -1) { | |
113 | - $scope.cardCols[col].splice(found, 1); | |
114 | - console.log('card hidden'); | |
115 | - return col; | |
116 | - } | |
110 | + col = $scope.cardTable[card.id].colNum; | |
111 | + found = $scope.cardCols[col].indexOf(card); | |
112 | + if (found != -1) { | |
113 | + $scope.cardCols[col].splice(found, 1); | |
114 | + console.log('card hidden'); | |
115 | + return col; | |
116 | + } | |
117 | 117 | console.log('Error finding card to hide:'); |
118 | 118 | console.log(card); |
119 | - return -1; | |
120 | - }; << | |
121 | -<< << < HEAD; | |
119 | + return -1; | |
120 | + }; | |
121 | + $scope.update = function(id, new_score) { // NOT WORKING | |
122 | + /*card = $scope.cardTable[id].obj; | |
123 | + if (new_score == card.score) { | |
124 | + console.log('score same, no update required'); | |
125 | + return; | |
126 | + } | |
127 | + console.log('updating'); | |
128 | + card.score = new_score; | |
129 | + console.log(card); | |
130 | + col = $scope.hide(card) | |
131 | + if (col != -1) { | |
132 | + $scope.sortAdd(card, $scope.cardCols[col]); | |
133 | + }*/ | |
134 | + }; | |
122 | 135 | |
123 | - $scope.update = function(id, new_score) { === // NOT WORKING | |
124 | - /*card = $scope.cardTable[id].obj; | |
125 | - if (new_score == card.score) { | |
126 | -======= | |
127 | - | |
128 | - $scope.update = function(id, new_score) { | |
129 | - card = $scope.cardTable[id].obj; | |
130 | - if (Math.abs(new_score - card.score) < .0001) { | |
131 | ->>>>>>> 5d2fe8fd2eba8b425eb41fe6382ff57ae66bb100 | |
132 | - console.log('score same, no update required'); | |
133 | - return; | |
134 | - } | |
135 | - console.log('updating'); | |
136 | - card.score = new_score; | |
137 | - console.log(card); | |
138 | -<<<<<<< HEAD | |
139 | - | |
140 | - col = $scope.hide(card) | |
141 | - if (col != -1) { | |
142 | - $scope.sortAdd(card, $scope.cardCols[col]); | |
143 | - }*/ | |
144 | -=== = | |
145 | -var column = $scope.cardCols[$scope.cardTable[id].colNum]; | |
146 | - var found = column.indexOf(card); | |
147 | - var i = 0; | |
148 | - for (; i < column.length; i++) | |
149 | - if (column[i].score <= card.score) break; | |
150 | - column.splice(i, 0, column.splice(found, 1)[0]); >>> | |
151 | ->>> > 5d2fe8fd2eba8b425eb41fe6382ff57ae66bb100; | |
152 | - }; | |
153 | - | |
154 | 136 | var loc = window.location, new_uri; |
155 | 137 | if (loc.protocol === 'https:') { |
156 | 138 | new_uri = 'wss:'; |
157 | 139 | |
158 | 140 | |
... | ... | @@ -164,14 +146,14 @@ |
164 | 146 | console.log('websocket connected'); |
165 | 147 | }; |
166 | 148 | ws.onmessage = function(e) { |
167 | - data = JSON.parse(e.data); | |
149 | + data = JSON.parse(e.data); | |
168 | 150 | console.log('got websocket message ' + e.data); |
169 | - console.log(data); | |
151 | + console.log(data); | |
170 | 152 | if (data.event_type == 'new_card') { |
171 | 153 | $scope.add(data.flashcard); |
172 | 154 | } else if (data.event_type == 'score_change') { |
173 | - $scope.update(data.flashcard_id, data.new_score); | |
174 | - } | |
155 | + $scope.update(data.flashcard_id, data.new_score); | |
156 | + } | |
175 | 157 | }; |
176 | 158 | ws.onerror = function(e) { |
177 | 159 | console.error(e); |