2020-08-05 08:14:22 +03:00
|
|
|
import React from "react";
|
|
|
|
|
import "gantt-task-react/dist/index.css";
|
2020-08-23 22:33:25 +03:00
|
|
|
import { Task, ViewMode, Gantt } from "gantt-task-react";
|
2020-08-05 08:14:22 +03:00
|
|
|
import { ViewSwitcher } from "./components/view-switcher";
|
|
|
|
|
|
|
|
|
|
//Init
|
|
|
|
|
const App = () => {
|
|
|
|
|
const currentDate = new Date();
|
|
|
|
|
const [view, setView] = React.useState<ViewMode>(ViewMode.Day);
|
2020-08-23 22:33:25 +03:00
|
|
|
const [isChecked, setIsChecked] = React.useState(true);
|
|
|
|
|
let columnWidth = 60;
|
|
|
|
|
if (view === ViewMode.Month) {
|
|
|
|
|
columnWidth = 300;
|
|
|
|
|
} else if (view === ViewMode.Week) {
|
|
|
|
|
columnWidth = 250;
|
|
|
|
|
}
|
2020-08-05 08:14:22 +03:00
|
|
|
let tasks: Task[] = [
|
|
|
|
|
{
|
|
|
|
|
start: new Date(currentDate.getFullYear(), currentDate.getMonth(), 1),
|
|
|
|
|
end: new Date(
|
|
|
|
|
currentDate.getFullYear(),
|
|
|
|
|
currentDate.getMonth(),
|
|
|
|
|
2,
|
|
|
|
|
12,
|
|
|
|
|
28
|
|
|
|
|
),
|
|
|
|
|
name: "Idea",
|
|
|
|
|
id: "Task 0",
|
|
|
|
|
progress: 45,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
start: new Date(currentDate.getFullYear(), currentDate.getMonth(), 2),
|
|
|
|
|
end: new Date(currentDate.getFullYear(), currentDate.getMonth(), 4, 0, 0),
|
|
|
|
|
name: "Research",
|
|
|
|
|
id: "Task 1",
|
|
|
|
|
progress: 25,
|
|
|
|
|
dependencies: ["Task 0"],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
start: new Date(currentDate.getFullYear(), currentDate.getMonth(), 4),
|
|
|
|
|
end: new Date(currentDate.getFullYear(), currentDate.getMonth(), 8, 0, 0),
|
|
|
|
|
name: "Discussion with team",
|
|
|
|
|
id: "Task 2",
|
|
|
|
|
progress: 10,
|
|
|
|
|
dependencies: ["Task 1"],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
start: new Date(currentDate.getFullYear(), currentDate.getMonth(), 8),
|
|
|
|
|
end: new Date(currentDate.getFullYear(), currentDate.getMonth(), 9, 0, 0),
|
|
|
|
|
name: "Developing",
|
|
|
|
|
id: "Task 3",
|
|
|
|
|
progress: 2,
|
|
|
|
|
dependencies: ["Task 2"],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
start: new Date(currentDate.getFullYear(), currentDate.getMonth(), 8),
|
|
|
|
|
end: new Date(currentDate.getFullYear(), currentDate.getMonth(), 10),
|
|
|
|
|
name: "Review",
|
|
|
|
|
id: "Task 4",
|
|
|
|
|
progress: 70,
|
|
|
|
|
dependencies: ["Task 2"],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
start: new Date(currentDate.getFullYear(), currentDate.getMonth(), 15),
|
2020-08-09 10:51:25 +03:00
|
|
|
end: new Date(currentDate.getFullYear(), currentDate.getMonth(), 16),
|
2020-08-23 22:33:25 +03:00
|
|
|
name: "Release & Eat Pizza",
|
2020-08-05 08:14:22 +03:00
|
|
|
id: "Task 6",
|
|
|
|
|
progress: currentDate.getMonth(),
|
|
|
|
|
dependencies: ["Task 4"],
|
|
|
|
|
styles: { progressColor: "#ffbb54", progressSelectedColor: "#ff9e0d" },
|
|
|
|
|
},
|
2020-08-23 22:33:25 +03:00
|
|
|
{
|
|
|
|
|
start: new Date(currentDate.getFullYear(), currentDate.getMonth(), 24),
|
|
|
|
|
end: new Date(currentDate.getFullYear(), currentDate.getMonth(), 25),
|
|
|
|
|
name: "Closing",
|
|
|
|
|
id: "Task 9",
|
|
|
|
|
progress: 0,
|
|
|
|
|
isDisabled: true,
|
|
|
|
|
},
|
2020-08-05 08:14:22 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let onTaskChange = (task: Task) => {
|
|
|
|
|
console.log("On date change Id:" + task.id);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let onTaskDelete = (task: Task) => {
|
|
|
|
|
const conf = window.confirm("Are you sure?");
|
|
|
|
|
if (!conf) throw "No del Id:" + task.id;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let onProgressChange = (task: Task) => {
|
|
|
|
|
console.log("On progress change Id:" + task.id);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let onDblClick = (task: Task) => {
|
|
|
|
|
alert("On Double Click event Id:" + task.id);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
2020-08-23 22:33:25 +03:00
|
|
|
<ViewSwitcher
|
|
|
|
|
onViewModeChange={viewMode => setView(viewMode)}
|
|
|
|
|
onViewListChange={setIsChecked}
|
|
|
|
|
isChecked={isChecked}
|
|
|
|
|
/>
|
|
|
|
|
<h3>Gantt With Unlimited Height</h3>
|
|
|
|
|
<Gantt
|
|
|
|
|
tasks={tasks}
|
|
|
|
|
viewMode={view}
|
|
|
|
|
onDateChange={onTaskChange}
|
|
|
|
|
onTaskDelete={onTaskDelete}
|
|
|
|
|
onProgressChange={onProgressChange}
|
|
|
|
|
onDoubleClick={onDblClick}
|
|
|
|
|
listCellWidth={isChecked ? "150px" : ""}
|
|
|
|
|
columnWidth={columnWidth}
|
|
|
|
|
/>
|
|
|
|
|
<h3>Gantt With Limited Height</h3>
|
|
|
|
|
<Gantt
|
2020-08-05 08:14:22 +03:00
|
|
|
tasks={tasks}
|
|
|
|
|
viewMode={view}
|
|
|
|
|
onDateChange={onTaskChange}
|
|
|
|
|
onTaskDelete={onTaskDelete}
|
|
|
|
|
onProgressChange={onProgressChange}
|
|
|
|
|
onDoubleClick={onDblClick}
|
2020-08-23 22:33:25 +03:00
|
|
|
listCellWidth={isChecked ? "150px" : ""}
|
|
|
|
|
ganttHeight={300}
|
|
|
|
|
columnWidth={columnWidth}
|
2020-08-05 08:14:22 +03:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default App;
|