Skip to content

Commit c116626

Browse files
authored
Merge pull request #3244 from VisActor/3235-feature-gantttable-schedulecreatable
feat: tasksShowMode sub_task mode support createSchedule #3235
2 parents 815be5f + ee13616 commit c116626

21 files changed

+275
-87
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "docs: add scheduleCreatable doc\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vtable"
7+
}
8+
],
9+
"packageName": "@visactor/vtable",
10+
"email": "[email protected]"
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "fix: change taskRecord type from string to any\n\n",
5+
"type": "none",
6+
"packageName": "@visactor/vtable"
7+
}
8+
],
9+
"packageName": "@visactor/vtable",
10+
"email": "[email protected]"
11+
}

docs/assets/api/en/GanttAPI.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ update markLine
6767
Update a specific data record
6868

6969
```
70-
updateTaskRecord: (record: any, index: number) => void
70+
/** Updating data information can be passed into a specific index, and updating subtasks can also be passed into an index array */
71+
updateTaskRecord(record: any, task_index: number | number[]): void;
72+
updateTaskRecord(record: any, task_index: number, sub_task_index: number): void;
7173
```
7274

7375
### release(Function)

docs/assets/api/zh/GanttAPI.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
更新某一条数据
6868

6969
```
70-
updateTaskRecord: (record: any, index: number) => void
70+
/** 更新数据信息 可以传入具体的索引,更新子任务也可以传入索引数组 */
71+
updateTaskRecord(record: any, task_index: number | number[]): void;
72+
updateTaskRecord(record: any, task_index: number, sub_task_index: number): void;
7173
```
7274

7375
### release(Function)

docs/assets/guide/en/gantt/introduction.md

+7
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,18 @@ Through the `dependency.linkCreatable` configuration item, you can set whether t
151151

152152
#### Creation Schedule
153153

154+
Configuration taskBar. ScheduleCreatable to true.
155+
154156
If there is no field data for the task date in the original data, you can create a schedule to specify a start time and end time for the task. By default, when you hover over a grid without date data, a button to add a schedule will appear.
155157

156158
The button style can be configured via `taskBar.scheduleCreation.buttonStyle`.
157159

158160
If the current configuration does not meet your needs, you can also customize the display effect of the creation schedule through the `taskBar.scheduleCreation.customLayout` configuration item.
161+
**Note: Different Gantt chart instances have different capabilities to create schedules.**
162+
163+
When `tasksShowMode` is `TasksShowMode.Tasks_Separate` or `TasksShowMode.Sub_Tasks_Separate`, each piece of data has a corresponding row position display, but when there is no `startDate` and `endDate` field set in the data, a create button will appear when the mouse hovers over the row, and clicking the button will create a schedule and display the task bar.
164+
165+
When `tasksShowMode` is `TasksShowMode.Sub_Tasks_Inline`, `TasksShowMode.Sub_Tasks_Arrange`, or `TasksShowMode.Sub_Tasks_Compact`, a create button will be displayed when the mouse hovers over the blank area, and clicking the button will trigger the event `GANTT_EVENT_TYPE.CREATE_TASK_SCHEDULE`, but it will not actually create a task schedule. The user needs to listen for this event and create a schedule update data according to business needs.
159166

160167
## Leveraging the Capabilities of the Table
161168

docs/assets/guide/zh/gantt/introduction.md

+8
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,20 @@ links:[
151151

152152
#### 创建排期
153153

154+
配置 taskBar.scheduleCreatable 为 true。
155+
154156
原始数据中如果没有任务日期的字段数据,那么可以通过创建排期能力来给任务指定一个开始时间和结束时间。默认当 hover 到没有日期数据的网格上时,会出现一个添加排期的按钮。
155157

156158
按钮的样式可以通过`taskBar.scheduleCreation.buttonStyle`配置。
157159

158160
如果当前配置不能满足需求,也可以通过`taskBar.scheduleCreation.customLayout`配置项自定义创建排期的展示效果。
159161

162+
**注意:不同的甘特图实例,创建排期能力不同。:**
163+
164+
`tasksShowMode``TasksShowMode.Tasks_Separate``TasksShowMode.Sub_Tasks_Separate`,也就是没条数据有对应的一行位置展示,但是数据中没有设置 startDate 和 endDate 的字段时,鼠标 hover 到该行会出现创建按钮,点击按钮会创建排期并展示任务条。
165+
166+
`tasksShowMode``TasksShowMode.Sub_Tasks_Inline``TasksShowMode.Sub_Tasks_Arrange``TasksShowMode.Sub_Tasks_Compact`,当鼠标 hover 到空白区域即会显示创建按钮,点击按钮会触发事件`GANTT_EVENT_TYPE.CREATE_TASK_SCHEDULE`但不会真正的创建任务排期,使用者需要监听该事件根据业务需求来自行创建排期更新数据。
167+
160168
## 借助表格的能力
161169

162170
甘特图是基于 VTable 的 ListTable 实现的,看上去相当于一个拼接形式,左侧是任务信息表格,右侧是任务条列表。

docs/assets/option/en/common/gantt/task-bar.md

+15-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Optional
7070
| ((interactionArgs: TaskBarInteractionArgumentType) => boolean | [boolean, boolean]);
7171
7272
export type TaskBarInteractionArgumentType = {
73-
taskRecord: string;
73+
taskRecord: any;
7474
index: number;
7575
startDate: Date;
7676
endDate: Date;
@@ -88,7 +88,7 @@ Optional
8888
moveable?: boolean | ((interactionArgs: TaskBarInteractionArgumentType) => boolean);
8989
9090
export type TaskBarInteractionArgumentType = {
91-
taskRecord: string;
91+
taskRecord: any;
9292
index: number;
9393
startDate: Date;
9494
endDate: Date;
@@ -137,12 +137,24 @@ Whether the service clause is optional, the default is true
137137

138138
Not required
139139

140-
${prefix} scheduleCreatable(boolean) = true
140+
${prefix} scheduleCreatable(boolean | Function) = true
141141

142142
When there is no schedule, you can create a task bar schedule by clicking on the create button. The default is true.
143143

144144
Optional
145145

146+
```
147+
scheduleCreatable?: boolean | ((interactionArgs: TaskBarInteractionArgumentType) => boolean);
148+
149+
export type TaskBarInteractionArgumentType = {
150+
taskRecord: any;
151+
index: number;
152+
startDate: Date;
153+
endDate: Date;
154+
ganttInstance: Gantt;
155+
};
156+
```
157+
146158
${prefix} scheduleCreation(Object)
147159

148160
For tasks without assigned dates, you can display the create button.

docs/assets/option/zh/common/gantt/task-bar.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ ${prefix} resizable(boolean | [ boolean, boolean ] | Function) = true
7272
7373
//其中:
7474
export type TaskBarInteractionArgumentType = {
75-
taskRecord: string;
75+
taskRecord: any;
7676
index: number;
7777
startDate: Date;
7878
endDate: Date;
@@ -91,7 +91,7 @@ moveable?: boolean | ((interactionArgs: TaskBarInteractionArgumentType) => boole
9191
9292
//其中:
9393
export type TaskBarInteractionArgumentType = {
94-
taskRecord: string;
94+
taskRecord: any;
9595
index: number;
9696
startDate: Date;
9797
endDate: Date;
@@ -140,12 +140,25 @@ ${prefix} selectable(boolean)
140140

141141
非必填
142142

143-
${prefix} scheduleCreatable(boolean) = true
143+
${prefix} scheduleCreatable(boolean | Function) = true
144144

145145
数据没有排期时,可通过创建任务条排期。默认为 true
146146

147147
非必填
148148

149+
```
150+
scheduleCreatable?: boolean | ((interactionArgs: TaskBarInteractionArgumentType) => boolean);
151+
152+
//其中:
153+
export type TaskBarInteractionArgumentType = {
154+
taskRecord: any;
155+
index: number;
156+
startDate: Date;
157+
endDate: Date;
158+
ganttInstance: Gantt;
159+
};
160+
```
161+
149162
${prefix} scheduleCreation(Object)
150163

151164
针对没有分配日期的任务,可以显示出创建按钮

packages/vtable-gantt/examples/gantt/gantt-Sub_Tasks_Arrange.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ export function createTable() {
307307
},
308308
headerRowHeight: 60,
309309
taskBar: {
310+
scheduleCreatable: true,
310311
startDateField: 'start',
311312
endDateField: 'end',
312313
progressField: 'progress',
@@ -457,7 +458,9 @@ export function createTable() {
457458
ganttInstance.on('scroll', e => {
458459
console.log('scroll', e);
459460
});
460-
461+
ganttInstance.on('create_task_schedule', e => {
462+
console.log('CREATE_TASK_SCHEDULE', e);
463+
});
461464
ganttInstance.listTableInstance?.on('scroll', e => {
462465
console.log('listTable scroll', e);
463466
});

packages/vtable-gantt/examples/gantt/gantt-Sub_Tasks_Inline.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,9 @@ export function createTable() {
444444
ganttInstance.on('scroll', e => {
445445
console.log('scroll', e);
446446
});
447-
447+
ganttInstance.on('create_task_schedule', e => {
448+
console.log('CREATE_TASK_SCHEDULE', e);
449+
});
448450
ganttInstance.listTableInstance?.on('scroll', e => {
449451
console.log('listTable scroll', e);
450452
});

packages/vtable-gantt/examples/gantt/gantt-Sub_Tasks_Separate.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ export function createTable() {
9191
id: 7,
9292
title: 'Determine project scope',
9393
developer: '[email protected]',
94-
start: '2024-08-09',
95-
end: '2024-09-11',
94+
9695
progress: 100,
9796
priority: 'P1'
9897
}

packages/vtable-gantt/src/Gantt.ts

+31-14
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
} from './tools/util';
6363
import { DataSource } from './data/DataSource';
6464
import { isValid } from '@visactor/vutils';
65+
import type { GanttTaskBarNode } from './scenegraph/gantt-node';
6566
// import { generateGanttChartColumns } from './gantt-helper';
6667
export function createRootElement(padding: any, className: string = 'vtable-gantt'): HTMLElement {
6768
const element = document.createElement('div');
@@ -141,7 +142,7 @@ export class Gantt extends EventTarget {
141142
taskBarDragOrder: boolean;
142143
taskBarLabelStyle: ITaskBarLabelTextStyle;
143144
taskBarCustomLayout: ITaskBarCustomLayout;
144-
taskBarCreatable: boolean;
145+
taskBarCreatable: boolean | ((interactionArgs: TaskBarInteractionArgumentType) => boolean);
145146
taskBarCreationButtonStyle: ILineStyle & {
146147
cornerRadius?: number;
147148
backgroundColor?: string;
@@ -736,22 +737,22 @@ export class Gantt extends EventTarget {
736737
return this.records[taskShowIndex];
737738
}
738739

739-
_refreshTaskBar(taskShowIndex: number) {
740+
_refreshTaskBar(taskShowIndex: number, sub_task_index: number) {
740741
// this.taskListTableInstance.updateRecords([record], [index]);
741-
this.scenegraph.taskBar.updateTaskBarNode(taskShowIndex);
742+
this.scenegraph.taskBar.updateTaskBarNode(taskShowIndex, sub_task_index);
742743
this.scenegraph.refreshRecordLinkNodes(
743744
taskShowIndex,
744745
undefined,
745-
this.scenegraph.taskBar.getTaskBarNodeByIndex(taskShowIndex)
746+
this.scenegraph.taskBar.getTaskBarNodeByIndex(taskShowIndex, sub_task_index) as GanttTaskBarNode
746747
);
747748
this.scenegraph.updateNextFrame();
748749
}
749-
_updateRecordToListTable(record: any, index: number) {
750-
const indexs = this.taskListTableInstance.getRecordIndexByCell(
751-
0,
752-
index + this.taskListTableInstance.columnHeaderLevelCount
753-
);
754-
this.taskListTableInstance.updateRecords([record], [indexs]);
750+
_updateRecordToListTable(record: any, index: number | number[]) {
751+
// const indexs = this.taskListTableInstance.getRecordIndexByCell(
752+
// 0,
753+
// index + this.taskListTableInstance.columnHeaderLevelCount
754+
// );
755+
this.taskListTableInstance.updateRecords([record], [index]);
755756
}
756757
/**
757758
* 获取指定index处任务数据的具体信息
@@ -882,11 +883,27 @@ export class Gantt extends EventTarget {
882883
// const source_taskRecord = this.getRecordByIndex(source_index, source_sub_task_index);
883884
this.data.adjustOrder(source_index, source_sub_task_index, target_index, target_sub_task_index);
884885
}
885-
/** 目前不支持树形tree的情况更新单条数据 需要的话目前可以setRecords。 */
886-
updateTaskRecord(record: any, index: number) {
887-
//const taskRecord = this.getRecordByIndex(index);
886+
// 定义多个函数签名
887+
/** 更新数据信息 */
888+
updateTaskRecord(record: any, task_index: number | number[]): void;
889+
updateTaskRecord(record: any, task_index: number, sub_task_index: number): void;
890+
updateTaskRecord(record: any, task_index: number | number[], sub_task_index?: number) {
891+
if (isValid(sub_task_index)) {
892+
const index = typeof task_index === 'number' ? task_index : task_index[0];
893+
this._updateRecordToListTable(record, [index, sub_task_index]);
894+
this._refreshTaskBar(index, sub_task_index);
895+
return;
896+
}
897+
if (Array.isArray(task_index)) {
898+
const index = (task_index as number[])[0];
899+
const sub_index = (task_index as number[])[1];
900+
this._updateRecordToListTable(record, isValid(sub_index) ? [index, sub_index] : index);
901+
this._refreshTaskBar(index, sub_index);
902+
return;
903+
}
904+
const index = task_index as number;
888905
this._updateRecordToListTable(record, index);
889-
this._refreshTaskBar(index);
906+
this._refreshTaskBar(index, undefined);
890907
}
891908

892909
/**

0 commit comments

Comments
 (0)