Only run expensive filters on filter keyword change instead of every digest cycle.
authorCameron Ball <cameron@getapproved.com.au>
Fri, 19 Dec 2014 03:34:46 +0000 (11:34 +0800)
committerCameron Ball <cameron@getapproved.com.au>
Fri, 19 Dec 2014 03:34:46 +0000 (11:34 +0800)
app/pages/packs/packs.html
app/pages/packs/packs.js

index de8a98a..ce8a2a9 100644 (file)
@@ -46,6 +46,7 @@
         </select>\r
     </div>\r
 </div>\r
+\r
 <accordion close-others="false">\r
     <accordion-group class         = "simfileListing"\r
                      is-open       = "isOpen"\r
                      ng-class      = "{active: isOpen}"\r
                      heading       = "{{isOpen ? '- ' + pack.title : '+ ' + pack.title}}"\r
                      ng-init       = "contributors=getContributors(pack.contributors); beast=false"\r
-                     ng-repeat     = "pack in filteredPackList = (packList | filter: packTitleFilter\r
-                                                                       | filter: simfileFilter)\r
-                                                                       | startFrom: (currentPage-1)*pageSize\r
-                                                                       | limitTo: pageSize"\r
+                     ng-repeat     = "pack in filteredPackList | startFrom: (currentPage-1)*pageSize | limitTo: pageSize"\r
     >\r
         <div ng-if="beast || isOpen">\r
             <img ng-src="{{rockEndpoint}}{{pack.banner}}" alt="swage" />\r
index 3eeab02..38138c3 100644 (file)
@@ -2,7 +2,7 @@
 
 angular.module("DivinElegy.pages.packs", ["DivinElegy.components.simfiles","DivinElegy.components.user","DivinElegy.components.config","DivinElegy.components.ui", "ui.bootstrap"])
 
-.controller("PackController", ['$scope', '$rootScope', 'rockEndpoint', 'SimfileService', 'UserService', 'UiSettingsService', 'HelloService', function($scope, $rootScope, rockEndpoint, SimfileService, UserService, UiSettingsService, HelloService)
+.controller("PackController", ['$scope', '$rootScope', 'rockEndpoint', 'SimfileService', 'UserService', 'UiSettingsService', 'HelloService', 'filterFilter', function($scope, $rootScope, rockEndpoint, SimfileService, UserService, UiSettingsService, HelloService, filterFilter)
 {
     $scope.rockEndpoint = rockEndpoint;
     $scope.packTitleFilterKeyword = null;
@@ -15,6 +15,13 @@ angular.module("DivinElegy.pages.packs", ["DivinElegy.components.simfiles","Divi
     $scope.bgChangesFilterKeyword = 'Any';
     $scope.bpmChangesFilterKeyword = 'Any';
     $scope.modeFilterKeyword = 'Any';
+    $scope.packList = [];
+    $scope.filteredPackList = [];
+    
+    var watchMen = ['packTitleFilterKeyword', 'artistFilterKeyword', 'songTitleFilterKeyword', 'difficultyFilterKeyword', 'ratingFilterKeyword', 'stepArtistFilterKeyword', 'fgChangesFilterKeyword', 'bgChangesFilterKeyword', 'bpmChangesFilterKeyword', 'modeFilterKeyword'];
+    $scope.$watchGroup(watchMen, function(newValues, oldValues) {
+        $scope.applyFilters();
+    });
     
     var filesizeBytes = function(size)  
     {  
@@ -169,13 +176,17 @@ angular.module("DivinElegy.pages.packs", ["DivinElegy.components.simfiles","Divi
         
         return match;
     };
-           
-    $scope.packList = [];
-           
+    
+    $scope.applyFilters = function()
+    {
+        $scope.filteredPackList = filterFilter(filterFilter($scope.packList, $scope.packTitleFilter), $scope.simfileFilter);
+    };
+
     SimfileService.getPacks().then(function(packs)
     {
         $scope.pageSize = UiSettingsService.getDirective('simfilesPerPage');
         $scope.currentPage = 1;
         $scope.packList = packs;
+        $scope.filteredPackList = packs;
     });
 }]);
\ No newline at end of file