@worktile/gantt 11.0.2 → 12.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.all-contributorsrc +53 -0
- package/.angulardoc.json +4 -0
- package/.circleci/config.yml +17 -0
- package/.coveralls.yml +1 -0
- package/.docgenirc.js +64 -0
- package/.editorconfig +22 -0
- package/.prettierrc +24 -0
- package/.travis.yml +23 -0
- package/CHANGELOG.md +564 -0
- package/Dockerfile +4 -0
- package/LICENSE +21 -0
- package/README.md +116 -13
- package/angular.json +136 -0
- package/docs/guides/basic/components.md +54 -0
- package/docs/guides/basic/event.md +70 -0
- package/docs/guides/basic/index.md +4 -0
- package/docs/guides/basic/style.md +68 -0
- package/docs/guides/basic/type.md +70 -0
- package/docs/guides/basic/usage.md +189 -0
- package/docs/guides/index.md +5 -0
- package/docs/guides/intro/getting-started.md +79 -0
- package/docs/guides/intro/index.md +51 -0
- package/docs/index.md +0 -0
- package/example/browserslist +12 -0
- package/example/src/app/app-routing.module.ts +26 -0
- package/example/src/app/app.component.html +2 -0
- package/example/src/app/app.component.ts +11 -0
- package/example/src/app/app.module.ts +57 -0
- package/example/src/app/components/components.component.html +6 -0
- package/example/src/app/components/components.component.ts +33 -0
- package/example/src/app/configuration/parameters/api/zh-cn.js +350 -0
- package/example/src/app/configuration/parameters/doc/zh-cn.md +5 -0
- package/example/src/app/gantt/gantt.component.html +51 -0
- package/example/src/app/gantt/gantt.component.ts +119 -0
- package/example/src/app/gantt-advanced/component/flat.component.html +30 -0
- package/example/src/app/gantt-advanced/component/flat.component.ts +72 -0
- package/example/src/app/gantt-advanced/component/flat.scss +31 -0
- package/example/src/app/gantt-advanced/gantt-advanced.component.html +32 -0
- package/example/src/app/gantt-advanced/gantt-advanced.component.ts +34 -0
- package/example/src/app/gantt-advanced/mocks.ts +158 -0
- package/example/src/app/gantt-groups/gantt-groups.component.html +42 -0
- package/example/src/app/gantt-groups/gantt-groups.component.ts +62 -0
- package/example/src/app/gantt-range/gantt-range.component.html +66 -0
- package/example/src/app/gantt-range/gantt-range.component.ts +67 -0
- package/example/src/app/gantt-range/mocks.ts +150 -0
- package/example/src/app/helper.ts +38 -0
- package/example/src/assets/.gitkeep +0 -0
- package/example/src/environments/environment.prod.ts +3 -0
- package/example/src/environments/environment.ts +16 -0
- package/example/src/favicon.ico +0 -0
- package/example/src/index.html +13 -0
- package/example/src/main.ts +12 -0
- package/example/src/polyfills.ts +63 -0
- package/example/src/styles.scss +56 -0
- package/example/tsconfig.app.json +18 -0
- package/nginx.conf +17 -0
- package/package.json +113 -17
- package/packages/gantt/README.md +24 -0
- package/packages/gantt/karma.conf.js +46 -0
- package/packages/gantt/ng-package.json +7 -0
- package/packages/gantt/ng-package.prod.json +7 -0
- package/packages/gantt/package.json +16 -0
- package/packages/gantt/src/class/date-point.ts +14 -0
- package/{class/event.d.ts → packages/gantt/src/class/event.ts} +12 -6
- package/packages/gantt/src/class/group.ts +36 -0
- package/{class/index.d.ts → packages/gantt/src/class/index.ts} +0 -0
- package/packages/gantt/src/class/item.ts +129 -0
- package/packages/gantt/src/class/test/group.spec.ts +21 -0
- package/packages/gantt/src/class/test/item.spec.ts +102 -0
- package/packages/gantt/src/class/view-type.ts +7 -0
- package/packages/gantt/src/components/bar/bar-drag.ts +298 -0
- package/packages/gantt/src/components/bar/bar.component.html +17 -0
- package/packages/gantt/src/components/bar/bar.component.scss +169 -0
- package/packages/gantt/src/components/bar/bar.component.ts +109 -0
- package/packages/gantt/src/components/bar/test/bar.component.spec.ts +54 -0
- package/packages/gantt/src/components/bar/test/bar.drag.spec.ts +196 -0
- package/packages/gantt/src/components/calendar/calendar.component.html +52 -0
- package/packages/gantt/src/components/calendar/calendar.component.scss +77 -0
- package/packages/gantt/src/components/calendar/calendar.component.ts +100 -0
- package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.html +6 -0
- package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.scss +48 -0
- package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.ts +13 -0
- package/packages/gantt/src/components/icon/icon.component.scss +13 -0
- package/packages/gantt/src/components/icon/icon.component.ts +28 -0
- package/packages/gantt/src/components/icon/icons.ts +86 -0
- package/packages/gantt/src/components/links/links.component.html +19 -0
- package/packages/gantt/src/components/links/links.component.scss +27 -0
- package/packages/gantt/src/components/links/links.component.ts +263 -0
- package/packages/gantt/src/components/main/gantt-main.component.html +35 -0
- package/packages/gantt/src/components/main/gantt-main.component.ts +35 -0
- package/packages/gantt/src/components/range/range.component.html +8 -0
- package/packages/gantt/src/components/range/range.component.scss +35 -0
- package/packages/gantt/src/components/range/range.component.ts +27 -0
- package/packages/gantt/src/components/range/test/range.component.spec.ts +80 -0
- package/packages/gantt/src/components/table/gantt-table.component.html +105 -0
- package/packages/gantt/src/components/table/gantt-table.component.scss +144 -0
- package/packages/gantt/src/components/table/gantt-table.component.ts +166 -0
- package/packages/gantt/src/components/table/test/table.spec.ts +129 -0
- package/packages/gantt/src/gantt-abstract.ts +14 -0
- package/packages/gantt/src/gantt-dom.service.ts +134 -0
- package/packages/gantt/src/gantt-drag-container.ts +73 -0
- package/packages/gantt/src/gantt-item-upper.ts +50 -0
- package/packages/gantt/src/gantt-print.service.ts +104 -0
- package/packages/gantt/src/gantt-upper.ts +289 -0
- package/packages/gantt/src/gantt.component.html +18 -0
- package/packages/gantt/src/gantt.component.scss +77 -0
- package/packages/gantt/src/gantt.component.ts +134 -0
- package/packages/gantt/src/gantt.module.ts +47 -0
- package/packages/gantt/src/gantt.pipe.ts +31 -0
- package/packages/gantt/src/gantt.styles.ts +28 -0
- package/{public-api.d.ts → packages/gantt/src/public-api.ts} +6 -0
- package/packages/gantt/src/root.component.html +12 -0
- package/packages/gantt/src/root.component.ts +121 -0
- package/packages/gantt/src/styles/index.scss +9 -0
- package/packages/gantt/src/styles/variables.scss +46 -0
- package/packages/gantt/src/table/gantt-column.component.ts +25 -0
- package/packages/gantt/src/table/gantt-table.component.ts +14 -0
- package/packages/gantt/src/table/test/table.spec.ts +56 -0
- package/packages/gantt/src/test/gantt.component.spec.ts +404 -0
- package/packages/gantt/src/test/mocks/data.ts +303 -0
- package/packages/gantt/src/test.ts +21 -0
- package/packages/gantt/src/utils/date.ts +276 -0
- package/packages/gantt/src/utils/helpers.ts +66 -0
- package/packages/gantt/src/utils/test/date.spec.ts +105 -0
- package/packages/gantt/src/utils/test/helpers.spec.ts +73 -0
- package/packages/gantt/src/utils/testing.ts +64 -0
- package/packages/gantt/src/views/day.ts +74 -0
- package/packages/gantt/src/views/factory.ts +25 -0
- package/packages/gantt/src/views/month.ts +66 -0
- package/packages/gantt/src/views/quarter.ts +68 -0
- package/packages/gantt/src/views/test/day.spec.ts +45 -0
- package/packages/gantt/src/views/test/factory.spec.ts +41 -0
- package/packages/gantt/src/views/test/mock.ts +14 -0
- package/packages/gantt/src/views/test/month.spec.ts +45 -0
- package/packages/gantt/src/views/test/quarter.spec.ts +45 -0
- package/packages/gantt/src/views/test/view.spec.ts +144 -0
- package/packages/gantt/src/views/test/week.spec.ts +45 -0
- package/packages/gantt/src/views/test/year.spec.ts +45 -0
- package/packages/gantt/src/views/view.ts +186 -0
- package/packages/gantt/src/views/week.ts +66 -0
- package/packages/gantt/src/views/year.ts +62 -0
- package/packages/gantt/tsconfig.lib.json +20 -0
- package/packages/gantt/tsconfig.lib.prod.json +9 -0
- package/packages/gantt/tsconfig.schematics.json +25 -0
- package/packages/gantt/tsconfig.spec.json +17 -0
- package/packages/gantt/tslint.json +18 -0
- package/scss-bundle.config.json +7 -0
- package/tsconfig.json +26 -0
- package/tslint.json +51 -0
- package/bundles/worktile-gantt.umd.js +0 -3129
- package/bundles/worktile-gantt.umd.js.map +0 -1
- package/bundles/worktile-gantt.umd.min.js +0 -16
- package/bundles/worktile-gantt.umd.min.js.map +0 -1
- package/class/date-point.d.ts +0 -15
- package/class/group.d.ts +0 -22
- package/class/item.d.ts +0 -70
- package/class/view-type.d.ts +0 -7
- package/components/bar/bar-drag.d.ts +0 -34
- package/components/bar/bar.component.d.ts +0 -23
- package/components/calendar/calendar.component.d.ts +0 -25
- package/components/drag-backdrop/drag-backdrop.component.d.ts +0 -6
- package/components/icon/icon.component.d.ts +0 -10
- package/components/icon/icons.d.ts +0 -8
- package/components/links/links.component.d.ts +0 -44
- package/components/main/gantt-main.component.d.ts +0 -18
- package/components/range/range.component.d.ts +0 -10
- package/components/table/gantt-table.component.d.ts +0 -31
- package/esm2015/class/date-point.js +0 -10
- package/esm2015/class/event.js +0 -13
- package/esm2015/class/group.js +0 -17
- package/esm2015/class/index.js +0 -6
- package/esm2015/class/item.js +0 -78
- package/esm2015/class/view-type.js +0 -9
- package/esm2015/components/bar/bar-drag.js +0 -266
- package/esm2015/components/bar/bar.component.js +0 -91
- package/esm2015/components/calendar/calendar.component.js +0 -82
- package/esm2015/components/drag-backdrop/drag-backdrop.component.js +0 -18
- package/esm2015/components/icon/icon.component.js +0 -36
- package/esm2015/components/icon/icons.js +0 -87
- package/esm2015/components/links/links.component.js +0 -207
- package/esm2015/components/main/gantt-main.component.js +0 -35
- package/esm2015/components/range/range.component.js +0 -32
- package/esm2015/components/table/gantt-table.component.js +0 -128
- package/esm2015/gantt-dom.service.js +0 -101
- package/esm2015/gantt-drag-container.js +0 -57
- package/esm2015/gantt-item-upper.js +0 -55
- package/esm2015/gantt-print.service.js +0 -92
- package/esm2015/gantt-upper.js +0 -231
- package/esm2015/gantt.component.js +0 -105
- package/esm2015/gantt.module.js +0 -43
- package/esm2015/gantt.pipe.js +0 -33
- package/esm2015/gantt.styles.js +0 -15
- package/esm2015/public-api.js +0 -16
- package/esm2015/root.component.js +0 -111
- package/esm2015/table/gantt-column.component.js +0 -28
- package/esm2015/table/gantt-table.component.js +0 -18
- package/esm2015/utils/date.js +0 -160
- package/esm2015/utils/helpers.js +0 -45
- package/esm2015/views/day.js +0 -54
- package/esm2015/views/factory.js +0 -23
- package/esm2015/views/month.js +0 -48
- package/esm2015/views/quarter.js +0 -51
- package/esm2015/views/view.js +0 -121
- package/esm2015/views/week.js +0 -49
- package/esm2015/views/year.js +0 -50
- package/esm2015/worktile-gantt.js +0 -16
- package/fesm2015/worktile-gantt.js +0 -2491
- package/fesm2015/worktile-gantt.js.map +0 -1
- package/gantt-dom.service.d.ts +0 -29
- package/gantt-drag-container.d.ts +0 -20
- package/gantt-item-upper.d.ts +0 -17
- package/gantt-print.service.d.ts +0 -10
- package/gantt-upper.d.ts +0 -62
- package/gantt.component.d.ts +0 -28
- package/gantt.module.d.ts +0 -2
- package/gantt.pipe.d.ts +0 -11
- package/gantt.styles.d.ts +0 -15
- package/root.component.d.ts +0 -25
- package/style.scss +0 -645
- package/table/gantt-column.component.d.ts +0 -12
- package/table/gantt-table.component.d.ts +0 -7
- package/utils/date.d.ts +0 -59
- package/utils/helpers.d.ts +0 -11
- package/views/day.d.ts +0 -14
- package/views/factory.d.ts +0 -8
- package/views/month.d.ts +0 -12
- package/views/quarter.d.ts +0 -12
- package/views/view.d.ts +0 -56
- package/views/week.d.ts +0 -12
- package/views/year.d.ts +0 -12
- package/worktile-gantt.d.ts +0 -15
- package/worktile-gantt.metadata.json +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { GanttDate } from '../../utils/date';
|
|
2
|
+
import { GanttItem, GanttItemInternal } from '../item';
|
|
3
|
+
import { GanttViewType } from '../view-type';
|
|
4
|
+
|
|
5
|
+
describe('GanttItemInternal', () => {
|
|
6
|
+
let ganttItemInternal: GanttItemInternal;
|
|
7
|
+
let ganttItem: GanttItem;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
ganttItem = {
|
|
11
|
+
id: 'item-0101',
|
|
12
|
+
title: 'VERSION 0101',
|
|
13
|
+
start: new GanttDate('2020-05-21 12:34:35').getUnixTime(),
|
|
14
|
+
group_id: '00001',
|
|
15
|
+
color: '#FF0000',
|
|
16
|
+
children: [
|
|
17
|
+
{
|
|
18
|
+
id: 'item-child-0101',
|
|
19
|
+
title: 'VERSION Children 0101',
|
|
20
|
+
start: new GanttDate('2020-05-21 12:34:35').getUnixTime(),
|
|
21
|
+
group_id: '00001',
|
|
22
|
+
color: '#FF0000',
|
|
23
|
+
linkable: false
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
};
|
|
27
|
+
ganttItemInternal = new GanttItemInternal(ganttItem);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it(`should has correct children`, () => {
|
|
31
|
+
expect(ganttItemInternal.children.length).toBe(1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it(`should has correct end`, () => {
|
|
35
|
+
expect(ganttItemInternal.end.getUnixTime()).toBe(new GanttDate('2020-06-20 23:59:59').getUnixTime());
|
|
36
|
+
|
|
37
|
+
ganttItem.end = null;
|
|
38
|
+
ganttItem.start = new GanttDate('2020-05-21 12:34:35').getUnixTime();
|
|
39
|
+
ganttItemInternal = new GanttItemInternal(ganttItem);
|
|
40
|
+
expect(ganttItemInternal.end.getUnixTime()).toBe(new GanttDate('2020-06-20 23:59:59').getUnixTime());
|
|
41
|
+
|
|
42
|
+
ganttItemInternal = new GanttItemInternal(ganttItem, { viewType: GanttViewType.day });
|
|
43
|
+
expect(ganttItemInternal.end.getUnixTime()).toBe(new GanttDate('2020-05-21 23:59:59').getUnixTime());
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it(`should has correct start`, () => {
|
|
47
|
+
ganttItem.start = null;
|
|
48
|
+
ganttItem.end = new GanttDate('2020-05-21 12:34:35').getUnixTime();
|
|
49
|
+
ganttItemInternal = new GanttItemInternal(ganttItem);
|
|
50
|
+
expect(ganttItemInternal.start.getUnixTime()).toBe(new GanttDate('2020-04-21 00:00:00').getUnixTime());
|
|
51
|
+
|
|
52
|
+
ganttItemInternal = new GanttItemInternal(ganttItem, { viewType: GanttViewType.day });
|
|
53
|
+
expect(ganttItemInternal.start.getUnixTime()).toBe(new GanttDate('2020-05-21 00:00:00').getUnixTime());
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it(`should update refs`, () => {
|
|
57
|
+
const refs = { width: 200, x: 200, y: 200 };
|
|
58
|
+
ganttItemInternal.updateRefs(refs);
|
|
59
|
+
expect(ganttItemInternal.refs.width).toBe(refs.width);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it(`should update date`, () => {
|
|
63
|
+
const start = new GanttDate('2020-04-21 12:34:35');
|
|
64
|
+
const end = new GanttDate('2020-09-21 12:34:35');
|
|
65
|
+
ganttItemInternal.updateDate(start, end);
|
|
66
|
+
expect(ganttItemInternal.start.getUnixTime()).toBe(start.startOfDay().getUnixTime());
|
|
67
|
+
expect(ganttItemInternal.end.getUnixTime()).toBe(end.endOfDay().getUnixTime());
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it(`should add children`, () => {
|
|
71
|
+
const items = [
|
|
72
|
+
{
|
|
73
|
+
id: 'item-child-0102',
|
|
74
|
+
title: 'VERSION Children 0102',
|
|
75
|
+
start: new GanttDate('2020-05-21 12:34:35').getUnixTime(),
|
|
76
|
+
group_id: '00001',
|
|
77
|
+
color: '#FF0000',
|
|
78
|
+
linkable: false
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'item-child-0103',
|
|
82
|
+
title: 'VERSION Children 0103',
|
|
83
|
+
start: new GanttDate('2020-06-21 12:34:35').getUnixTime(),
|
|
84
|
+
group_id: '00001',
|
|
85
|
+
color: '#FF0000',
|
|
86
|
+
linkable: false
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
ganttItemInternal.addChildren(items);
|
|
90
|
+
expect(ganttItemInternal.children.length).toBe(2);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it(`should set expand`, () => {
|
|
94
|
+
ganttItemInternal.setExpand(true);
|
|
95
|
+
expect(ganttItemInternal.expanded).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it(`should add link`, () => {
|
|
99
|
+
ganttItemInternal.addLink('0102');
|
|
100
|
+
expect(ganttItemInternal.links).toContain('0102');
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import { Injectable, ElementRef, OnDestroy, NgZone } from '@angular/core';
|
|
2
|
+
import { DragRef, DragDrop } from '@angular/cdk/drag-drop';
|
|
3
|
+
import { GanttDomService } from '../../gantt-dom.service';
|
|
4
|
+
import { GanttDragContainer } from '../../gantt-drag-container';
|
|
5
|
+
import { GanttItemInternal } from '../../class/item';
|
|
6
|
+
import { GanttDate, differenceInCalendarDays } from '../../utils/date';
|
|
7
|
+
import { fromEvent, Subject } from 'rxjs';
|
|
8
|
+
import { takeUntil } from 'rxjs/operators';
|
|
9
|
+
import { GanttUpper } from '../../gantt-upper';
|
|
10
|
+
|
|
11
|
+
const dragMinWidth = 10;
|
|
12
|
+
const activeClass = 'gantt-bar-active';
|
|
13
|
+
const linkDropClass = 'gantt-bar-link-drop';
|
|
14
|
+
|
|
15
|
+
function createSvgElement(qualifiedName: string, className: string) {
|
|
16
|
+
const element = document.createElementNS('http://www.w3.org/2000/svg', qualifiedName);
|
|
17
|
+
element.classList.add(className);
|
|
18
|
+
return element;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Injectable()
|
|
22
|
+
export class GanttBarDrag implements OnDestroy {
|
|
23
|
+
private ganttUpper: GanttUpper;
|
|
24
|
+
|
|
25
|
+
private barElement: HTMLElement;
|
|
26
|
+
|
|
27
|
+
private item: GanttItemInternal;
|
|
28
|
+
|
|
29
|
+
private get dragDisabled() {
|
|
30
|
+
return !this.item.draggable || !this.ganttUpper.draggable;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private get linkDragDisabled() {
|
|
34
|
+
return !this.item.linkable || !this.ganttUpper.linkable;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private linkDraggingLine: SVGElement;
|
|
38
|
+
|
|
39
|
+
private barDragRef: DragRef;
|
|
40
|
+
|
|
41
|
+
private dragRefs: DragRef[] = [];
|
|
42
|
+
|
|
43
|
+
private destroy$ = new Subject();
|
|
44
|
+
|
|
45
|
+
constructor(private dragDrop: DragDrop, private dom: GanttDomService, private dragContainer: GanttDragContainer) {}
|
|
46
|
+
|
|
47
|
+
private createMouseEvents() {
|
|
48
|
+
fromEvent(this.barElement, 'mouseenter')
|
|
49
|
+
.pipe(takeUntil(this.destroy$))
|
|
50
|
+
.subscribe(() => {
|
|
51
|
+
if (this.dragContainer.linkDraggingId && this.dragContainer.linkDraggingId !== this.item.id) {
|
|
52
|
+
if (this.item.linkable) {
|
|
53
|
+
this.barElement.classList.add(linkDropClass);
|
|
54
|
+
this.dragContainer.emitLinkDragEntered(this.item);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
this.barElement.classList.add(activeClass);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
fromEvent(this.barElement, 'mouseleave')
|
|
62
|
+
.pipe(takeUntil(this.destroy$))
|
|
63
|
+
.subscribe(() => {
|
|
64
|
+
if (!this.dragContainer.linkDraggingId) {
|
|
65
|
+
this.barElement.classList.remove(activeClass);
|
|
66
|
+
} else {
|
|
67
|
+
this.dragContainer.emitLinkDragLeaved();
|
|
68
|
+
}
|
|
69
|
+
this.barElement.classList.remove(linkDropClass);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private createBarDrag() {
|
|
74
|
+
const dragRef = this.dragDrop.createDrag(this.barElement);
|
|
75
|
+
dragRef.lockAxis = 'x';
|
|
76
|
+
dragRef.started.subscribe(() => {
|
|
77
|
+
this.setDraggingStyles();
|
|
78
|
+
this.dragContainer.dragStarted.emit({ item: this.item.origin });
|
|
79
|
+
});
|
|
80
|
+
dragRef.moved.subscribe((event) => {
|
|
81
|
+
const x = this.item.refs.x + event.distance.x;
|
|
82
|
+
const days = differenceInCalendarDays(this.item.end.value, this.item.start.value);
|
|
83
|
+
const start = this.ganttUpper.view.getDateByXPoint(x);
|
|
84
|
+
const end = start.addDays(days);
|
|
85
|
+
this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(x), end);
|
|
86
|
+
});
|
|
87
|
+
dragRef.ended.subscribe((event) => {
|
|
88
|
+
const days = differenceInCalendarDays(this.item.end.value, this.item.start.value);
|
|
89
|
+
const start = this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x);
|
|
90
|
+
const end = start.addDays(days);
|
|
91
|
+
this.item.updateDate(start, end);
|
|
92
|
+
this.clearDraggingStyles();
|
|
93
|
+
this.closeDragBackdrop();
|
|
94
|
+
event.source.reset();
|
|
95
|
+
this.dragContainer.dragEnded.emit({ item: this.item.origin });
|
|
96
|
+
});
|
|
97
|
+
this.barDragRef = dragRef;
|
|
98
|
+
return dragRef;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private createBarHandleDrags() {
|
|
102
|
+
const dragRefs = [];
|
|
103
|
+
const handles = this.barElement.querySelectorAll<HTMLElement>('.drag-handles .handle');
|
|
104
|
+
handles.forEach((handle, index) => {
|
|
105
|
+
const isBefore = index === 0;
|
|
106
|
+
const dragRef = this.dragDrop.createDrag(handle);
|
|
107
|
+
dragRef.lockAxis = 'x';
|
|
108
|
+
dragRef.withBoundaryElement(this.dom.root as HTMLElement);
|
|
109
|
+
|
|
110
|
+
dragRef.started.subscribe(() => {
|
|
111
|
+
this.setDraggingStyles();
|
|
112
|
+
this.dragContainer.dragStarted.emit({ item: this.item.origin });
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
dragRef.moved.subscribe((event) => {
|
|
116
|
+
if (isBefore) {
|
|
117
|
+
const x = this.item.refs.x + event.distance.x;
|
|
118
|
+
const width = this.item.refs.width + event.distance.x * -1;
|
|
119
|
+
if (width > dragMinWidth) {
|
|
120
|
+
this.barElement.style.width = width + 'px';
|
|
121
|
+
this.barElement.style.left = x + 'px';
|
|
122
|
+
this.openDragBackdrop(
|
|
123
|
+
this.barElement,
|
|
124
|
+
this.ganttUpper.view.getDateByXPoint(x),
|
|
125
|
+
this.ganttUpper.view.getDateByXPoint(x + width)
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
const width = this.item.refs.width + event.distance.x;
|
|
130
|
+
if (width > dragMinWidth) {
|
|
131
|
+
this.barElement.style.width = width + 'px';
|
|
132
|
+
this.openDragBackdrop(
|
|
133
|
+
this.barElement,
|
|
134
|
+
this.ganttUpper.view.getDateByXPoint(this.item.refs.x),
|
|
135
|
+
this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width)
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
event.source.reset();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
dragRef.ended.subscribe((event) => {
|
|
143
|
+
if (isBefore) {
|
|
144
|
+
const width = this.item.refs.width + event.distance.x * -1;
|
|
145
|
+
if (width > dragMinWidth) {
|
|
146
|
+
this.item.updateDate(this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x), this.item.end);
|
|
147
|
+
} else {
|
|
148
|
+
this.item.updateDate(this.item.end.startOfDay(), this.item.end);
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
const width = this.item.refs.width + event.distance.x;
|
|
152
|
+
if (width > dragMinWidth) {
|
|
153
|
+
this.item.updateDate(
|
|
154
|
+
this.item.start,
|
|
155
|
+
this.ganttUpper.view.getDateByXPoint(this.item.refs.x + this.item.refs.width + event.distance.x)
|
|
156
|
+
);
|
|
157
|
+
} else {
|
|
158
|
+
this.item.updateDate(this.item.start, this.item.start.endOfDay());
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
this.clearDraggingStyles();
|
|
162
|
+
this.closeDragBackdrop();
|
|
163
|
+
this.dragContainer.dragEnded.emit({ item: this.item.origin });
|
|
164
|
+
});
|
|
165
|
+
dragRefs.push(dragRef);
|
|
166
|
+
});
|
|
167
|
+
return dragRefs;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private createLinkHandleDrags() {
|
|
171
|
+
const dragRefs = [];
|
|
172
|
+
const handles = this.barElement.querySelectorAll<HTMLElement>('.link-handles .handle');
|
|
173
|
+
handles.forEach((handle, index) => {
|
|
174
|
+
const isBefore = index === 0;
|
|
175
|
+
const dragRef = this.dragDrop.createDrag(handle);
|
|
176
|
+
dragRef.withBoundaryElement(this.dom.root as HTMLElement);
|
|
177
|
+
dragRef.beforeStarted.subscribe(() => {
|
|
178
|
+
handle.style.pointerEvents = 'none';
|
|
179
|
+
if (this.barDragRef) {
|
|
180
|
+
this.barDragRef.disabled = true;
|
|
181
|
+
}
|
|
182
|
+
this.createLinkDraggingLine();
|
|
183
|
+
this.dragContainer.emitLinkDragStarted(isBefore ? 'target' : 'source', this.item);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
dragRef.moved.subscribe(() => {
|
|
187
|
+
const positions = this.calcLinkLinePositions(handle, isBefore);
|
|
188
|
+
this.linkDraggingLine.setAttribute('x1', positions.x1.toString());
|
|
189
|
+
this.linkDraggingLine.setAttribute('y1', positions.y1.toString());
|
|
190
|
+
this.linkDraggingLine.setAttribute('x2', positions.x2.toString());
|
|
191
|
+
this.linkDraggingLine.setAttribute('y2', positions.y2.toString());
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
dragRef.ended.subscribe((event) => {
|
|
195
|
+
event.source.reset();
|
|
196
|
+
handle.style.pointerEvents = '';
|
|
197
|
+
if (this.barDragRef) {
|
|
198
|
+
this.barDragRef.disabled = false;
|
|
199
|
+
}
|
|
200
|
+
this.barElement.classList.remove(activeClass);
|
|
201
|
+
this.destroyLinkDraggingLine();
|
|
202
|
+
this.dragContainer.emitLinkDragEnded();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
dragRefs.push(dragRef);
|
|
206
|
+
});
|
|
207
|
+
return dragRefs;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private openDragBackdrop(dragElement: HTMLElement, start: GanttDate, end: GanttDate) {
|
|
211
|
+
const dragMaskElement = this.dom.root.querySelector('.gantt-drag-mask') as HTMLElement;
|
|
212
|
+
const dragBackdropElement = this.dom.root.querySelector('.gantt-drag-backdrop') as HTMLElement;
|
|
213
|
+
const rootRect = this.dom.root.getBoundingClientRect();
|
|
214
|
+
const dragRect = dragElement.getBoundingClientRect();
|
|
215
|
+
const left = dragRect.left - rootRect.left - this.dom.side.clientWidth;
|
|
216
|
+
const width = dragRect.right - dragRect.left;
|
|
217
|
+
dragMaskElement.style.left = left + 'px';
|
|
218
|
+
dragMaskElement.style.width = width + 'px';
|
|
219
|
+
dragMaskElement.querySelector('.start').innerHTML = start.format('MM-dd');
|
|
220
|
+
dragMaskElement.querySelector('.end').innerHTML = end.format('MM-dd');
|
|
221
|
+
dragMaskElement.style.display = 'block';
|
|
222
|
+
dragBackdropElement.style.display = 'block';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
private closeDragBackdrop() {
|
|
226
|
+
const dragMaskElement = this.dom.root.querySelector('.gantt-drag-mask') as HTMLElement;
|
|
227
|
+
const dragBackdropElement = this.dom.root.querySelector('.gantt-drag-backdrop') as HTMLElement;
|
|
228
|
+
dragMaskElement.style.display = 'none';
|
|
229
|
+
dragBackdropElement.style.display = 'none';
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private setDraggingStyles() {
|
|
233
|
+
this.barElement.style.pointerEvents = 'none';
|
|
234
|
+
this.barElement.classList.add('gantt-bar-draggable-drag');
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
private clearDraggingStyles() {
|
|
238
|
+
this.barElement.style.pointerEvents = '';
|
|
239
|
+
this.barElement.classList.remove('gantt-bar-draggable-drag');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private calcLinkLinePositions(target: HTMLElement, isBefore: boolean) {
|
|
243
|
+
const rootRect = this.dom.root.getBoundingClientRect();
|
|
244
|
+
const targetRect = target.getBoundingClientRect();
|
|
245
|
+
const layerRect = target.parentElement.parentElement.getBoundingClientRect();
|
|
246
|
+
return {
|
|
247
|
+
x1: layerRect.left + (isBefore ? 0 : layerRect.width) - rootRect.left,
|
|
248
|
+
y1: layerRect.top + layerRect.height / 2 - rootRect.top,
|
|
249
|
+
x2: targetRect.left - rootRect.left + targetRect.width / 2,
|
|
250
|
+
y2: targetRect.top - rootRect.top + targetRect.height / 2
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
private createLinkDraggingLine() {
|
|
255
|
+
if (!this.linkDraggingLine) {
|
|
256
|
+
const svgElement = createSvgElement('svg', 'gantt-link-drag-container');
|
|
257
|
+
const linElement = createSvgElement('line', 'link-dragging-line');
|
|
258
|
+
svgElement.appendChild(linElement);
|
|
259
|
+
this.dom.root.appendChild(svgElement);
|
|
260
|
+
this.linkDraggingLine = linElement;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private destroyLinkDraggingLine() {
|
|
265
|
+
if (this.linkDraggingLine) {
|
|
266
|
+
this.linkDraggingLine.parentElement.remove();
|
|
267
|
+
this.linkDraggingLine = null;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
createDrags(elementRef: ElementRef, item: GanttItemInternal, ganttUpper: GanttUpper) {
|
|
272
|
+
this.item = item;
|
|
273
|
+
this.barElement = elementRef.nativeElement;
|
|
274
|
+
this.ganttUpper = ganttUpper;
|
|
275
|
+
|
|
276
|
+
if (!item.draggable || (this.dragDisabled && this.linkDragDisabled)) {
|
|
277
|
+
return;
|
|
278
|
+
} else {
|
|
279
|
+
this.createMouseEvents();
|
|
280
|
+
if (!this.dragDisabled) {
|
|
281
|
+
const dragRef = this.createBarDrag();
|
|
282
|
+
const dragHandlesRefs = this.createBarHandleDrags();
|
|
283
|
+
this.dragRefs.push(dragRef, ...dragHandlesRefs);
|
|
284
|
+
}
|
|
285
|
+
if (!this.linkDragDisabled) {
|
|
286
|
+
const linkDragRefs = this.createLinkHandleDrags();
|
|
287
|
+
this.dragRefs.push(...linkDragRefs);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
ngOnDestroy() {
|
|
293
|
+
this.closeDragBackdrop();
|
|
294
|
+
this.dragRefs.forEach((dragRef) => dragRef.dispose());
|
|
295
|
+
this.destroy$.next();
|
|
296
|
+
this.destroy$.complete();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<div class="gantt-bar-layer">
|
|
2
|
+
<div *ngIf="item.draggable && ganttUpper.draggable" class="drag-handles">
|
|
3
|
+
<ng-container>
|
|
4
|
+
<span class="handle" (mousedown)="stopPropagation($event)"></span>
|
|
5
|
+
<span class="handle" (mousedown)="stopPropagation($event)"></span>
|
|
6
|
+
</ng-container>
|
|
7
|
+
</div>
|
|
8
|
+
<div *ngIf="item.linkable && ganttUpper.linkable" class="link-handles">
|
|
9
|
+
<span class="handle"><span class="point"></span></span>
|
|
10
|
+
<span class="handle"> <span class="point"></span></span>
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
<div class="gantt-bar-border"></div>
|
|
14
|
+
<div #content class="gantt-bar-content" (click)="onBarClick($event)">
|
|
15
|
+
<div class="gantt-bar-content-progress" *ngIf="item.progress >= 0" [style.width.%]="item.progress * 100"></div>
|
|
16
|
+
<ng-template [ngTemplateOutlet]="template" [ngTemplateOutletContext]="{ item: item.origin, refs: item.refs }"></ng-template>
|
|
17
|
+
</div>
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
$gantt-bar-layer-append-width: 32px;
|
|
2
|
+
$gantt-bar-layer-append-height: 42px;
|
|
3
|
+
$gantt-bar-link-height: 16px;
|
|
4
|
+
$gantt-bar-link-drop-border: 5px;
|
|
5
|
+
|
|
6
|
+
@mixin link-handles {
|
|
7
|
+
.link-handles {
|
|
8
|
+
.handle {
|
|
9
|
+
position: absolute;
|
|
10
|
+
display: inline-block;
|
|
11
|
+
cursor: pointer;
|
|
12
|
+
width: $gantt-bar-link-height;
|
|
13
|
+
height: $gantt-bar-link-height;
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: center;
|
|
17
|
+
z-index: 1001;
|
|
18
|
+
|
|
19
|
+
&:first-child {
|
|
20
|
+
left: 0;
|
|
21
|
+
top: 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&:last-child {
|
|
25
|
+
right: 0;
|
|
26
|
+
bottom: 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.point {
|
|
30
|
+
color: #348fe4;
|
|
31
|
+
width: 10px;
|
|
32
|
+
height: 10px;
|
|
33
|
+
border-radius: 50%;
|
|
34
|
+
background: #348fe4;
|
|
35
|
+
transition: 0.3 ease;
|
|
36
|
+
|
|
37
|
+
&:hover {
|
|
38
|
+
width: 12px;
|
|
39
|
+
height: 12px;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@mixin drag-handles {
|
|
47
|
+
.drag-handles {
|
|
48
|
+
background: $gantt-bar-layer-bg;
|
|
49
|
+
width: 100%;
|
|
50
|
+
height: calc(100% - #{$gantt-bar-link-height} * 2);
|
|
51
|
+
position: absolute;
|
|
52
|
+
border-radius: 4px;
|
|
53
|
+
top: $gantt-bar-link-height;
|
|
54
|
+
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.15);
|
|
55
|
+
|
|
56
|
+
.handle {
|
|
57
|
+
width: 15px;
|
|
58
|
+
height: 100%;
|
|
59
|
+
position: absolute;
|
|
60
|
+
cursor: col-resize;
|
|
61
|
+
display: flex;
|
|
62
|
+
align-items: center;
|
|
63
|
+
justify-content: center;
|
|
64
|
+
|
|
65
|
+
&:before,
|
|
66
|
+
&:after {
|
|
67
|
+
content: '';
|
|
68
|
+
display: inline-block;
|
|
69
|
+
width: 1px;
|
|
70
|
+
height: $gantt-bar-handle-height;
|
|
71
|
+
background: $gantt-bar-handle-color;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&::before {
|
|
75
|
+
margin-right: 2px;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
&:first-child {
|
|
79
|
+
left: 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
&:last-child {
|
|
83
|
+
right: 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@mixin active-bar {
|
|
90
|
+
z-index: 1000;
|
|
91
|
+
|
|
92
|
+
.gantt-bar-layer {
|
|
93
|
+
display: block;
|
|
94
|
+
z-index: 1;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.gantt-bar-content {
|
|
98
|
+
z-index: 1;
|
|
99
|
+
box-shadow: none;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.cdk-drag {
|
|
103
|
+
transition: none;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.gantt-bar {
|
|
108
|
+
position: absolute;
|
|
109
|
+
border-radius: 4px;
|
|
110
|
+
z-index: 2;
|
|
111
|
+
background: $gantt-bar-bg;
|
|
112
|
+
|
|
113
|
+
.gantt-bar-layer {
|
|
114
|
+
width: calc(100% + #{$gantt-bar-layer-append-width});
|
|
115
|
+
height: calc(100% + #{$gantt-bar-layer-append-height});
|
|
116
|
+
position: absolute;
|
|
117
|
+
border-radius: 4px;
|
|
118
|
+
left: $gantt-bar-layer-append-width / 2 * -1;
|
|
119
|
+
top: $gantt-bar-layer-append-height / 2 * -1;
|
|
120
|
+
display: none;
|
|
121
|
+
@include drag-handles();
|
|
122
|
+
@include link-handles();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.gantt-bar-border {
|
|
126
|
+
width: calc(100% + #{$gantt-bar-link-drop-border} * 2);
|
|
127
|
+
height: calc(100% + #{$gantt-bar-link-drop-border} * 2);
|
|
128
|
+
position: absolute;
|
|
129
|
+
border-radius: 4px;
|
|
130
|
+
left: $gantt-bar-link-drop-border * -1;
|
|
131
|
+
top: $gantt-bar-link-drop-border * -1;
|
|
132
|
+
display: none;
|
|
133
|
+
background: #fff;
|
|
134
|
+
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.gantt-bar-content {
|
|
138
|
+
width: 100%;
|
|
139
|
+
height: 100%;
|
|
140
|
+
position: absolute;
|
|
141
|
+
cursor: pointer;
|
|
142
|
+
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
|
|
143
|
+
border-radius: 4px;
|
|
144
|
+
background: $gantt-bar-background-color;
|
|
145
|
+
overflow: hidden;
|
|
146
|
+
box-sizing: border-box;
|
|
147
|
+
.gantt-bar-content-progress {
|
|
148
|
+
position: absolute;
|
|
149
|
+
left: 0;
|
|
150
|
+
top: 0;
|
|
151
|
+
height: 100%;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
&-active {
|
|
157
|
+
@include active-bar();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
&-link-drop {
|
|
161
|
+
.gantt-bar-border {
|
|
162
|
+
display: block;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.gantt-bar-content {
|
|
166
|
+
box-shadow: none;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|