-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIssueHandler.js
executable file
·47 lines (41 loc) · 1.3 KB
/
IssueHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
define(['StatCalculator'], function(StatCalculator) {
function IssueHandler() {
this.issues = [];
}
IssueHandler.prototype.addIssue = function(issue) {
this.issues.push(issue);
}
IssueHandler.prototype.getIssue = function(issueId) {
for (var i=0; i < this.issues.length; i++) {
var issue = this.issues[i];
if (issue.id.match(/\d+/)[0] === issueId) {
return issue;
}
}
return null;
}
getDataWithJSON = function(callback, username, password, requestUrl) {
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://cors-anywhere.herokuapp.com/" + requestUrl)
if (this.username !== "") {
this.setAuthorizationHeader(xhr, username, password);
}
xhr.setRequestHeader("x-requested-with", "love");
xhr.send();
xhr.onload = function(response) {
if (this.status === 401) {
callback(this.status);
} else {
callback(response);
}
}
};
setAuthorizationHeader = function(xhr, username, password) {
var authHeader = "Basic "+btoa(username + ":" + password);
xhr.setRequestHeader("Authorization", authHeader);
}
if (window.localStorage.getItem("jiraData")) {
statisticsCalculator = new StatCalculator(JSON.parse(window.localStorage.getItem("jiraData")).issues);
}
return IssueHandler;
});