forked from hustcc/gantt-for-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGantt.jsx
84 lines (76 loc) · 2.28 KB
/
Gantt.jsx
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
import React, { Component } from 'react';
import ReactGantt from '..';
export default class Gantt extends Component {
constructor(props) {
super(props);
this.state = {
viewMode: 'Day',
tasks: this.getTasks(),
};
}
componentDidMount() {
window.setInterval(function() {
this.setState({
viewMode: ['Quarter Day', 'Half Day', 'Day', 'Week', 'Month'][parseInt(Math.random() * 5 + 1) - 1],
tasks: this.getTasks().slice(0, parseInt(Math.random() * 4 + 1))
});
}.bind(this), 5000)
};
getTasks = () => {
let names = [
["Redesign website", [0, 7]],
["Write new content", [1, 4]],
["Apply new styles", [3, 6]],
["Review", [7, 7]],
["Deploy", [8, 9]],
["Go Live!", [10, 10]]
];
let tasks = names.map(function(name, i) {
let today = new Date();
let start = new Date(today.getFullYear(), today.getMonth(), today.getDate());
let end = new Date(today.getFullYear(), today.getMonth(), today.getDate());
start.setDate(today.getDate() + name[1][0]);
end.setDate(today.getDate() + name[1][1]);
return {
start: start,
end: end,
name: name[0],
id: "Task " + i,
progress: parseInt(Math.random() * 100, 10)
}
});
tasks[1].dependencies = "Task 0";
tasks[2].dependencies = "Task 1, Task 0";
tasks[3].dependencies = "Task 2";
tasks[5].dependencies = "Task 4";
tasks[0].custom_class = "bar-milestone";
tasks[0].progress = 60;
return tasks;
};
customPopupHtml = task => {
const end_date = task._end.format('MMM D');
return `
<div class="details-container">
<h5>${task.name}</h5>
<p>Expected to finish by ${end_date}</p>
<p>${task.progress}% completed!</p>
</div>
`;
};
render() {
return (
<div className='examples'>
<div className='parent'>
<label> render ReactGantt Component </label>
<div style={{overflow: 'scroll'}}>
<ReactGantt tasks={this.state.tasks}
viewMode={this.state.viewMode}
customPopupHtml={this.customPopupHtml}
scrollOffsets={this.state.scrollOffsets}
/>
</div>
</div>
</div>
);
}
}