@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.
Files changed (232) hide show
  1. package/.all-contributorsrc +53 -0
  2. package/.angulardoc.json +4 -0
  3. package/.circleci/config.yml +17 -0
  4. package/.coveralls.yml +1 -0
  5. package/.docgenirc.js +64 -0
  6. package/.editorconfig +22 -0
  7. package/.prettierrc +24 -0
  8. package/.travis.yml +23 -0
  9. package/CHANGELOG.md +564 -0
  10. package/Dockerfile +4 -0
  11. package/LICENSE +21 -0
  12. package/README.md +116 -13
  13. package/angular.json +136 -0
  14. package/docs/guides/basic/components.md +54 -0
  15. package/docs/guides/basic/event.md +70 -0
  16. package/docs/guides/basic/index.md +4 -0
  17. package/docs/guides/basic/style.md +68 -0
  18. package/docs/guides/basic/type.md +70 -0
  19. package/docs/guides/basic/usage.md +189 -0
  20. package/docs/guides/index.md +5 -0
  21. package/docs/guides/intro/getting-started.md +79 -0
  22. package/docs/guides/intro/index.md +51 -0
  23. package/docs/index.md +0 -0
  24. package/example/browserslist +12 -0
  25. package/example/src/app/app-routing.module.ts +26 -0
  26. package/example/src/app/app.component.html +2 -0
  27. package/example/src/app/app.component.ts +11 -0
  28. package/example/src/app/app.module.ts +57 -0
  29. package/example/src/app/components/components.component.html +6 -0
  30. package/example/src/app/components/components.component.ts +33 -0
  31. package/example/src/app/configuration/parameters/api/zh-cn.js +350 -0
  32. package/example/src/app/configuration/parameters/doc/zh-cn.md +5 -0
  33. package/example/src/app/gantt/gantt.component.html +51 -0
  34. package/example/src/app/gantt/gantt.component.ts +119 -0
  35. package/example/src/app/gantt-advanced/component/flat.component.html +30 -0
  36. package/example/src/app/gantt-advanced/component/flat.component.ts +72 -0
  37. package/example/src/app/gantt-advanced/component/flat.scss +31 -0
  38. package/example/src/app/gantt-advanced/gantt-advanced.component.html +32 -0
  39. package/example/src/app/gantt-advanced/gantt-advanced.component.ts +34 -0
  40. package/example/src/app/gantt-advanced/mocks.ts +158 -0
  41. package/example/src/app/gantt-groups/gantt-groups.component.html +42 -0
  42. package/example/src/app/gantt-groups/gantt-groups.component.ts +62 -0
  43. package/example/src/app/gantt-range/gantt-range.component.html +66 -0
  44. package/example/src/app/gantt-range/gantt-range.component.ts +67 -0
  45. package/example/src/app/gantt-range/mocks.ts +150 -0
  46. package/example/src/app/helper.ts +38 -0
  47. package/example/src/assets/.gitkeep +0 -0
  48. package/example/src/environments/environment.prod.ts +3 -0
  49. package/example/src/environments/environment.ts +16 -0
  50. package/example/src/favicon.ico +0 -0
  51. package/example/src/index.html +13 -0
  52. package/example/src/main.ts +12 -0
  53. package/example/src/polyfills.ts +63 -0
  54. package/example/src/styles.scss +56 -0
  55. package/example/tsconfig.app.json +18 -0
  56. package/nginx.conf +17 -0
  57. package/package.json +113 -17
  58. package/packages/gantt/README.md +24 -0
  59. package/packages/gantt/karma.conf.js +46 -0
  60. package/packages/gantt/ng-package.json +7 -0
  61. package/packages/gantt/ng-package.prod.json +7 -0
  62. package/packages/gantt/package.json +16 -0
  63. package/packages/gantt/src/class/date-point.ts +14 -0
  64. package/{class/event.d.ts → packages/gantt/src/class/event.ts} +12 -6
  65. package/packages/gantt/src/class/group.ts +36 -0
  66. package/{class/index.d.ts → packages/gantt/src/class/index.ts} +0 -0
  67. package/packages/gantt/src/class/item.ts +129 -0
  68. package/packages/gantt/src/class/test/group.spec.ts +21 -0
  69. package/packages/gantt/src/class/test/item.spec.ts +102 -0
  70. package/packages/gantt/src/class/view-type.ts +7 -0
  71. package/packages/gantt/src/components/bar/bar-drag.ts +298 -0
  72. package/packages/gantt/src/components/bar/bar.component.html +17 -0
  73. package/packages/gantt/src/components/bar/bar.component.scss +169 -0
  74. package/packages/gantt/src/components/bar/bar.component.ts +109 -0
  75. package/packages/gantt/src/components/bar/test/bar.component.spec.ts +54 -0
  76. package/packages/gantt/src/components/bar/test/bar.drag.spec.ts +196 -0
  77. package/packages/gantt/src/components/calendar/calendar.component.html +52 -0
  78. package/packages/gantt/src/components/calendar/calendar.component.scss +77 -0
  79. package/packages/gantt/src/components/calendar/calendar.component.ts +100 -0
  80. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.html +6 -0
  81. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.scss +48 -0
  82. package/packages/gantt/src/components/drag-backdrop/drag-backdrop.component.ts +13 -0
  83. package/packages/gantt/src/components/icon/icon.component.scss +13 -0
  84. package/packages/gantt/src/components/icon/icon.component.ts +28 -0
  85. package/packages/gantt/src/components/icon/icons.ts +86 -0
  86. package/packages/gantt/src/components/links/links.component.html +19 -0
  87. package/packages/gantt/src/components/links/links.component.scss +27 -0
  88. package/packages/gantt/src/components/links/links.component.ts +263 -0
  89. package/packages/gantt/src/components/main/gantt-main.component.html +35 -0
  90. package/packages/gantt/src/components/main/gantt-main.component.ts +35 -0
  91. package/packages/gantt/src/components/range/range.component.html +8 -0
  92. package/packages/gantt/src/components/range/range.component.scss +35 -0
  93. package/packages/gantt/src/components/range/range.component.ts +27 -0
  94. package/packages/gantt/src/components/range/test/range.component.spec.ts +80 -0
  95. package/packages/gantt/src/components/table/gantt-table.component.html +105 -0
  96. package/packages/gantt/src/components/table/gantt-table.component.scss +144 -0
  97. package/packages/gantt/src/components/table/gantt-table.component.ts +166 -0
  98. package/packages/gantt/src/components/table/test/table.spec.ts +129 -0
  99. package/packages/gantt/src/gantt-abstract.ts +14 -0
  100. package/packages/gantt/src/gantt-dom.service.ts +134 -0
  101. package/packages/gantt/src/gantt-drag-container.ts +73 -0
  102. package/packages/gantt/src/gantt-item-upper.ts +50 -0
  103. package/packages/gantt/src/gantt-print.service.ts +104 -0
  104. package/packages/gantt/src/gantt-upper.ts +289 -0
  105. package/packages/gantt/src/gantt.component.html +18 -0
  106. package/packages/gantt/src/gantt.component.scss +77 -0
  107. package/packages/gantt/src/gantt.component.ts +134 -0
  108. package/packages/gantt/src/gantt.module.ts +47 -0
  109. package/packages/gantt/src/gantt.pipe.ts +31 -0
  110. package/packages/gantt/src/gantt.styles.ts +28 -0
  111. package/{public-api.d.ts → packages/gantt/src/public-api.ts} +6 -0
  112. package/packages/gantt/src/root.component.html +12 -0
  113. package/packages/gantt/src/root.component.ts +121 -0
  114. package/packages/gantt/src/styles/index.scss +9 -0
  115. package/packages/gantt/src/styles/variables.scss +46 -0
  116. package/packages/gantt/src/table/gantt-column.component.ts +25 -0
  117. package/packages/gantt/src/table/gantt-table.component.ts +14 -0
  118. package/packages/gantt/src/table/test/table.spec.ts +56 -0
  119. package/packages/gantt/src/test/gantt.component.spec.ts +404 -0
  120. package/packages/gantt/src/test/mocks/data.ts +303 -0
  121. package/packages/gantt/src/test.ts +21 -0
  122. package/packages/gantt/src/utils/date.ts +276 -0
  123. package/packages/gantt/src/utils/helpers.ts +66 -0
  124. package/packages/gantt/src/utils/test/date.spec.ts +105 -0
  125. package/packages/gantt/src/utils/test/helpers.spec.ts +73 -0
  126. package/packages/gantt/src/utils/testing.ts +64 -0
  127. package/packages/gantt/src/views/day.ts +74 -0
  128. package/packages/gantt/src/views/factory.ts +25 -0
  129. package/packages/gantt/src/views/month.ts +66 -0
  130. package/packages/gantt/src/views/quarter.ts +68 -0
  131. package/packages/gantt/src/views/test/day.spec.ts +45 -0
  132. package/packages/gantt/src/views/test/factory.spec.ts +41 -0
  133. package/packages/gantt/src/views/test/mock.ts +14 -0
  134. package/packages/gantt/src/views/test/month.spec.ts +45 -0
  135. package/packages/gantt/src/views/test/quarter.spec.ts +45 -0
  136. package/packages/gantt/src/views/test/view.spec.ts +144 -0
  137. package/packages/gantt/src/views/test/week.spec.ts +45 -0
  138. package/packages/gantt/src/views/test/year.spec.ts +45 -0
  139. package/packages/gantt/src/views/view.ts +186 -0
  140. package/packages/gantt/src/views/week.ts +66 -0
  141. package/packages/gantt/src/views/year.ts +62 -0
  142. package/packages/gantt/tsconfig.lib.json +20 -0
  143. package/packages/gantt/tsconfig.lib.prod.json +9 -0
  144. package/packages/gantt/tsconfig.schematics.json +25 -0
  145. package/packages/gantt/tsconfig.spec.json +17 -0
  146. package/packages/gantt/tslint.json +18 -0
  147. package/scss-bundle.config.json +7 -0
  148. package/tsconfig.json +26 -0
  149. package/tslint.json +51 -0
  150. package/bundles/worktile-gantt.umd.js +0 -3129
  151. package/bundles/worktile-gantt.umd.js.map +0 -1
  152. package/bundles/worktile-gantt.umd.min.js +0 -16
  153. package/bundles/worktile-gantt.umd.min.js.map +0 -1
  154. package/class/date-point.d.ts +0 -15
  155. package/class/group.d.ts +0 -22
  156. package/class/item.d.ts +0 -70
  157. package/class/view-type.d.ts +0 -7
  158. package/components/bar/bar-drag.d.ts +0 -34
  159. package/components/bar/bar.component.d.ts +0 -23
  160. package/components/calendar/calendar.component.d.ts +0 -25
  161. package/components/drag-backdrop/drag-backdrop.component.d.ts +0 -6
  162. package/components/icon/icon.component.d.ts +0 -10
  163. package/components/icon/icons.d.ts +0 -8
  164. package/components/links/links.component.d.ts +0 -44
  165. package/components/main/gantt-main.component.d.ts +0 -18
  166. package/components/range/range.component.d.ts +0 -10
  167. package/components/table/gantt-table.component.d.ts +0 -31
  168. package/esm2015/class/date-point.js +0 -10
  169. package/esm2015/class/event.js +0 -13
  170. package/esm2015/class/group.js +0 -17
  171. package/esm2015/class/index.js +0 -6
  172. package/esm2015/class/item.js +0 -78
  173. package/esm2015/class/view-type.js +0 -9
  174. package/esm2015/components/bar/bar-drag.js +0 -266
  175. package/esm2015/components/bar/bar.component.js +0 -91
  176. package/esm2015/components/calendar/calendar.component.js +0 -82
  177. package/esm2015/components/drag-backdrop/drag-backdrop.component.js +0 -18
  178. package/esm2015/components/icon/icon.component.js +0 -36
  179. package/esm2015/components/icon/icons.js +0 -87
  180. package/esm2015/components/links/links.component.js +0 -207
  181. package/esm2015/components/main/gantt-main.component.js +0 -35
  182. package/esm2015/components/range/range.component.js +0 -32
  183. package/esm2015/components/table/gantt-table.component.js +0 -128
  184. package/esm2015/gantt-dom.service.js +0 -101
  185. package/esm2015/gantt-drag-container.js +0 -57
  186. package/esm2015/gantt-item-upper.js +0 -55
  187. package/esm2015/gantt-print.service.js +0 -92
  188. package/esm2015/gantt-upper.js +0 -231
  189. package/esm2015/gantt.component.js +0 -105
  190. package/esm2015/gantt.module.js +0 -43
  191. package/esm2015/gantt.pipe.js +0 -33
  192. package/esm2015/gantt.styles.js +0 -15
  193. package/esm2015/public-api.js +0 -16
  194. package/esm2015/root.component.js +0 -111
  195. package/esm2015/table/gantt-column.component.js +0 -28
  196. package/esm2015/table/gantt-table.component.js +0 -18
  197. package/esm2015/utils/date.js +0 -160
  198. package/esm2015/utils/helpers.js +0 -45
  199. package/esm2015/views/day.js +0 -54
  200. package/esm2015/views/factory.js +0 -23
  201. package/esm2015/views/month.js +0 -48
  202. package/esm2015/views/quarter.js +0 -51
  203. package/esm2015/views/view.js +0 -121
  204. package/esm2015/views/week.js +0 -49
  205. package/esm2015/views/year.js +0 -50
  206. package/esm2015/worktile-gantt.js +0 -16
  207. package/fesm2015/worktile-gantt.js +0 -2491
  208. package/fesm2015/worktile-gantt.js.map +0 -1
  209. package/gantt-dom.service.d.ts +0 -29
  210. package/gantt-drag-container.d.ts +0 -20
  211. package/gantt-item-upper.d.ts +0 -17
  212. package/gantt-print.service.d.ts +0 -10
  213. package/gantt-upper.d.ts +0 -62
  214. package/gantt.component.d.ts +0 -28
  215. package/gantt.module.d.ts +0 -2
  216. package/gantt.pipe.d.ts +0 -11
  217. package/gantt.styles.d.ts +0 -15
  218. package/root.component.d.ts +0 -25
  219. package/style.scss +0 -645
  220. package/table/gantt-column.component.d.ts +0 -12
  221. package/table/gantt-table.component.d.ts +0 -7
  222. package/utils/date.d.ts +0 -59
  223. package/utils/helpers.d.ts +0 -11
  224. package/views/day.d.ts +0 -14
  225. package/views/factory.d.ts +0 -8
  226. package/views/month.d.ts +0 -12
  227. package/views/quarter.d.ts +0 -12
  228. package/views/view.d.ts +0 -56
  229. package/views/week.d.ts +0 -12
  230. package/views/year.d.ts +0 -12
  231. package/worktile-gantt.d.ts +0 -15
  232. package/worktile-gantt.metadata.json +0 -1
@@ -0,0 +1,109 @@
1
+ import {
2
+ Component,
3
+ OnInit,
4
+ Input,
5
+ TemplateRef,
6
+ HostBinding,
7
+ ElementRef,
8
+ OnChanges,
9
+ OnDestroy,
10
+ Inject,
11
+ ViewChild,
12
+ Output,
13
+ EventEmitter,
14
+ AfterViewInit
15
+ } from '@angular/core';
16
+ import { takeUntil } from 'rxjs/operators';
17
+ import { GanttBarDrag } from './bar-drag';
18
+ import { hexToRgb } from '../../utils/helpers';
19
+ import { GanttDragContainer } from '../../gantt-drag-container';
20
+ import { barBackground } from '../../gantt.styles';
21
+ import { GanttBarClickEvent } from '../../class';
22
+ import { GANTT_UPPER_TOKEN, GanttUpper } from '../../gantt-upper';
23
+ import { GanttItemUpper } from '../../gantt-item-upper';
24
+
25
+ function linearGradient(sideOrCorner: string, color: string, stop: string) {
26
+ return `linear-gradient(${sideOrCorner},${color} 0%,${stop} 40%)`;
27
+ }
28
+
29
+ @Component({
30
+ selector: 'ngx-gantt-bar,gantt-bar',
31
+ templateUrl: './bar.component.html',
32
+ providers: [GanttBarDrag]
33
+ })
34
+ export class NgxGanttBarComponent extends GanttItemUpper implements OnInit, AfterViewInit, OnChanges, OnDestroy {
35
+ @Output() barClick = new EventEmitter<GanttBarClickEvent>();
36
+
37
+ @ViewChild('content') contentElementRef: ElementRef<HTMLDivElement>;
38
+
39
+ @HostBinding('class.gantt-bar') ganttItemClass = true;
40
+
41
+ color = 'red';
42
+
43
+ constructor(
44
+ private dragContainer: GanttDragContainer,
45
+ private drag: GanttBarDrag,
46
+ elementRef: ElementRef<HTMLDivElement>,
47
+ @Inject(GANTT_UPPER_TOKEN) public ganttUpper: GanttUpper
48
+ ) {
49
+ super(elementRef, ganttUpper);
50
+ }
51
+
52
+ ngOnInit() {
53
+ super.onInit();
54
+ this.dragContainer.dragEnded.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
55
+ this.setContentBackground();
56
+ });
57
+ }
58
+
59
+ ngAfterViewInit() {
60
+ this.drag.createDrags(this.elementRef, this.item, this.ganttUpper);
61
+ this.setContentBackground();
62
+ }
63
+
64
+ ngOnChanges(): void {
65
+ super.onChanges();
66
+ }
67
+
68
+ onBarClick(event: Event) {
69
+ this.barClick.emit({ event, item: this.item.origin });
70
+ }
71
+
72
+ private setContentBackground() {
73
+ const contentElement = this.contentElementRef.nativeElement;
74
+ const color = this.item.color || barBackground;
75
+ const style: Partial<CSSStyleDeclaration> = this.item.barStyle || {};
76
+ if (this.item.origin.start && this.item.origin.end) {
77
+ style.background = color;
78
+ style.borderRadius = '';
79
+ }
80
+ if (this.item.origin.start && !this.item.origin.end) {
81
+ style.background = linearGradient('to left', hexToRgb(color, 0.55), hexToRgb(color, 1));
82
+ style.borderRadius = '4px 12.5px 12.5px 4px';
83
+ }
84
+ if (!this.item.origin.start && this.item.origin.end) {
85
+ style.background = linearGradient('to right', hexToRgb(color, 0.55), hexToRgb(color, 1));
86
+ style.borderRadius = '12.5px 4px 4px 12.5px';
87
+ }
88
+ if (this.item.progress >= 0) {
89
+ const contentProgressElement = contentElement.querySelector('.gantt-bar-content-progress') as HTMLDivElement;
90
+ style.background = hexToRgb(color, 0.3);
91
+ style.borderRadius = '';
92
+ contentProgressElement.style.background = color;
93
+ }
94
+
95
+ for (const key in style) {
96
+ if (style.hasOwnProperty(key)) {
97
+ contentElement.style[key] = style[key];
98
+ }
99
+ }
100
+ }
101
+
102
+ stopPropagation(event: Event) {
103
+ event.stopPropagation();
104
+ }
105
+
106
+ ngOnDestroy() {
107
+ super.onDestroy();
108
+ }
109
+ }
@@ -0,0 +1,54 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { Component, DebugElement } from '@angular/core';
3
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
4
+ import { By } from '@angular/platform-browser';
5
+ import { NgxGanttComponent } from '../../../gantt.component';
6
+ import { NgxGanttModule } from '../../../gantt.module';
7
+ import { GanttDate } from '../../../utils/date';
8
+
9
+ const mockBarItems = [
10
+ {
11
+ id: 'item-0101',
12
+ title: 'VERSION 0101',
13
+ start: new GanttDate('2020-05-31 22:34:35').getUnixTime(),
14
+ end: new GanttDate('2020-06-05 08:53:20').getUnixTime(),
15
+ progress: 0.5
16
+ }
17
+ ];
18
+
19
+ @Component({
20
+ selector: 'test-gantt-bar',
21
+ template: ` <ngx-gantt #gantt [items]="items" [viewType]="viewType">
22
+ <ngx-gantt-table>
23
+ <ngx-gantt-column name="标题" width="200px">
24
+ <ng-template #cell let-item="item">
25
+ {{ item.title }}
26
+ </ng-template>
27
+ </ngx-gantt-column>
28
+ </ngx-gantt-table>
29
+ </ngx-gantt>`
30
+ })
31
+ export class TestGanttBarComponent {
32
+ constructor() {}
33
+
34
+ viewType = 'month';
35
+
36
+ items = mockBarItems;
37
+ }
38
+
39
+ describe('ngx-gantt-bar', () => {
40
+ let fixture: ComponentFixture<TestGanttBarComponent>;
41
+ beforeEach(async () => {
42
+ TestBed.configureTestingModule({
43
+ imports: [CommonModule, NgxGanttModule],
44
+ declarations: [TestGanttBarComponent]
45
+ }).compileComponents();
46
+ fixture = TestBed.createComponent(TestGanttBarComponent);
47
+ fixture.detectChanges();
48
+ });
49
+
50
+ it('should has bar progress', () => {
51
+ const barProgress = fixture.debugElement.queryAll(By.css('.gantt-bar-content-progress'));
52
+ expect(barProgress.length).toEqual(1);
53
+ });
54
+ });
@@ -0,0 +1,196 @@
1
+ import { CommonModule } from '@angular/common';
2
+ import { Component, DebugElement, Directive } from '@angular/core';
3
+ import { ComponentFixture, TestBed, fakeAsync, tick, flush } from '@angular/core/testing';
4
+ import { By } from '@angular/platform-browser';
5
+ import { GanttDragEvent, GanttLinkDragEvent } from '../../../class';
6
+ import { NgxGanttComponent } from '../../../gantt.component';
7
+ import { NgxGanttModule } from '../../../gantt.module';
8
+ import { NgxGanttRootComponent } from '../../../root.component';
9
+ import { GanttDate } from '../../../utils/date';
10
+ import { dispatchMouseEvent } from '../../../utils/testing';
11
+ import { NgxGanttBarComponent } from '../bar.component';
12
+
13
+ const activeClass = 'gantt-bar-active';
14
+
15
+ const mockBarItems = [
16
+ {
17
+ id: 'item-0101',
18
+ title: 'VERSION 0101',
19
+ start: new GanttDate('2020-03-31 22:34:35').getUnixTime(),
20
+ end: new GanttDate('2020-06-05 08:53:20').getUnixTime(),
21
+ color: '#FF0000'
22
+ },
23
+ {
24
+ id: 'item-0203',
25
+ title: 'VERSION 0203',
26
+ start: new GanttDate('2020-04-23 20:07:55').getUnixTime(),
27
+ end: new GanttDate('2020-06-23 00:00:00').getUnixTime(),
28
+ links: ['item-0204']
29
+ },
30
+ {
31
+ id: 'item-0204',
32
+ title: 'VERSION 0204',
33
+ start: new GanttDate('2020-06-02 02:21:15').getUnixTime(),
34
+ end: new GanttDate('2020-06-18 02:26:40').getUnixTime(),
35
+ links: ['item-0101']
36
+ }
37
+ ];
38
+
39
+ @Component({
40
+ selector: 'test-gantt-bar',
41
+ template: ` <ngx-gantt
42
+ #gantt
43
+ [items]="items"
44
+ [viewType]="viewType"
45
+ [draggable]="draggable"
46
+ [linkable]="linkable"
47
+ (dragEnded)="dragEnded($event)"
48
+ (dragStarted)="dragStarted($event)"
49
+ (linkDragEnded)="linkDragEnded($event)"
50
+ (linkDragStarted)="linkDragStarted($event)"
51
+ >
52
+ <ngx-gantt-table>
53
+ <ngx-gantt-column name="标题" width="200px">
54
+ <ng-template #cell let-item="item">
55
+ {{ item.title }}
56
+ </ng-template>
57
+ </ngx-gantt-column>
58
+ </ngx-gantt-table>
59
+ </ngx-gantt>`
60
+ })
61
+ export class TestGanttBarComponent {
62
+ constructor() {}
63
+
64
+ viewType = 'month';
65
+
66
+ items = mockBarItems;
67
+
68
+ draggable = true;
69
+
70
+ linkable = true;
71
+
72
+ dragEnded(event: GanttDragEvent) {
73
+ console.log(event);
74
+ }
75
+
76
+ dragStarted(event: GanttDragEvent) {
77
+ console.log(event);
78
+ }
79
+
80
+ linkDragEnded(event: GanttLinkDragEvent) {
81
+ console.log(event);
82
+ }
83
+
84
+ linkDragStarted(event: GanttLinkDragEvent) {
85
+ console.log(event);
86
+ }
87
+ }
88
+
89
+ function dragEvent(fixture: ComponentFixture<TestGanttBarComponent>, dragElement: HTMLElement, barElement?: HTMLElement) {
90
+ const dragMaskElement = fixture.debugElement.query(By.css('.gantt-drag-mask')).nativeElement;
91
+ const dragBackdropElement = fixture.debugElement.query(By.css('.gantt-drag-backdrop')).nativeElement;
92
+ const dragStartSpy = spyOn(fixture.componentInstance, 'dragStarted');
93
+ const dragEndSpy = spyOn(fixture.componentInstance, 'dragEnded');
94
+ barElement = barElement || dragElement;
95
+
96
+ dispatchMouseEvent(dragElement, 'mousedown');
97
+ fixture.detectChanges();
98
+
99
+ dispatchMouseEvent(document, 'mousemove', 50);
100
+ fixture.detectChanges();
101
+ expect(dragStartSpy).toHaveBeenCalledTimes(1);
102
+ expect(barElement.style.getPropertyValue('pointer-events')).toEqual('none');
103
+ expect(barElement.classList).toContain('gantt-bar-draggable-drag');
104
+
105
+ dispatchMouseEvent(document, 'mousemove', 200);
106
+ fixture.detectChanges();
107
+ expect(dragMaskElement.style.getPropertyValue('display')).toEqual('block');
108
+ expect(dragBackdropElement.style.getPropertyValue('display')).toEqual('block');
109
+
110
+ dispatchMouseEvent(document, 'mouseup', 200);
111
+ fixture.detectChanges();
112
+ expect(barElement.style.getPropertyValue('pointer-events')).toEqual('');
113
+ expect(barElement.classList).not.toContain('gantt-bar-draggable-drag');
114
+ expect(dragMaskElement.style.getPropertyValue('display')).toEqual('none');
115
+ expect(dragBackdropElement.style.getPropertyValue('display')).toEqual('none');
116
+ expect(dragEndSpy).toHaveBeenCalledTimes(1);
117
+ }
118
+
119
+ function linkDragEvent(fixture: ComponentFixture<TestGanttBarComponent>, dragElement: HTMLElement) {
120
+ const root = fixture.debugElement.query(By.directive(NgxGanttRootComponent));
121
+
122
+ dispatchMouseEvent(dragElement, 'mousedown');
123
+ fixture.detectChanges();
124
+
125
+ dispatchMouseEvent(document, 'mousemove', 10, 10);
126
+ fixture.detectChanges();
127
+
128
+ const ganttLinkDragContainer = root.nativeElement.querySelector('.gantt-link-drag-container');
129
+ const linkDraggingLine = root.nativeElement.querySelector('.link-dragging-line');
130
+ expect(ganttLinkDragContainer).toBeTruthy();
131
+ expect(linkDraggingLine).toBeTruthy();
132
+
133
+ dispatchMouseEvent(document, 'mousemove', 200, -30);
134
+ fixture.detectChanges();
135
+
136
+ dispatchMouseEvent(document, 'mouseup', 200, -30);
137
+ fixture.detectChanges();
138
+ }
139
+
140
+ describe('bar-drag', () => {
141
+ let fixture: ComponentFixture<TestGanttBarComponent>;
142
+ let ganttComponentInstance: TestGanttBarComponent;
143
+ let ganttDebugElement: DebugElement;
144
+
145
+ beforeEach(async () => {
146
+ TestBed.configureTestingModule({
147
+ imports: [CommonModule, NgxGanttModule],
148
+ declarations: [TestGanttBarComponent]
149
+ }).compileComponents();
150
+ fixture = TestBed.createComponent(TestGanttBarComponent);
151
+ ganttDebugElement = fixture.debugElement.query(By.directive(NgxGanttComponent));
152
+ ganttComponentInstance = fixture.componentInstance;
153
+ fixture.detectChanges();
154
+ });
155
+
156
+ it('should active when mouse enter bar', () => {
157
+ const barElement = fixture.debugElement.query(By.directive(NgxGanttBarComponent)).nativeElement;
158
+ dispatchMouseEvent(barElement, 'mouseenter');
159
+ expect(barElement.classList).toContain(activeClass);
160
+ dispatchMouseEvent(barElement, 'mouseleave');
161
+ expect(barElement.classList).not.toContain(activeClass);
162
+ });
163
+
164
+ it('should bar drag', () => {
165
+ const bar = fixture.debugElement.queryAll(By.directive(NgxGanttBarComponent))[0];
166
+ dragEvent(fixture, bar.nativeElement);
167
+ expect(bar.componentInstance.item.start.getUnixTime()).toEqual(new GanttDate('2020-04-21 00:00:00').getUnixTime());
168
+ expect(bar.componentInstance.item.end.getUnixTime()).toEqual(new GanttDate('2020-06-26 23:59:59').getUnixTime());
169
+ });
170
+
171
+ it('should first bar handle drag', () => {
172
+ const bar = fixture.debugElement.queryAll(By.directive(NgxGanttBarComponent))[1];
173
+ const firstHandleElement = bar.queryAll(By.css('.drag-handles .handle'))[0].nativeElement;
174
+ dragEvent(fixture, firstHandleElement, bar.nativeElement);
175
+ expect(bar.componentInstance.item.start.getUnixTime()).toEqual(new GanttDate('2020-05-14 00:00:00').getUnixTime());
176
+ });
177
+
178
+ it('should last bar handles drag', () => {
179
+ const bar = fixture.debugElement.queryAll(By.directive(NgxGanttBarComponent))[1];
180
+ const lastHandleElement = bar.queryAll(By.css('.drag-handles .handle'))[1].nativeElement;
181
+ dragEvent(fixture, lastHandleElement, bar.nativeElement);
182
+ expect(bar.componentInstance.item.end.getUnixTime()).toEqual(new GanttDate('2020-07-15 23:59:59').getUnixTime());
183
+ });
184
+
185
+ it('should first bar link handle drag', () => {
186
+ const bar = fixture.debugElement.queryAll(By.directive(NgxGanttBarComponent))[2];
187
+ const firstHandleElement = bar.queryAll(By.css('.link-handles .handle'))[0].nativeElement;
188
+ linkDragEvent(fixture, firstHandleElement);
189
+ });
190
+
191
+ it('should last bar link handles drag', () => {
192
+ const bar = fixture.debugElement.queryAll(By.directive(NgxGanttBarComponent))[2];
193
+ const lastHandleElement = bar.queryAll(By.css('.link-handles .handle'))[1].nativeElement;
194
+ linkDragEvent(fixture, lastHandleElement);
195
+ });
196
+ });
@@ -0,0 +1,52 @@
1
+ <div class="gantt-calendar-today-overlay" [style.width.px]="view.width">
2
+ <span class="today-rect" [hidden]="ganttUpper.viewType !== viewTypes.day"> </span>
3
+ <span class="today-line" *ngIf="ganttUpper.showTodayLine"> </span>
4
+ </div>
5
+
6
+ <svg class="gantt-calendar-overlay-main" [attr.width]="view.width" [attr.height]="headerHeight">
7
+ <g>
8
+ <text class="primary-text" *ngFor="let point of view.primaryDatePoints; trackBy: trackBy" [attr.x]="point.x" [attr.y]="point.y">
9
+ {{ point.text }}
10
+ </text>
11
+ <ng-container *ngFor="let point of view.secondaryDatePoints; trackBy: trackBy">
12
+ <text class="secondary-text" [class.secondary-text-weekend]="point.additions?.isWeekend" [attr.x]="point.x" [attr.y]="point.y">
13
+ {{ point.text }}
14
+ </text>
15
+ </ng-container>
16
+
17
+ <g>
18
+ <line
19
+ *ngFor="let point of view.primaryDatePoints; let i = index; trackBy: trackBy"
20
+ [attr.x1]="(i + 1) * view.primaryWidth"
21
+ [attr.x2]="(i + 1) * view.primaryWidth"
22
+ [attr.y1]="0"
23
+ [attr.y2]="mainHeight"
24
+ class="primary-line"
25
+ ></line>
26
+ </g>
27
+
28
+ <g>
29
+ <line [attr.x1]="0" [attr.x2]="view.width" [attr.y1]="headerHeight" [attr.y2]="headerHeight" class="header-line"></line>
30
+ </g>
31
+ </g>
32
+ <g>
33
+ <g *ngIf="view.showTimeline">
34
+ <line
35
+ *ngFor="let point of view.secondaryDatePoints; let i = index; trackBy: trackBy"
36
+ [attr.x1]="(i + 1) * view.cellWidth"
37
+ [attr.x2]="(i + 1) * view.cellWidth"
38
+ [attr.y1]="headerHeight"
39
+ [attr.y2]="mainHeight"
40
+ class="secondary-line"
41
+ ></line>
42
+ <line
43
+ *ngFor="let point of view.primaryDatePoints; let i = index; trackBy: trackBy"
44
+ [attr.x1]="(i + 1) * view.primaryWidth"
45
+ [attr.x2]="(i + 1) * view.primaryWidth"
46
+ [attr.y1]="0"
47
+ [attr.y2]="mainHeight"
48
+ class="primary-line"
49
+ ></line>
50
+ </g>
51
+ </g>
52
+ </svg>
@@ -0,0 +1,77 @@
1
+ .gantt-calendar-overlay {
2
+ display: block;
3
+ height: 100%;
4
+ overflow: hidden;
5
+
6
+ .gantt-calendar-today-overlay {
7
+ position: relative;
8
+ z-index: 2;
9
+ .today-rect {
10
+ width: 35px;
11
+ height: 24px;
12
+ position: absolute;
13
+ background: $gantt-date-today-color;
14
+ color: $gantt-date-today-text-color;
15
+ text-align: center;
16
+ border-radius: 4px;
17
+ }
18
+ .today-line {
19
+ position: absolute;
20
+ width: 3px;
21
+ background: $gantt-date-today-color;
22
+ transform: scaleX(0.5);
23
+ transform-origin: 100% 0;
24
+ margin-left: -2px;
25
+ }
26
+ }
27
+
28
+ .gantt-calendar-overlay-main {
29
+ position: relative;
30
+ z-index: 1;
31
+ background-color: $gantt-bg-color;
32
+ }
33
+
34
+ svg {
35
+ overflow: visible;
36
+ }
37
+
38
+ line {
39
+ shape-rendering: crispEdges;
40
+ }
41
+
42
+ .primary-text {
43
+ fill: $gantt-date-primary-color;
44
+ font-size: $gantt-date-primary-font-size;
45
+ }
46
+
47
+ .secondary-text {
48
+ fill: $gantt-date-secondary-color;
49
+ font-size: $gantt-date-secondary-font-size;
50
+
51
+ &-weekend {
52
+ fill: $gantt-date-secondary-weekend-color;
53
+ }
54
+ }
55
+
56
+ .primary-text,
57
+ .secondary-text {
58
+ text-anchor: middle;
59
+ }
60
+
61
+ .primary-line {
62
+ stroke: $gantt-date-primary-border;
63
+ }
64
+
65
+ .secondary-line {
66
+ stroke-dasharray: 2px 5px;
67
+ stroke: #cacaca;
68
+ }
69
+
70
+ .header-line {
71
+ stroke: $gantt-border-color;
72
+ }
73
+
74
+ .secondary-backdrop {
75
+ fill: $gantt-date-week-backdrop-bg;
76
+ }
77
+ }
@@ -0,0 +1,100 @@
1
+ import {
2
+ Component,
3
+ OnInit,
4
+ HostBinding,
5
+ OnChanges,
6
+ SimpleChanges,
7
+ OnDestroy,
8
+ NgZone,
9
+ Inject,
10
+ ElementRef,
11
+ AfterViewInit
12
+ } from '@angular/core';
13
+ import { GanttDatePoint } from '../../class/date-point';
14
+ import { Subject, merge } from 'rxjs';
15
+ import { take, takeUntil } from 'rxjs/operators';
16
+ import { headerHeight, todayHeight, todayWidth, todayBorderRadius } from '../../gantt.styles';
17
+ import { isNumber } from '../../utils/helpers';
18
+ import { GanttDate } from '../../utils/date';
19
+ import { GANTT_UPPER_TOKEN, GanttUpper } from '../../gantt-upper';
20
+ import { GanttViewType } from './../../class/view-type';
21
+
22
+ const mainHeight = 5000;
23
+
24
+ @Component({
25
+ selector: 'gantt-calendar-overlay',
26
+ templateUrl: './calendar.component.html'
27
+ })
28
+ export class GanttCalendarComponent implements OnInit, AfterViewInit, OnChanges, OnDestroy {
29
+ get view() {
30
+ return this.ganttUpper.view;
31
+ }
32
+
33
+ private unsubscribe$ = new Subject();
34
+
35
+ headerHeight = headerHeight;
36
+
37
+ mainHeight = mainHeight;
38
+
39
+ todayHeight = todayHeight;
40
+
41
+ todayWidth = todayWidth;
42
+
43
+ todayBorderRadius = todayBorderRadius;
44
+
45
+ viewTypes = GanttViewType;
46
+
47
+ @HostBinding('class.gantt-calendar-overlay') className = true;
48
+
49
+ constructor(
50
+ @Inject(GANTT_UPPER_TOKEN) public ganttUpper: GanttUpper,
51
+ private ngZone: NgZone,
52
+ private elementRef: ElementRef<HTMLElement>
53
+ ) {}
54
+
55
+ setTodayPoint() {
56
+ const x = this.view.getTodayXPoint();
57
+ const today = new GanttDate().getDate();
58
+ const todayEle = this.elementRef.nativeElement.getElementsByClassName('gantt-calendar-today-overlay')[0] as HTMLElement;
59
+ const rect = this.elementRef.nativeElement.getElementsByClassName('today-rect')[0] as HTMLElement;
60
+ const line = this.elementRef.nativeElement.getElementsByClassName('today-line')[0] as HTMLElement;
61
+
62
+ if (isNumber(x)) {
63
+ if (rect) {
64
+ rect.style.left = `${x - todayWidth / 2}px`;
65
+ rect.style.top = `${headerHeight - todayHeight}px`;
66
+ rect.innerHTML = today.toString();
67
+ }
68
+ if (line) {
69
+ line.style.left = `${x}px`;
70
+ line.style.top = `${headerHeight}px`;
71
+ line.style.bottom = `${-mainHeight}px`;
72
+ }
73
+ } else {
74
+ todayEle.style.display = 'none';
75
+ }
76
+ }
77
+
78
+ ngOnInit() {
79
+ this.ngZone.onStable.pipe(take(1)).subscribe(() => {
80
+ merge(this.ganttUpper.viewChange, this.ganttUpper.view.start$)
81
+ .pipe(takeUntil(this.unsubscribe$))
82
+ .subscribe(() => {
83
+ this.setTodayPoint();
84
+ });
85
+ });
86
+ }
87
+
88
+ ngAfterViewInit() {}
89
+
90
+ ngOnChanges(changes: SimpleChanges): void {}
91
+
92
+ trackBy(point: GanttDatePoint, index: number) {
93
+ return point.text || index;
94
+ }
95
+
96
+ ngOnDestroy() {
97
+ this.unsubscribe$.next();
98
+ this.unsubscribe$.complete();
99
+ }
100
+ }
@@ -0,0 +1,6 @@
1
+ <div class="gantt-drag-mask">
2
+ <div class="date-range">
3
+ <span class="start"></span>
4
+ <span class="end"></span>
5
+ </div>
6
+ </div>
@@ -0,0 +1,48 @@
1
+ .gantt-drag-backdrop {
2
+ position: absolute;
3
+ top: 0;
4
+ right: 0;
5
+ bottom: 0;
6
+ left: 0;
7
+ z-index: 2;
8
+ display: none;
9
+ }
10
+
11
+ .gantt-drag-mask {
12
+ position: absolute;
13
+ top: $gantt-header-height;
14
+ z-index: 1;
15
+ height: 100%;
16
+ display: none;
17
+ background: rgba($color: $gantt-item-drag-mask-color, $alpha: 0.05);
18
+
19
+ .date-range {
20
+ width: 100%;
21
+ min-width: 120px;
22
+ top: -23px;
23
+ background: $gantt-item-drag-mask-color;
24
+ line-height: 23px;
25
+ border-radius: 4px;
26
+ color: #fff;
27
+ position: absolute;
28
+ display: flex;
29
+ justify-content: space-between;
30
+ padding: 0 10px;
31
+ box-sizing: border-box
32
+ }
33
+ }
34
+
35
+ .gantt-link-drag-container {
36
+ width: 100%;
37
+ height: 1px;
38
+ overflow: visible !important;
39
+ position: absolute;
40
+ top: 0;
41
+ left: 0;
42
+ z-index: 2000;
43
+
44
+ .link-dragging-line {
45
+ stroke: $gantt-link-dragging-line-color;
46
+ stroke-width: 2px;
47
+ }
48
+ }
@@ -0,0 +1,13 @@
1
+ import { Component, OnInit, HostBinding } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'gantt-drag-backdrop',
5
+ templateUrl: `./drag-backdrop.component.html`
6
+ })
7
+ export class GanttDragBackdropComponent implements OnInit {
8
+ @HostBinding('class.gantt-drag-backdrop') backdropClass = true;
9
+
10
+ constructor() {}
11
+
12
+ ngOnInit() {}
13
+ }
@@ -0,0 +1,13 @@
1
+ .gantt-icon {
2
+ font-size: 1rem;
3
+ line-height: 0;
4
+
5
+ svg {
6
+ width: 1em;
7
+ height: 1em;
8
+ fill: currentColor;
9
+ vertical-align: -0.125em;
10
+ background-repeat: no-repeat;
11
+ }
12
+
13
+ }