-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.js
141 lines (130 loc) · 5.01 KB
/
get.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
define(function (require, exports, module) {
"use strict";
/* Main Data Object */
var data = function(userData)
{
/* Properties */
this.userInfo = userData;
this.data = null;
this.projectSelection = 'All';
this.fetchingData = false;
this.projectNames = [];
this.issues = null;
this.onFinish = null;
this.onFail = null;
this.issueGenerator = require('./issue');
var obj = this;
/* Images */
var refreshPng = require.toUrl('./img/refresh.png');
/* Ajax Method */
var xhtp = new XMLHttpRequest();
var fetchData = function(options)
{
xhtp.onreadystatechange = function()
{
if(xhtp.readyState == 4)
{
if(xhtp.status == 200)
{
obj.data = JSON.parse(xhtp.responseText);
if(typeof obj.data.warningMessages != 'undefined')
{
obj.onFail('there was an error retrieving the data. ERROR: ',600);
return;
}
obj.loadIssues();
if(obj.onFinish)
{
obj.onFinish(obj.data);
}
}
else
{
if(obj.onFail)
{
obj.onFail('there was an error retrieving the data. ERROR: ',xhtp.status);
}
}
}
}
xhtp.open(options.method, 'https://'+options.host+options.port+options.path, true);
for(var h in options.headers)
{
xhtp.setRequestHeader(h,options.headers[h]);
}
xhtp.send();
}
/* Events */
this.switchProject = function(e)
{
if(!obj.fetchingData)
{
obj.projectSelection = this.innerHTML;
obj.loadIssues();
}
else
{
$('#jiraB_Loader').html('Please Wait For Data Before Selecting Projects');
setTimeout(function(){$('#jiraB_Loader').html('Fetching Data');},1000);
}
}
/* Methods */
this.requestData = function(userInfo)
{
if(!this.fetchingData)
{
this.fetchingData = true;
var auth = btoa(userInfo.user+':'+userInfo.password);
var port = userInfo.port;
if(port.length > 0)
{
port = ':'+port;
}
var options =
{
host: userInfo.domain,
port: port,
path: '/rest/api/2/search?jql=assignee%3D%27'+userInfo.user+'%27%26status%20IN%20(%271%27%2C%273%27)%0A',
method: 'GET',
headers:{'Content-Encoding':'gzip','X-Atlassian-Token': 'no-check','Content-Type':'application/json;charset=UTF-8','Authorization':'Basic '+auth}
};
fetchData(options);
}
}
this.loadIssues = function()
{
var projectList = $('#jiraB_Projects');
this.issues = [];
if(this.projectNames.indexOf('All') < 0)
{
this.projectNames.push('All');
var projectNode = $('<li>All</li>');
projectList.append(projectNode);
projectNode.on('click',this.switchProject);
}
$('#jiraB_IssueWrapper').html('');
for(var x=0;x<this.data.issues.length;x++)
{
if(this.projectNames.indexOf(this.data.issues[x].fields.project.name) < 0)
{
this.projectNames.push(this.data.issues[x].fields.project.name);
var projectNode = $('<li>'+this.data.issues[x].fields.project.name+'</li>');
projectList.append(projectNode);
projectNode.on('click',this.switchProject);
}
if(this.projectSelection == 'All')
{
this.issues.push(new this.issueGenerator.issue(this.data.issues[x]));
}
else if(this.projectSelection == this.data.issues[x].fields.project.name)
{
this.issues.push(new this.issueGenerator.issue(this.data.issues[x]));
}
}
$('#jiraB_Loader').css('display','none');
$('#jiraB_Refresh').attr('src',refreshPng);
this.fetchingData = false;
}
}
exports.data = data;
});