Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit a706f1c

Browse files
committed
Merge pull request #408 from appirio-tech/feature/challenge-paginator-fixes
Feature/challenge paginator fixes
2 parents a0c44c4 + 3bddf5e commit a706f1c

File tree

7 files changed

+98
-49
lines changed

7 files changed

+98
-49
lines changed

app/filters/challengeTile.filter.js renamed to app/filters/challengeLinks.filter.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
};
1515
switch (type) {
1616
case 'forums':
17-
return String.supplant('http://apps.{domain}/forums/?module=Category&categoryID={forumId}', data);
17+
return String.supplant('https://apps.{domain}/forums/?module=ThreadList&forumID={forumId}', data);
1818
case 'registrants':
1919
return String.supplant('https://community.{domain}/longcontest/?module=ViewStandings&rd={roundId}', data);
2020
case 'detail':
@@ -24,11 +24,20 @@
2424
var data = {
2525
domain: CONSTANTS.domain,
2626
track: challenge.track,
27-
forumId: challenge.forumId
27+
forumId: challenge.forumId,
28+
id: challenge.id
2829
};
2930
switch (type) {
3031
case 'forums':
31-
return String.supplant('http://apps.{domain}/forums/?module=Category&categoryID={forumId}', data);
32+
switch (challenge.track) {
33+
case 'DEVELOP':
34+
return String.supplant('https://apps.{domain}/forums/?module=Category&categoryID={forumId}', data);
35+
case 'DATA':
36+
return String.supplant('https://apps.{domain}/forums/?module=Category&categoryID={forumId}', data);
37+
case 'DESIGN':
38+
return String.supplant('https://apps.{domain}/forums/?module=ThreadList&forumId={forumId}', data);
39+
}
40+
3241
case 'submissions':
3342
case 'registrants':
3443
return String.supplant('https://www.{domain}/challenge-details/{id}/?type={track}#viewRegistrant', data);

app/filters/filters.spec.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ describe('filters', function() {
22

33
beforeEach(function() {
44
bard.appModule('topcoder');
5-
bard.inject(this, 'roleFilter', 'percentageFilter', 'ordinalFilter', 'displayLocationFilter', 'listRolesFilter', 'trackFilter');
5+
bard.inject(this, 'CONSTANTS', 'roleFilter', 'percentageFilter', 'ordinalFilter', 'displayLocationFilter', 'listRolesFilter', 'trackFilter', 'challengeLinksFilter');
66
});
77

88
describe('role filter', function() {
@@ -56,4 +56,45 @@ describe('filters', function() {
5656
expect(listRolesFilter([1,2])).to.be.equal('1, 2');
5757
});
5858
});
59+
60+
describe('challengeLinksFilter', function() {
61+
// bard.inject(this, 'CONSTANTS');
62+
it ('should have the correct links for DEVELOP challenge', function() {
63+
var _ch = {
64+
id: 1,
65+
forumId: 2,
66+
track: 'DEVELOP',
67+
subTrack : 'CODE'
68+
};
69+
expect(challengeLinksFilter(_ch, 'detail')).to.be.equal('https://www.topcoder-dev.com/challenge-details/1/?type=DEVELOP');
70+
expect(challengeLinksFilter(_ch, 'forums')).to.be.equal('https://apps.topcoder-dev.com/forums/?module=Category&categoryID=2');
71+
expect(challengeLinksFilter(_ch, 'registrants')).to.be.equal('https://www.topcoder-dev.com/challenge-details/1/?type=DEVELOP#viewRegistrant');
72+
expect(challengeLinksFilter(_ch, 'submissions')).to.be.equal('https://www.topcoder-dev.com/challenge-details/1/?type=DEVELOP#viewRegistrant');
73+
});
74+
75+
it ('should have the correct links for DESIGN challenge', function() {
76+
var _ch = {
77+
id: 1,
78+
forumId: 2,
79+
track: 'DESIGN',
80+
subTrack : 'WEB_DESIGN'
81+
};
82+
expect(challengeLinksFilter(_ch, 'detail')).to.be.equal('https://www.topcoder-dev.com/challenge-details/1/?type=DESIGN');
83+
expect(challengeLinksFilter(_ch, 'forums')).to.be.equal('https://apps.topcoder-dev.com/forums/?module=ThreadList&forumId=2');
84+
expect(challengeLinksFilter(_ch, 'registrants')).to.be.equal('https://www.topcoder-dev.com/challenge-details/1/?type=DESIGN#viewRegistrant');
85+
expect(challengeLinksFilter(_ch, 'submissions')).to.be.equal('https://www.topcoder-dev.com/challenge-details/1/?type=DESIGN#viewRegistrant');
86+
});
87+
88+
it ('should have the correct links for DATA_SCIENCE challenge', function() {
89+
var _ch = {
90+
id: 1,
91+
rounds: [{id: 3,forumId: 2}],
92+
track: 'DATA_SCIENCE',
93+
subTrack : 'MARATHON_MATCH'
94+
};
95+
expect(challengeLinksFilter(_ch, 'detail')).to.be.equal('https://community.topcoder-dev.com/tc?module=MatchDetails&rd=3');
96+
expect(challengeLinksFilter(_ch, 'forums')).to.be.equal('https://apps.topcoder-dev.com/forums/?module=ThreadList&forumID=2');
97+
expect(challengeLinksFilter(_ch, 'registrants')).to.be.equal('https://community.topcoder-dev.com/longcontest/?module=ViewStandings&rd=3');
98+
});
99+
});
59100
});

app/index.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ html
191191
script(src="directives/tc-transclude.directive.js")
192192
script(src="directives/track-toggle/track-toggle.directive.js")
193193
script(src="topcoder.module.js")
194-
script(src="filters/challengeTile.filter.js")
194+
script(src="filters/challengeLinks.filter.js")
195195
script(src="filters/deadline-msg.filter.js")
196196
script(src="filters/empty.filter.js")
197197
script(src="filters/external-link-color.filter.js")

app/my-srms/my-srms.controller.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
angular.module('tc.myDashboard').controller('MySRMsController', MySRMsController);
55

6-
MySRMsController.$inject = ['UserService','SRMService', '$log', '$state', '$stateParams', 'CONSTANTS'];
6+
MySRMsController.$inject = ['UserService','SRMService', '$log', '$state', '$stateParams', 'CONSTANTS', '$scope'];
77

8-
function MySRMsController(UserService, SRMService, $log, $state, $stateParams, CONSTANTS) {
8+
function MySRMsController(UserService, SRMService, $log, $state, $stateParams, CONSTANTS, $scope) {
99
$log = $log.getInstance('MySRMsController');
1010
var vm = this;
1111
vm.srms = [];
@@ -15,13 +15,15 @@
1515
vm.view = UserService.getPreference($state.$current.name+'.challengeListView') || 'tile';
1616
vm.changeView = changeView;
1717
vm.changeFilter = changeFilter;
18-
vm.loadMore = loadMore;
19-
vm.totalCount = 0;
2018
vm.getSRMs = getSRMs;
21-
var currentOffset = 0;
22-
var defaultParams = {
23-
orderBy: '',
24-
limit: 12
19+
// paging params, these are updated by tc-pager
20+
vm.pageParams = {
21+
currentOffset : 0,
22+
limit: 16,
23+
currentCount: 0,
24+
totalCount: 0,
25+
// counter used to indicate page change
26+
updated: 0
2527
};
2628

2729
var userId = UserService.getUserIdentity().userId;
@@ -31,6 +33,13 @@
3133

3234
function activate() {
3335
vm.srms = [];
36+
// watches page change counter to reload the data
37+
$scope.$watch('vm.pageParams.updated', function(newValue, oldValue) {
38+
if (newValue !== oldValue) {
39+
getSRMs();
40+
}
41+
});
42+
// initial call
3443
changeFilter(vm.statusFilter);
3544
}
3645

@@ -41,31 +50,29 @@
4150
}
4251

4352
function changeFilter(filter) {
44-
currentOffset = 0;
4553
vm.statusFilter = filter;
4654
vm.orderBy = filter === 'future'? 'startDate': 'endDate';
4755
vm.reverseOrder = filter !== 'future';
4856
// update url but don't reload
4957
$state.go($state.$current.name, {status: filter}, {notify: false});
50-
getSRMs(0);
58+
// reset
59+
vm.srms = [];
60+
vm.pageParams.currentOffset = 0;
61+
getSRMs();
5162
}
5263

53-
function getSRMs(offset) {
64+
function getSRMs() {
5465
vm.loading = CONSTANTS.STATE_LOADING;
55-
if (!offset) {
56-
// reset
57-
offset = 0;
58-
vm.srms = [];
59-
}
66+
6067
// reverseOrder implies we need to send 'desc' in orderBy clause.
61-
var _filterString = 'status=' + vm.statusFilter;
68+
var _orderByString = vm.orderBy;
6269
if (vm.reverseOrder)
63-
_filterString += ' desc';
70+
_orderByString += ' desc';
6471
var params = {
65-
limit: defaultParams.limit,
66-
orderBy: vm.orderBy,
67-
offset: offset,
68-
filter: _filterString
72+
limit: vm.pageParams.limit,
73+
orderBy: _orderByString,
74+
offset: vm.pageParams.currentOffset,
75+
filter: 'status=' + vm.statusFilter
6976
};
7077

7178
if (vm.statusFilter === 'past') {
@@ -78,20 +85,15 @@
7885
}
7986

8087
function handleSRMsLoad(data) {
88+
vm.pageParams.totalCount = data.metadata.totalCount;
8189
vm.srms = vm.srms.concat(data);
90+
vm.pageParams.currentCount = vm.srms.length;
8291
vm.loading = CONSTANTS.STATE_READY;
83-
vm.totalCount = data.metadata.totalCount;
8492
}
8593

8694
function handleSRMsFailure(resp) {
8795
$log.error(resp);
8896
vm.loading = CONSTANTS.STATE_ERROR;
8997
}
90-
91-
function loadMore() {
92-
currentOffset+=1;
93-
getSRMs(currentOffset);
94-
}
95-
9698
}
9799
})();

app/my-srms/my-srms.jade

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@
2828
ng-repeat="srm in vm.srms | orderBy:vm.orderBy:vm.reverseOrder",
2929
srm="srm", view="vm.view", ng-class="vm.view + '-view'", show-results="vm.statusFilter === 'past'")
3030

31-
tc-section(state="vm.loading")
32-
button.tc-btn(ng-show="vm.totalCount > vm.srms.length", ng-click="vm.loadMore()") Load More
31+
tc-endless-paginator(state="vm.loading", page-params="vm.pageParams")

app/my-srms/my-srms.spec.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ describe('My SRMs Controller', function() {
55
var srms = mockData.getMockSRMs();
66
var results = mockData.getMockSRMResults();
77

8-
98
beforeEach(function() {
109
bard.appModule('topcoder');
1110
bard.inject(this,
@@ -73,7 +72,8 @@ describe('My SRMs Controller', function() {
7372
mySRMs = $controller('MySRMsController', {
7473
SRMService : srmService,
7574
UserService : userService,
76-
$state: mockState
75+
$state: mockState,
76+
$scope: $scope
7777
});
7878
$rootScope.$apply();
7979
spy = sinon.spy(mySRMs, 'getSRMs');
@@ -92,12 +92,6 @@ describe('My SRMs Controller', function() {
9292
expect(mySRMs.srms.length).to.equal(srms.length - 1);
9393
expect(spy.withArgs(0).calledOnce);
9494
});
95-
96-
it('more past SRMs should be fetched', function() {
97-
mySRMs.loadMore();
98-
expect(spy.withArgs(1).calledOnce);
99-
});
100-
10195
});
10296

10397
describe('upcoming/past filters', function() {
@@ -109,7 +103,8 @@ describe('My SRMs Controller', function() {
109103
SRMService : srmService,
110104
UserService : userService,
111105
$state: mockState,
112-
$stateParams: {'status': 'future'}
106+
$stateParams: {'status': 'future'},
107+
$scope: $scope
113108
});
114109
$rootScope.$apply();
115110
spy = sinon.spy(mySRMs, 'getSRMs');

app/specs.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,13 @@ <h1><a href="specs.html">Spec Runner</a></h1>
168168
<script src="/app/filters/external-link-color.filter.js"></script>
169169
<script src="/app/filters/empty.filter.js"></script>
170170
<script src="/app/filters/deadline-msg.filter.js"></script>
171+
<script src="/app/filters/challengeLinks.filter.js"></script>
171172
<script src="/app/directives/tcui-components.module.js"></script>
172173
<script src="/app/directives/track-toggle/track-toggle.directive.js"></script>
173174
<script src="/app/directives/tc-transclude.directive.js"></script>
174175
<script src="/app/directives/tc-section/tc-section.directive.js"></script>
175176
<script src="/app/directives/tc-paginator/tc-paginator.directive.js"></script>
177+
<script src="/app/directives/tc-endless-paginator/tc-endless-paginator.directive.js"></script>
176178
<script src="/app/directives/srm-tile/srm-tile.directive.js"></script>
177179
<script src="/app/directives/slideable.directive.js"></script>
178180
<script src="/app/directives/skill-tile/skill-tile.directive.js"></script>
@@ -215,9 +217,9 @@ <h1><a href="specs.html">Spec Runner</a></h1>
215217
<script src="/app/topcoder.interceptors.spec.js"></script>
216218
<script src="/app/filters/filters.spec.js"></script>
217219
<script src="/app/my-challenges/my-challenges.spec.js"></script>
220+
<script src="/app/my-srms/my-srms.spec.js"></script>
218221
<script src="/app/my-dashboard/my-dashboard.spec.js"></script>
219222
<script src="/app/profile/profile.controller.spec.js"></script>
220-
<script src="/app/my-srms/my-srms.spec.js"></script>
221223
<script src="/app/services/authToken.service.spec.js"></script>
222224
<script src="/app/services/challenge.service.spec.js"></script>
223225
<script src="/app/services/helpers.service.spec.js"></script>
@@ -228,19 +230,20 @@ <h1><a href="specs.html">Spec Runner</a></h1>
228230
<script src="/app/settings/settings.spec.js"></script>
229231
<script src="/app/skill-picker/skill-picker.spec.js"></script>
230232
<script src="/app/account/login/login.spec.js"></script>
233+
<script src="/app/blocks/exception/exception-handler.provider.spec.js"></script>
231234
<script src="/app/account/register/register.spec.js"></script>
232235
<script src="/app/account/reset-password/reset-password.spec.js"></script>
233-
<script src="/app/blocks/exception/exception-handler.provider.spec.js"></script>
234236
<script src="/app/directives/badges/badge-tooltip.spec.js"></script>
235237
<script src="/app/directives/busy-button/busy-button.directive.spec.js"></script>
236238
<script src="/app/directives/challenge-tile/challenge-tile.spec.js"></script>
237239
<script src="/app/directives/external-account/external-account.directive.spec.js"></script>
240+
<script src="/app/directives/tc-endless-paginator/tc-endless-paginator.spec.js"></script>
238241
<script src="/app/directives/tc-paginator/tc-paginator.spec.js"></script>
239242
<script src="/app/my-dashboard/community-updates/community-updates.spec.js"></script>
240243
<script src="/app/my-dashboard/header-dashboard/header-dashboard.spec.js"></script>
241244
<script src="/app/my-dashboard/my-challenges/my-challenges.spec.js"></script>
242-
<script src="/app/my-dashboard/srms/srms.spec.js"></script>
243245
<script src="/app/my-dashboard/programs/programs.spec.js"></script>
246+
<script src="/app/my-dashboard/srms/srms.spec.js"></script>
244247
<script src="/app/peer-review/completed-review/completed-review.spec.js"></script>
245248
<script src="/app/peer-review/edit-review/edit-review.spec.js"></script>
246249
<script src="/app/peer-review/readOnlyScorecard/readOnlyScorecard.spec.js"></script>
@@ -251,8 +254,8 @@ <h1><a href="specs.html">Spec Runner</a></h1>
251254
<script src="/app/settings/account-info/account-info.spec.js"></script>
252255
<script src="/app/settings/edit-profile/edit-profile.spec.js"></script>
253256
<script src="/app/settings/preferences/preferences.spec.js"></script>
254-
<script src="/app/directives/account/toggle-password/toggle-password.spec.js"></script>
255257
<script src="/app/directives/account/toggle-password-with-tips/toggle-password-with-tips.spec.js"></script>
258+
<script src="/app/directives/account/toggle-password/toggle-password.spec.js"></script>
256259
<!-- endinject -->
257260

258261
<!-- inject:templates:js -->

0 commit comments

Comments
 (0)