@@ -19,7 +19,7 @@ import _ from 'lodash';
19
19
import React , { PropTypes as PT } from 'react' ;
20
20
import Sticky from 'react-stickynode' ;
21
21
22
- import { DESIGN_TRACK , DEVELOP_TRACK } from './ChallengeFilter' ;
22
+ import { DESIGN_TRACK , DEVELOP_TRACK , DATA_SCIENCE_TRACK } from './ChallengeFilter' ;
23
23
import ChallengeFilterWithSearch from './ChallengeFilterWithSearch' ;
24
24
import ChallengeFilters from './ChallengeFilters' ;
25
25
import SideBarFilter , { MODE as SideBarFilterModes } from '../SideBarFilters/SideBarFilter' ;
@@ -231,67 +231,78 @@ class ChallengeFiltersExample extends React.Component {
231
231
/* Normalizes challenge objects received from different API endpoints,
232
232
* and adds them to the list of loaded challenges. */
233
233
function helper2 ( response , community ) {
234
- return response . json ( ) . then ( res => res . result . content . forEach ( ( item ) => {
234
+ return response . json ( ) . then ( ( res ) => {
235
+ const content = res . result ? res . result . content : res . data ;
236
+ content . forEach ( ( item ) => {
235
237
/* Only marathon matches, when received from the /data/marathon/challenges
236
238
* endpoint, satisfy this. */
237
- if ( item . roundId ) {
238
- const endTimestamp = new Date ( item . endDate ) . getTime ( ) ;
239
- _ . defaults ( item , {
240
- challengeId : item . roundId ,
241
- challengeName : item . fullName ,
242
- challengeCommunity : 'Data' ,
243
- challengeType : 'Marathon' ,
244
- communities : new Set ( [ community ] ) ,
245
- currentPhaseEndDate : item . endDate ,
246
- currentPhaseName : endTimestamp > Date . now ( ) ? 'Registration' : '' ,
247
- numRegistrants : item . numberOfRegistrants ,
248
- numSubmissions : item . numberOfSubmissions ,
249
- platforms : [ ] ,
250
- prize : [ ] ,
251
- registrationOpen : endTimestamp > Date . now ( ) ? 'Yes' : 'No' ,
252
- registrationStartDate : item . startDate ,
253
- submissionEndDate : item . endDate ,
254
- submissionEndTimestamp : endTimestamp ,
255
- technologies : [ ] ,
256
- totalPrize : 0 ,
257
- track : 'DATA_SCIENCE' ,
258
- status : endTimestamp > Date . now ( ) ? 'Active' : 'Completed' ,
259
- subTrack : 'MARATHON_MATCH' ,
260
- } ) ;
261
- map [ item . id ] = item ;
262
- } else if ( item . track === 'SRM' ) {
263
- /* We don't support SRM yet, so we don't want them around */
264
- } else { /* All challenges from other endpoints have the same format. */
265
- const existing = map [ item . id ] ;
266
- if ( existing ) existing . communities . add ( community ) ;
267
- else {
239
+ if ( item . roundId ) {
240
+ const endTimestamp = new Date ( item . endDate ) . getTime ( ) ;
241
+ const allphases = [ {
242
+ challengeId : item . roundId ,
243
+ phaseType : 'Registration' ,
244
+ phaseStatus : endTimestamp > Date . now ( ) ? 'Open' : 'Close' ,
245
+ scheduledEndTime : item . endDate ,
246
+ } ,
247
+ ] ;
268
248
_ . defaults ( item , {
249
+ id : item . roundId ,
250
+ name : item . fullName ,
251
+ challengeCommunity : 'Data' ,
252
+ challengeType : 'Marathon' ,
253
+ allPhases : allphases ,
254
+ currentPhases : allphases . filter ( phase => phase . phaseStatus === 'Open' ) ,
269
255
communities : new Set ( [ community ] ) ,
256
+ currentPhaseName : endTimestamp > Date . now ( ) ? 'Registration' : '' ,
257
+ numRegistrants : item . numberOfRegistrants ,
258
+ numSubmissions : item . numberOfSubmissions ,
270
259
platforms : '' ,
271
- registrationOpen : item . allPhases . filter ( d => d . phaseType === 'Registration' ) [ 0 ] . phaseStatus === 'Open' ? 'Yes' : 'No' ,
260
+ prizes : [ 0 ] ,
261
+ registrationOpen : endTimestamp > Date . now ( ) ? 'Yes' : 'No' ,
262
+ registrationStartDate : item . startDate ,
263
+ submissionEndDate : item . endDate ,
264
+ submissionEndTimestamp : endTimestamp ,
272
265
technologies : '' ,
273
- track : item . track ,
274
- status : item . status ,
275
- submissionEndTimestamp : item . submissionEndDate ,
276
- subTrack : item . subTrack ,
266
+ totalPrize : 0 ,
267
+ track : 'DATA_SCIENCE' ,
268
+ status : endTimestamp > Date . now ( ) ? 'ACTIVE' : 'COMPLETED' ,
269
+ subTrack : 'MARATHON_MATCH' ,
277
270
} ) ;
278
271
map [ item . id ] = item ;
279
- if ( item . platforms ) {
280
- item . platforms . split ( ',' ) . forEach ( helper1 ) ;
281
- }
282
- if ( item . technologies ) {
283
- item . technologies . split ( ',' ) . forEach ( helper1 ) ;
272
+ } else if ( item . track === 'SRM' ) {
273
+ /* We don't support SRM yet, so we don't want them around */
274
+ } else { /* All challenges from other endpoints have the same format. */
275
+ const existing = map [ item . id ] ;
276
+ if ( existing ) existing . communities . add ( community ) ;
277
+ else {
278
+ _ . defaults ( item , {
279
+ communities : new Set ( [ community ] ) ,
280
+ platforms : '' ,
281
+ registrationOpen : item . allPhases . filter ( d => d . phaseType === 'Registration' ) [ 0 ] . phaseStatus === 'Open' ? 'Yes' : 'No' ,
282
+ technologies : '' ,
283
+ submissionEndTimestamp : item . submissionEndDate ,
284
+ } ) ;
285
+ map [ item . id ] = item ;
286
+ if ( item . platforms ) {
287
+ item . platforms . split ( ',' ) . forEach ( helper1 ) ;
288
+ }
289
+ if ( item . technologies ) {
290
+ item . technologies . split ( ',' ) . forEach ( helper1 ) ;
291
+ }
284
292
}
285
293
}
286
- }
287
- } ) ) ;
294
+ } ) ;
295
+ } ,
296
+ ) ;
288
297
}
289
298
const api = this . props . config . API_URL ;
299
+ const api2 = this . props . config . API_URL_V2 ;
290
300
return Promise . all ( [
291
301
/* Fetching of active challenges */
292
302
fetch ( `${ api } /challenges/?filter=track%3Ddesign` ) . then ( res => helper2 ( res , DESIGN_TRACK ) ) ,
293
303
fetch ( `${ api } /challenges/?filter=track%3Ddevelop` ) . then ( res => helper2 ( res , DEVELOP_TRACK ) ) ,
294
- fetch ( `${ api } /challenges/marathonMatches` ) ,
304
+ fetch ( `${ api2 } /data/marathon/challenges/?listType=past&pageSize=100` ) . then ( res => helper2 ( res , DATA_SCIENCE_TRACK ) ) ,
305
+ fetch ( `${ api2 } /data/marathon/challenges/?listType=active` ) . then ( res => helper2 ( res , DATA_SCIENCE_TRACK ) ) ,
295
306
] ) . then ( ( ) => {
296
307
_ . forIn ( map , item => challenges . push ( item ) ) ;
297
308
challenges . sort ( ( a , b ) => b . submissionEndDate - a . submissionEndDate ) ;
0 commit comments