diff --git a/frontend/src/css/modules/challenge.scss b/frontend/src/css/modules/challenge.scss index 337aa741d6..0ea0ce0c8b 100644 --- a/frontend/src/css/modules/challenge.scss +++ b/frontend/src/css/modules/challenge.scss @@ -370,4 +370,16 @@ md-select .md-select-value span:first-child:after { .filter-icon { padding: 10px; +} + +.domain-filter { + margin-top: 45px; +} + +.filter-icon { + padding: 10px; +} +.md-select-menu-container{ + z-index: 1000; + margin-top: 10px; } \ No newline at end of file diff --git a/frontend/src/js/controllers/challengeListCtrl.js b/frontend/src/js/controllers/challengeListCtrl.js index 6c9db6e240..83d604feea 100644 --- a/frontend/src/js/controllers/challengeListCtrl.js +++ b/frontend/src/js/controllers/challengeListCtrl.js @@ -6,9 +6,9 @@ .module('evalai') .controller('ChallengeListCtrl', ChallengeListCtrl); - ChallengeListCtrl.$inject = ['utilities', '$window', 'moment']; + ChallengeListCtrl.$inject = ['utilities', '$window', 'moment', '$rootScope']; - function ChallengeListCtrl(utilities, $window, moment) { + function ChallengeListCtrl(utilities, $window, moment, $rootScope) { var vm = this; var userKey = utilities.getData('userKey'); var gmtOffset = moment().utcOffset(); @@ -23,6 +23,8 @@ vm.currentList = []; vm.upcomingList = []; vm.pastList = []; + vm.searchTitle = []; + vm.selecteddomain = []; vm.noneCurrentChallenge = false; vm.noneUpcomingChallenge = false; @@ -112,6 +114,30 @@ } }); }; + + parameters.url = "challenges/challenge/get_domain_choices/"; + parameters.method = 'GET'; + parameters.data = {}; + vm.domain_choices = []; + parameters.callback = { + onSuccess: function(response) { + vm.domain_choices.push(["All", "All"]); + for(var i=0; i regex.test(item)) || tags.split(' ').some(item => regex.test(item)) || domain.split(' ').some(item => regex.test(item)); + }); + }; + } + + angular.module('evalai') + .filter('customDomainFilter', customDomainFilter); + + function customDomainFilter() { + return function(challenges, selecteddomain) { + selecteddomain = selecteddomain.toString().toLowerCase(); + if (selecteddomain === "all") { + return challenges; + } + else if (selecteddomain === "none") { + return challenges.filter(function(challenge) { + return challenge.domain_name === null; + }); + } + return challenges.filter(function(challenge) { + if (selecteddomain === "") { + return true; + } + if (challenge.domain_name !== null) { + return challenge.domain_name.toLowerCase().indexOf(selecteddomain) !== -1; + } + }); + }; + } + })(); diff --git a/frontend/src/views/web/challenge-list.html b/frontend/src/views/web/challenge-list.html index b0e1247c4c..e7e861d7af 100644 --- a/frontend/src/views/web/challenge-list.html +++ b/frontend/src/views/web/challenge-list.html @@ -1,9 +1,24 @@
+
+
+ + Search + +
+
+ + + {{ option[1] }} + + +
+
+
Ongoing Challenges
None
-
+
@@ -46,7 +61,7 @@
Upcoming Challenges
None
-
+
@@ -71,7 +86,7 @@
Past Challenges
None
-
+
-
+
diff --git a/frontend/tests/controllers-test/challengeCtrl.test.js b/frontend/tests/controllers-test/challengeCtrl.test.js index 1ebfa38326..e74e068215 100644 --- a/frontend/tests/controllers-test/challengeCtrl.test.js +++ b/frontend/tests/controllers-test/challengeCtrl.test.js @@ -2715,3 +2715,67 @@ describe('Unit tests for challenge controller', function () { }); }); }); + +describe('Filters', function() { + beforeEach(angular.mock.module('evalai')); + + var ceilFilter, formatExecutionTimeFilter, customTitleFilter, customDomainFilter; + + beforeEach(inject(function ($injector) { + ceilFilter = $injector.get('$filter')('ceil'); + formatExecutionTimeFilter = $injector.get('$filter')('format_execution_time'); + customTitleFilter = $injector.get('$filter')('customTitleFilter'); + customDomainFilter = $injector.get('$filter')('customDomainFilter'); + })); + + describe('ceil filter', function() { + it('should round up input numbers', function() { + expect(ceilFilter(1.23)).toEqual(2); + expect(ceilFilter(-1.23)).toEqual(-1); + expect(ceilFilter(0)).toEqual(0); + }); + }); + + describe('format_execution_time filter', function() { + it('should format execution times correctly', function() { + expect(formatExecutionTimeFilter(0)).toEqual('00 sec'); + expect(formatExecutionTimeFilter(60)).toEqual('01 min '); + expect(formatExecutionTimeFilter(3661)).toEqual('01 hr 01 min 01 sec'); + expect(formatExecutionTimeFilter(86461)).toEqual('01 day 01 min 01 sec'); + }); + + }); + + describe('customTitleFilter', function() { + it('should filter challenges based on title search text', function() { + var challenges = [ + {title: 'AngularJS', domain_name: 'web', list_tags: ['js', 'tag2']}, + {title: 'React', domain_name: 'web', list_tags: ['tag3', 'tag4']}, + {title: 'Nodejs', domain_name: 'server', list_tags: ['js', 'tag6']}, + {title: 'ebay facebook', domain_name: 'web', list_tags: ['tag7', 'tag8']}, + + ]; + expect(customTitleFilter(challenges, 'A')).toEqual([challenges[0]]); + expect(customTitleFilter(challenges, 'e f')).toEqual([challenges[3]]); + expect(customTitleFilter(challenges, 'ebay face')).toEqual([challenges[3]]); + expect(customTitleFilter(challenges, 'React')).toEqual([challenges[1]]); + expect(customTitleFilter(challenges, 'Ang rea')).toEqual([challenges[0],challenges[1]]); + expect(customTitleFilter(challenges, 'js')).toEqual([challenges[0],challenges[2]]); + + }); + }); + + describe('customDomainFilter', function() { + it('should filter challenges based on domain', function() { + var challenges = [ + {title: 'AngularJS', domain_name: 'webdev'}, + {title: 'React', domain_name: 'web'}, + {title: 'Node.js', domain_name: null} + ]; + expect(customDomainFilter(challenges, 'none')).toEqual([challenges[2]]); + expect(customDomainFilter(challenges, 'web')).toEqual([challenges[0], challenges[1]]); + expect(customDomainFilter(challenges, 'webdev')).toEqual([challenges[0]]); + expect(customDomainFilter(challenges, '')).toEqual([challenges[0], challenges[1], challenges[2]]); + }); + }); +});