Packs page and filters.
authorCameron Ball <cameron@getapproved.com.au>
Wed, 26 Nov 2014 08:31:54 +0000 (16:31 +0800)
committerCameron Ball <cameron@getapproved.com.au>
Wed, 26 Nov 2014 08:31:54 +0000 (16:31 +0800)
app/components/simfiles/simfile-directive.js
app/divinelegy.js
app/index.html
app/pages/packs/packs.html [new file with mode: 0644]
app/pages/packs/packs.js [new file with mode: 0644]
app/pages/simfiles/simfiles.js

index 3ce3470..6442079 100644 (file)
@@ -18,11 +18,6 @@ directive('simfile', function()
             bgChanges: '=',
             fgChanges: '='
         },
-        templateUrl: 'components/simfiles/simfile.html',
-        link: function(scope, element, attrs){
-            
-            console.log(scope.simfile);
-            console.log(scope.bpmChanges);
-        }
+        templateUrl: 'components/simfiles/simfile.html'
     };
 });
\ No newline at end of file
index d53d25e..7c7cb1d 100644 (file)
@@ -9,7 +9,8 @@ angular.module('DivinElegy', [
   'DivinElegy.components.simfiles',
   'DivinElegy.pages.index',
   'DivinElegy.pages.upload',
-  'DivinElegy.pages.simfiles'
+  'DivinElegy.pages.simfiles',
+  'DivinElegy.pages.packs'
 ]).
 
 config(['$routeProvider', '$locationProvider', function($routeProvider) {
@@ -34,6 +35,11 @@ config(['$routeProvider', '$locationProvider', function($routeProvider) {
         templateUrl: 'pages/simfiles/simfiles.html',
         controller: 'SimfileController'
     }).
+    when('/packs',
+    {
+        templateUrl: 'pages/packs/packs.html',
+        controller: 'PackController'
+    }).
     otherwise({redirectTo: '/'});
 }]).
         
index 5de5f42..55ff012 100644 (file)
@@ -33,6 +33,7 @@
         <script src="pages/index/index.js"></script>
         <script src="pages/upload/upload.js"></script>
         <script src="pages/simfiles/simfiles.js"></script>
+        <script src="pages/packs/packs.js"></script>
         <!-- End -->
         
         <!-- good luck cameron -->
diff --git a/app/pages/packs/packs.html b/app/pages/packs/packs.html
new file mode 100644 (file)
index 0000000..1945719
--- /dev/null
@@ -0,0 +1,61 @@
+<input type="text" ng-model="packTitleFilterKeyword" placeholder="pack title..."/>\r
+<input type="text" ng-model="artistFilterKeyword" placeholder="artist..."/>\r
+<input type="text" ng-model="songTitleFilterKeyword" placeholder="song title..."/>\r
+<select ng-model="difficultyFilterKeyword">\r
+    <option value="Any" selected="selected">Any</option>\r
+    <option value="Novice">Novice</option>\r
+    <option value="Easy">Easy</option>\r
+    <option value="Medium">Medium</option>\r
+    <option value="Hard">Hard</option>\r
+    <option value="Expert">Expert</option>\r
+</select>\r
+<input type="text" ng-model="ratingFilterKeyword" placeholder="rating..."/>\r
+<input type="text" ng-model="stepArtistFilterKeyword" placeholder="step artist..."/>\r
+FG changes: <input type="checkbox" ng-model="fgChangesFilterKeyword">\r
+BG changes: <input type="checkbox" ng-model="bgChangesFilterKeyword">\r
+BPM changes: <input type="checkbox" ng-model="bpmChangesFilterKeyword">\r
+\r
+<ul class="simfileList">\r
+    <li class="simfileListing" ng-class="{active: isListingActive($index)}" ng-repeat="pack in packList | filter: packTitleFilter\r
+                                                                                                        | filter: artistFilter\r
+                                                                                                        | filter: songTitleFilter\r
+                                                                                                        | filter: stepsFilter\r
+                                                                                                        | filter: fgChangesFilter\r
+                                                                                                        | filter: bgChangesFilter\r
+                                                                                                        | filter: bpmChangesFilter\r
+    " ng-init="contributors=getContributors(pack.contributors)">\r
+        <a ng-click="openListing($index)">{{pack.title}}</a>\r
+        <div class="content" ng-show="isListingActive($index)">\r
+            <img ng-src="{{rockEndpoint}}{{pack.banner}}" alt="swage" />\r
+            <table>\r
+                <tr>\r
+                    <th>Title:</th>\r
+                    <td>{{pack.title}}</td>\r
+                </tr>\r
+                <tr>\r
+                    <th>Contributors:</th>\r
+                    <td>{{contributors}}</td>\r
+                </tr>\r
+            </table>\r
+            <div class="clearfix"></div>\r
+            <h1>Charts</h1>\r
+            <ul>\r
+                <li class="simfileListing" ng-repeat="simfile in pack.simfiles" ng-class="{active: isListingActive(getSimfileListingIndex(pack.title,$index))}">\r
+                    <a ng-click="openListing(getSimfileListingIndex(pack.title,$index))">{{simfile.title}}</a>\r
+                    <div class="content" ng-show="isListingActive(getSimfileListingIndex(pack.title,$index))">\r
+                        <simfile rock-endpoint="rockEndpoint"\r
+                                 simfile="simfile"\r
+                                 banner="simfile.banner"\r
+                                 title="simfile.title"\r
+                                 artist="simfile.artist"\r
+                                 steps="simfile.steps"\r
+                                 bpm-changes="simfile.bpmChanges"\r
+                                 bg-changes="simfile.bgChanges"\r
+                                 fg-changes="simfile.fgChanges"\r
+                        />\r
+                    </div>\r
+                </li>\r
+            </ul>\r
+        </div>\r
+    </li>\r
+</ul>
\ No newline at end of file
diff --git a/app/pages/packs/packs.js b/app/pages/packs/packs.js
new file mode 100644 (file)
index 0000000..d5f69ff
--- /dev/null
@@ -0,0 +1,164 @@
+'use strict';
+
+angular.module("DivinElegy.pages.packs", ["DivinElegy.components.simfiles","DivinElegy.components.config"])
+
+.controller("PackController", ['$scope', 'rockEndpoint', 'SimfileService', function($scope, rockEndpoint, SimfileService)
+{
+    $scope.rockEndpoint = rockEndpoint;
+    $scope.activeListings = [];
+    $scope.packTitleFilterKeyword = null;
+    $scope.artistFilterKeyword = null;
+    $scope.songTitleFilterKeyword = null;
+    $scope.difficultyFilterKeyword = 'Any';
+    $scope.ratingFilterKeyword = null;
+    $scope.contributorFilterKeyword = null;
+    $scope.fgChangesFilterKeyword = null;
+    $scope.bgChangesFilterKeyword = null;
+    $scope.bpmChangesFilterKeyword = null;
+    $scope.simfileList = [];
+    
+    $scope.openListing = function(listing)
+    {
+        if($scope.isListingActive(listing))
+        {
+            $scope.activeListings.splice($scope.activeListings.indexOf(listing), 1);
+        } else {
+            $scope.activeListings.push(listing);
+        }
+    };
+    
+    $scope.isListingActive = function(listing)
+    {
+        if($scope.activeListings.indexOf(listing) > -1)
+        {
+            return true;
+        } else {
+            return false;
+        }
+    };
+    
+    $scope.getContributors = function(contribs)
+    {
+        return contribs.join(', ');
+    }
+    
+    $scope.getSimfileListingIndex = function(packName, index)
+    {
+        return packName + "" + index;
+    }
+    
+    $scope.packTitleFilter = function (pack)
+    {
+        var re = new RegExp($scope.packTitleFilterKeyword, 'i');
+        return !$scope.packTitleFilterKeyword || re.test(pack.title);
+    };
+    
+    $scope.artistFilter = function (pack)
+    {
+        var re = new RegExp($scope.artistFilterKeyword, 'i');
+        var simfiles = pack.simfiles;
+        var match = false;
+        for(var i=0; i<simfiles.length; i++)
+        {
+            match = re.test(simfiles[i].artist);
+            if(match) break;
+        }
+        
+        return !$scope.artistFilterKeyword || match;
+    };
+    
+    $scope.songTitleFilter = function (pack)
+    {
+        var re = new RegExp($scope.songTitleFilterKeyword, 'i');
+        var simfiles = pack.simfiles;
+        var match = false;
+        for(var i=0; i<simfiles.length; i++)
+        {
+            match = re.test(simfiles[i].title);
+            if(match) break;
+        }
+        
+        return !$scope.songTitleFilterKeyword || match;
+    };
+    
+    $scope.stepsFilter = function(pack)
+    {
+        // Step 0: Both rating and difficulty keyword are null
+        if(!$scope.ratingFilterKeyword && $scope.difficultyFilterKeyword === 'Any' && !$scope.stepArtistFilterKeyword)
+        {
+            return true;
+        }
+        
+        var re = new RegExp($scope.stepArtistFilterKeyword, 'i');
+        var simfiles = pack.simfiles;
+        
+        for(var i=0; i<simfiles.length; i++)
+        {
+            for(var j=0; j<simfiles[i].steps.single.length; j++)
+            {
+                var chartInfo = simfiles[i].steps.single[j];
+                var match = true;
+                if($scope.ratingFilterKeyword && chartInfo.rating !== $scope.ratingFilterKeyword)
+                {
+                    match = false;
+                }
+
+                if($scope.difficultyFilterKeyword !== 'Any' && chartInfo.difficulty !== $scope.difficultyFilterKeyword)
+                {
+                    match = false;
+                }
+
+                if($scope.stepArtistFilterKeyword && !re.test(chartInfo.artist))
+                {
+                    match = false;
+                }
+
+                if(match) return true;
+            }
+            
+            for(var j=0; j<simfiles[i].steps.double.length; j++)
+            {
+                var chartInfo = simfiles[i].steps.double[j];
+                var match = true;
+                if($scope.ratingFilterKeyword && chartInfo.rating !== $scope.ratingFilterKeyword)
+                {
+                    match = false;
+                }
+
+                if($scope.difficultyFilterKeyword !== 'Any' && chartInfo.difficulty !== $scope.difficultyFilterKeyword)
+                {
+                    match = false;
+                }
+
+                if($scope.stepArtistFilterKeyword && !re.test(chartInfo.artist))
+                {
+                    match = false;
+                }
+
+                if(match) return true;;
+            }
+        }
+
+        return false;
+    };
+
+    $scope.fgChangesFilter = function(simfile)
+    {
+            return !$scope.fgChangesFilterKeyword || simfile.fbChanges === 'Yes';
+    };
+    
+    $scope.bgChangesFilter = function(simfile)
+    {
+            return !$scope.bgChangesFilterKeyword || simfile.bgChanges === 'Yes';
+    };
+
+    $scope.bpmChangesFilter = function(simfile)
+    {
+            return !$scope.bpmChangesFilterKeyword || simfile.bpmChanges === 'Yes';
+    };
+    
+    SimfileService.getPacks().then(function(packs)
+    {
+        $scope.packList = packs;
+    });
+}]);
\ No newline at end of file
index 17e1923..278fd16 100644 (file)
@@ -126,9 +126,4 @@ angular.module("DivinElegy.pages.simfiles", ["DivinElegy.components.simfiles","D
     {
         $scope.simfileList = simfiles;
     });
-    
-    SimfileService.getPacks().then(function(packs)
-    {
-        $scope.packList = packs;
-    });
 }]);
\ No newline at end of file