Skip to content

Commit 1148386

Browse files
author
Maria Rudenko
committed
Merge pull request '[update] 'Task Types' article' (#80) from GS-2745 into master
Reviewed-on: https://git.webix.io/Servers/gantt-docs/pulls/80
2 parents b1d9756 + cb86118 commit 1148386

File tree

7 files changed

+101
-73
lines changed

7 files changed

+101
-73
lines changed

data/desktop/task_types.md

Lines changed: 101 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,35 @@ There are 3 predefined types of tasks that you can present in a Gantt chart ([yo
1313
<img style="border: 1px #C4C4C5 solid;margin: 20px auto 20px auto;display: block;box-shadow: #D8D8D8 0px 0px 7px 1px;" src="desktop/task_types.png"/>
1414

1515

16-
To set the type of a task, use the [type](desktop/loading.md#specifyingdataproperties) property of a data item (*values are stored in the api/gantt_types_config.md object*):
16+
To set the type of a task, use the [type](desktop/task_properties.md) property of a data item (*values are stored in the api/gantt_types_config.md object*):
1717

1818
{{snippet
1919
Specifying the type of a task in the data set
2020
}}
21+
2122
~~~js
22-
var data = {
23-
task:[
24-
{id:1, text:"Project #1", type:"project", open:true}, /*!*/
25-
{id:2, text:"Task #1", start_date:"12-04-2020", duration:3, parent:1},
26-
{id:3, text:"Alpha release", type:"milestone", parent:1, /*!*/
27-
start_date:"14-04-2020"}, /*!*/
28-
{id:4, text:"Task #2", start_date:"17-04-2020", duration:3, parent:1}],
29-
links:[]
23+
const data = {
24+
tasks: [
25+
{ id: 1, text: "Project #1", type: "project", open: true },
26+
{ id: 2, text: "Task #1", start_date: "12-04-2025", duration: 3, parent: 1 },
27+
{ id: 3, text: "Alpha release", start_date: "16-04-2025", type: "milestone",
28+
parent: 1 },
29+
{ id: 4, text: "Task #2", start_date: "17-04-2025", duration: 3, parent: 1 },
30+
],
31+
links: [
32+
{ id: 1, source: "1", target: "2", type: "1" },
33+
{ id: 2, source: "2", target: "3", type: "0" },
34+
{ id: 3, source: "3", target: "4", type: "0" },
35+
],
3036
};
3137
~~~
38+
3239
{{sample
3340
01_initialization/16_projects_and_milestones.html
3441
}}
3542

43+
44+
3645
Regular tasks
3746
-----------------
3847

@@ -43,25 +52,30 @@ By default, dhtmlxGantt provides creating of regular tasks (tasks with **type="t
4352
{{snippet
4453
Specifying regular tasks
4554
}}
55+
4656
~~~js
47-
var data = {
48-
tasks:[{id:2, text:"Task #1", start_date:"12-04-2020", duration:3}], /*!*/
49-
links:[]
57+
const data = {
58+
tasks: [
59+
{ id: 2, text: "Task #1", start_date: "12-04-2025", duration: 3, parent: 1 }, /*!*/
60+
],
61+
links: [],
5062
};
5163
//or
52-
var data = {
53-
tasks:[{id:2, text:"Task #1", start_date:"12-04-2020", duration:3, /*!*/
54-
type:"task"}], /*!*/
55-
links:[]
64+
const data = {
65+
tasks: [
66+
{ id: 2, text: "Task #1", start_date: "12-04-2025", duration: 3, parent: 1, /*!*/
67+
type: "task" }, /*!*/
68+
],
69+
links: [],
5670
};
5771
~~~
72+
5873
{{sample
5974
01_initialization/16_projects_and_milestones.html
6075
}}
6176

6277
<br>
6378

64-
6579
Tasks with **type="task"** can be characterized as follows:
6680

6781
- Can have 1 parent and any number of child tasks.
@@ -71,6 +85,7 @@ Tasks with **type="task"** can be characterized as follows:
7185
- Can be hidden in the timeline. See [details](desktop/milestones.md#hidingtasksandmilestones).
7286

7387

88+
7489
Project tasks
7590
-----------------
7691

@@ -86,14 +101,17 @@ The difference between project and regular tasks is that the duration of a proje
86101
{{snippet
87102
Specifying project tasks
88103
}}
104+
89105
~~~js
90-
var data = {
91-
tasks:[
92-
{id:1, text:"Project #1", type:"project", open:true}, /*!*/
93-
{id:2, text:"Task #1", start_date:"12-04-2020", duration:3, parent:1},
94-
{id:3, text:"Alpha release", type:"milestone", parent:1,
95-
start_date:"14-04-2020"}],
96-
links:[]
106+
const data = {
107+
tasks: [
108+
{ id: 1, text: "Project #1", type: "project", open: true }, /*!*/
109+
{ id: 2, text: "Task #1", start_date: "12-04-2025", duration: 3, parent: 1 },
110+
{ id: 3, text: "Alpha release", start_date: "16-04-2025", type: "milestone",
111+
parent: 1 },
112+
{ id: 4, text: "Task #2", start_date: "17-04-2025", duration: 3, parent: 1 },
113+
],
114+
links: [],
97115
};
98116
~~~
99117

@@ -116,6 +134,8 @@ Tasks with **type="project"** can be characterized as follows:
116134
To provide a possibility of adding project tasks, read article desktop/milestones.md. A possibility to add milestones guarantees that your end users can add project tasks as well.
117135
}}
118136

137+
138+
119139
Milestones
120140
--------------------------------------------------------
121141

@@ -128,15 +148,15 @@ Milestones
128148
Specifying milestones
129149
}}
130150
~~~js
131-
var data = {
132-
tasks:[
133-
{id:1, text:"Project #1", type:"project", open:true},
134-
{id:2, text:"Task #1", start_date:"12-04-2020", duration:3, parent:1},
135-
{id:3, text:"Alpha release", type:"milestone", parent:1, /*!*/
136-
start_date:"14-04-2020"}],/*!*/
137-
links:[]
151+
const data = {
152+
tasks: [
153+
{ id: 3, text: "Alpha release", start_date: "16-04-2025", type: "milestone", /*!*/
154+
parent: 1 }, /*!*/
155+
],
156+
links: [],
138157
};
139158
~~~
159+
140160
{{sample
141161
01_initialization/16_projects_and_milestones.html
142162
}}
@@ -156,6 +176,8 @@ Tasks with **type="milestone"** can be characterized as follows:
156176
To provide a possibility of adding milestones, read article desktop/milestones.md.
157177
}}
158178

179+
180+
159181
Specific lightbox per task type
160182
----------------------------------------------
161183

@@ -172,18 +194,20 @@ The default configuration settings are the following:
172194

173195
~~~js
174196
gantt.config.lightbox.sections = [
175-
{name: "description", height: 70, map_to: "text", type: "textarea", focus: true},
176-
{name: "time", type: "duration", map_to: "auto"}
197+
{ name: "description", type: "textarea", map_to: "text", height: 70, focus: true },
198+
{ name: "time", type: "duration", map_to: "auto" }
177199
];
178-
gantt.config.lightbox.project_sections= [
179-
{name: "description", height: 70, map_to: "text", type: "textarea", focus: true},
180-
{name: "type", type: "typeselect", map_to: "type"},
181-
{name: "time", type: "duration", readonly: true, map_to: "auto"}
200+
201+
gantt.config.lightbox.project_sections = [
202+
{ name: "description", type: "textarea", map_to: "text", height: 70, focus: true },
203+
{ name: "type", type: "typeselect", map_to: "type" },
204+
{ name: "time", type: "duration", map_to: "auto", readonly: true }
182205
];
183-
gantt.config.lightbox.milestone_sections= [
184-
{name: "description", height: 70, map_to: "text", type: "textarea", focus: true},
185-
{name: "type", type: "typeselect", map_to: "type"},
186-
{name: "time", type: "duration", single_date: true, map_to: "auto"}
206+
207+
gantt.config.lightbox.milestone_sections = [
208+
{ name: "description", type: "textarea", map_to: "text", height: 70, focus: true },
209+
{ name: "type", type: "typeselect", map_to: "type" },
210+
{ name: "time", type: "duration", map_to: "auto", single_date: true }
187211
];
188212
~~~
189213

@@ -194,6 +218,7 @@ You can [add a custom type](desktop/task_types.md#creatingacustomtype) and speci
194218
To go into details on a lightbox configuration, you can read the desktop/edit_form.md chapter.
195219

196220

221+
197222
Creating a custom type
198223
-----------------------------------------------
199224

@@ -202,13 +227,11 @@ All tasks' types are defined in the api/gantt_types_config.md object. <br>Genera
202227
1. Add a new value to the api/gantt_types_config.md object.
203228
2. Define individual settings for the new type.
204229

205-
206230
Let's assume, you want to add a new type of tasks - **meeting**.
207231
**Meeting** will be an ordinary task but colored in different color and with different inputs in the lightbox.
208232

209233
<img style="border: 1px #C4C4C5 solid;margin: 20px auto 20px auto;display: block;box-shadow: #D8D8D8 0px 0px 7px 1px;" src="desktop/custom_task_type.png">
210234

211-
212235
To define a new type with the name **meeting** and specify an individual lightbox for it, use the following technique:
213236

214237
<ol>
@@ -217,6 +240,7 @@ To define a new type with the name **meeting** and specify an individual lightbo
217240
~~~js
218241
gantt.config.types.meeting = "type_id";
219242
~~~
243+
220244
<i>
221245
where "meeting" is a programmatic name of the type. It doesn't affect anything. The only purpose of the programmatic type name is to make work with types more readable.<br>
222246
"type_id" is the type identifier, that will be stored in the database. The type identifier must be unique within the <a href="api/gantt_types_config.md ">types</a> object.</i>
@@ -227,17 +251,19 @@ where "meeting" is a programmatic name of the type. It doesn't affect anything.
227251
~~~js
228252
gantt.locale.labels.type_meeting = "Meeting";
229253
~~~
254+
230255
<br>
231256
</li>
232257
<li>Specify a new structure of the lightbox for the newly-created type:<br><br>
233258

234259
~~~js
235260
gantt.config.lightbox.meeting_sections = [
236-
{name:"title", height:20, map_to:"text", type:"textarea", focus:true},
237-
{name:"details", height:70, map_to: "details", type: "textarea"},
238-
{name:"type", type:"typeselect", map_to:"type"},
239-
{name:"time", height:72, type:"time", map_to:"auto"}
261+
{ name: "title", type: "textarea", map_to: "text", height: 20, focus: true },
262+
{ name: "details", type: "textarea", map_to: "details", height: 70 },
263+
{ name: "type", type: "typeselect", map_to: "type" },
264+
{ name: "time", type: "time", map_to: "auto", height: 72 }
240265
];
266+
241267
gantt.locale.labels.section_title = "Subject";
242268
gantt.locale.labels.section_details = "Details";
243269
~~~
@@ -251,30 +277,28 @@ gantt.locale.labels.section_details = "Details";
251277
color:#6ba8e3;
252278
background: #F2F67E;
253279
}
280+
254281
.meeting_task .gantt_task_progress{
255282
background:#D9DF29;
256283
}
257284
~~~
258285

259286
~~~js
260-
gantt.templates.task_class = function(start, end, task){
261-
if(task.type == gantt.config.types.meeting){
262-
return "meeting_task";
263-
}
264-
return "";
287+
gantt.templates.task_class = (start, end, task) => {
288+
return task.type === gantt.config.types.meeting
289+
? "meeting_task"
290+
: "";
265291
};
266292
~~~
267293
<br>
268294
</li>
269295
<li>Set the template for text of the "meeting" tasks using the api/gantt_task_text_template.md template: <br><br>
270296

271297
~~~js
272-
gantt.templates.task_text = function(start, end, task){
273-
if(task.type == gantt.config.types.meeting){
274-
return "Meeting: <b>" + task.text + "</b>";
275-
}
276-
return task.text;
277-
};
298+
gantt.templates.task_text = (start, end, task) =>
299+
task.type === gantt.config.types.meeting
300+
? `Meeting: <b>${task.text}</b>`
301+
: task.text;
278302
~~~
279303
</li>
280304
</ol>
@@ -283,6 +307,8 @@ gantt.templates.task_text = function(start, end, task){
283307
04_customization/12_custom_task_type.html
284308
}}
285309

310+
311+
286312
Custom display of task types
287313
-----------------------------------------------------------------
288314

@@ -291,23 +317,25 @@ To customize the look of existing task types, use the api/gantt_type_renderers_c
291317
<img src="desktop/custom_look.png"/>
292318

293319
~~~js
294-
gantt.config.type_renderers["project"]=function(task, defaultRender){
295-
var main_el = document.createElement("div");
296-
main_el.setAttribute(gantt.config.task_attribute, task.id);
297-
var size = gantt.getTaskPosition(task);
298-
main_el.innerHTML = [
299-
"<div class='project-left'></div>",
300-
"<div class='project-right'></div>"
301-
].join('');
302-
main_el.className = "custom-project";
303-
304-
main_el.style.left = size.left + "px";
305-
main_el.style.top = size.top + 7 + "px";
306-
main_el.style.width = size.width + "px";
307-
308-
return main_el;
320+
gantt.config.type_renderers["project"] = (task, defaultRender) => {
321+
const taskBar = document.createElement("div");
322+
taskBar.setAttribute(gantt.config.task_attribute, task.id);
323+
taskBar.className = "custom-project";
324+
325+
const taskSize = gantt.getTaskPosition(task);
326+
taskBar.innerHTML = [
327+
"<div class='project-left'></div>",
328+
"<div class='project-right'></div>"
329+
].join('');
330+
331+
taskBar.style.left = `${taskSize.left}px`;
332+
taskBar.style.top = `${taskSize.top + 7}px`;
333+
taskBar.style.width = `${taskSize.width}px`;
334+
335+
return taskBar;
309336
};
310337
~~~
338+
311339
{{sample
312340
04_customization/17_classic_gantt_look.html
313341
}}

media/desktop/custom_look.png

7.16 KB
Loading

media/desktop/custom_task_type.png

19 KB
Loading

media/desktop/task_types.png

9.41 KB
Loading

media/desktop/type_milestone.png

19.4 KB
Loading

media/desktop/type_project.png

20 KB
Loading

media/desktop/type_task.png

20.6 KB
Loading

0 commit comments

Comments
 (0)