Skip to content

Commit

Permalink
Merge pull request #24 from schultyy/add-filter-for-pull-requests
Browse files Browse the repository at this point in the history
Add filter for pull requests. Resolves #18
  • Loading branch information
Jan Schulte committed Feb 3, 2016
2 parents 4747fa3 + 6180f3a commit 26ae5c5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
13 changes: 11 additions & 2 deletions lib/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Facade.prototype.initialFetch = function() {
});
}

Facade.prototype.loadIssues = function() {
Facade.prototype.loadIssues = function(opts) {
var withPullRequests = (opts && opts.withPullRequests) || false;
return this.db.fetchDocuments().then((resultSet) => {
if (resultSet.total_rows > 0) {
return Promise.resolve(resultSet);
Expand All @@ -59,8 +60,16 @@ Facade.prototype.loadIssues = function() {
}
})
.then(function(resultSet) {
return Promise.resolve(resultSet.rows.map((row) => {
var docs = resultSet.rows.map((row) => {
return row.doc;
});

if(withPullRequests) {
return Promise.resolve(docs);
}

return Promise.resolve(docs.filter((doc) => {
return !doc.pull_request
}));
});
}
Expand Down
41 changes: 36 additions & 5 deletions lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ MainWindow.prototype.renderError = function(message) {
screen.render();
};

MainWindow.prototype.initialize = function() {
MainWindow.prototype.initialize = function(opts) {
var self = this;
this.showProgressbar();
return this.facade.loadIssues()
return this.facade.loadIssues(opts)
.then(function(resultSet) {
var sorted = resultSet.sort(function(a,b) {
if(a.created_at == b.created_at) {
if(a.created_at === b.created_at) {
return 0;
} else if (a.created_at < b.created_at) {
return 1;
Expand All @@ -101,7 +101,11 @@ MainWindow.prototype.initialize = function() {
var createTitle = function(d) {
let title = d.title.toString();
let id = d.number.toString();
return `${id}-${title}`;
if (!d.pull_request) {
return `${id}-${title}`;
}

return `${id}-[Pull Request] ${title}`;
};
self.list.setItems(resultSet.map(createTitle));
screen.render();
Expand Down Expand Up @@ -159,6 +163,23 @@ MainWindow.prototype.createMenubar = function() {
console.log(err.stack);
});
}
},
'Show Pull Requests': {
keys: ['p'],
callback: function() {
if(self.modal) {
self.modal.close();
screen.render();
self.modal = null;
}
self.initialize({
withPullRequests: true
})
.catch(function(err) {
console.log(err);
console.log(err.stack);
});
}
}
}
});
Expand Down Expand Up @@ -242,7 +263,17 @@ DetailWindow.prototype.updateBoxContent = function() {
return label.name;
}).join(", ");

var content = `{bold}${this.issue.title}{/bold}\n\nCreated by: ${creator}\nAssignee: ${assignee}\nLabels: ${labels}\n\n${body}`;
var title = null;

if(this.issue.pull_request) {
title = `${this.issue.number}-[Pull Request] ${this.issue.title}`;
}
else {
title = `${this.issue.number} - ${this.issue.title}`;
}


var content = `{bold}${title}{/bold}\n\nCreated by: ${creator}\nAssignee: ${assignee}\nLabels: ${labels}\n\n${body}`;
this.box.setContent(content);
};

Expand Down

0 comments on commit 26ae5c5

Please sign in to comment.