Skip to content

Commit c6078b0

Browse files
🤖 Merge PR DefinitelyTyped#71925 @types/frappe-gantt: Update to latest frappe-gantt library by @IILimitlessII
1 parent d2b9248 commit c6078b0

File tree

3 files changed

+223
-50
lines changed

3 files changed

+223
-50
lines changed
Lines changed: 145 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,167 @@
11
import Gantt from "frappe-gantt";
22

3-
const tasks = [
3+
// Test basic task structure
4+
const tasks: Gantt.Task[] = [
45
{
56
id: "Task 1",
67
name: "Redesign website",
78
start: "2016-12-28",
89
end: "2016-12-31",
910
progress: 20,
11+
color: "#fff",
1012
dependencies: "Task 2, Task 3",
1113
},
14+
{
15+
id: "Task 2",
16+
name: "Task with duration",
17+
start: "2016-12-28",
18+
duration: "2 days",
19+
color: "#000",
20+
progress: 50,
21+
},
22+
{
23+
id: "Task 3",
24+
name: "Custom class task",
25+
start: "2016-12-28",
26+
end: "2016-12-31",
27+
progress: 75,
28+
color_progress: "#fff",
29+
custom_class: "custom-task",
30+
},
1231
];
13-
const gantt1 = new Gantt("#gantt", tasks);
1432

33+
// Test different constructor signatures
34+
const gantt1 = new Gantt("#gantt", tasks);
1535
const gantt2 = new Gantt(new HTMLElement(), tasks);
1636
const gantt3 = new Gantt(new SVGElement(), tasks);
1737

18-
gantt1.change_view_mode(Gantt.VIEW_MODE.WEEK);
19-
gantt1.refresh(tasks);
38+
// Test view modes
39+
gantt1.change_view_mode("Week");
40+
gantt1.change_view_mode("Day", true);
2041

21-
new Gantt("#gantt", tasks, {
22-
on_click: task => {},
23-
on_date_change: (task, start, end) => {},
24-
on_progress_change: (task, progress) => {},
25-
on_view_change: mode => {},
42+
// Test view mode object
43+
gantt1.change_view_mode({
44+
name: "Month",
45+
padding: "1 day",
46+
date_format: "YYYY-MM-DD",
47+
upper_text: (date: Date) => date.toLocaleDateString(),
48+
lower_text: "DD",
49+
column_width: 50,
50+
step: "1 day",
51+
snap_at: "1 day",
52+
thick_line: (date: Date) => date.getDate() === 1,
2653
});
2754

55+
// Test task operations
56+
gantt1.refresh(tasks);
57+
gantt1.update_task("Task 1", { progress: 50 });
58+
const task = gantt1.get_task("Task 1");
59+
60+
// Test view checks
61+
gantt1.view_is("Week");
62+
gantt1.view_is(["Week", "Day"]);
63+
gantt1.view_is({ name: "Week" });
64+
65+
// Test utility methods
66+
gantt1.unselect_all();
67+
const oldestDate = gantt1.get_oldest_starting_date();
68+
gantt1.clear();
69+
70+
// Test comprehensive options
2871
new Gantt("#gantt", tasks, {
29-
custom_popup_html: task => {
30-
const end_date = task._end.toDateString();
31-
return `
32-
<div class="details-container">
33-
<h5>${task.name}</h5>
34-
<p>Expected to finish by ${end_date}</p>
35-
<p>${task.progress}% completed!</p>
36-
</div>
37-
`;
72+
// Basic display options
73+
arrow_curve: 5,
74+
auto_move_label: true,
75+
bar_corner_radius: 3,
76+
bar_height: 20,
77+
column_width: 30,
78+
container_height: "auto",
79+
date_format: "YYYY-MM-DD",
80+
81+
// Holiday and ignore settings
82+
holidays: {
83+
red: "weekend",
84+
blue: ["2023-12-25", "2023-12-26"],
85+
green: (date: Date) => date.getDay() === 5,
86+
purple: [
87+
{ date: "2023-12-31", name: "New Year's Eve" },
88+
{ date: "2024-01-01", name: "New Year's Day" },
89+
],
3890
},
91+
ignore: ["2023-12-24", "2023-12-25"],
92+
93+
// Layout options
94+
infinite_padding: true,
3995
language: "es",
96+
lines: "both",
97+
lower_header_height: 20,
98+
move_dependencies: true,
99+
padding: 10,
100+
101+
// Popup options
102+
popup: true,
103+
popup_on: "click",
104+
105+
// Readonly options
106+
readonly: false,
107+
readonly_dates: false,
108+
readonly_progress: false,
109+
110+
// Scroll and progress options
111+
scroll_to: "today",
112+
show_expected_progress: true,
113+
snap_at: "1 day",
114+
today_button: true,
115+
upper_header_height: 50,
116+
117+
// View mode options
118+
view_mode: "Week",
119+
view_mode_select: true,
120+
view_modes: [
121+
{
122+
name: "Quarter Day",
123+
padding: "1 hour",
124+
date_format: "HH:mm",
125+
upper_text: "DD MMM",
126+
lower_text: "HH:mm",
127+
column_width: 25,
128+
step: "15 mins",
129+
snap_at: "15 mins",
130+
},
131+
{
132+
name: "Day",
133+
padding: "1 day",
134+
date_format: "DD MMM",
135+
upper_text: "MMMM YYYY",
136+
lower_text: "DD",
137+
column_width: 50,
138+
step: "1 day",
139+
snap_at: "1 day",
140+
thick_line: (date: Date) => date.getDay() === 1,
141+
},
142+
],
143+
144+
// Event handlers
145+
on_click: (task: Gantt.Task) => {
146+
console.log(`Task ${task.name} clicked`);
147+
},
148+
on_date_change: (task: Gantt.Task, start: Date, end: Date) => {
149+
console.log(`Task ${task.name} dates changed to ${start} - ${end}`);
150+
},
151+
on_progress_change: (task: Gantt.Task, progress: number) => {
152+
console.log(`Task ${task.name} progress changed to ${progress}%`);
153+
},
154+
on_view_change: (mode: Gantt.ViewModeObject) => {
155+
console.log(`View changed to ${mode.name}`);
156+
},
40157
});
158+
159+
// Test static VIEW_MODE property
160+
const viewModes = {
161+
quarterDay: Gantt.VIEW_MODE.QUARTER_DAY,
162+
halfDay: Gantt.VIEW_MODE.HALF_DAY,
163+
day: Gantt.VIEW_MODE.DAY,
164+
week: Gantt.VIEW_MODE.WEEK,
165+
month: Gantt.VIEW_MODE.MONTH,
166+
year: Gantt.VIEW_MODE.YEAR,
167+
};
Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,93 @@
1-
export = Gantt;
1+
export default Gantt;
22

33
declare class Gantt {
44
constructor(wrapper: string | HTMLElement | SVGElement, tasks: Gantt.Task[], options?: Gantt.Options);
55

6-
change_view_mode(mode: Gantt.viewMode): void;
6+
tasks: Gantt.Task[];
7+
options: Gantt.Options;
8+
9+
setup_wrapper(element: string | HTMLElement | SVGElement): void;
10+
setup_options(options: Gantt.Options): void;
11+
setup_tasks(tasks: Gantt.Task[]): void;
712
refresh(tasks: Gantt.Task[]): void;
13+
change_view_mode(mode?: Gantt.viewMode | Gantt.ViewModeObject, maintain_scroll?: boolean): void;
14+
update_task(id: string, new_details: Partial<Gantt.Task>): void;
15+
get_task(id: string): Gantt.Task | undefined;
16+
unselect_all(): void;
17+
view_is(modes: string | string[] | Gantt.ViewModeObject): boolean;
18+
get_oldest_starting_date(): Date;
19+
clear(): void;
20+
21+
static VIEW_MODE: Record<Gantt.viewModeKey, Gantt.viewMode>;
822
}
923

1024
declare namespace Gantt {
1125
interface Task {
12-
id: string;
26+
id?: string;
1327
name: string;
1428
start: string;
15-
end: string;
29+
end?: string;
30+
duration?: string;
1631
progress: number;
17-
dependencies: string;
18-
custom_class?: string | undefined;
32+
dependencies?: string | string[];
33+
custom_class?: string;
34+
color?: string | undefined;
35+
color_progress?: string | undefined;
36+
_start?: Date;
37+
_end?: Date;
38+
_index?: number;
1939
}
2040

21-
interface EnrichedTask extends Task {
22-
_start: Date;
23-
_end: Date;
24-
_index: number;
25-
invalid?: boolean | undefined;
41+
interface ViewModeObject {
42+
name: viewMode;
43+
padding?: string | [string, string];
44+
date_format?: string;
45+
upper_text?: string | ((date: Date, last_date: Date | null, language: string) => string);
46+
lower_text?: string | ((date: Date, last_date: Date | null, language: string) => string);
47+
column_width?: number;
48+
step?: string;
49+
snap_at?: string;
50+
thick_line?: (date: Date) => boolean;
2651
}
2752

2853
interface Options {
29-
header_height?: number | undefined;
30-
column_width?: number | undefined;
31-
step?: number | undefined;
32-
view_modes?: viewMode[] | undefined;
33-
bar_height?: number | undefined;
34-
bar_corner_radius?: number | undefined;
35-
arrow_curve?: number | undefined;
36-
padding?: number | undefined;
37-
view_mode?: viewMode | undefined;
38-
date_format?: string | undefined;
39-
custom_popup_html?: string | ((task: EnrichedTask) => string) | undefined;
40-
language?: string | undefined;
41-
on_click?: ((task: EnrichedTask) => void) | undefined;
42-
on_date_change?: ((task: EnrichedTask, start: Date, end: Date) => void) | undefined;
43-
on_progress_change?: ((task: EnrichedTask, progress: number) => void) | undefined;
44-
on_view_change?: ((mode: viewMode) => void) | undefined;
54+
arrow_curve?: number;
55+
auto_move_label?: boolean;
56+
bar_corner_radius?: number;
57+
bar_height?: number;
58+
column_width?: number;
59+
container_height?: "auto" | number;
60+
date_format?: string;
61+
holidays?: Record<
62+
string,
63+
string | string[] | ((date: Date) => boolean) | Array<{ date: string; name: string }>
64+
>;
65+
ignore?: string | string[] | ((date: Date) => boolean);
66+
infinite_padding?: boolean;
67+
language?: string;
68+
lines?: "vertical" | "horizontal" | "both" | "none";
69+
lower_header_height?: number;
70+
move_dependencies?: boolean;
71+
padding?: number;
72+
popup?: boolean | string | ((task: Task) => string);
73+
popup_on?: string;
74+
readonly?: boolean;
75+
readonly_dates?: boolean;
76+
readonly_progress?: boolean;
77+
scroll_to?: string | "today" | "start" | "end" | Date;
78+
show_expected_progress?: boolean;
79+
snap_at?: string;
80+
today_button?: boolean;
81+
upper_header_height?: number;
82+
view_mode?: viewMode;
83+
view_mode_select?: boolean;
84+
view_modes?: ViewModeObject[];
85+
on_click?: (task: Task) => void;
86+
on_date_change?: (task: Task, start: Date, end: Date) => void;
87+
on_progress_change?: (task: Task, progress: number) => void;
88+
on_view_change?: (mode: ViewModeObject) => void;
4589
}
4690

47-
type viewMode = "Quarter Day" | "Half Day" | "Day" | "Week" | "Month" | "Year";
48-
91+
type viewMode = "Hour" | "Quarter Day" | "Half Day" | "Day" | "Week" | "Month" | "Year";
4992
type viewModeKey = "QUARTER_DAY" | "HALF_DAY" | "DAY" | "WEEK" | "MONTH" | "YEAR";
50-
51-
const VIEW_MODE: Record<viewModeKey, viewMode>;
5293
}

‎types/frappe-gantt/package.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"private": true,
33
"name": "@types/frappe-gantt",
4-
"version": "0.6.9999",
4+
"version": "0.9.9999",
5+
"type": "module",
56
"projects": [
67
"https://github.com/frappe/gantt"
78
],
@@ -16,6 +17,10 @@
1617
{
1718
"name": "Elijah Lucian",
1819
"githubUsername": "eli7vh"
20+
},
21+
{
22+
"name": "Rahul Singh",
23+
"githubUsername": "IILimitlessII"
1924
}
2025
]
2126
}

0 commit comments

Comments
 (0)