Skip to content

Commit

Permalink
Support pagination to retrieve all issues in a repo #73
Browse files Browse the repository at this point in the history
  • Loading branch information
alyssaq committed Oct 5, 2014
1 parent 1a49061 commit ed71b87
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 48 deletions.
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "drywall-web",
"dependencies": {
"backbone-loading": "*",
"backbone.paginator": "*",
"hammerjs": "*",
"handlebars-helpers-pack": "*",
"urlbuilder": "*",
Expand Down
4 changes: 4 additions & 0 deletions source/js/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require.config({
'jquery': '//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min',
'backbone.layoutmanager': '//cdnjs.cloudflare.com/ajax/libs/backbone.layoutmanager/0.9.4/backbone.layoutmanager.min',
'backbone.localstorage': '//cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.1.13/backbone.localStorage-min',
'backbone.paginator': '../bower_components/backbone.paginator/lib/backbone.paginator.min',
'underscore': '//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min',
'backbone-loading': '../bower_components/backbone-loading/backbone-loading',
'urlbuilder': '../bower_components/urlbuilder/urlbuilder',
Expand Down Expand Up @@ -53,6 +54,9 @@ require.config({
'backbone.localstorage': {
deps: ['backbone']
},
'backbone.paginator': {
deps: ['backbone']
},
'mustache': {
exports: 'mustache'
},
Expand Down
22 changes: 19 additions & 3 deletions source/js/modules/GitHub.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
define([
'jquery', 'underscore', 'backbone', 'app',
'libs/api'
'libs/api',
'backbone.paginator'
],
function (
$, _, Backbone, app,
api
api,
PageableCollection
) {
var Models = {};
var Collections = {};
Expand Down Expand Up @@ -75,13 +77,27 @@ function (
}
});

Collections.Issues = ghCollection.extend({
Collections.Issues = PageableCollection.extend({
sync: ghSync,
initialize: function (models, options) {
this.options = options || {};
this.options.numPages = 1;
this.on('sync', this._addNextPage);
},
url: function () {
return ghApi(
'repos/:owner/:repository/issues',
this.options,
{state: 'all'}
);
},
state: {
pageSize: 100
},
_addNextPage: function (collection, models) {
if (models.length === this.state.pageSize) {
this.getNextPage({remove: false});
}
}
});

Expand Down
76 changes: 33 additions & 43 deletions source/js/modules/Stickies.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,49 @@ function (
model: Models.Stickies,
initialize: function (models, options) {
this.options = options || {};
var untouchedIssues = [];
options.issues.reduce(this._layoutStickies, untouchedIssues, this);
this._layoutUntouchedIssues(untouchedIssues);

this.listenTo(
options.issues,
'add remove change',
this._merge
);
this.listenTo(
options.coordinates,
'add remove change',
this._merge
);
this.options.bounds = this._bounds();
options.issues.each(this._layoutStickie, this);
this.listenTo(options.issues, 'add', this._layoutStickie);
},
_layoutStickies: function(arr, issue) {
_layoutStickie: function (issue) {
var match = issue.pick('number');
var coordinate = this.options.coordinates.findWhere(match);

if (coordinate) {
this.addStickie(issue, coordinate);
} else {
arr.push(issue);
if (!coordinate) {
var bounds = this.options.bounds;
coordinate = new this.options.coordinates.model(
this._randomCoordinates(issue)
);
this.options.coordinates.add(coordinate);
}
return arr;
this._addStickie(issue, coordinate);
},
_layoutUntouchedIssues: function (issues) {
var that = this;
var bounds = that.bounds();

issues.forEach(function (issue) {
var coordinate = new that.options.coordinates.model({
number: issue.get('number'),
x: (Math.random() * bounds.width / 2) + bounds.left,
y: (Math.random() * 200) + bounds.bottom + stickieWidth
});
that.options.coordinates.add(coordinate);
that.addStickie(issue, coordinate);
});
_randomCoordinates: function (issue) {
var bounds = this.options.bounds;
return {
number: issue.get('number'),
x: (Math.random() * bounds.width / 2) + bounds.left,
y: (Math.random() * 200) + bounds.bottom + stickieWidth,
autocreated: true
};
},
addStickie: function(issue, coordinate) {
_addStickie: function(issue, coordinate) {
var data = _.extend(issue.toJSON(), coordinate.toJSON());
var stickie = new this.model(data);
this.add(stickie);
},
bounds: function () {
var x = this.map(function (stickie) {
return stickie.get('x');
_bounds: function () {
var coordinates = this.options.coordinates.filter(
function (coordinate) {
return !coordinate.get('autocreated');
}
);

var x = coordinates.map(function (coordinate) {
return coordinate.get('x');
});
var y = this.map(function (stickie) {
return stickie.get('y');
var y = coordinates.map(function (coordinate) {
return coordinate.get('y');
});
x = _.isEmpty(x) ? [0] : x;
y = _.isEmpty(y) ? [0] : y;
Expand All @@ -92,11 +84,9 @@ function (
top: _.min(y),
bottom: _.max(y) + stickieHeight
};
box.width = box.right - box.left;

return _.extend(box, {
width: box.right - box.left,
height: box.bottom - box.top
});
return box;
}
});

Expand Down
2 changes: 0 additions & 2 deletions source/styles/modules/walls/wall.styl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
position relative
display flex
flex-direction column
width 100%
height 100%

> .controls
position absolute
Expand Down

0 comments on commit ed71b87

Please sign in to comment.