forked from Shikaga/TimesheetBuddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimelinePanel.js
57 lines (53 loc) · 1.94 KB
/
TimelinePanel.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
define(['lib/react'], function(React) {
var TimelinePanel = React.createClass({
getInitialState: function() {
return {
}
},
render: function() {
function getEventClassName(event) {
if (event.date.getDay() === 6 || event.date.getDay() === 0) {
return {className: "danger"};
} else {
return {};
}
}
var dateCells = [];
var maxStatuses = this.props.events.map(function(e) {return e.statusChanges ? e.statusChanges.length : 0}).reduce(function(left, right) {return Math.max(left, right)}, 0);
var maxComments = this.props.events.map(function(e) {return e.comments ? e.comments.length : 0}).reduce(function(left, right) {return Math.max(left, right)}, 0);
var statusRows = [];
var commentRows = [];
for (var i=0; i < maxStatuses; i++) {
var cells = [];
for (var j=0; j < this.props.events.length; j++) {
cells.push(React.DOM.td(getEventClassName(this.props.events[j]), ""));
}
statusRows.push(React.DOM.tr({},cells));
}
for (var i=0; i < maxComments; i++) {
var cells = [];
for (var j=0; j < this.props.events.length; j++) {
cells.push(React.DOM.td(getEventClassName(this.props.events[j]), ""));
}
commentRows.push(React.DOM.tr({},cells));
}
this.props.events.forEach(function(event, index) {
dateCells.push(React.DOM.td({}, event.date.getDate()+"/"+(event.date.getMonth()+1)+"/"+(event.date.getYear()+1900)));
// debugger;
event.statusChanges.forEach(function(status, statusIndex) {
statusRows[statusIndex].props.children[index] = React.DOM.td(getEventClassName(event), status);
})
event.comments.forEach(function(comment, commentIndex) {
commentRows[commentIndex].props.children[index] = React.DOM.td(getEventClassName(event), comment);
})
});
return React.DOM.table({className: "table"},
React.DOM.h1({}, this.props.jiraId),
React.DOM.tr({},dateCells),
statusRows,
commentRows
);
}
});
return TimelinePanel;
});