-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJiraStatisticsCompilerPanel.js
executable file
·120 lines (109 loc) · 6.04 KB
/
JiraStatisticsCompilerPanel.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
define(['lib/react', 'LoginPanel', 'TimelinePanel', 'StatCalculator'], function(React, LoginPanel, TimelinePanel,StatCalculator) {
var JiraStatisticsCompilerPanel = React.createClass({
render: function() {
return React.DOM.div({className: "container"}, LoginPanel({login: this.login}), TimelinePanel({jiraId: this.props.jiraId, events: this.props.events}));
},
getInitialState: function() {
return {
}
},
selectProject: function(projectIds, user) {
getDataWithJSON(function(response) {
window.sameDay = function(d1, d2) {
return d1.getFullYear() === d2.getFullYear() &&
d1.getMonth() === d2.getMonth() &&
d1.getDate() === d2.getDate();
}
window.last10days = Array.from({length:10},(v,k)=>k).map(function(v) {
var date = new Date();
date.setDate(date.getDate() - v);
return {date, events: {}};
})
var data = JSON.parse(response.target.response);
var yourData = data.issues.filter(function(issue) {
for (var j=0; j < issue.changelog.histories.length; j++) {
var change = issue.changelog.histories[j];
for (var i=0; i < change.items.length; i++) {
if (change.items[i].field == "assignee") {
if (change.items[i].from == user) return true;
if (change.items[i].to == user) return true;
}
}
}
return false;
});
console.log("Total issues worked on in last 10 days:", data.issues.length);
console.log("Issues you have worked on in last 10 days:", yourData.length);
yourData.map(function(issue) {
for (var i=0; i < issue.changelog.histories.length; i++) {
if (issue.changelog.histories[i].items.filter(function(item) {return item.field == "status"}).length > 0) {
}
else {
if (issue.changelog.histories[i-1] && issue.changelog.histories[i-1].items.filter(function(item) {return item.field == "status"}).length > 0) {
issue.changelog.histories[i].items.push(
{field: "status",
fromString: issue.changelog.histories[i-1].items.filter(function(item) {return item.field == "status"}).map(function(item) {return item.fromString})[0],
toString: issue.changelog.histories[i-1].items.filter(function(item) {return item.field == "status"}).map(function(item) {return item.toString})[0]
})
}
}
if (issue.changelog.histories[i].items.filter(function(item) {return item.field == "assignee"}).length > 0) {
}
else {
if (issue.changelog.histories[i-1] && issue.changelog.histories[i-1].items.filter(function(item) {return item.field == "assignee"}).length > 0) {
issue.changelog.histories[i].items.push(
{field: "assignee",
from: issue.changelog.histories[i-1].items.filter(function(item) {return item.field == "assignee"}).map(function(item) {return item.from})[0],
to: issue.changelog.histories[i-1].items.filter(function(item) {return item.field == "assignee"}).map(function(item) {return item.to})[0]
})
}
}
}
issue.changelog.histories.map(function(change) {
change.items.map(function(fieldChanged) {
if (fieldChanged.field=="status" && change.items.filter(function(item) {return item.field == "assignee"})[0] && change.items.filter(function(item) {return item.field == "assignee"})[0].to == user) {
for (var i=0; i < window.last10days.length; i++) {
if (window.sameDay(window.last10days[i].date, new Date(Date.parse(change.created)))) {
window.last10days[i].events[issue.key+":"+issue.fields.summary+" - "+issue.fields.customfield_11670] = window.last10days[i].events[issue.key+":"+issue.fields.summary+" - "+issue.fields.customfield_11670] || [];
window.last10days[i].events[issue.key+":"+issue.fields.summary+" - "+issue.fields.customfield_11670].push({
toString: function() {return this.event + " - " + this.time.getHours() + ":" + this.time.getMinutes()},
event: fieldChanged.fromString + " -> " + fieldChanged.toString,
time: new Date(Date.parse(change.created))
})
}
}
}
}.bind(this))
}.bind(this));
})
window.days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
window.months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
window.last10days.map(function(day) {
console.log(window.days[day.date.getDay()], day.date.getDate(), window.months[day.date.getMonth()]);
Object.keys(day.events).forEach(function(jiraId,index) {
console.log(" ", jiraId);
var jira = day.events[jiraId];
jira.map(function(event) {
console.log(" ", event.toString());
})
});
})
}, this.state.username, this.state.password,
this.state.url + "/rest/api/latest/search?jql=" + "updatedDate > -10d AND (" + projectIds.map(function(e) {return "project = " + e}).join(" OR ") + ") &maxResults=1000&expand=changelog");
},
login: function(url, username, password, projects, user) {
window.url = url;
this.state.url = url;
this.state.username = username;
this.state.password = password;
this.setState({
url: url,
username: username,
password: password,
mode: "loggedIn"
});
this.selectProject(projects, user);
}
});
return JiraStatisticsCompilerPanel;
});