@@ -270,6 +270,7 @@ issueList.IssueView = Backbone.View.extend({
270
270
initialize : function ( ) {
271
271
this . issues = new issueList . IssueCollection ( ) ;
272
272
// check to see if we should pre-filter results
273
+ // otherwise load default (unfiltered "all")
273
274
this . loadIssues ( ) ;
274
275
275
276
// set up event listeners.
@@ -331,10 +332,10 @@ issueList.IssueView = Backbone.View.extend({
331
332
var nextButton = $ ( '.js-pagination-next' ) ;
332
333
var prevButton = $ ( '.js-pagination-previous' ) ;
333
334
var isLastPage = _ . bind ( function ( ) {
334
- return this . issues . getNextPageNumber ( ) == null ;
335
+ return this . issues . getNextPage ( ) == null ;
335
336
} , this ) ;
336
337
var isFirstPage = _ . bind ( function ( ) {
337
- return this . issues . getPreviousPageNumber ( ) == null ;
338
+ return this . issues . getPrevPage ( ) == null ;
338
339
} , this ) ;
339
340
var isSinglePage = isLastPage ( ) && isFirstPage ( ) ;
340
341
@@ -365,61 +366,79 @@ issueList.IssueView = Backbone.View.extend({
365
366
e . preventDefault ( ) ;
366
367
} ,
367
368
requestNextPage : function ( ) {
368
- if ( this . issues . getNextPageNumber ( ) ) {
369
- // chop off the last character, which is the page number
370
- // TODO: this feels gross. ideally we should get the URL from the
371
- // link header and send that to an API endpoint which then requests
372
- // it from GitHub.
373
- this . updateModelParams ( "page" , this . issues . getNextPageNumber ( ) ) ;
369
+ var nextPage ;
370
+ if ( nextPage = this . issues . getNextPage ( ) ) {
371
+ this . issues . url = nextPage ;
372
+ this . fetchAndRenderIssues ( ) ;
374
373
}
375
374
} ,
376
375
requestPreviousPage : function ( ) {
377
- if ( this . issues . getPreviousPageNumber ( ) ) {
378
- this . updateModelParams ( "page" , this . issues . getPreviousPageNumber ( ) ) ;
376
+ var prevPage ;
377
+ if ( prevPage = this . issues . getPrevPage ( ) ) {
378
+ this . issues . url = prevPage ;
379
+ this . fetchAndRenderIssues ( ) ;
379
380
}
380
381
} ,
381
382
updateIssues : function ( category ) {
382
383
// depending on what category was clicked (or if a search came in),
383
384
// update the collection instance url property and fetch the issues.
384
- var labelCategories = [ 'closed' , 'contactready' , 'needsdiagnosis' , 'sitewait' ] ;
385
385
386
- //TODO(miket): make generic getModelParams method which can get the latest state
386
+ // note: until GitHub fixes a bug where requesting issues filtered by labels
387
+ // doesn't return pagination via Link, we get those results via the Search API.
388
+ var searchCategories = [ 'untriaged' , 'contactready' , 'needsdiagnosis' , 'sitewait' ] ;
389
+
390
+ // TODO(miket): make generic getModelParams method which can get the latest state
387
391
// merge param objects and serialize
388
- var paramsBag = $ . extend ( { page : 1 } , this . getPageLimit ( ) ) ;
392
+ var paramsBag = $ . extend ( { page : 1 , per_page : 50 } , this . getPageLimit ( ) ) ;
389
393
var params = $ . param ( paramsBag ) ;
390
394
391
395
// note: if query is the empty string, it will load all issues from the
392
396
// '/api/issues' endpoint (which I think we want).
393
397
if ( category && category . query ) {
394
398
params = $ . param ( $ . extend ( paramsBag , { q : category . query } ) ) ;
395
399
this . issues . url = '/api/issues/search?' + params ;
396
- } else if ( _ . contains ( labelCategories , category ) ) {
400
+ } else if ( _ . contains ( searchCategories , category ) ) {
401
+ this . issues . url = '/api/issues/search/' + category + '?' + params ;
402
+ } else if ( category === "closed" ) {
397
403
this . issues . url = '/api/issues/category/' + category + '?' + params ;
398
- } else if ( category === "untriaged" ) {
399
- this . issues . url = '/api/issues/search/untriaged?' + params ;
400
404
} else {
401
405
this . issues . url = '/api/issues?' + params ;
402
406
}
403
407
this . fetchAndRenderIssues ( ) ;
404
408
} ,
405
409
updateModelParams : function ( paramKey , paramValue ) {
406
- var modelUrl = this . issues . url . split ( '?' ) ;
407
- var modelPath = modelUrl [ 0 ] ;
408
- var modelParams = modelUrl [ 1 ] ;
410
+ var decomposeUrl = function ( url ) {
411
+ var _url = url . split ( '?' ) ;
412
+ return { path : _url [ 0 ] , params : _url [ 1 ] } ;
413
+ } ;
414
+ var linkUrl ;
415
+ var newParams ;
416
+ var modelUrl = decomposeUrl ( this . issues . url ) ;
417
+ var parsedModelParams = $ . deparam ( modelUrl . params ) ;
409
418
410
419
var updateParams = { } ;
411
420
updateParams [ paramKey ] = paramValue ;
412
421
422
+ // do we have a ?link param in the model URL from traversing pagination?
423
+ if ( parsedModelParams . hasOwnProperty ( 'link' ) ) {
424
+ // if so, decompose link param url, merge updated params, and recompose
425
+ linkUrl = decomposeUrl ( parsedModelParams . link ) ;
426
+ newParams = $ . extend ( $ . deparam ( linkUrl . params ) , updateParams ) ;
427
+ this . issues . url = modelUrl . path + '?link=' + encodeURIComponent ( linkUrl . path + '?' + $ . param ( newParams ) ) ;
428
+ this . fetchAndRenderIssues ( ) ;
429
+ return ;
430
+ }
431
+
413
432
// merge old params with passed in param data
414
433
// $.extend will update existing object keys, and add new ones
415
- var newParams = $ . extend ( $ . deparam ( modelParams ) , updateParams ) ;
434
+ newParams = $ . extend ( $ . deparam ( modelUrl . params ) , updateParams ) ;
416
435
417
436
if ( paramKey === 'per_page' ) {
418
437
this . _pageLimit = paramValue ;
419
438
}
420
439
421
440
// construct new model URL and re-request issues
422
- this . issues . url = modelPath + '?' + $ . param ( newParams ) ;
441
+ this . issues . url = modelUrl . path + '?' + $ . param ( newParams ) ;
423
442
this . fetchAndRenderIssues ( ) ;
424
443
}
425
444
} ) ;
0 commit comments