Commit 0175b92bdf2ec0763c8025d761c84efa222cb674

Authored by Andrew Buss
1 parent 212592d24c

fix some inefficient reloads

Showing 1 changed file with 10 additions and 24 deletions Side-by-side Diff

scripts/FeedController.js View file @ 0175b92
... ... @@ -15,24 +15,24 @@
15 15 return Math.floor(avail / 250);
16 16 }
17 17  
18   - function createCols(data) {
  18 + $scope.refreshLayout = function() {
19 19 $scope.cardCols = [];
20 20 for (i = 0; i < $scope.cols; i++) $scope.cardCols.push([]);
21 21 var i = 0;
22   - for (card in data) {
  22 + for (card in $scope.cards) {
23 23 if (i >= $scope.cols) i = 0;
24 24 $scope.cardCols[i++].push(card);
25 25 }
26 26 }
27 27  
28   - angular.element($window).bind('resize', $scope.refreshCards);
  28 +
29 29 console.log('cols:' + calculate_cols());
30 30  
31 31 $scope.refreshCards = function () {
32 32 $http.get('/api/sections/' + sectionId + '/feed/').
33 33 success(function (data) {
34 34 console.log(data);
35   - createCols(data);
  35 + $scope.cards = data;
36 36 console.log('success in refresh cards...');
37 37 }).
38 38 error(function (err) {
... ... @@ -40,6 +40,10 @@
40 40 });
41 41 };
42 42  
  43 + angular.element($window).bind('resize', function(){
  44 + if($scope.cols != calculate_cols()) $scope.refreshLayout();
  45 + });
  46 +
43 47 $scope.add = function (card) {
44 48 var col = Math.floor(Math.random() * $scope.cols);
45 49 $scope.cols[col].unshift(card);
... ... @@ -58,25 +62,6 @@
58 62 if (found == -1) console.log('Error finding card to hide:' + card);
59 63 };
60 64  
61   - /* Instance creation */
62   - $http.get('/api/sections/' + sectionId + '/feed/').
63   - success(function (data) {
64   - console.log(data);
65   - $scope.noCards = function () {
66   - alert(data.length);
67   - if (data.length == 0) {
68   - return true;
69   - } else {
70   - return false;
71   - }
72   - }
73   - createCols();
74   - console.log('success in refresh cards...');
75   - }).
76   - error(function (err) {
77   - console.log('pulling feed failed');
78   - });
79   -
80 65 var loc = window.location, new_uri;
81 66 if (loc.protocol === 'https:') {
82 67 new_uri = 'wss:';
... ... @@ -210,7 +195,8 @@
210 195 document.execCommand('bold');
211 196 });
212 197 });
213   -
  198 + $scope.refreshCards();
  199 + $scope.refreshLayout();
214 200 $scope.$on('$destroy', function () {
215 201 ws.close();
216 202 $rootScope.currentSection = {};