-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A huge refactor to split a lot of initialization into their own files.
* Also make sure to refetch the issue list every time the panel is opened. close #22
- Loading branch information
1 parent
ef1dee0
commit cc55d4c
Showing
10 changed files
with
412 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
"use strict"; | ||
|
||
const { Cc, Ci } = require("chrome"); | ||
|
||
exports.Helpers = { | ||
getAnchorElement: function(name) { | ||
let browserWindow = Cc["@mozilla.org/appshell/window-mediator;1"]. | ||
getService(Ci.nsIWindowMediator). | ||
getMostRecentWindow("navigator:browser"); | ||
let anchors = browserWindow.document.querySelectorAll('#addon-bar > toolbaritem'), | ||
len = anchors.length; | ||
let anchor = null; | ||
|
||
for(let index = 0, anc; index < len, anc = anchors[index]; index++) { | ||
if(anc.getAttribute("label") === name) { | ||
anchor = anc; | ||
} | ||
} | ||
|
||
return anchor; | ||
|
||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
"use strict"; | ||
|
||
const {Request} = require("request"); | ||
const {Repos} = require("./repos"); | ||
const {Labels} = require("./labels"); | ||
const {prefs} = require("simple-prefs"); | ||
|
||
exports.Issues = { | ||
get: getIssues, | ||
search: search, | ||
getCount: getCount | ||
}; | ||
|
||
function getIssues(opts, callback) { | ||
opts = opts || {}; | ||
opts.state = opts.state || "open"; | ||
opts.per_page = opts.per_page || prefs.page_size; | ||
|
||
let url = Repos.BASE_URL + "/issues" + getURLString(opts); | ||
|
||
console.log("requesting: " + url); | ||
Request({ | ||
url: url, | ||
onComplete: function(response) { | ||
callback && callback(response.json); | ||
} | ||
}).get(); | ||
} | ||
|
||
function getCount(callback) { | ||
let issuesRequest = Request({ | ||
url: Repos.BASE_URL, | ||
onComplete: function(response) { | ||
let count = response.json.open_issues; | ||
callback && callback(count); | ||
} | ||
}).get(); | ||
} | ||
|
||
function search(search_term, callback) { | ||
let searchTerm = search_term.replace(/[\t ]+/, " ").replace(" ", "+"); | ||
|
||
let url = "http://github.com/api/v2/json/issues/search/" + prefs.repo_url + "/open/" + searchTerm; | ||
console.log(url); | ||
Request({ | ||
url: url, | ||
onComplete: function(response) { | ||
convertV2toV3(response.json.issues, callback); | ||
} | ||
}).get(); | ||
} | ||
|
||
function convertV2toV3(issues, callback) { | ||
Labels.get(function(labels) { | ||
let labelsHash = getLabelsHash(labels); | ||
// Issues by default come back in chronological order | ||
issues = issues.reverse(); | ||
issues.forEach(function(issue) { | ||
issue.assignee = { | ||
avatar_url: "http://www.gravatar.com/avatar/" + issue.gravatar_id, | ||
login: issue.user | ||
}; | ||
|
||
let labels = issue.labels || [], | ||
newLabels = []; | ||
|
||
issue.labels = newLabels; | ||
|
||
labels.forEach(function(label) { | ||
newLabels.push(labelsHash[label]); | ||
}); | ||
|
||
callback && callback(issues); | ||
}); | ||
}); | ||
|
||
} | ||
|
||
function getLabelsHash(labels) { | ||
let labelsHash = {}; | ||
labels = labels || []; | ||
|
||
labels.forEach(function(label) { | ||
labelsHash[label.name] = label; | ||
}); | ||
|
||
return labelsHash; | ||
} | ||
|
||
function getURLString(opts) { | ||
let urlString = ""; | ||
let optsArr = []; | ||
for(let key in opts) { | ||
optsArr.push(encodeURIComponent(key) + "=" + encodeURIComponent(opts[key])); | ||
} | ||
|
||
if(optsArr.length) { | ||
urlString += "?" + optsArr.join("&"); | ||
} | ||
return urlString; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
"use strict"; | ||
|
||
const {data} = require("self"); | ||
const {Panel} = require("panel"); | ||
|
||
exports.get = function() { | ||
return Panel({ | ||
width: 400, | ||
height: 700, | ||
contentURL: data.url("issues.html"), | ||
contentScriptFile: [ data.url("mustache.js"), data.url("shared.js"), data.url("issues.js") ] | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
"use strict"; | ||
|
||
const {Request} = require("request"); | ||
const {Repos} = require("./repos"); | ||
|
||
exports.Labels = { | ||
get: function(callback) { | ||
let url = Repos.BASE_URL + "/labels"; | ||
Request({ | ||
url: url, | ||
onComplete: function(response) { | ||
let labels = response.json; | ||
labels.splice(0, 0, { | ||
name: "all" | ||
}); | ||
|
||
callback(labels); | ||
} | ||
}).get(); | ||
} | ||
}; |
Oops, something went wrong.