@worktile/gantt 12.0.0 → 12.1.0

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 (63) hide show
  1. package/bundles/worktile-gantt.umd.js +1293 -1080
  2. package/bundles/worktile-gantt.umd.js.map +1 -1
  3. package/components/bar/bar-drag.d.ts +3 -0
  4. package/components/bar/bar.component.d.ts +3 -0
  5. package/components/calendar/calendar.component.d.ts +4 -1
  6. package/components/drag-backdrop/drag-backdrop.component.d.ts +3 -0
  7. package/components/icon/icon.component.d.ts +3 -0
  8. package/components/links/links.component.d.ts +3 -0
  9. package/components/main/gantt-main.component.d.ts +3 -0
  10. package/components/range/range.component.d.ts +3 -0
  11. package/components/table/gantt-table.component.d.ts +8 -3
  12. package/esm2015/components/bar/bar-drag.js +10 -12
  13. package/esm2015/components/bar/bar.component.js +29 -22
  14. package/esm2015/components/calendar/calendar.component.js +21 -17
  15. package/esm2015/components/drag-backdrop/drag-backdrop.component.js +14 -11
  16. package/esm2015/components/icon/icon.component.js +17 -15
  17. package/esm2015/components/links/links.component.js +28 -22
  18. package/esm2015/components/main/gantt-main.component.js +40 -22
  19. package/esm2015/components/range/range.component.js +21 -16
  20. package/esm2015/components/table/gantt-table.component.js +44 -23
  21. package/esm2015/gantt-abstract.js +3 -0
  22. package/esm2015/gantt-dom.service.js +7 -5
  23. package/esm2015/gantt-drag-container.js +7 -5
  24. package/esm2015/gantt-item-upper.js +17 -14
  25. package/esm2015/gantt-print.service.js +7 -5
  26. package/esm2015/gantt-upper.js +74 -44
  27. package/esm2015/gantt.component.js +66 -36
  28. package/esm2015/gantt.config.js +13 -0
  29. package/esm2015/gantt.module.js +67 -25
  30. package/esm2015/gantt.pipe.js +26 -16
  31. package/esm2015/public-api.js +4 -1
  32. package/esm2015/root.component.js +37 -25
  33. package/esm2015/table/gantt-column.component.js +26 -17
  34. package/esm2015/table/gantt-table.component.js +13 -11
  35. package/esm2015/utils/helpers.js +11 -1
  36. package/esm2015/views/day.js +2 -2
  37. package/esm2015/views/month.js +3 -3
  38. package/esm2015/views/quarter.js +3 -3
  39. package/esm2015/views/view.js +4 -2
  40. package/esm2015/views/week.js +3 -3
  41. package/esm2015/views/year.js +2 -2
  42. package/esm2015/worktile-gantt.js +1 -12
  43. package/fesm2015/worktile-gantt.js +1380 -1199
  44. package/fesm2015/worktile-gantt.js.map +1 -1
  45. package/gantt-abstract.d.ts +12 -0
  46. package/gantt-dom.service.d.ts +3 -0
  47. package/gantt-drag-container.d.ts +3 -0
  48. package/gantt-item-upper.d.ts +3 -0
  49. package/gantt-print.service.d.ts +3 -0
  50. package/gantt-upper.d.ts +6 -2
  51. package/gantt.component.d.ts +5 -3
  52. package/gantt.config.d.ts +23 -0
  53. package/gantt.module.d.ts +19 -0
  54. package/gantt.pipe.d.ts +7 -0
  55. package/package.json +1 -2
  56. package/public-api.d.ts +3 -0
  57. package/root.component.d.ts +3 -0
  58. package/table/gantt-column.component.d.ts +3 -0
  59. package/table/gantt-table.component.d.ts +3 -0
  60. package/utils/helpers.d.ts +2 -1
  61. package/views/view.d.ts +2 -0
  62. package/worktile-gantt.d.ts +1 -11
  63. package/worktile-gantt.metadata.json +0 -1
@@ -1,11 +1,14 @@
1
- import { EventEmitter, Directive, ElementRef, ChangeDetectorRef, NgZone, Input, Output, ContentChild, HostBinding, InjectionToken, Component, Inject, ChangeDetectionStrategy, ContentChildren, ViewChild, Injectable, Optional, Pipe, NgModule } from '@angular/core';
1
+ import * as i0 from '@angular/core';
2
+ import { InjectionToken, EventEmitter, Directive, Inject, Input, Output, ContentChild, HostBinding, Component, Pipe, ViewChild, Injectable, Optional, forwardRef, ChangeDetectionStrategy, ContentChildren, NgModule } from '@angular/core';
3
+ import * as i2 from '@angular/common';
2
4
  import { CommonModule } from '@angular/common';
3
- import { take, skip, takeUntil, startWith, finalize, map, pairwise, auditTime } from 'rxjs/operators';
5
+ import { take, skip, takeUntil, startWith, map, pairwise, auditTime, finalize } from 'rxjs/operators';
4
6
  import { BehaviorSubject, Subject, merge, fromEvent } from 'rxjs';
5
7
  import { fromUnixTime, getWeek, getDaysInMonth, differenceInCalendarDays, setDate, addSeconds, addMinutes, addHours, addDays, addWeeks, addMonths, addQuarters, addYears, startOfDay, startOfWeek, startOfMonth, startOfQuarter, startOfYear, endOfDay, endOfWeek, endOfMonth, endOfQuarter, endOfYear, getUnixTime, format, isWeekend, isToday, differenceInDays, differenceInCalendarQuarters, eachMonthOfInterval, eachYearOfInterval, eachWeekOfInterval, eachDayOfInterval, differenceInCalendarYears } from 'date-fns';
6
8
  export { addDays, addHours, addMinutes, addMonths, addQuarters, addSeconds, addWeeks, addYears, differenceInCalendarDays, differenceInCalendarQuarters, differenceInDays, eachDayOfInterval, eachMonthOfInterval, eachWeekOfInterval, endOfDay, endOfMonth, endOfQuarter, endOfWeek, endOfYear, format, fromUnixTime, getDaysInMonth, getUnixTime, getWeek, isToday, isWeekend, setDate, startOfDay, startOfMonth, startOfQuarter, startOfWeek, startOfYear } from 'date-fns';
7
9
  import { coerceCssPixelValue } from '@angular/cdk/coercion';
8
- import { DragDrop, DragDropModule } from '@angular/cdk/drag-drop';
10
+ import * as i1 from '@angular/cdk/drag-drop';
11
+ import { DragDropModule } from '@angular/cdk/drag-drop';
9
12
  import html2canvas from 'html2canvas';
10
13
 
11
14
  class GanttDatePoint {
@@ -290,11 +293,24 @@ class GanttGroupInternal {
290
293
  }
291
294
  }
292
295
 
296
+ const defaultConfig = {
297
+ dateFormat: {
298
+ week: '第w周',
299
+ month: 'M月',
300
+ quarter: 'QQQ',
301
+ year: 'yyyy年',
302
+ yearMonth: 'yyyy年MM月',
303
+ yearQuarter: 'yyyy年QQQ',
304
+ }
305
+ };
306
+ const GANTT_GLOBAL_CONFIG = new InjectionToken('GANTT_GLOBAL_CONFIG');
307
+
293
308
  const primaryDatePointTop = 18;
294
309
  const secondaryDatePointTop = 36;
295
310
  const viewOptions$5 = {
296
311
  min: new GanttDate().addYears(-1).startOfYear(),
297
- max: new GanttDate().addYears(1).endOfYear()
312
+ max: new GanttDate().addYears(1).endOfYear(),
313
+ dateFormat: defaultConfig.dateFormat
298
314
  };
299
315
  class GanttView {
300
316
  constructor(start, end, options) {
@@ -437,7 +453,7 @@ class GanttViewMonth extends GanttView {
437
453
  const points = [];
438
454
  for (let i = 0; i < quarters; i++) {
439
455
  const start = this.start.addQuarters(i);
440
- const point = new GanttDatePoint(start, start.format('yyyy年QQQ'), (this.getCellWidth() * 3) / 2 + i * (this.getCellWidth() * 3), primaryDatePointTop);
456
+ const point = new GanttDatePoint(start, start.format(this.options.dateFormat.yearQuarter), (this.getCellWidth() * 3) / 2 + i * (this.getCellWidth() * 3), primaryDatePointTop);
441
457
  points.push(point);
442
458
  }
443
459
  return points;
@@ -447,7 +463,7 @@ class GanttViewMonth extends GanttView {
447
463
  const points = [];
448
464
  for (let i = 0; i < months.length; i++) {
449
465
  const start = new GanttDate(months[i]);
450
- const point = new GanttDatePoint(start, `${start.getMonth() + 1}月`, i * this.getCellWidth() + this.getCellWidth() / 2, secondaryDatePointTop);
466
+ const point = new GanttDatePoint(start, start.format(this.options.dateFormat.month), i * this.getCellWidth() + this.getCellWidth() / 2, secondaryDatePointTop);
451
467
  points.push(point);
452
468
  }
453
469
  return points;
@@ -484,7 +500,7 @@ class GanttViewQuarter extends GanttView {
484
500
  const points = [];
485
501
  for (let i = 0; i < years.length; i++) {
486
502
  const start = new GanttDate(years[i]);
487
- const point = new GanttDatePoint(start, `${start.format('yyyy')}年`, (this.getCellWidth() * 4) / 2 + i * (this.getCellWidth() * 4), primaryDatePointTop);
503
+ const point = new GanttDatePoint(start, `${start.format(this.options.dateFormat.year)}`, (this.getCellWidth() * 4) / 2 + i * (this.getCellWidth() * 4), primaryDatePointTop);
488
504
  points.push(point);
489
505
  }
490
506
  return points;
@@ -494,7 +510,7 @@ class GanttViewQuarter extends GanttView {
494
510
  const points = [];
495
511
  for (let i = 0; i <= quarters; i++) {
496
512
  const start = this.start.addQuarters(i);
497
- const point = new GanttDatePoint(start, start.format('QQQ'), i * this.getCellWidth() + this.getCellWidth() / 2, secondaryDatePointTop);
513
+ const point = new GanttDatePoint(start, start.format(this.options.dateFormat.quarter), i * this.getCellWidth() + this.getCellWidth() / 2, secondaryDatePointTop);
498
514
  points.push(point);
499
515
  }
500
516
  return points;
@@ -532,7 +548,7 @@ class GanttViewDay extends GanttView {
532
548
  for (let i = 0; i < weeks.length; i++) {
533
549
  const weekStart = new GanttDate(weeks[i]);
534
550
  const increaseWeek = weekStart.getDaysInMonth() - weekStart.getDate() >= 3 ? 0 : 1;
535
- const point = new GanttDatePoint(weekStart, weekStart.addWeeks(increaseWeek).format('yyyy年MM月'), (this.getCellWidth() * 7) / 2 + i * (this.getCellWidth() * 7), primaryDatePointTop);
551
+ const point = new GanttDatePoint(weekStart, weekStart.addWeeks(increaseWeek).format(this.options.dateFormat.yearMonth), (this.getCellWidth() * 7) / 2 + i * (this.getCellWidth() * 7), primaryDatePointTop);
536
552
  points.push(point);
537
553
  }
538
554
  return points;
@@ -581,7 +597,7 @@ class GanttViewWeek extends GanttView {
581
597
  for (let i = 0; i < weeks.length; i++) {
582
598
  const weekStart = new GanttDate(weeks[i]);
583
599
  const increaseWeek = weekStart.getDaysInMonth() - weekStart.getDate() >= 3 ? 0 : 1;
584
- const point = new GanttDatePoint(weekStart, weekStart.addWeeks(increaseWeek).format('yyyy年'), this.getCellWidth() / 2 + i * this.getCellWidth(), primaryDatePointTop);
600
+ const point = new GanttDatePoint(weekStart, weekStart.addWeeks(increaseWeek).format(this.options.dateFormat.year), this.getCellWidth() / 2 + i * this.getCellWidth(), primaryDatePointTop);
585
601
  points.push(point);
586
602
  }
587
603
  return points;
@@ -591,7 +607,7 @@ class GanttViewWeek extends GanttView {
591
607
  const points = [];
592
608
  for (let i = 0; i < weeks.length; i++) {
593
609
  const start = new GanttDate(weeks[i]);
594
- const point = new GanttDatePoint(start, `第${start.format('w')}周`, i * this.getCellWidth() + this.getCellWidth() / 2, secondaryDatePointTop);
610
+ const point = new GanttDatePoint(start, `${start.format(this.options.dateFormat.week)}`, i * this.getCellWidth() + this.getCellWidth() / 2, secondaryDatePointTop);
595
611
  points.push(point);
596
612
  }
597
613
  return points;
@@ -637,7 +653,7 @@ class GanttViewYear extends GanttView {
637
653
  const pointTop = 27;
638
654
  for (let i = 0; i <= years; i++) {
639
655
  const start = this.start.addYears(i);
640
- const point = new GanttDatePoint(start, `${start.format('yyyy')}年`, i * this.getCellWidth() + this.getCellWidth() / 2, pointTop);
656
+ const point = new GanttDatePoint(start, `${start.format(this.options.dateFormat.year)}`, i * this.getCellWidth() + this.getCellWidth() / 2, pointTop);
641
657
  points.push(point);
642
658
  }
643
659
  return points;
@@ -720,16 +736,28 @@ function recursiveItems(items) {
720
736
  });
721
737
  return result;
722
738
  }
739
+ function getFlatItems(items) {
740
+ const result = [];
741
+ (items || []).forEach((item) => {
742
+ result.push(item);
743
+ if (item.children) {
744
+ result.push(...getFlatItems(item.children));
745
+ }
746
+ });
747
+ return result;
748
+ }
723
749
 
724
750
  class GanttUpper {
725
- constructor(elementRef, cdr, ngZone) {
751
+ constructor(elementRef, cdr, ngZone, config) {
726
752
  this.elementRef = elementRef;
727
753
  this.cdr = cdr;
728
754
  this.ngZone = ngZone;
755
+ this.config = config;
729
756
  this.originItems = [];
730
757
  this.originGroups = [];
731
758
  this.viewType = GanttViewType.month;
732
759
  this.showTodayLine = true;
760
+ this.viewOptions = {};
733
761
  this.loadOnScroll = new EventEmitter();
734
762
  this.dragStarted = new EventEmitter();
735
763
  this.dragEnded = new EventEmitter();
@@ -741,7 +769,6 @@ class GanttUpper {
741
769
  this.expandChange = new EventEmitter();
742
770
  this.firstChange = true;
743
771
  this.unsubscribe$ = new Subject();
744
- this.expandedItemIds = [];
745
772
  this.ganttClass = true;
746
773
  }
747
774
  get element() {
@@ -763,14 +790,8 @@ class GanttUpper {
763
790
  });
764
791
  }
765
792
  setupItems() {
766
- this.items = [];
767
793
  this.originItems = uniqBy(this.originItems, 'id');
768
- // 根据上一次数据展开状态同步新的数据展开状态
769
- this.originItems.forEach((item) => {
770
- if (!this.firstChange) {
771
- item.expanded = this.expandedItemIds.includes(item.id);
772
- }
773
- });
794
+ this.items = [];
774
795
  if (this.groups.length > 0) {
775
796
  this.originItems.forEach((origin) => {
776
797
  const group = this.groupsMap[origin.group_id];
@@ -788,17 +809,23 @@ class GanttUpper {
788
809
  }
789
810
  }
790
811
  setupExpandedState() {
812
+ this.originItems = uniqBy(this.originItems, 'id');
791
813
  let items = [];
814
+ const flatOriginItems = getFlatItems(this.originItems);
792
815
  if (this.items.length > 0) {
793
816
  items = recursiveItems(this.items);
794
817
  }
795
818
  else {
796
819
  items = flatten(this.groups.map((group) => recursiveItems(group.items)));
797
820
  }
798
- this.expandedItemIds = [];
799
821
  items.forEach((item) => {
800
822
  if (item.origin.expanded) {
801
- this.expandedItemIds.push(item.id);
823
+ const newItem = flatOriginItems.find((originItem) => originItem.id === item.id);
824
+ if (newItem) {
825
+ if (newItem.expanded === undefined) {
826
+ newItem.expanded = true;
827
+ }
828
+ }
802
829
  }
803
830
  });
804
831
  }
@@ -843,6 +870,7 @@ class GanttUpper {
843
870
  }
844
871
  onInit() {
845
872
  this.styles = Object.assign({}, defaultStyles, this.styles);
873
+ this.viewOptions.dateFormat = Object.assign({}, defaultConfig.dateFormat, this.config.dateFormat, this.viewOptions.dateFormat);
846
874
  this.createView();
847
875
  this.setupGroups();
848
876
  this.setupItems();
@@ -912,36 +940,62 @@ class GanttUpper {
912
940
  this.expandGroups(false);
913
941
  }
914
942
  }
915
- GanttUpper.decorators = [
916
- { type: Directive }
917
- ];
918
- GanttUpper.ctorParameters = () => [
919
- { type: ElementRef },
920
- { type: ChangeDetectorRef },
921
- { type: NgZone }
922
- ];
923
- GanttUpper.propDecorators = {
924
- originItems: [{ type: Input, args: ['items',] }],
925
- originGroups: [{ type: Input, args: ['groups',] }],
926
- viewType: [{ type: Input }],
927
- start: [{ type: Input }],
928
- end: [{ type: Input }],
929
- showTodayLine: [{ type: Input }],
930
- draggable: [{ type: Input }],
931
- styles: [{ type: Input }],
932
- viewOptions: [{ type: Input }],
933
- disabledLoadOnScroll: [{ type: Input }],
934
- loadOnScroll: [{ type: Output }],
935
- dragStarted: [{ type: Output }],
936
- dragEnded: [{ type: Output }],
937
- barClick: [{ type: Output }],
938
- barTemplate: [{ type: ContentChild, args: ['bar', { static: true },] }],
939
- rangeTemplate: [{ type: ContentChild, args: ['range', { static: true },] }],
940
- itemTemplate: [{ type: ContentChild, args: ['item', { static: true },] }],
941
- groupTemplate: [{ type: ContentChild, args: ['group', { static: true },] }],
942
- groupHeaderTemplate: [{ type: ContentChild, args: ['groupHeader', { static: true },] }],
943
- ganttClass: [{ type: HostBinding, args: ['class.gantt',] }]
944
- };
943
+ GanttUpper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttUpper, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: GANTT_GLOBAL_CONFIG }], target: i0.ɵɵFactoryTarget.Directive });
944
+ GanttUpper.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.1.2", type: GanttUpper, inputs: { originItems: ["items", "originItems"], originGroups: ["groups", "originGroups"], viewType: "viewType", start: "start", end: "end", showTodayLine: "showTodayLine", draggable: "draggable", styles: "styles", viewOptions: "viewOptions", disabledLoadOnScroll: "disabledLoadOnScroll" }, outputs: { loadOnScroll: "loadOnScroll", dragStarted: "dragStarted", dragEnded: "dragEnded", barClick: "barClick" }, host: { properties: { "class.gantt": "this.ganttClass" } }, queries: [{ propertyName: "barTemplate", first: true, predicate: ["bar"], descendants: true, static: true }, { propertyName: "rangeTemplate", first: true, predicate: ["range"], descendants: true, static: true }, { propertyName: "itemTemplate", first: true, predicate: ["item"], descendants: true, static: true }, { propertyName: "groupTemplate", first: true, predicate: ["group"], descendants: true, static: true }, { propertyName: "groupHeaderTemplate", first: true, predicate: ["groupHeader"], descendants: true, static: true }], ngImport: i0 });
945
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttUpper, decorators: [{
946
+ type: Directive
947
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: undefined, decorators: [{
948
+ type: Inject,
949
+ args: [GANTT_GLOBAL_CONFIG]
950
+ }] }]; }, propDecorators: { originItems: [{
951
+ type: Input,
952
+ args: ['items']
953
+ }], originGroups: [{
954
+ type: Input,
955
+ args: ['groups']
956
+ }], viewType: [{
957
+ type: Input
958
+ }], start: [{
959
+ type: Input
960
+ }], end: [{
961
+ type: Input
962
+ }], showTodayLine: [{
963
+ type: Input
964
+ }], draggable: [{
965
+ type: Input
966
+ }], styles: [{
967
+ type: Input
968
+ }], viewOptions: [{
969
+ type: Input
970
+ }], disabledLoadOnScroll: [{
971
+ type: Input
972
+ }], loadOnScroll: [{
973
+ type: Output
974
+ }], dragStarted: [{
975
+ type: Output
976
+ }], dragEnded: [{
977
+ type: Output
978
+ }], barClick: [{
979
+ type: Output
980
+ }], barTemplate: [{
981
+ type: ContentChild,
982
+ args: ['bar', { static: true }]
983
+ }], rangeTemplate: [{
984
+ type: ContentChild,
985
+ args: ['range', { static: true }]
986
+ }], itemTemplate: [{
987
+ type: ContentChild,
988
+ args: ['item', { static: true }]
989
+ }], groupTemplate: [{
990
+ type: ContentChild,
991
+ args: ['group', { static: true }]
992
+ }], groupHeaderTemplate: [{
993
+ type: ContentChild,
994
+ args: ['groupHeader', { static: true }]
995
+ }], ganttClass: [{
996
+ type: HostBinding,
997
+ args: ['class.gantt']
998
+ }] } });
945
999
  const GANTT_UPPER_TOKEN = new InjectionToken('GANTT_UPPER_TOKEN');
946
1000
 
947
1001
  class NgxGanttTableColumnComponent {
@@ -953,21 +1007,28 @@ class NgxGanttTableColumnComponent {
953
1007
  }
954
1008
  ngOnInit() { }
955
1009
  }
956
- NgxGanttTableColumnComponent.decorators = [
957
- { type: Component, args: [{
958
- selector: 'ngx-gantt-column',
959
- template: ''
960
- },] }
961
- ];
962
- NgxGanttTableColumnComponent.ctorParameters = () => [
963
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] }
964
- ];
965
- NgxGanttTableColumnComponent.propDecorators = {
966
- width: [{ type: Input }],
967
- name: [{ type: Input }],
968
- templateRef: [{ type: ContentChild, args: ['cell', { static: true },] }],
969
- headerTemplateRef: [{ type: ContentChild, args: ['header', { static: true },] }]
970
- };
1010
+ NgxGanttTableColumnComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttTableColumnComponent, deps: [{ token: GANTT_UPPER_TOKEN }], target: i0.ɵɵFactoryTarget.Component });
1011
+ NgxGanttTableColumnComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: NgxGanttTableColumnComponent, selector: "ngx-gantt-column", inputs: { width: "width", name: "name" }, queries: [{ propertyName: "templateRef", first: true, predicate: ["cell"], descendants: true, static: true }, { propertyName: "headerTemplateRef", first: true, predicate: ["header"], descendants: true, static: true }], ngImport: i0, template: '', isInline: true });
1012
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttTableColumnComponent, decorators: [{
1013
+ type: Component,
1014
+ args: [{
1015
+ selector: 'ngx-gantt-column',
1016
+ template: ''
1017
+ }]
1018
+ }], ctorParameters: function () { return [{ type: GanttUpper, decorators: [{
1019
+ type: Inject,
1020
+ args: [GANTT_UPPER_TOKEN]
1021
+ }] }]; }, propDecorators: { width: [{
1022
+ type: Input
1023
+ }], name: [{
1024
+ type: Input
1025
+ }], templateRef: [{
1026
+ type: ContentChild,
1027
+ args: ['cell', { static: true }]
1028
+ }], headerTemplateRef: [{
1029
+ type: ContentChild,
1030
+ args: ['header', { static: true }]
1031
+ }] } });
971
1032
 
972
1033
  class NgxGanttTableComponent {
973
1034
  constructor() {
@@ -975,188 +1036,184 @@ class NgxGanttTableComponent {
975
1036
  }
976
1037
  ngOnInit() { }
977
1038
  }
978
- NgxGanttTableComponent.decorators = [
979
- { type: Component, args: [{
980
- selector: 'ngx-gantt-table',
981
- template: ''
982
- },] }
983
- ];
984
- NgxGanttTableComponent.ctorParameters = () => [];
985
- NgxGanttTableComponent.propDecorators = {
986
- columnChanges: [{ type: Output }]
987
- };
1039
+ NgxGanttTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttTableComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1040
+ NgxGanttTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: NgxGanttTableComponent, selector: "ngx-gantt-table", outputs: { columnChanges: "columnChanges" }, ngImport: i0, template: '', isInline: true });
1041
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttTableComponent, decorators: [{
1042
+ type: Component,
1043
+ args: [{
1044
+ selector: 'ngx-gantt-table',
1045
+ template: ''
1046
+ }]
1047
+ }], ctorParameters: function () { return []; }, propDecorators: { columnChanges: [{
1048
+ type: Output
1049
+ }] } });
988
1050
 
989
- const defaultColumnWidth = 100;
990
- const minColumnWidth = 80;
991
- class NgxGanttComponent extends GanttUpper {
992
- constructor(elementRef, cdr, ngZone) {
993
- super(elementRef, cdr, ngZone);
994
- this.maxLevel = 2;
995
- this.linkDragStarted = new EventEmitter();
996
- this.linkDragEnded = new EventEmitter();
997
- this.lineClick = new EventEmitter();
998
- this.ngUnsubscribe$ = new Subject();
999
- this.sideTableWidth = sideWidth;
1000
- }
1001
- ngOnInit() {
1002
- super.onInit();
1003
- this.ngZone.onStable.pipe(take(1)).subscribe(() => {
1004
- this.dragContainer.linkDragStarted.pipe(takeUntil(this.ngUnsubscribe$)).subscribe((event) => {
1005
- this.linkDragStarted.emit(event);
1006
- });
1007
- this.dragContainer.linkDragEnded.pipe(takeUntil(this.ngUnsubscribe$)).subscribe((event) => {
1008
- this.linkDragEnded.emit(event);
1009
- });
1010
- });
1011
- }
1012
- ngAfterViewInit() {
1013
- this.columns.changes.pipe(startWith(true), takeUntil(this.ngUnsubscribe$)).subscribe(() => {
1014
- this.columns.forEach((column) => {
1015
- if (!column.columnWidth) {
1016
- column.columnWidth = coerceCssPixelValue(defaultColumnWidth);
1017
- }
1018
- });
1019
- this.cdr.detectChanges();
1020
- });
1021
- }
1022
- ngOnChanges(changes) {
1023
- super.onChanges(changes);
1024
- }
1025
- expandChildren(item) {
1026
- if (!item.expanded) {
1027
- item.setExpand(true);
1028
- if (this.async && this.childrenResolve && item.children.length === 0) {
1029
- item.loading = true;
1030
- this.childrenResolve(item.origin)
1031
- .pipe(take(1), finalize(() => {
1032
- item.loading = false;
1033
- this.expandChange.emit();
1034
- this.cdr.detectChanges();
1035
- }))
1036
- .subscribe((items) => {
1037
- item.addChildren(items);
1038
- this.computeItemsRefs(...item.children);
1039
- });
1040
- }
1041
- else {
1042
- this.computeItemsRefs(...item.children);
1043
- this.expandChange.emit();
1044
- }
1045
- }
1046
- else {
1047
- item.setExpand(false);
1048
- this.expandChange.emit();
1049
- }
1050
- }
1051
- ngOnDestroy() {
1052
- super.onDestroy();
1053
- }
1054
- }
1055
- NgxGanttComponent.decorators = [
1056
- { type: Component, args: [{
1057
- selector: 'ngx-gantt',
1058
- template: "<ngx-gantt-root>\n <ng-template #sideTemplate>\n <gantt-table [groups]=\"groups\" [items]=\"items\" [columns]=\"columns\" [groupTemplate]=\"groupTemplate\" [emptyTemplate]=\"tableEmptyTemplate\"></gantt-table>\n </ng-template>\n <ng-template #mainTemplate>\n <gantt-main\n [groups]=\"groups\"\n [items]=\"items\"\n [groupHeaderTemplate]=\"groupHeaderTemplate\"\n [itemTemplate]=\"itemTemplate\"\n [barTemplate]=\"barTemplate\"\n [rangeTemplate]=\"rangeTemplate\"\n (barClick)=\"barClick.emit($event)\"\n (lineClick)=\"lineClick.emit($event)\"\n >\n </gantt-main>\n </ng-template>\n</ngx-gantt-root>\n",
1059
- changeDetection: ChangeDetectionStrategy.OnPush,
1060
- providers: [
1061
- {
1062
- provide: GANTT_UPPER_TOKEN,
1063
- useExisting: NgxGanttComponent
1064
- }
1065
- ]
1066
- },] }
1067
- ];
1068
- NgxGanttComponent.ctorParameters = () => [
1069
- { type: ElementRef },
1070
- { type: ChangeDetectorRef },
1071
- { type: NgZone }
1072
- ];
1073
- NgxGanttComponent.propDecorators = {
1074
- maxLevel: [{ type: Input }],
1075
- async: [{ type: Input }],
1076
- childrenResolve: [{ type: Input }],
1077
- linkable: [{ type: Input }],
1078
- linkDragStarted: [{ type: Output }],
1079
- linkDragEnded: [{ type: Output }],
1080
- lineClick: [{ type: Output }],
1081
- table: [{ type: ContentChild, args: [NgxGanttTableComponent,] }],
1082
- columns: [{ type: ContentChildren, args: [NgxGanttTableColumnComponent, { descendants: true },] }],
1083
- tableEmptyTemplate: [{ type: ContentChild, args: ['tableEmpty', { static: true },] }]
1051
+ const GANTT_ABSTRACT_TOKEN = new InjectionToken('gantt-abstract-token');
1052
+
1053
+ const angleRight = `<svg xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="amnavigation/angle-right" stroke-width="1" fill-rule="evenodd"><path d="M7.978 11.498l-.005.005L2.3 5.831 3.13 5l4.848 4.848L12.826 5l.83.831-5.673 5.672-.005-.005z" transform="rotate(-90 7.978 8.252)"></path></g></svg>`;
1054
+ const angleDown = `<svg xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="aknavigation/angle-down" stroke-width="1" fill-rule="evenodd"><path d="M7.978 11.997l-.005.006L2.3 6.33l.83-.831 4.848 4.848L12.826 5.5l.83.83-5.673 5.673-.005-.006z" ></path></g></svg>`;
1055
+ const plusSquare = `<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="kxaction/plus-square" stroke-width="1" fill-rule="evenodd"><path d="M2 0h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm0 1.2a.8.8 0 0 0-.8.8v12a.8.8 0 0 0 .8.8h12a.8.8 0 0 0 .8-.8V2a.8.8 0 0 0-.8-.8H2zm5.45 6.2V4.75h1.2V7.4h2.65v1.2H8.65v2.65h-1.2V8.6H4.8V7.4h2.65z"></path></g></svg>`;
1056
+ const minusSquare = `<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="jnaction/minus-square" stroke-width="1" fill-rule="evenodd"><path d="M2 0h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm0 1.2a.8.8 0 0 0-.8.8v12a.8.8 0 0 0 .8.8h12a.8.8 0 0 0 .8-.8V2a.8.8 0 0 0-.8-.8H2zm2.8 6.2h6.5v1.2H4.8V7.4z"></path></g></svg>`;
1057
+ const loadingIcon = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50" xml:space="preserve">
1058
+ <path fill="#aaa" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z" transform="rotate(275.098 25 25)">
1059
+ <animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"></animateTransform>
1060
+ </path>
1061
+ </svg>`;
1062
+ const emptyIcon = `<svg
1063
+ width="148px"
1064
+ height="134px"
1065
+ viewBox="0 0 148 134"
1066
+ version="1.1"
1067
+ xmlns="http://www.w3.org/2000/svg"
1068
+ xmlns:xlink="http://www.w3.org/1999/xlink"
1069
+ >
1070
+ <defs>
1071
+ <filter x="0.0%" y="0.0%" width="100.0%" height="100.0%" filterUnits="objectBoundingBox" id="filter-1">
1072
+ <feGaussianBlur stdDeviation="0" in="SourceGraphic"></feGaussianBlur>
1073
+ </filter>
1074
+ </defs>
1075
+ <g id="148x134" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
1076
+ <g id="编组-6" transform="translate(1.000000, 1.000000)">
1077
+ <ellipse
1078
+ id="椭圆形"
1079
+ fill="#EDEEF2"
1080
+ opacity="0.3"
1081
+ filter="url(#filter-1)"
1082
+ cx="73.0800017"
1083
+ cy="115.920003"
1084
+ rx="73.0800017"
1085
+ ry="16.8000004"
1086
+ ></ellipse>
1087
+ <g id="编组-5" transform="translate(15.120000, 0.000000)">
1088
+ <polygon
1089
+ id="矩形"
1090
+ fill="#E2E4E9"
1091
+ points="19.2789848 49.5600011 99.1200023 48.7200011 117.600003 75.9297673 117.600003 92.313049 0 92.313049 0 75.0356267"
1092
+ ></polygon>
1093
+ <path
1094
+ d="M23.5200005,0 L94.0800002,0 C97.7913538,2.06413823e-16 100.8,3.00864655 100.8,6.72000015 L100.8,99.1200023 L100.8,99.1200023 L16.8000004,99.1200023 L16.8000004,6.72000015 C16.8000004,3.00864655 19.8086469,1.56994302e-15 23.5200005,0 Z"
1095
+ id="矩形"
1096
+ fill="#F9FAFB"
1097
+ ></path>
1098
+ <path
1099
+ d="M30.9200007,12.4400003 L86.6800019,12.4400003 C88.5356787,12.4400003 90.040002,13.9443236 90.040002,15.8000004 L90.040002,42.000001 C90.040002,43.8556778 88.5356787,45.360001 86.6800019,45.360001 L30.9200007,45.360001 C29.0643239,45.360001 27.5600006,43.8556778 27.5600006,42.000001 L27.5600006,15.8000004 C27.5600006,13.9443236 29.0643239,12.4400003 30.9200007,12.4400003 Z"
1100
+ id="矩形"
1101
+ fill="#E8EAEE"
1102
+ ></path>
1103
+ <text
1104
+ id="&lt;/null&gt;"
1105
+ font-family="PingFangSC-Medium, PingFang SC"
1106
+ font-size="15.1200003"
1107
+ font-weight="400"
1108
+ fill="#BCBECD"
1109
+ >
1110
+ <tspan x="33.6000008" y="32.8000004">&lt;/null&gt;</tspan>
1111
+ </text>
1112
+ <rect id="矩形" fill="#E8EAEE" x="27.5600006" y="52.0800012" width="61.4800014" height="5.04000011" rx="2.52000006"></rect>
1113
+ <rect
1114
+ id="矩形备份"
1115
+ fill="#E8EAEE"
1116
+ x="27.5600006"
1117
+ y="63.8400014"
1118
+ width="61.4800014"
1119
+ height="5.04000011"
1120
+ rx="2.52000006"
1121
+ ></rect>
1122
+ <path
1123
+ d="M0,75.6000017 L29.280235,75.6000017 C32.0637502,75.6000017 34.3202352,77.8564866 34.3202352,80.6400018 L34.3202352,86.2591426 C34.3202352,89.0426578 36.5767201,91.2991427 39.3602353,91.2991427 L78.4136737,91.2991427 C81.1971889,91.2991427 83.4536738,89.0426578 83.4536738,86.2591426 L83.4536738,80.6400018 C83.4536738,77.8564866 85.7101587,75.6000017 88.4936739,75.6000017 L117.600003,75.6000017 L117.600003,75.6000017 L117.600003,110.880003 C117.600003,115.519195 113.839194,119.280003 109.200002,119.280003 L8.40000019,119.280003 C3.76080819,119.280003 -6.53729019e-15,115.519195 0,110.880003 L0,75.6000017 L0,75.6000017 Z"
1124
+ id="矩形"
1125
+ fill="#EDEFF2"
1126
+ ></path>
1127
+ </g>
1128
+ </g>
1129
+ </g>
1130
+ </svg>`;
1131
+ const icons = {
1132
+ 'angle-right': angleRight,
1133
+ 'angle-down': angleDown,
1134
+ 'plus-square': plusSquare,
1135
+ 'minus-square': minusSquare,
1136
+ loading: loadingIcon,
1137
+ empty: emptyIcon
1084
1138
  };
1085
1139
 
1086
- const mainHeight = 5000;
1087
- class GanttCalendarComponent {
1088
- constructor(ganttUpper, ngZone, elementRef) {
1089
- this.ganttUpper = ganttUpper;
1090
- this.ngZone = ngZone;
1140
+ class GanttIconComponent {
1141
+ constructor(elementRef) {
1091
1142
  this.elementRef = elementRef;
1092
- this.unsubscribe$ = new Subject();
1093
- this.headerHeight = headerHeight;
1094
- this.mainHeight = mainHeight;
1095
- this.todayHeight = todayHeight;
1096
- this.todayWidth = todayWidth;
1097
- this.todayBorderRadius = todayBorderRadius;
1098
- this.viewTypes = GanttViewType;
1099
- this.className = true;
1143
+ this.isIcon = true;
1100
1144
  }
1101
- get view() {
1102
- return this.ganttUpper.view;
1145
+ set iconName(name) {
1146
+ this.setSvg(name);
1103
1147
  }
1104
- setTodayPoint() {
1105
- const x = this.view.getTodayXPoint();
1106
- const today = new GanttDate().getDate();
1107
- const todayEle = this.elementRef.nativeElement.getElementsByClassName('gantt-calendar-today-overlay')[0];
1108
- const rect = this.elementRef.nativeElement.getElementsByClassName('today-rect')[0];
1109
- const line = this.elementRef.nativeElement.getElementsByClassName('today-line')[0];
1110
- if (isNumber(x)) {
1111
- if (rect) {
1112
- rect.style.left = `${x - todayWidth / 2}px`;
1113
- rect.style.top = `${headerHeight - todayHeight}px`;
1114
- rect.innerHTML = today.toString();
1115
- }
1116
- if (line) {
1117
- line.style.left = `${x}px`;
1118
- line.style.top = `${headerHeight}px`;
1119
- line.style.bottom = `${-mainHeight}px`;
1120
- }
1148
+ ngOnInit() { }
1149
+ ngAfterViewInit() { }
1150
+ setSvg(name) {
1151
+ const iconSvg = icons[name];
1152
+ if (iconSvg) {
1153
+ this.elementRef.nativeElement.innerHTML = iconSvg;
1121
1154
  }
1122
1155
  else {
1123
- todayEle.style.display = 'none';
1156
+ this.elementRef.nativeElement.innerHTML = '';
1124
1157
  }
1125
1158
  }
1126
- ngOnInit() {
1127
- this.ngZone.onStable.pipe(take(1)).subscribe(() => {
1128
- merge(this.ganttUpper.viewChange, this.ganttUpper.view.start$)
1129
- .pipe(takeUntil(this.unsubscribe$))
1130
- .subscribe(() => {
1131
- this.setTodayPoint();
1132
- });
1133
- });
1159
+ }
1160
+ GanttIconComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttIconComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
1161
+ GanttIconComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: GanttIconComponent, selector: "gantt-icon", inputs: { iconName: "iconName" }, host: { properties: { "class.gantt-icon": "this.isIcon" } }, ngImport: i0, template: '', isInline: true });
1162
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttIconComponent, decorators: [{
1163
+ type: Component,
1164
+ args: [{
1165
+ selector: 'gantt-icon',
1166
+ template: ''
1167
+ }]
1168
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { isIcon: [{
1169
+ type: HostBinding,
1170
+ args: ['class.gantt-icon']
1171
+ }], iconName: [{
1172
+ type: Input
1173
+ }] } });
1174
+
1175
+ class IsGanttRangeItemPipe {
1176
+ transform(value) {
1177
+ return value === GanttItemType.range;
1134
1178
  }
1135
- ngAfterViewInit() { }
1136
- ngOnChanges(changes) { }
1137
- trackBy(point, index) {
1138
- return point.text || index;
1179
+ }
1180
+ IsGanttRangeItemPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: IsGanttRangeItemPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1181
+ IsGanttRangeItemPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: IsGanttRangeItemPipe, name: "isGanttRangeItem" });
1182
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: IsGanttRangeItemPipe, decorators: [{
1183
+ type: Pipe,
1184
+ args: [{
1185
+ name: 'isGanttRangeItem'
1186
+ }]
1187
+ }] });
1188
+ class IsGanttBarItemPipe {
1189
+ transform(value) {
1190
+ return value === GanttItemType.bar;
1139
1191
  }
1140
- ngOnDestroy() {
1141
- this.unsubscribe$.next();
1142
- this.unsubscribe$.complete();
1192
+ }
1193
+ IsGanttBarItemPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: IsGanttBarItemPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1194
+ IsGanttBarItemPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: IsGanttBarItemPipe, name: "isGanttBarItem" });
1195
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: IsGanttBarItemPipe, decorators: [{
1196
+ type: Pipe,
1197
+ args: [{
1198
+ name: 'isGanttBarItem'
1199
+ }]
1200
+ }] });
1201
+ class IsGanttCustomItemPipe {
1202
+ transform(value) {
1203
+ return value === GanttItemType.custom;
1143
1204
  }
1144
1205
  }
1145
- GanttCalendarComponent.decorators = [
1146
- { type: Component, args: [{
1147
- selector: 'gantt-calendar-overlay',
1148
- template: "<div class=\"gantt-calendar-today-overlay\" [style.width.px]=\"view.width\">\n <span class=\"today-rect\" [hidden]=\"ganttUpper.viewType !== viewTypes.day\"> </span>\n <span class=\"today-line\" *ngIf=\"ganttUpper.showTodayLine\"> </span>\n</div>\n\n<svg class=\"gantt-calendar-overlay-main\" [attr.width]=\"view.width\" [attr.height]=\"headerHeight\">\n <g>\n <text class=\"primary-text\" *ngFor=\"let point of view.primaryDatePoints; trackBy: trackBy\" [attr.x]=\"point.x\" [attr.y]=\"point.y\">\n {{ point.text }}\n </text>\n <ng-container *ngFor=\"let point of view.secondaryDatePoints; trackBy: trackBy\">\n <text class=\"secondary-text\" [class.secondary-text-weekend]=\"point.additions?.isWeekend\" [attr.x]=\"point.x\" [attr.y]=\"point.y\">\n {{ point.text }}\n </text>\n </ng-container>\n\n <g>\n <line\n *ngFor=\"let point of view.primaryDatePoints; let i = index; trackBy: trackBy\"\n [attr.x1]=\"(i + 1) * view.primaryWidth\"\n [attr.x2]=\"(i + 1) * view.primaryWidth\"\n [attr.y1]=\"0\"\n [attr.y2]=\"mainHeight\"\n class=\"primary-line\"\n ></line>\n </g>\n\n <g>\n <line [attr.x1]=\"0\" [attr.x2]=\"view.width\" [attr.y1]=\"headerHeight\" [attr.y2]=\"headerHeight\" class=\"header-line\"></line>\n </g>\n </g>\n <g>\n <g *ngIf=\"view.showTimeline\">\n <line\n *ngFor=\"let point of view.secondaryDatePoints; let i = index; trackBy: trackBy\"\n [attr.x1]=\"(i + 1) * view.cellWidth\"\n [attr.x2]=\"(i + 1) * view.cellWidth\"\n [attr.y1]=\"headerHeight\"\n [attr.y2]=\"mainHeight\"\n class=\"secondary-line\"\n ></line>\n <line\n *ngFor=\"let point of view.primaryDatePoints; let i = index; trackBy: trackBy\"\n [attr.x1]=\"(i + 1) * view.primaryWidth\"\n [attr.x2]=\"(i + 1) * view.primaryWidth\"\n [attr.y1]=\"0\"\n [attr.y2]=\"mainHeight\"\n class=\"primary-line\"\n ></line>\n </g>\n </g>\n</svg>\n"
1149
- },] }
1150
- ];
1151
- GanttCalendarComponent.ctorParameters = () => [
1152
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] },
1153
- { type: NgZone },
1154
- { type: ElementRef }
1155
- ];
1156
- GanttCalendarComponent.propDecorators = {
1157
- className: [{ type: HostBinding, args: ['class.gantt-calendar-overlay',] }]
1158
- };
1206
+ IsGanttCustomItemPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: IsGanttCustomItemPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
1207
+ IsGanttCustomItemPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: IsGanttCustomItemPipe, name: "isGanttCustomItem" });
1208
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: IsGanttCustomItemPipe, decorators: [{
1209
+ type: Pipe,
1210
+ args: [{
1211
+ name: 'isGanttCustomItem'
1212
+ }]
1213
+ }] });
1159
1214
 
1215
+ const defaultColumnWidth = 100;
1216
+ const minColumnWidth = 80;
1160
1217
  class GanttTableComponent {
1161
1218
  constructor(gantt, elementRef) {
1162
1219
  this.gantt = gantt;
@@ -1178,6 +1235,9 @@ class GanttTableComponent {
1178
1235
  if (!((_a = changes.groups.currentValue) === null || _a === void 0 ? void 0 : _a.length) && !((_b = changes.items.currentValue) === null || _b === void 0 ? void 0 : _b.length)) {
1179
1236
  this.ganttTableEmptyClass = true;
1180
1237
  }
1238
+ else {
1239
+ this.ganttTableEmptyClass = false;
1240
+ }
1181
1241
  }
1182
1242
  dragFixed(config) {
1183
1243
  if (config.movedWidth < config.minWidth) {
@@ -1258,26 +1318,37 @@ class GanttTableComponent {
1258
1318
  this.draglineElementRef.nativeElement.style.display = 'none';
1259
1319
  }
1260
1320
  }
1261
- GanttTableComponent.decorators = [
1262
- { type: Component, args: [{
1263
- selector: 'gantt-table',
1264
- template: "<div class=\"gantt-table-header gantt-table-row\">\n <div class=\"gantt-table-column\" *ngFor=\"let column of columnList; let i = index\" [style.width]=\"column.columnWidth\">\n <ng-container *ngIf=\"column.headerTemplateRef; else default\" [ngTemplateOutlet]=\"column.headerTemplateRef\"></ng-container>\n <ng-template #default>\n {{ column.name }}\n </ng-template>\n <div\n class=\"gantt-table-drag-trigger\"\n cdkDrag\n cdkDragLockAxis=\"x\"\n cdkDragBoundary=\".gantt\"\n (cdkDragMoved)=\"dragMoved($event, column)\"\n (cdkDragStarted)=\"dragStarted($event)\"\n (cdkDragEnded)=\"columnDragEnded($event, column)\"\n ></div>\n </div>\n</div>\n<div class=\"gantt-table-body\">\n <ng-container *ngIf=\"!groups.length && !items.length\">\n <ng-container *ngIf=\"!emptyTemplate\">\n <gantt-icon class=\"empty-icon\" iconName=\"empty\"></gantt-icon>\n <div class=\"empty-text\">\u6CA1\u6709\u6570\u636E</div>\n </ng-container>\n <ng-template [ngTemplateOutlet]=\"emptyTemplate\"></ng-template>\n </ng-container>\n\n <ng-container *ngIf=\"groups && groups.length > 0; else itemsTemplate\">\n <ng-container *ngFor=\"let group of groups\">\n <div class=\"gantt-table-group\" [ngClass]=\"group.class\">\n <div class=\"gantt-table-group-title\" [class.expanded]=\"group.expanded\" (click)=\"expandGroup(group)\">\n <gantt-icon class=\"expand-icon\" [iconName]=\"group.expanded ? 'angle-down' : 'angle-right'\"></gantt-icon>\n <ng-container *ngIf=\"groupTemplate; else default\">\n <ng-template\n [ngTemplateOutlet]=\"groupTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: group.origin, group: group.origin }\"\n ></ng-template>\n </ng-container>\n <ng-template #default>\n <span class=\"group-title\">{{ group.title }}</span>\n </ng-template>\n </div>\n </div>\n\n <ng-container *ngIf=\"group.expanded\">\n <ng-template\n [ngTemplateOutlet]=\"ganttItems\"\n [ngTemplateOutletContext]=\"{ group: group, items: group.items, level: 0 }\"\n ></ng-template>\n </ng-container>\n </ng-container>\n </ng-container>\n</div>\n\n<div\n class=\"gantt-table-drag-trigger\"\n cdkDrag\n cdkDragLockAxis=\"x\"\n cdkDragBoundary=\".gantt\"\n (cdkDragMoved)=\"dragMoved($event)\"\n (cdkDragStarted)=\"dragStarted($event)\"\n (cdkDragEnded)=\"tableDragEnded($event)\"\n></div>\n\n<div #dragLine class=\"gantt-table-drag-auxiliary-line\"></div>\n\n<ng-template #itemsTemplate>\n <ng-template [ngTemplateOutlet]=\"ganttItems\" [ngTemplateOutletContext]=\"{ items: items, level: 0 }\"></ng-template>\n</ng-template>\n\n<ng-template #ganttItems let-group=\"group\" let-items=\"items\" let-level=\"level\">\n <ng-container *ngFor=\"let item of items\">\n <div\n class=\"gantt-table-item gantt-table-row\"\n [class.gantt-table-item-first-level-group]=\"level === 0 && (item.type | isGanttRangeItem)\"\n [class.gantt-table-item-with-group]=\"group\"\n [style.height.px]=\"gantt.styles.lineHeight\"\n [style.lineHeight.px]=\"gantt.styles.lineHeight\"\n >\n <div class=\"gantt-table-column\" *ngFor=\"let column of columnList; let first = first\" [style.width]=\"column.columnWidth\">\n <div *ngIf=\"first\" class=\"gantt-expand-icon\" [style.marginLeft.px]=\"level * 20\">\n <ng-container *ngIf=\"level < gantt.maxLevel - 1 && item.expandable\">\n <gantt-icon\n *ngIf=\"!item.loading\"\n class=\"expand-icon\"\n [iconName]=\"item.expanded ? 'angle-down' : 'angle-right'\"\n (click)=\"expandChildren(item)\"\n ></gantt-icon>\n <gantt-icon *ngIf=\"item.loading\" [iconName]=\"'loading'\"></gantt-icon>\n </ng-container>\n </div>\n <div class=\"gantt-table-column-content\">\n <ng-template\n [ngTemplateOutlet]=\"column.templateRef\"\n [ngTemplateOutletContext]=\"{ $implicit: item.origin, item: item.origin }\"\n ></ng-template>\n </div>\n </div>\n </div>\n <ng-template\n *ngIf=\"item.children && item.expanded\"\n [ngTemplateOutlet]=\"ganttItems\"\n [ngTemplateOutletContext]=\"{ items: item.children, level: level + 1, group: group }\"\n ></ng-template>\n </ng-container>\n</ng-template>\n"
1265
- },] }
1266
- ];
1267
- GanttTableComponent.ctorParameters = () => [
1268
- { type: NgxGanttComponent },
1269
- { type: ElementRef }
1270
- ];
1271
- GanttTableComponent.propDecorators = {
1272
- groups: [{ type: Input }],
1273
- items: [{ type: Input }],
1274
- columns: [{ type: Input }],
1275
- groupTemplate: [{ type: Input }],
1276
- emptyTemplate: [{ type: Input }],
1277
- draglineElementRef: [{ type: ViewChild, args: ['dragLine', { static: true },] }],
1278
- ganttTableClass: [{ type: HostBinding, args: ['class.gantt-table',] }],
1279
- ganttTableEmptyClass: [{ type: HostBinding, args: ['class.gantt-table-empty',] }]
1280
- };
1321
+ GanttTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttTableComponent, deps: [{ token: GANTT_ABSTRACT_TOKEN }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
1322
+ GanttTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: GanttTableComponent, selector: "gantt-table", inputs: { groups: "groups", items: "items", columns: "columns", groupTemplate: "groupTemplate", emptyTemplate: "emptyTemplate" }, host: { properties: { "class.gantt-table": "this.ganttTableClass", "class.gantt-table-empty": "this.ganttTableEmptyClass" } }, viewQueries: [{ propertyName: "draglineElementRef", first: true, predicate: ["dragLine"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: "<div class=\"gantt-table-header gantt-table-row\">\n <div class=\"gantt-table-column\" *ngFor=\"let column of columnList; let i = index\" [style.width]=\"column.columnWidth\">\n <ng-container *ngIf=\"column.headerTemplateRef; else default\" [ngTemplateOutlet]=\"column.headerTemplateRef\"></ng-container>\n <ng-template #default>\n {{ column.name }}\n </ng-template>\n <div\n class=\"gantt-table-drag-trigger\"\n cdkDrag\n cdkDragLockAxis=\"x\"\n cdkDragBoundary=\".gantt\"\n (cdkDragMoved)=\"dragMoved($event, column)\"\n (cdkDragStarted)=\"dragStarted($event)\"\n (cdkDragEnded)=\"columnDragEnded($event, column)\"\n ></div>\n </div>\n</div>\n<div class=\"gantt-table-body\">\n <ng-container *ngIf=\"!groups.length && !items.length\">\n <ng-container *ngIf=\"!emptyTemplate\">\n <gantt-icon class=\"empty-icon\" iconName=\"empty\"></gantt-icon>\n <div class=\"empty-text\">\u6CA1\u6709\u6570\u636E</div>\n </ng-container>\n <ng-template [ngTemplateOutlet]=\"emptyTemplate\"></ng-template>\n </ng-container>\n\n <ng-container *ngIf=\"groups && groups.length > 0; else itemsTemplate\">\n <ng-container *ngFor=\"let group of groups\">\n <div class=\"gantt-table-group\" [ngClass]=\"group.class\">\n <div class=\"gantt-table-group-title\" [class.expanded]=\"group.expanded\" (click)=\"expandGroup(group)\">\n <gantt-icon class=\"expand-icon\" [iconName]=\"group.expanded ? 'angle-down' : 'angle-right'\"></gantt-icon>\n <ng-container *ngIf=\"groupTemplate; else default\">\n <ng-template\n [ngTemplateOutlet]=\"groupTemplate\"\n [ngTemplateOutletContext]=\"{ $implicit: group.origin, group: group.origin }\"\n ></ng-template>\n </ng-container>\n <ng-template #default>\n <span class=\"group-title\">{{ group.title }}</span>\n </ng-template>\n </div>\n </div>\n\n <ng-container *ngIf=\"group.expanded\">\n <ng-template\n [ngTemplateOutlet]=\"ganttItems\"\n [ngTemplateOutletContext]=\"{ group: group, items: group.items, level: 0 }\"\n ></ng-template>\n </ng-container>\n </ng-container>\n </ng-container>\n</div>\n\n<div\n class=\"gantt-table-drag-trigger\"\n cdkDrag\n cdkDragLockAxis=\"x\"\n cdkDragBoundary=\".gantt\"\n (cdkDragMoved)=\"dragMoved($event)\"\n (cdkDragStarted)=\"dragStarted($event)\"\n (cdkDragEnded)=\"tableDragEnded($event)\"\n></div>\n\n<div #dragLine class=\"gantt-table-drag-auxiliary-line\"></div>\n\n<ng-template #itemsTemplate>\n <ng-template [ngTemplateOutlet]=\"ganttItems\" [ngTemplateOutletContext]=\"{ items: items, level: 0 }\"></ng-template>\n</ng-template>\n\n<ng-template #ganttItems let-group=\"group\" let-items=\"items\" let-level=\"level\">\n <ng-container *ngFor=\"let item of items\">\n <div\n class=\"gantt-table-item gantt-table-row\"\n [class.gantt-table-item-first-level-group]=\"level === 0 && (item.type | isGanttRangeItem)\"\n [class.gantt-table-item-with-group]=\"group\"\n [style.height.px]=\"gantt.styles.lineHeight\"\n [style.lineHeight.px]=\"gantt.styles.lineHeight\"\n >\n <div class=\"gantt-table-column\" *ngFor=\"let column of columnList; let first = first\" [style.width]=\"column.columnWidth\">\n <div *ngIf=\"first\" class=\"gantt-expand-icon\" [style.marginLeft.px]=\"level * 20\">\n <ng-container *ngIf=\"level < gantt.maxLevel - 1 && item.expandable\">\n <gantt-icon\n *ngIf=\"!item.loading\"\n class=\"expand-icon\"\n [iconName]=\"item.expanded ? 'angle-down' : 'angle-right'\"\n (click)=\"expandChildren(item)\"\n ></gantt-icon>\n <gantt-icon *ngIf=\"item.loading\" [iconName]=\"'loading'\"></gantt-icon>\n </ng-container>\n </div>\n <div class=\"gantt-table-column-content\">\n <ng-template\n [ngTemplateOutlet]=\"column.templateRef\"\n [ngTemplateOutletContext]=\"{ $implicit: item.origin, item: item.origin }\"\n ></ng-template>\n </div>\n </div>\n </div>\n <ng-template\n *ngIf=\"item.children && item.expanded\"\n [ngTemplateOutlet]=\"ganttItems\"\n [ngTemplateOutletContext]=\"{ items: item.children, level: level + 1, group: group }\"\n ></ng-template>\n </ng-container>\n</ng-template>\n", components: [{ type: GanttIconComponent, selector: "gantt-icon", inputs: ["iconName"] }], directives: [{ type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }, { type: i1.CdkDrag, selector: "[cdkDrag]", inputs: ["cdkDragDisabled", "cdkDragStartDelay", "cdkDragLockAxis", "cdkDragConstrainPosition", "cdkDragPreviewClass", "cdkDragBoundary", "cdkDragRootElement", "cdkDragData", "cdkDragFreeDragPosition"], outputs: ["cdkDragStarted", "cdkDragReleased", "cdkDragEnded", "cdkDragEntered", "cdkDragExited", "cdkDragDropped", "cdkDragMoved"], exportAs: ["cdkDrag"] }, { type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], pipes: { "isGanttRangeItem": IsGanttRangeItemPipe } });
1323
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttTableComponent, decorators: [{
1324
+ type: Component,
1325
+ args: [{
1326
+ selector: 'gantt-table',
1327
+ templateUrl: './gantt-table.component.html'
1328
+ }]
1329
+ }], ctorParameters: function () { return [{ type: undefined, decorators: [{
1330
+ type: Inject,
1331
+ args: [GANTT_ABSTRACT_TOKEN]
1332
+ }] }, { type: i0.ElementRef }]; }, propDecorators: { groups: [{
1333
+ type: Input
1334
+ }], items: [{
1335
+ type: Input
1336
+ }], columns: [{
1337
+ type: Input
1338
+ }], groupTemplate: [{
1339
+ type: Input
1340
+ }], emptyTemplate: [{
1341
+ type: Input
1342
+ }], draglineElementRef: [{
1343
+ type: ViewChild,
1344
+ args: ['dragLine', { static: true }]
1345
+ }], ganttTableClass: [{
1346
+ type: HostBinding,
1347
+ args: ['class.gantt-table']
1348
+ }], ganttTableEmptyClass: [{
1349
+ type: HostBinding,
1350
+ args: ['class.gantt-table-empty']
1351
+ }] } });
1281
1352
 
1282
1353
  const scrollThreshold = 50;
1283
1354
  var ScrollDirection;
@@ -1371,10 +1442,11 @@ class GanttDomService {
1371
1442
  this.unsubscribe$.complete();
1372
1443
  }
1373
1444
  }
1374
- GanttDomService.decorators = [
1375
- { type: Injectable }
1376
- ];
1377
- GanttDomService.ctorParameters = () => [];
1445
+ GanttDomService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttDomService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1446
+ GanttDomService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttDomService });
1447
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttDomService, decorators: [{
1448
+ type: Injectable
1449
+ }], ctorParameters: function () { return []; } });
1378
1450
 
1379
1451
  class GanttDragContainer {
1380
1452
  constructor() {
@@ -1427,1054 +1499,1163 @@ class GanttDragContainer {
1427
1499
  this.linkDragTarget = null;
1428
1500
  }
1429
1501
  }
1430
- GanttDragContainer.decorators = [
1431
- { type: Injectable }
1432
- ];
1433
- GanttDragContainer.ctorParameters = () => [];
1502
+ GanttDragContainer.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttDragContainer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1503
+ GanttDragContainer.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttDragContainer });
1504
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttDragContainer, decorators: [{
1505
+ type: Injectable
1506
+ }], ctorParameters: function () { return []; } });
1434
1507
 
1435
- const dragMinWidth = 10;
1436
- const activeClass = 'gantt-bar-active';
1437
- const linkDropClass = 'gantt-bar-link-drop';
1438
- function createSvgElement(qualifiedName, className) {
1439
- const element = document.createElementNS('http://www.w3.org/2000/svg', qualifiedName);
1440
- element.classList.add(className);
1441
- return element;
1442
- }
1443
- class GanttBarDrag {
1444
- constructor(dragDrop, dom, dragContainer) {
1445
- this.dragDrop = dragDrop;
1446
- this.dom = dom;
1447
- this.dragContainer = dragContainer;
1448
- this.dragRefs = [];
1449
- this.destroy$ = new Subject();
1508
+ class GanttPrintService {
1509
+ constructor() { }
1510
+ setInlineStyles(targetElem) {
1511
+ const svgElements = Array.from(targetElem.getElementsByTagName('svg'));
1512
+ for (const svgElement of svgElements) {
1513
+ this.recursElementChildren(svgElement);
1514
+ }
1450
1515
  }
1451
- get dragDisabled() {
1452
- return !this.item.draggable || !this.ganttUpper.draggable;
1516
+ recursElementChildren(node) {
1517
+ const transformProperties = [
1518
+ 'fill',
1519
+ 'color',
1520
+ 'font-size',
1521
+ 'stroke',
1522
+ 'font',
1523
+ 'text-anchor',
1524
+ 'stroke-dasharray',
1525
+ 'shape-rendering',
1526
+ 'stroke-width'
1527
+ ];
1528
+ if (!node.style) {
1529
+ return;
1530
+ }
1531
+ const styles = getComputedStyle(node);
1532
+ for (const transformProperty of transformProperties) {
1533
+ node.style[transformProperty] = styles[transformProperty];
1534
+ }
1535
+ for (const child of Array.from(node.childNodes)) {
1536
+ this.recursElementChildren(child);
1537
+ }
1453
1538
  }
1454
- get linkDragDisabled() {
1455
- return !this.item.linkable || !this.ganttUpper.linkable;
1539
+ register(root) {
1540
+ this.root = root.nativeElement;
1541
+ this.mainContainer = this.root.getElementsByClassName('gantt-main-container')[0];
1456
1542
  }
1457
- createMouseEvents() {
1458
- fromEvent(this.barElement, 'mouseenter')
1459
- .pipe(takeUntil(this.destroy$))
1460
- .subscribe(() => {
1461
- if (this.dragContainer.linkDraggingId && this.dragContainer.linkDraggingId !== this.item.id) {
1462
- if (this.item.linkable) {
1463
- this.barElement.classList.add(linkDropClass);
1464
- this.dragContainer.emitLinkDragEntered(this.item);
1543
+ print(name = 'download', ignoreElementClass) {
1544
+ const root = this.root;
1545
+ const mainContainer = this.mainContainer;
1546
+ // set print width
1547
+ const printWidth = root.offsetWidth;
1548
+ // set print height
1549
+ const printHeight = root.offsetHeight - mainContainer.offsetHeight + mainContainer.scrollHeight;
1550
+ html2canvas(root, {
1551
+ logging: false,
1552
+ allowTaint: true,
1553
+ useCORS: true,
1554
+ width: printWidth,
1555
+ height: printHeight,
1556
+ ignoreElements: (element) => {
1557
+ if (ignoreElementClass && element.classList.contains(ignoreElementClass)) {
1558
+ return true;
1465
1559
  }
1560
+ if (element.classList.contains('gantt-calendar-today-overlay')) {
1561
+ return true;
1562
+ }
1563
+ },
1564
+ onclone: (cloneDocument) => {
1565
+ const ganttClass = root.className;
1566
+ const cloneGanttDom = cloneDocument.querySelector(`.${ganttClass.replace(/\s+/g, '.')}`);
1567
+ const cloneGanttContainerDom = cloneDocument.querySelector('.gantt-container');
1568
+ const cloneCalendarOverlay = cloneDocument.querySelector('.gantt-calendar-overlay-main');
1569
+ const cloneLinksOverlay = cloneDocument.querySelector('.gantt-links-overlay-main');
1570
+ // change targetDom width
1571
+ cloneGanttDom.style.width = `${printWidth}px`;
1572
+ cloneGanttDom.style.height = `${printHeight}px`;
1573
+ cloneGanttDom.style.overflow = `unset`;
1574
+ cloneGanttContainerDom.style.backgroundColor = '#fff';
1575
+ cloneCalendarOverlay.setAttribute('height', `${printHeight}`);
1576
+ cloneCalendarOverlay.setAttribute('style', `background: transparent`);
1577
+ if (cloneLinksOverlay) {
1578
+ cloneLinksOverlay.setAttribute('height', `${printHeight}`);
1579
+ cloneLinksOverlay.setAttribute('style', `height: ${printHeight}px`);
1580
+ }
1581
+ // setInlineStyles for svg
1582
+ this.setInlineStyles(cloneGanttDom);
1466
1583
  }
1467
- else {
1468
- this.barElement.classList.add(activeClass);
1469
- }
1584
+ }).then((canvas) => {
1585
+ const link = document.createElement('a');
1586
+ const dataUrl = canvas.toDataURL('image/png');
1587
+ link.download = `${name}.png`;
1588
+ link.href = dataUrl;
1589
+ link.click();
1470
1590
  });
1471
- fromEvent(this.barElement, 'mouseleave')
1472
- .pipe(takeUntil(this.destroy$))
1473
- .subscribe(() => {
1474
- if (!this.dragContainer.linkDraggingId) {
1475
- this.barElement.classList.remove(activeClass);
1591
+ }
1592
+ }
1593
+ GanttPrintService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttPrintService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1594
+ GanttPrintService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttPrintService });
1595
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttPrintService, decorators: [{
1596
+ type: Injectable
1597
+ }], ctorParameters: function () { return []; } });
1598
+
1599
+ const mainHeight = 5000;
1600
+ class GanttCalendarComponent {
1601
+ constructor(ganttUpper, ngZone, elementRef) {
1602
+ this.ganttUpper = ganttUpper;
1603
+ this.ngZone = ngZone;
1604
+ this.elementRef = elementRef;
1605
+ this.unsubscribe$ = new Subject();
1606
+ this.headerHeight = headerHeight;
1607
+ this.mainHeight = mainHeight;
1608
+ this.todayHeight = todayHeight;
1609
+ this.todayWidth = todayWidth;
1610
+ this.todayBorderRadius = todayBorderRadius;
1611
+ this.viewTypes = GanttViewType;
1612
+ this.className = true;
1613
+ }
1614
+ get view() {
1615
+ return this.ganttUpper.view;
1616
+ }
1617
+ setTodayPoint() {
1618
+ const x = this.view.getTodayXPoint();
1619
+ const today = new GanttDate().getDate();
1620
+ const todayEle = this.elementRef.nativeElement.getElementsByClassName('gantt-calendar-today-overlay')[0];
1621
+ const rect = this.elementRef.nativeElement.getElementsByClassName('today-rect')[0];
1622
+ const line = this.elementRef.nativeElement.getElementsByClassName('today-line')[0];
1623
+ if (isNumber(x)) {
1624
+ if (rect) {
1625
+ rect.style.left = `${x - todayWidth / 2}px`;
1626
+ rect.style.top = `${headerHeight - todayHeight}px`;
1627
+ rect.innerHTML = today.toString();
1476
1628
  }
1477
- else {
1478
- this.dragContainer.emitLinkDragLeaved();
1629
+ if (line) {
1630
+ line.style.left = `${x}px`;
1631
+ line.style.top = `${headerHeight}px`;
1632
+ line.style.bottom = `${-mainHeight}px`;
1479
1633
  }
1480
- this.barElement.classList.remove(linkDropClass);
1481
- });
1634
+ }
1635
+ else {
1636
+ todayEle.style.display = 'none';
1637
+ }
1482
1638
  }
1483
- createBarDrag() {
1484
- const dragRef = this.dragDrop.createDrag(this.barElement);
1485
- dragRef.lockAxis = 'x';
1486
- dragRef.started.subscribe(() => {
1487
- this.setDraggingStyles();
1488
- this.dragContainer.dragStarted.emit({ item: this.item.origin });
1639
+ ngOnInit() {
1640
+ this.ngZone.onStable.pipe(take(1)).subscribe(() => {
1641
+ merge(this.ganttUpper.viewChange, this.ganttUpper.view.start$)
1642
+ .pipe(takeUntil(this.unsubscribe$))
1643
+ .subscribe(() => {
1644
+ this.setTodayPoint();
1645
+ });
1489
1646
  });
1490
- dragRef.moved.subscribe((event) => {
1491
- const x = this.item.refs.x + event.distance.x;
1492
- const days = differenceInCalendarDays(this.item.end.value, this.item.start.value);
1493
- const start = this.ganttUpper.view.getDateByXPoint(x);
1494
- const end = start.addDays(days);
1495
- this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(x), end);
1647
+ }
1648
+ ngAfterViewInit() { }
1649
+ ngOnChanges(changes) { }
1650
+ trackBy(point, index) {
1651
+ return point.text || index;
1652
+ }
1653
+ ngOnDestroy() {
1654
+ this.unsubscribe$.next();
1655
+ this.unsubscribe$.complete();
1656
+ }
1657
+ }
1658
+ GanttCalendarComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttCalendarComponent, deps: [{ token: GANTT_UPPER_TOKEN }, { token: i0.NgZone }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
1659
+ GanttCalendarComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: GanttCalendarComponent, selector: "gantt-calendar-overlay", host: { properties: { "class.gantt-calendar-overlay": "this.className" } }, usesOnChanges: true, ngImport: i0, template: "<div class=\"gantt-calendar-today-overlay\" [style.width.px]=\"view.width\">\n <span class=\"today-rect\" [hidden]=\"ganttUpper.viewType !== viewTypes.day\"> </span>\n <span class=\"today-line\" *ngIf=\"ganttUpper.showTodayLine\"> </span>\n</div>\n\n<svg class=\"gantt-calendar-overlay-main\" [attr.width]=\"view.width\" [attr.height]=\"headerHeight\">\n <g>\n <text class=\"primary-text\" *ngFor=\"let point of view.primaryDatePoints; trackBy: trackBy\" [attr.x]=\"point.x\" [attr.y]=\"point.y\">\n {{ point.text }}\n </text>\n <ng-container *ngFor=\"let point of view.secondaryDatePoints; trackBy: trackBy\">\n <text class=\"secondary-text\" [class.secondary-text-weekend]=\"point.additions?.isWeekend\" [attr.x]=\"point.x\" [attr.y]=\"point.y\">\n {{ point.text }}\n </text>\n </ng-container>\n\n <g>\n <line\n *ngFor=\"let point of view.primaryDatePoints; let i = index; trackBy: trackBy\"\n [attr.x1]=\"(i + 1) * view.primaryWidth\"\n [attr.x2]=\"(i + 1) * view.primaryWidth\"\n [attr.y1]=\"0\"\n [attr.y2]=\"mainHeight\"\n class=\"primary-line\"\n ></line>\n </g>\n\n <g>\n <line [attr.x1]=\"0\" [attr.x2]=\"view.width\" [attr.y1]=\"headerHeight\" [attr.y2]=\"headerHeight\" class=\"header-line\"></line>\n </g>\n </g>\n <g>\n <g *ngIf=\"view.showTimeline\">\n <line\n *ngFor=\"let point of view.secondaryDatePoints; let i = index; trackBy: trackBy\"\n [attr.x1]=\"(i + 1) * view.cellWidth\"\n [attr.x2]=\"(i + 1) * view.cellWidth\"\n [attr.y1]=\"headerHeight\"\n [attr.y2]=\"mainHeight\"\n class=\"secondary-line\"\n ></line>\n <line\n *ngFor=\"let point of view.primaryDatePoints; let i = index; trackBy: trackBy\"\n [attr.x1]=\"(i + 1) * view.primaryWidth\"\n [attr.x2]=\"(i + 1) * view.primaryWidth\"\n [attr.y1]=\"0\"\n [attr.y2]=\"mainHeight\"\n class=\"primary-line\"\n ></line>\n </g>\n </g>\n</svg>\n", directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }] });
1660
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttCalendarComponent, decorators: [{
1661
+ type: Component,
1662
+ args: [{
1663
+ selector: 'gantt-calendar-overlay',
1664
+ templateUrl: './calendar.component.html'
1665
+ }]
1666
+ }], ctorParameters: function () { return [{ type: GanttUpper, decorators: [{
1667
+ type: Inject,
1668
+ args: [GANTT_UPPER_TOKEN]
1669
+ }] }, { type: i0.NgZone }, { type: i0.ElementRef }]; }, propDecorators: { className: [{
1670
+ type: HostBinding,
1671
+ args: ['class.gantt-calendar-overlay']
1672
+ }] } });
1673
+
1674
+ class GanttDragBackdropComponent {
1675
+ constructor() {
1676
+ this.backdropClass = true;
1677
+ }
1678
+ ngOnInit() { }
1679
+ }
1680
+ GanttDragBackdropComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttDragBackdropComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
1681
+ GanttDragBackdropComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: GanttDragBackdropComponent, selector: "gantt-drag-backdrop", host: { properties: { "class.gantt-drag-backdrop": "this.backdropClass" } }, ngImport: i0, template: "<div class=\"gantt-drag-mask\">\n <div class=\"date-range\">\n <span class=\"start\"></span>\n <span class=\"end\"></span>\n </div>\n</div>\n" });
1682
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttDragBackdropComponent, decorators: [{
1683
+ type: Component,
1684
+ args: [{
1685
+ selector: 'gantt-drag-backdrop',
1686
+ templateUrl: `./drag-backdrop.component.html`
1687
+ }]
1688
+ }], ctorParameters: function () { return []; }, propDecorators: { backdropClass: [{
1689
+ type: HostBinding,
1690
+ args: ['class.gantt-drag-backdrop']
1691
+ }] } });
1692
+
1693
+ class NgxGanttRootComponent {
1694
+ constructor(elementRef, ngZone, dom, dragContainer, ganttUpper, printService) {
1695
+ this.elementRef = elementRef;
1696
+ this.ngZone = ngZone;
1697
+ this.dom = dom;
1698
+ this.dragContainer = dragContainer;
1699
+ this.ganttUpper = ganttUpper;
1700
+ this.printService = printService;
1701
+ this.ganttClass = true;
1702
+ this.unsubscribe$ = new Subject();
1703
+ this.ganttUpper.dragContainer = dragContainer;
1704
+ }
1705
+ get view() {
1706
+ return this.ganttUpper.view;
1707
+ }
1708
+ ngOnInit() {
1709
+ this.ngZone.onStable.pipe(take(1)).subscribe(() => {
1710
+ this.dom.initialize(this.elementRef);
1711
+ if (this.printService) {
1712
+ this.printService.register(this.elementRef);
1713
+ }
1714
+ this.setupScrollClass();
1715
+ this.setupResize();
1716
+ this.setupViewScroll();
1717
+ // 优化初始化时Scroll滚动体验问题,通过透明度解决,默认透明度为0,滚动结束后恢复
1718
+ this.elementRef.nativeElement.style.opacity = '1';
1719
+ this.ganttUpper.viewChange.pipe(startWith(null)).subscribe(() => {
1720
+ this.scrollToToday();
1721
+ });
1496
1722
  });
1497
- dragRef.ended.subscribe((event) => {
1498
- const days = differenceInCalendarDays(this.item.end.value, this.item.start.value);
1499
- const start = this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x);
1500
- const end = start.addDays(days);
1501
- this.item.updateDate(start, end);
1502
- this.clearDraggingStyles();
1503
- this.closeDragBackdrop();
1504
- event.source.reset();
1505
- this.dragContainer.dragEnded.emit({ item: this.item.origin });
1723
+ }
1724
+ setupViewScroll() {
1725
+ if (this.ganttUpper.disabledLoadOnScroll) {
1726
+ return;
1727
+ }
1728
+ this.dom
1729
+ .getViewerScroll()
1730
+ .pipe(takeUntil(this.unsubscribe$))
1731
+ .subscribe((event) => {
1732
+ if (event.direction === ScrollDirection.LEFT) {
1733
+ const dates = this.view.addStartDate();
1734
+ if (dates) {
1735
+ event.target.scrollLeft += this.view.getDateRangeWidth(dates.start, dates.end);
1736
+ this.ngZone.run(() => {
1737
+ this.ganttUpper.loadOnScroll.emit({ start: dates.start.getUnixTime(), end: dates.end.getUnixTime() });
1738
+ });
1739
+ }
1740
+ }
1741
+ if (event.direction === ScrollDirection.RIGHT) {
1742
+ const dates = this.view.addEndDate();
1743
+ if (dates) {
1744
+ this.ngZone.run(() => {
1745
+ this.ganttUpper.loadOnScroll.emit({ start: dates.start.getUnixTime(), end: dates.end.getUnixTime() });
1746
+ });
1747
+ }
1748
+ }
1506
1749
  });
1507
- this.barDragRef = dragRef;
1508
- return dragRef;
1509
1750
  }
1510
- createBarHandleDrags() {
1511
- const dragRefs = [];
1512
- const handles = this.barElement.querySelectorAll('.drag-handles .handle');
1513
- handles.forEach((handle, index) => {
1514
- const isBefore = index === 0;
1515
- const dragRef = this.dragDrop.createDrag(handle);
1516
- dragRef.lockAxis = 'x';
1517
- dragRef.withBoundaryElement(this.dom.root);
1518
- dragRef.started.subscribe(() => {
1519
- this.setDraggingStyles();
1520
- this.dragContainer.dragStarted.emit({ item: this.item.origin });
1521
- });
1522
- dragRef.moved.subscribe((event) => {
1523
- if (isBefore) {
1524
- const x = this.item.refs.x + event.distance.x;
1525
- const width = this.item.refs.width + event.distance.x * -1;
1526
- if (width > dragMinWidth) {
1527
- this.barElement.style.width = width + 'px';
1528
- this.barElement.style.left = x + 'px';
1529
- this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(x), this.ganttUpper.view.getDateByXPoint(x + width));
1530
- }
1531
- }
1532
- else {
1533
- const width = this.item.refs.width + event.distance.x;
1534
- if (width > dragMinWidth) {
1535
- this.barElement.style.width = width + 'px';
1536
- this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(this.item.refs.x), this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width));
1537
- }
1538
- }
1539
- event.source.reset();
1540
- });
1541
- dragRef.ended.subscribe((event) => {
1542
- if (isBefore) {
1543
- const width = this.item.refs.width + event.distance.x * -1;
1544
- if (width > dragMinWidth) {
1545
- this.item.updateDate(this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x), this.item.end);
1546
- }
1547
- else {
1548
- this.item.updateDate(this.item.end.startOfDay(), this.item.end);
1549
- }
1550
- }
1551
- else {
1552
- const width = this.item.refs.width + event.distance.x;
1553
- if (width > dragMinWidth) {
1554
- this.item.updateDate(this.item.start, this.ganttUpper.view.getDateByXPoint(this.item.refs.x + this.item.refs.width + event.distance.x));
1555
- }
1556
- else {
1557
- this.item.updateDate(this.item.start, this.item.start.endOfDay());
1558
- }
1559
- }
1560
- this.clearDraggingStyles();
1561
- this.closeDragBackdrop();
1562
- this.dragContainer.dragEnded.emit({ item: this.item.origin });
1563
- });
1564
- dragRefs.push(dragRef);
1565
- });
1566
- return dragRefs;
1567
- }
1568
- createLinkHandleDrags() {
1569
- const dragRefs = [];
1570
- const handles = this.barElement.querySelectorAll('.link-handles .handle');
1571
- handles.forEach((handle, index) => {
1572
- const isBefore = index === 0;
1573
- const dragRef = this.dragDrop.createDrag(handle);
1574
- dragRef.withBoundaryElement(this.dom.root);
1575
- dragRef.beforeStarted.subscribe(() => {
1576
- handle.style.pointerEvents = 'none';
1577
- if (this.barDragRef) {
1578
- this.barDragRef.disabled = true;
1579
- }
1580
- this.createLinkDraggingLine();
1581
- this.dragContainer.emitLinkDragStarted(isBefore ? 'target' : 'source', this.item);
1582
- });
1583
- dragRef.moved.subscribe(() => {
1584
- const positions = this.calcLinkLinePositions(handle, isBefore);
1585
- this.linkDraggingLine.setAttribute('x1', positions.x1.toString());
1586
- this.linkDraggingLine.setAttribute('y1', positions.y1.toString());
1587
- this.linkDraggingLine.setAttribute('x2', positions.x2.toString());
1588
- this.linkDraggingLine.setAttribute('y2', positions.y2.toString());
1589
- });
1590
- dragRef.ended.subscribe((event) => {
1591
- event.source.reset();
1592
- handle.style.pointerEvents = '';
1593
- if (this.barDragRef) {
1594
- this.barDragRef.disabled = false;
1595
- }
1596
- this.barElement.classList.remove(activeClass);
1597
- this.destroyLinkDraggingLine();
1598
- this.dragContainer.emitLinkDragEnded();
1599
- });
1600
- dragRefs.push(dragRef);
1751
+ setupResize() {
1752
+ this.dom
1753
+ .getResize()
1754
+ .pipe(takeUntil(this.unsubscribe$))
1755
+ .subscribe(() => {
1756
+ this.setupScrollClass();
1601
1757
  });
1602
- return dragRefs;
1603
- }
1604
- openDragBackdrop(dragElement, start, end) {
1605
- const dragMaskElement = this.dom.root.querySelector('.gantt-drag-mask');
1606
- const dragBackdropElement = this.dom.root.querySelector('.gantt-drag-backdrop');
1607
- const rootRect = this.dom.root.getBoundingClientRect();
1608
- const dragRect = dragElement.getBoundingClientRect();
1609
- const left = dragRect.left - rootRect.left - this.dom.side.clientWidth;
1610
- const width = dragRect.right - dragRect.left;
1611
- dragMaskElement.style.left = left + 'px';
1612
- dragMaskElement.style.width = width + 'px';
1613
- dragMaskElement.querySelector('.start').innerHTML = start.format('MM-dd');
1614
- dragMaskElement.querySelector('.end').innerHTML = end.format('MM-dd');
1615
- dragMaskElement.style.display = 'block';
1616
- dragBackdropElement.style.display = 'block';
1617
1758
  }
1618
- closeDragBackdrop() {
1619
- const dragMaskElement = this.dom.root.querySelector('.gantt-drag-mask');
1620
- const dragBackdropElement = this.dom.root.querySelector('.gantt-drag-backdrop');
1621
- dragMaskElement.style.display = 'none';
1622
- dragBackdropElement.style.display = 'none';
1623
- }
1624
- setDraggingStyles() {
1625
- this.barElement.style.pointerEvents = 'none';
1626
- this.barElement.classList.add('gantt-bar-draggable-drag');
1627
- }
1628
- clearDraggingStyles() {
1629
- this.barElement.style.pointerEvents = '';
1630
- this.barElement.classList.remove('gantt-bar-draggable-drag');
1631
- }
1632
- calcLinkLinePositions(target, isBefore) {
1633
- const rootRect = this.dom.root.getBoundingClientRect();
1634
- const targetRect = target.getBoundingClientRect();
1635
- const layerRect = target.parentElement.parentElement.getBoundingClientRect();
1636
- return {
1637
- x1: layerRect.left + (isBefore ? 0 : layerRect.width) - rootRect.left,
1638
- y1: layerRect.top + layerRect.height / 2 - rootRect.top,
1639
- x2: targetRect.left - rootRect.left + targetRect.width / 2,
1640
- y2: targetRect.top - rootRect.top + targetRect.height / 2
1641
- };
1642
- }
1643
- createLinkDraggingLine() {
1644
- if (!this.linkDraggingLine) {
1645
- const svgElement = createSvgElement('svg', 'gantt-link-drag-container');
1646
- const linElement = createSvgElement('line', 'link-dragging-line');
1647
- svgElement.appendChild(linElement);
1648
- this.dom.root.appendChild(svgElement);
1649
- this.linkDraggingLine = linElement;
1650
- }
1651
- }
1652
- destroyLinkDraggingLine() {
1653
- if (this.linkDraggingLine) {
1654
- this.linkDraggingLine.parentElement.remove();
1655
- this.linkDraggingLine = null;
1656
- }
1657
- }
1658
- createDrags(elementRef, item, ganttUpper) {
1659
- this.item = item;
1660
- this.barElement = elementRef.nativeElement;
1661
- this.ganttUpper = ganttUpper;
1662
- if (!item.draggable || (this.dragDisabled && this.linkDragDisabled)) {
1663
- return;
1759
+ setupScrollClass() {
1760
+ const mainContainer = this.dom.mainContainer;
1761
+ const height = mainContainer.offsetHeight;
1762
+ const scrollHeight = mainContainer.scrollHeight;
1763
+ if (scrollHeight > height) {
1764
+ this.elementRef.nativeElement.className = 'gantt gantt-scroll';
1664
1765
  }
1665
1766
  else {
1666
- this.createMouseEvents();
1667
- if (!this.dragDisabled) {
1668
- const dragRef = this.createBarDrag();
1669
- const dragHandlesRefs = this.createBarHandleDrags();
1670
- this.dragRefs.push(dragRef, ...dragHandlesRefs);
1671
- }
1672
- if (!this.linkDragDisabled) {
1673
- const linkDragRefs = this.createLinkHandleDrags();
1674
- this.dragRefs.push(...linkDragRefs);
1675
- }
1767
+ this.elementRef.nativeElement.className = 'gantt';
1676
1768
  }
1677
1769
  }
1678
- ngOnDestroy() {
1679
- this.closeDragBackdrop();
1680
- this.dragRefs.forEach((dragRef) => dragRef.dispose());
1681
- this.destroy$.next();
1682
- this.destroy$.complete();
1770
+ scrollToToday() {
1771
+ const x = this.view.getTodayXPoint();
1772
+ this.dom.scrollMainContainer(x);
1683
1773
  }
1684
1774
  }
1685
- GanttBarDrag.decorators = [
1686
- { type: Injectable }
1687
- ];
1688
- GanttBarDrag.ctorParameters = () => [
1689
- { type: DragDrop },
1690
- { type: GanttDomService },
1691
- { type: GanttDragContainer }
1692
- ];
1775
+ NgxGanttRootComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttRootComponent, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }, { token: GanttDomService }, { token: GanttDragContainer }, { token: GANTT_UPPER_TOKEN }, { token: GanttPrintService, optional: true }], target: i0.ɵɵFactoryTarget.Component });
1776
+ NgxGanttRootComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: NgxGanttRootComponent, selector: "ngx-gantt-root", inputs: { sideWidth: "sideWidth" }, host: { properties: { "class.gantt": "this.ganttClass" } }, providers: [GanttDomService, GanttDragContainer], queries: [{ propertyName: "sideTemplate", first: true, predicate: ["sideTemplate"], descendants: true, static: true }, { propertyName: "mainTemplate", first: true, predicate: ["mainTemplate"], descendants: true, static: true }], ngImport: i0, template: "<div class=\"gantt-side\" [style.width.px]=\"sideWidth\">\n <div class=\"gantt-side-container\">\n <ng-template [ngTemplateOutlet]=\"sideTemplate\"></ng-template>\n </div>\n</div>\n<div class=\"gantt-container\">\n <gantt-calendar-overlay></gantt-calendar-overlay>\n <gantt-drag-backdrop></gantt-drag-backdrop>\n <div class=\"gantt-main\">\n <ng-template [ngTemplateOutlet]=\"mainTemplate\"></ng-template>\n </div>\n</div>\n", components: [{ type: GanttCalendarComponent, selector: "gantt-calendar-overlay" }, { type: GanttDragBackdropComponent, selector: "gantt-drag-backdrop" }], directives: [{ type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }] });
1777
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttRootComponent, decorators: [{
1778
+ type: Component,
1779
+ args: [{
1780
+ selector: 'ngx-gantt-root',
1781
+ templateUrl: './root.component.html',
1782
+ providers: [GanttDomService, GanttDragContainer]
1783
+ }]
1784
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: GanttDomService }, { type: GanttDragContainer }, { type: GanttUpper, decorators: [{
1785
+ type: Inject,
1786
+ args: [GANTT_UPPER_TOKEN]
1787
+ }] }, { type: GanttPrintService, decorators: [{
1788
+ type: Optional
1789
+ }] }]; }, propDecorators: { sideWidth: [{
1790
+ type: Input
1791
+ }], ganttClass: [{
1792
+ type: HostBinding,
1793
+ args: ['class.gantt']
1794
+ }], sideTemplate: [{
1795
+ type: ContentChild,
1796
+ args: ['sideTemplate', { static: true }]
1797
+ }], mainTemplate: [{
1798
+ type: ContentChild,
1799
+ args: ['mainTemplate', { static: true }]
1800
+ }] } });
1693
1801
 
1694
- class GanttItemUpper {
1695
- constructor(elementRef, ganttUpper) {
1696
- this.elementRef = elementRef;
1802
+ var LinkColors;
1803
+ (function (LinkColors) {
1804
+ LinkColors["default"] = "#cacaca";
1805
+ LinkColors["blocked"] = "#FF7575";
1806
+ LinkColors["active"] = "#348FE4";
1807
+ })(LinkColors || (LinkColors = {}));
1808
+ class GanttLinksComponent {
1809
+ constructor(ganttUpper, cdr, elementRef, ganttDragContainer) {
1697
1810
  this.ganttUpper = ganttUpper;
1811
+ this.cdr = cdr;
1812
+ this.elementRef = elementRef;
1813
+ this.ganttDragContainer = ganttDragContainer;
1814
+ this.groups = [];
1815
+ this.items = [];
1816
+ this.lineClick = new EventEmitter();
1817
+ this.links = [];
1818
+ this.linkItems = [];
1819
+ this.bezierWeight = -0.5;
1698
1820
  this.firstChange = true;
1699
1821
  this.unsubscribe$ = new Subject();
1822
+ this.ganttLinksOverlay = true;
1700
1823
  }
1701
- onInit() {
1824
+ ngOnInit() {
1825
+ this.buildLinks();
1702
1826
  this.firstChange = false;
1703
- this.item.refs$.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
1704
- this.setPositions();
1827
+ this.ganttDragContainer.dragStarted.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
1828
+ this.elementRef.nativeElement.style.visibility = 'hidden';
1829
+ });
1830
+ merge(this.ganttUpper.viewChange, this.ganttUpper.expandChange, this.ganttUpper.view.start$, this.ganttUpper.dragEnded, this.ganttUpper.linkDragEnded)
1831
+ .pipe(takeUntil(this.unsubscribe$), skip(1))
1832
+ .subscribe(() => {
1833
+ this.elementRef.nativeElement.style.visibility = 'visible';
1834
+ this.buildLinks();
1835
+ this.cdr.detectChanges();
1705
1836
  });
1706
1837
  }
1707
- onChanges() {
1838
+ ngOnChanges() {
1708
1839
  if (!this.firstChange) {
1709
- this.setPositions();
1840
+ this.buildLinks();
1710
1841
  }
1711
1842
  }
1712
- setPositions() {
1713
- const itemElement = this.elementRef.nativeElement;
1714
- itemElement.style.left = this.item.refs.x + 'px';
1715
- itemElement.style.top = this.item.refs.y + 'px';
1716
- itemElement.style.width = this.item.refs.width + 'px';
1717
- if (this.item.type === GanttItemType.bar) {
1718
- itemElement.style.height = this.ganttUpper.styles.barHeight + 'px';
1719
- }
1720
- else if (this.item.type === GanttItemType.range) {
1721
- itemElement.style.height = rangeHeight + 'px';
1843
+ computeItemPosition() {
1844
+ const lineHeight = this.ganttUpper.styles.lineHeight;
1845
+ const barHeight = this.ganttUpper.styles.barHeight;
1846
+ this.linkItems = [];
1847
+ if (this.groups.length > 0) {
1848
+ let itemNum = 0;
1849
+ let groupNum = 0;
1850
+ this.groups.forEach((group) => {
1851
+ groupNum++;
1852
+ if (group.expanded) {
1853
+ const items = recursiveItems(group.items);
1854
+ items.forEach((item, itemIndex) => {
1855
+ const y = (groupNum + itemNum + itemIndex) * lineHeight + item.refs.y + barHeight / 2;
1856
+ this.linkItems.push(Object.assign(Object.assign({}, item), { before: {
1857
+ x: item.refs.x,
1858
+ y
1859
+ }, after: {
1860
+ x: item.refs.x + item.refs.width,
1861
+ y
1862
+ } }));
1863
+ });
1864
+ itemNum += items.length;
1865
+ }
1866
+ });
1722
1867
  }
1723
1868
  else {
1869
+ const items = recursiveItems(this.items);
1870
+ items.forEach((item, itemIndex) => {
1871
+ const y = itemIndex * lineHeight + item.refs.y + barHeight / 2;
1872
+ this.linkItems.push(Object.assign(Object.assign({}, item), { before: {
1873
+ x: item.refs.x,
1874
+ y
1875
+ }, after: {
1876
+ x: item.refs.x + item.refs.width,
1877
+ y
1878
+ } }));
1879
+ });
1724
1880
  }
1725
1881
  }
1726
- onDestroy() {
1727
- this.unsubscribe$.next();
1728
- this.unsubscribe$.complete();
1729
- }
1730
- }
1731
- GanttItemUpper.decorators = [
1732
- { type: Directive }
1733
- ];
1734
- GanttItemUpper.ctorParameters = () => [
1735
- { type: ElementRef },
1736
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] }
1737
- ];
1738
- GanttItemUpper.propDecorators = {
1739
- template: [{ type: Input }],
1740
- item: [{ type: Input }]
1741
- };
1882
+ generatePath(source, target) {
1883
+ if (source.before && source.after && target.before && target.after) {
1884
+ const x1 = source.after.x;
1885
+ const y1 = source.after.y;
1886
+ const x4 = target.before.x;
1887
+ const y4 = target.before.y;
1888
+ const dx = Math.abs(x4 - x1) * this.bezierWeight;
1889
+ const x2 = x1 - dx;
1890
+ const x3 = x4 + dx;
1891
+ const centerX = (x1 + x4) / 2;
1892
+ const centerY = (y1 + y4) / 2;
1893
+ let controlX = this.ganttUpper.styles.lineHeight / 2;
1894
+ const controlY = this.ganttUpper.styles.lineHeight / 2;
1895
+ if (x1 >= x4) {
1896
+ if (y4 > y1) {
1897
+ if (Math.abs(y4 - y1) <= this.ganttUpper.styles.lineHeight) {
1898
+ return `M ${x1} ${y1}
1899
+ C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 + controlX} ${x1} ${y1 + controlY}
1900
+ L ${x1} ${y1 + controlY} ${centerX} ${centerY}
1742
1901
 
1743
- function linearGradient(sideOrCorner, color, stop) {
1744
- return `linear-gradient(${sideOrCorner},${color} 0%,${stop} 40%)`;
1745
- }
1746
- class NgxGanttBarComponent extends GanttItemUpper {
1747
- constructor(dragContainer, drag, elementRef, ganttUpper) {
1748
- super(elementRef, ganttUpper);
1749
- this.dragContainer = dragContainer;
1750
- this.drag = drag;
1751
- this.ganttUpper = ganttUpper;
1752
- this.barClick = new EventEmitter();
1753
- this.ganttItemClass = true;
1754
- this.color = 'red';
1755
- }
1756
- ngOnInit() {
1757
- super.onInit();
1758
- this.dragContainer.dragEnded.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
1759
- this.setContentBackground();
1760
- });
1761
- }
1762
- ngAfterViewInit() {
1763
- this.drag.createDrags(this.elementRef, this.item, this.ganttUpper);
1764
- this.setContentBackground();
1765
- }
1766
- ngOnChanges() {
1767
- super.onChanges();
1768
- }
1769
- onBarClick(event) {
1770
- this.barClick.emit({ event, item: this.item.origin });
1771
- }
1772
- setContentBackground() {
1773
- const contentElement = this.contentElementRef.nativeElement;
1774
- const color = this.item.color || barBackground;
1775
- const style = this.item.barStyle || {};
1776
- if (this.item.origin.start && this.item.origin.end) {
1777
- style.background = color;
1778
- style.borderRadius = '';
1779
- }
1780
- if (this.item.origin.start && !this.item.origin.end) {
1781
- style.background = linearGradient('to left', hexToRgb(color, 0.55), hexToRgb(color, 1));
1782
- style.borderRadius = '4px 12.5px 12.5px 4px';
1783
- }
1784
- if (!this.item.origin.start && this.item.origin.end) {
1785
- style.background = linearGradient('to right', hexToRgb(color, 0.55), hexToRgb(color, 1));
1786
- style.borderRadius = '12.5px 4px 4px 12.5px';
1787
- }
1788
- if (this.item.progress >= 0) {
1789
- const contentProgressElement = contentElement.querySelector('.gantt-bar-content-progress');
1790
- style.background = hexToRgb(color, 0.3);
1791
- style.borderRadius = '';
1792
- contentProgressElement.style.background = color;
1793
- }
1794
- for (const key in style) {
1795
- if (style.hasOwnProperty(key)) {
1796
- contentElement.style[key] = style[key];
1797
- }
1798
- }
1799
- }
1800
- stopPropagation(event) {
1801
- event.stopPropagation();
1802
- }
1803
- ngOnDestroy() {
1804
- super.onDestroy();
1805
- }
1806
- }
1807
- NgxGanttBarComponent.decorators = [
1808
- { type: Component, args: [{
1809
- selector: 'ngx-gantt-bar,gantt-bar',
1810
- template: "<div class=\"gantt-bar-layer\">\n <div *ngIf=\"item.draggable && ganttUpper.draggable\" class=\"drag-handles\">\n <ng-container>\n <span class=\"handle\" (mousedown)=\"stopPropagation($event)\"></span>\n <span class=\"handle\" (mousedown)=\"stopPropagation($event)\"></span>\n </ng-container>\n </div>\n <div *ngIf=\"item.linkable && ganttUpper.linkable\" class=\"link-handles\">\n <span class=\"handle\"><span class=\"point\"></span></span>\n <span class=\"handle\"> <span class=\"point\"></span></span>\n </div>\n</div>\n<div class=\"gantt-bar-border\"></div>\n<div #content class=\"gantt-bar-content\" (click)=\"onBarClick($event)\">\n <div class=\"gantt-bar-content-progress\" *ngIf=\"item.progress >= 0\" [style.width.%]=\"item.progress * 100\"></div>\n <ng-template [ngTemplateOutlet]=\"template\" [ngTemplateOutletContext]=\"{ item: item.origin, refs: item.refs }\"></ng-template>\n</div>\n",
1811
- providers: [GanttBarDrag]
1812
- },] }
1813
- ];
1814
- NgxGanttBarComponent.ctorParameters = () => [
1815
- { type: GanttDragContainer },
1816
- { type: GanttBarDrag },
1817
- { type: ElementRef },
1818
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] }
1819
- ];
1820
- NgxGanttBarComponent.propDecorators = {
1821
- barClick: [{ type: Output }],
1822
- contentElementRef: [{ type: ViewChild, args: ['content',] }],
1823
- ganttItemClass: [{ type: HostBinding, args: ['class.gantt-bar',] }]
1824
- };
1902
+ M ${x4} ${y4}
1903
+ C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 - controlX} ${x4} ${y4 - controlY}
1904
+ L ${x4} ${y4 - controlY} ${centerX} ${centerY}`;
1905
+ }
1906
+ else {
1907
+ controlX = this.ganttUpper.styles.lineHeight;
1908
+ return `M ${x1} ${y1}
1909
+ C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 + controlX} ${centerX} ${centerY}
1825
1910
 
1826
- class GanttMainComponent {
1827
- constructor(ganttUpper) {
1828
- this.ganttUpper = ganttUpper;
1829
- this.barClick = new EventEmitter();
1830
- this.lineClick = new EventEmitter();
1831
- this.ganttMainClass = true;
1832
- }
1833
- ngOnInit() { }
1834
- trackBy(item, index) {
1835
- return item.id || index;
1836
- }
1837
- }
1838
- GanttMainComponent.decorators = [
1839
- { type: Component, args: [{
1840
- selector: 'gantt-main',
1841
- template: "<gantt-links-overlay [groups]=\"groups\" [items]=\"items\" (lineClick)=\"lineClick.emit($event)\"></gantt-links-overlay>\n<!-- groups -->\n<div class=\"gantt-main-groups\" *ngIf=\"groups && groups.length > 0; else itemsTemplate\" [style.width.px]=\"ganttUpper.view.width\">\n <ng-container *ngFor=\"let group of groups; trackBy: trackBy\">\n <div class=\"gantt-group\" [ngClass]=\"group.class\">\n <ng-template [ngTemplateOutlet]=\"groupHeaderTemplate\" [ngTemplateOutletContext]=\"{ group: group }\"></ng-template>\n </div>\n <div *ngIf=\"group.expanded\" class=\"gantt-items\">\n <ng-template [ngTemplateOutlet]=\"ganttItems\" [ngTemplateOutletContext]=\"{ items: group.items }\"></ng-template>\n </div>\n </ng-container>\n</div>\n<!-- items -->\n<ng-template #itemsTemplate>\n <div class=\"gantt-main-items\" [style.width.px]=\"ganttUpper.view.width\">\n <ng-template [ngTemplateOutlet]=\"ganttItems\" [ngTemplateOutletContext]=\"{ items: items }\"></ng-template>\n </div>\n</ng-template>\n\n<ng-template #ganttItems let-items=\"items\">\n <ng-container *ngFor=\"let item of items; trackBy: trackBy\">\n <div class=\"gantt-item\" [style.height.px]=\"ganttUpper.styles.lineHeight\">\n <ng-container *ngIf=\"item.type | isGanttCustomItem\">\n <ng-template [ngTemplateOutlet]=\"itemTemplate\" [ngTemplateOutletContext]=\"{ item: item.origin, refs: item.refs }\"></ng-template>\n </ng-container>\n <gantt-range *ngIf=\"item.type | isGanttRangeItem\" [template]=\"rangeTemplate\" [item]=\"item\"></gantt-range>\n <gantt-bar *ngIf=\"item.type | isGanttBarItem\" [item]=\"item\" [template]=\"barTemplate\" (barClick)=\"barClick.emit($event)\"></gantt-bar>\n </div>\n <ng-template\n *ngIf=\"item.children && item.expanded\"\n [ngTemplateOutlet]=\"ganttItems\"\n [ngTemplateOutletContext]=\"{ items: item.children }\"\n ></ng-template>\n </ng-container>\n</ng-template>\n"
1842
- },] }
1843
- ];
1844
- GanttMainComponent.ctorParameters = () => [
1845
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] }
1846
- ];
1847
- GanttMainComponent.propDecorators = {
1848
- groups: [{ type: Input }],
1849
- items: [{ type: Input }],
1850
- groupHeaderTemplate: [{ type: Input }],
1851
- itemTemplate: [{ type: Input }],
1852
- barTemplate: [{ type: Input }],
1853
- rangeTemplate: [{ type: Input }],
1854
- barClick: [{ type: Output }],
1855
- lineClick: [{ type: Output }],
1856
- ganttMainClass: [{ type: HostBinding, args: ['class.gantt-main-container',] }]
1857
- };
1858
1911
 
1859
- const angleRight = `<svg xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="amnavigation/angle-right" stroke-width="1" fill-rule="evenodd"><path d="M7.978 11.498l-.005.005L2.3 5.831 3.13 5l4.848 4.848L12.826 5l.83.831-5.673 5.672-.005-.005z" transform="rotate(-90 7.978 8.252)"></path></g></svg>`;
1860
- const angleDown = `<svg xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="aknavigation/angle-down" stroke-width="1" fill-rule="evenodd"><path d="M7.978 11.997l-.005.006L2.3 6.33l.83-.831 4.848 4.848L12.826 5.5l.83.83-5.673 5.673-.005-.006z" ></path></g></svg>`;
1861
- const plusSquare = `<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="kxaction/plus-square" stroke-width="1" fill-rule="evenodd"><path d="M2 0h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm0 1.2a.8.8 0 0 0-.8.8v12a.8.8 0 0 0 .8.8h12a.8.8 0 0 0 .8-.8V2a.8.8 0 0 0-.8-.8H2zm5.45 6.2V4.75h1.2V7.4h2.65v1.2H8.65v2.65h-1.2V8.6H4.8V7.4h2.65z"></path></g></svg>`;
1862
- const minusSquare = `<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fit="" preserveAspectRatio="xMidYMid meet" focusable="false"><g id="jnaction/minus-square" stroke-width="1" fill-rule="evenodd"><path d="M2 0h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V2a2 2 0 0 1 2-2zm0 1.2a.8.8 0 0 0-.8.8v12a.8.8 0 0 0 .8.8h12a.8.8 0 0 0 .8-.8V2a.8.8 0 0 0-.8-.8H2zm2.8 6.2h6.5v1.2H4.8V7.4z"></path></g></svg>`;
1863
- const loadingIcon = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 50 50" style="enable-background:new 0 0 50 50" xml:space="preserve">
1864
- <path fill="#aaa" d="M25.251,6.461c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615V6.461z" transform="rotate(275.098 25 25)">
1865
- <animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"></animateTransform>
1866
- </path>
1867
- </svg>`;
1868
- const emptyIcon = `<svg
1869
- width="148px"
1870
- height="134px"
1871
- viewBox="0 0 148 134"
1872
- version="1.1"
1873
- xmlns="http://www.w3.org/2000/svg"
1874
- xmlns:xlink="http://www.w3.org/1999/xlink"
1875
- >
1876
- <defs>
1877
- <filter x="0.0%" y="0.0%" width="100.0%" height="100.0%" filterUnits="objectBoundingBox" id="filter-1">
1878
- <feGaussianBlur stdDeviation="0" in="SourceGraphic"></feGaussianBlur>
1879
- </filter>
1880
- </defs>
1881
- <g id="148x134" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
1882
- <g id="编组-6" transform="translate(1.000000, 1.000000)">
1883
- <ellipse
1884
- id="椭圆形"
1885
- fill="#EDEEF2"
1886
- opacity="0.3"
1887
- filter="url(#filter-1)"
1888
- cx="73.0800017"
1889
- cy="115.920003"
1890
- rx="73.0800017"
1891
- ry="16.8000004"
1892
- ></ellipse>
1893
- <g id="编组-5" transform="translate(15.120000, 0.000000)">
1894
- <polygon
1895
- id="矩形"
1896
- fill="#E2E4E9"
1897
- points="19.2789848 49.5600011 99.1200023 48.7200011 117.600003 75.9297673 117.600003 92.313049 0 92.313049 0 75.0356267"
1898
- ></polygon>
1899
- <path
1900
- d="M23.5200005,0 L94.0800002,0 C97.7913538,2.06413823e-16 100.8,3.00864655 100.8,6.72000015 L100.8,99.1200023 L100.8,99.1200023 L16.8000004,99.1200023 L16.8000004,6.72000015 C16.8000004,3.00864655 19.8086469,1.56994302e-15 23.5200005,0 Z"
1901
- id="矩形"
1902
- fill="#F9FAFB"
1903
- ></path>
1904
- <path
1905
- d="M30.9200007,12.4400003 L86.6800019,12.4400003 C88.5356787,12.4400003 90.040002,13.9443236 90.040002,15.8000004 L90.040002,42.000001 C90.040002,43.8556778 88.5356787,45.360001 86.6800019,45.360001 L30.9200007,45.360001 C29.0643239,45.360001 27.5600006,43.8556778 27.5600006,42.000001 L27.5600006,15.8000004 C27.5600006,13.9443236 29.0643239,12.4400003 30.9200007,12.4400003 Z"
1906
- id="矩形"
1907
- fill="#E8EAEE"
1908
- ></path>
1909
- <text
1910
- id="&lt;/null&gt;"
1911
- font-family="PingFangSC-Medium, PingFang SC"
1912
- font-size="15.1200003"
1913
- font-weight="400"
1914
- fill="#BCBECD"
1915
- >
1916
- <tspan x="33.6000008" y="32.8000004">&lt;/null&gt;</tspan>
1917
- </text>
1918
- <rect id="矩形" fill="#E8EAEE" x="27.5600006" y="52.0800012" width="61.4800014" height="5.04000011" rx="2.52000006"></rect>
1919
- <rect
1920
- id="矩形备份"
1921
- fill="#E8EAEE"
1922
- x="27.5600006"
1923
- y="63.8400014"
1924
- width="61.4800014"
1925
- height="5.04000011"
1926
- rx="2.52000006"
1927
- ></rect>
1928
- <path
1929
- d="M0,75.6000017 L29.280235,75.6000017 C32.0637502,75.6000017 34.3202352,77.8564866 34.3202352,80.6400018 L34.3202352,86.2591426 C34.3202352,89.0426578 36.5767201,91.2991427 39.3602353,91.2991427 L78.4136737,91.2991427 C81.1971889,91.2991427 83.4536738,89.0426578 83.4536738,86.2591426 L83.4536738,80.6400018 C83.4536738,77.8564866 85.7101587,75.6000017 88.4936739,75.6000017 L117.600003,75.6000017 L117.600003,75.6000017 L117.600003,110.880003 C117.600003,115.519195 113.839194,119.280003 109.200002,119.280003 L8.40000019,119.280003 C3.76080819,119.280003 -6.53729019e-15,115.519195 0,110.880003 L0,75.6000017 L0,75.6000017 Z"
1930
- id="矩形"
1931
- fill="#EDEFF2"
1932
- ></path>
1933
- </g>
1934
- </g>
1935
- </g>
1936
- </svg>`;
1937
- const icons = {
1938
- 'angle-right': angleRight,
1939
- 'angle-down': angleDown,
1940
- 'plus-square': plusSquare,
1941
- 'minus-square': minusSquare,
1942
- loading: loadingIcon,
1943
- empty: emptyIcon
1944
- };
1912
+ M ${x4} ${y4}
1913
+ C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 - controlX} ${centerX} ${centerY}`;
1914
+ }
1915
+ }
1916
+ else {
1917
+ if (Math.abs(y4 - y1) <= this.ganttUpper.styles.lineHeight) {
1918
+ return `M ${x1} ${y1}
1919
+ C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 - controlX} ${x1} ${y1 - controlY}
1920
+ L ${x1} ${y1 - controlY} ${centerX} ${centerY}
1945
1921
 
1946
- class GanttIconComponent {
1947
- constructor(elementRef) {
1948
- this.elementRef = elementRef;
1949
- this.isIcon = true;
1922
+ M ${x4} ${y4}
1923
+ C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 + controlX} ${x4} ${y4 + controlY}
1924
+ L ${x4} ${y4 + controlY} ${centerX} ${centerY}
1925
+ `;
1926
+ }
1927
+ else {
1928
+ controlX = this.ganttUpper.styles.lineHeight;
1929
+ return `M ${x1} ${y1}
1930
+ C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 - controlX} ${centerX} ${centerY}
1931
+
1932
+ M ${x4} ${y4}
1933
+ C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 + controlX} ${centerX} ${centerY}`;
1934
+ }
1935
+ }
1936
+ }
1937
+ return `M ${x1} ${y1} C ${x2} ${y1} ${x3} ${y4} ${x4} ${y4}`;
1938
+ }
1939
+ }
1940
+ buildLinks() {
1941
+ this.computeItemPosition();
1942
+ this.links = [];
1943
+ this.linkItems.forEach((source) => {
1944
+ if (source.origin.start || source.origin.end) {
1945
+ source.links.forEach((linkId) => {
1946
+ const target = this.linkItems.find((item) => item.id === linkId);
1947
+ if (target && (target.origin.start || target.origin.end)) {
1948
+ this.links.push({
1949
+ path: this.generatePath(source, target),
1950
+ source: source.origin,
1951
+ target: target.origin,
1952
+ color: source.end.getTime() > target.start.getTime() ? LinkColors.blocked : LinkColors.default
1953
+ });
1954
+ }
1955
+ });
1956
+ }
1957
+ });
1950
1958
  }
1951
- set iconName(name) {
1952
- this.setSvg(name);
1959
+ trackBy(index) {
1960
+ return index;
1953
1961
  }
1954
- ngOnInit() { }
1955
- ngAfterViewInit() { }
1956
- setSvg(name) {
1957
- const iconSvg = icons[name];
1958
- if (iconSvg) {
1959
- this.elementRef.nativeElement.innerHTML = iconSvg;
1962
+ onLineClick(event, link) {
1963
+ this.lineClick.emit({
1964
+ event,
1965
+ source: link.source,
1966
+ target: link.target
1967
+ });
1968
+ }
1969
+ mouseEnterPath(link) {
1970
+ if (link.color === LinkColors.default) {
1971
+ link.color = LinkColors.active;
1960
1972
  }
1961
- else {
1962
- this.elementRef.nativeElement.innerHTML = '';
1973
+ }
1974
+ mouseLeavePath(link) {
1975
+ if (link.color === LinkColors.active) {
1976
+ link.color = LinkColors.default;
1963
1977
  }
1964
1978
  }
1965
- }
1966
- GanttIconComponent.decorators = [
1967
- { type: Component, args: [{
1968
- selector: 'gantt-icon',
1969
- template: ''
1970
- },] }
1971
- ];
1972
- GanttIconComponent.ctorParameters = () => [
1973
- { type: ElementRef }
1974
- ];
1975
- GanttIconComponent.propDecorators = {
1976
- isIcon: [{ type: HostBinding, args: ['class.gantt-icon',] }],
1977
- iconName: [{ type: Input }]
1978
- };
1979
-
1980
- class GanttDragBackdropComponent {
1981
- constructor() {
1982
- this.backdropClass = true;
1979
+ ngOnDestroy() {
1980
+ this.unsubscribe$.next();
1981
+ this.unsubscribe$.complete();
1983
1982
  }
1984
- ngOnInit() { }
1985
1983
  }
1986
- GanttDragBackdropComponent.decorators = [
1987
- { type: Component, args: [{
1988
- selector: 'gantt-drag-backdrop',
1989
- template: "<div class=\"gantt-drag-mask\">\n <div class=\"date-range\">\n <span class=\"start\"></span>\n <span class=\"end\"></span>\n </div>\n</div>\n"
1990
- },] }
1991
- ];
1992
- GanttDragBackdropComponent.ctorParameters = () => [];
1993
- GanttDragBackdropComponent.propDecorators = {
1994
- backdropClass: [{ type: HostBinding, args: ['class.gantt-drag-backdrop',] }]
1995
- };
1984
+ GanttLinksComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttLinksComponent, deps: [{ token: GANTT_UPPER_TOKEN }, { token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: GanttDragContainer }], target: i0.ɵɵFactoryTarget.Component });
1985
+ GanttLinksComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: GanttLinksComponent, selector: "gantt-links-overlay", inputs: { groups: "groups", items: "items" }, outputs: { lineClick: "lineClick" }, host: { properties: { "class.gantt-links-overlay": "this.ganttLinksOverlay" } }, usesOnChanges: true, ngImport: i0, template: "<svg [attr.width]=\"ganttUpper.view.width\" class=\"gantt-links-overlay-main\">\n <ng-container *ngFor=\"let link of links; let i = index; trackBy: trackBy\">\n <path [attr.d]=\"link.path\" fill=\"transparent\" stroke-width=\"2\" [attr.stroke]=\"link.color\" pointer-events=\"none\"></path>\n <g>\n <path\n class=\"link-line\"\n (click)=\"onLineClick($event, link)\"\n (mouseenter)=\"mouseEnterPath(link)\"\n (mouseleave)=\"mouseLeavePath(link)\"\n [attr.d]=\"link.path\"\n stroke=\"transparent\"\n stroke-width=\"9\"\n fill=\"none\"\n cursor=\"pointer\"\n ></path>\n </g>\n </ng-container>\n <line class=\"link-dragging-line\"></line>\n</svg>\n", directives: [{ type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }] });
1986
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttLinksComponent, decorators: [{
1987
+ type: Component,
1988
+ args: [{
1989
+ selector: 'gantt-links-overlay',
1990
+ templateUrl: './links.component.html'
1991
+ }]
1992
+ }], ctorParameters: function () { return [{ type: GanttUpper, decorators: [{
1993
+ type: Inject,
1994
+ args: [GANTT_UPPER_TOKEN]
1995
+ }] }, { type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: GanttDragContainer }]; }, propDecorators: { groups: [{
1996
+ type: Input
1997
+ }], items: [{
1998
+ type: Input
1999
+ }], lineClick: [{
2000
+ type: Output
2001
+ }], ganttLinksOverlay: [{
2002
+ type: HostBinding,
2003
+ args: ['class.gantt-links-overlay']
2004
+ }] } });
1996
2005
 
1997
- var LinkColors;
1998
- (function (LinkColors) {
1999
- LinkColors["default"] = "#cacaca";
2000
- LinkColors["blocked"] = "#FF7575";
2001
- LinkColors["active"] = "#348FE4";
2002
- })(LinkColors || (LinkColors = {}));
2003
- class GanttLinksComponent {
2004
- constructor(ganttUpper, cdr, elementRef, ganttDragContainer) {
2005
- this.ganttUpper = ganttUpper;
2006
- this.cdr = cdr;
2006
+ class GanttItemUpper {
2007
+ constructor(elementRef, ganttUpper) {
2007
2008
  this.elementRef = elementRef;
2008
- this.ganttDragContainer = ganttDragContainer;
2009
- this.groups = [];
2010
- this.items = [];
2011
- this.lineClick = new EventEmitter();
2012
- this.links = [];
2013
- this.linkItems = [];
2014
- this.bezierWeight = -0.5;
2009
+ this.ganttUpper = ganttUpper;
2015
2010
  this.firstChange = true;
2016
2011
  this.unsubscribe$ = new Subject();
2017
- this.ganttLinksOverlay = true;
2018
2012
  }
2019
- ngOnInit() {
2020
- this.buildLinks();
2013
+ onInit() {
2021
2014
  this.firstChange = false;
2022
- this.ganttDragContainer.dragStarted.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
2023
- this.elementRef.nativeElement.style.visibility = 'hidden';
2024
- });
2025
- merge(this.ganttUpper.viewChange, this.ganttUpper.expandChange, this.ganttUpper.view.start$, this.ganttUpper.dragEnded, this.ganttUpper.linkDragEnded)
2026
- .pipe(takeUntil(this.unsubscribe$), skip(1))
2027
- .subscribe(() => {
2028
- this.elementRef.nativeElement.style.visibility = 'visible';
2029
- this.buildLinks();
2030
- this.cdr.detectChanges();
2015
+ this.item.refs$.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
2016
+ this.setPositions();
2031
2017
  });
2032
2018
  }
2033
- ngOnChanges() {
2019
+ onChanges() {
2034
2020
  if (!this.firstChange) {
2035
- this.buildLinks();
2021
+ this.setPositions();
2036
2022
  }
2037
2023
  }
2038
- computeItemPosition() {
2039
- const lineHeight = this.ganttUpper.styles.lineHeight;
2040
- const barHeight = this.ganttUpper.styles.barHeight;
2041
- this.linkItems = [];
2042
- if (this.groups.length > 0) {
2043
- let itemNum = 0;
2044
- let groupNum = 0;
2045
- this.groups.forEach((group) => {
2046
- groupNum++;
2047
- if (group.expanded) {
2048
- const items = recursiveItems(group.items);
2049
- items.forEach((item, itemIndex) => {
2050
- const y = (groupNum + itemNum + itemIndex) * lineHeight + item.refs.y + barHeight / 2;
2051
- this.linkItems.push(Object.assign(Object.assign({}, item), { before: {
2052
- x: item.refs.x,
2053
- y
2054
- }, after: {
2055
- x: item.refs.x + item.refs.width,
2056
- y
2057
- } }));
2058
- });
2059
- itemNum += items.length;
2060
- }
2061
- });
2024
+ setPositions() {
2025
+ const itemElement = this.elementRef.nativeElement;
2026
+ itemElement.style.left = this.item.refs.x + 'px';
2027
+ itemElement.style.top = this.item.refs.y + 'px';
2028
+ itemElement.style.width = this.item.refs.width + 'px';
2029
+ if (this.item.type === GanttItemType.bar) {
2030
+ itemElement.style.height = this.ganttUpper.styles.barHeight + 'px';
2031
+ }
2032
+ else if (this.item.type === GanttItemType.range) {
2033
+ itemElement.style.height = rangeHeight + 'px';
2062
2034
  }
2063
2035
  else {
2064
- const items = recursiveItems(this.items);
2065
- items.forEach((item, itemIndex) => {
2066
- const y = itemIndex * lineHeight + item.refs.y + barHeight / 2;
2067
- this.linkItems.push(Object.assign(Object.assign({}, item), { before: {
2068
- x: item.refs.x,
2069
- y
2070
- }, after: {
2071
- x: item.refs.x + item.refs.width,
2072
- y
2073
- } }));
2036
+ }
2037
+ }
2038
+ onDestroy() {
2039
+ this.unsubscribe$.next();
2040
+ this.unsubscribe$.complete();
2041
+ }
2042
+ }
2043
+ GanttItemUpper.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttItemUpper, deps: [{ token: i0.ElementRef }, { token: GANTT_UPPER_TOKEN }], target: i0.ɵɵFactoryTarget.Directive });
2044
+ GanttItemUpper.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.1.2", type: GanttItemUpper, inputs: { template: "template", item: "item" }, ngImport: i0 });
2045
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttItemUpper, decorators: [{
2046
+ type: Directive
2047
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: GanttUpper, decorators: [{
2048
+ type: Inject,
2049
+ args: [GANTT_UPPER_TOKEN]
2050
+ }] }]; }, propDecorators: { template: [{
2051
+ type: Input
2052
+ }], item: [{
2053
+ type: Input
2054
+ }] } });
2055
+
2056
+ class NgxGanttRangeComponent extends GanttItemUpper {
2057
+ constructor(elementRef, ganttUpper) {
2058
+ super(elementRef, ganttUpper);
2059
+ this.ganttRangeClass = true;
2060
+ }
2061
+ ngOnInit() {
2062
+ super.onInit();
2063
+ }
2064
+ ngOnChanges() {
2065
+ super.onChanges();
2066
+ }
2067
+ ngOnDestroy() {
2068
+ super.onDestroy();
2069
+ }
2070
+ }
2071
+ NgxGanttRangeComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttRangeComponent, deps: [{ token: i0.ElementRef }, { token: GANTT_UPPER_TOKEN }], target: i0.ɵɵFactoryTarget.Component });
2072
+ NgxGanttRangeComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: NgxGanttRangeComponent, selector: "ngx-gantt-range,gantt-range", host: { properties: { "class.gantt-range": "this.ganttRangeClass" } }, usesInheritance: true, usesOnChanges: true, ngImport: i0, template: "<ng-container *ngIf=\"item.start && item.end\">\n <div class=\"gantt-range-main\">\n <div class=\"gantt-range-main-progress\" *ngIf=\"item.progress >= 0\" [style.width.%]=\"item.progress * 100\"></div>\n </div>\n <div class=\"gantt-range-triangle left\"></div>\n <div class=\"gantt-range-triangle right\"></div>\n <ng-template [ngTemplateOutlet]=\"template\" [ngTemplateOutletContext]=\"{ item: item.origin, refs: item.refs }\"></ng-template>\n</ng-container>\n", directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }] });
2073
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttRangeComponent, decorators: [{
2074
+ type: Component,
2075
+ args: [{
2076
+ selector: 'ngx-gantt-range,gantt-range',
2077
+ templateUrl: './range.component.html'
2078
+ }]
2079
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: GanttUpper, decorators: [{
2080
+ type: Inject,
2081
+ args: [GANTT_UPPER_TOKEN]
2082
+ }] }]; }, propDecorators: { ganttRangeClass: [{
2083
+ type: HostBinding,
2084
+ args: ['class.gantt-range']
2085
+ }] } });
2086
+
2087
+ const dragMinWidth = 10;
2088
+ const activeClass = 'gantt-bar-active';
2089
+ const linkDropClass = 'gantt-bar-link-drop';
2090
+ function createSvgElement(qualifiedName, className) {
2091
+ const element = document.createElementNS('http://www.w3.org/2000/svg', qualifiedName);
2092
+ element.classList.add(className);
2093
+ return element;
2094
+ }
2095
+ class GanttBarDrag {
2096
+ constructor(dragDrop, dom, dragContainer) {
2097
+ this.dragDrop = dragDrop;
2098
+ this.dom = dom;
2099
+ this.dragContainer = dragContainer;
2100
+ this.dragRefs = [];
2101
+ this.destroy$ = new Subject();
2102
+ }
2103
+ get dragDisabled() {
2104
+ return !this.item.draggable || !this.ganttUpper.draggable;
2105
+ }
2106
+ get linkDragDisabled() {
2107
+ return !this.item.linkable || !this.ganttUpper.linkable;
2108
+ }
2109
+ createMouseEvents() {
2110
+ fromEvent(this.barElement, 'mouseenter')
2111
+ .pipe(takeUntil(this.destroy$))
2112
+ .subscribe(() => {
2113
+ if (this.dragContainer.linkDraggingId && this.dragContainer.linkDraggingId !== this.item.id) {
2114
+ if (this.item.linkable) {
2115
+ this.barElement.classList.add(linkDropClass);
2116
+ this.dragContainer.emitLinkDragEntered(this.item);
2117
+ }
2118
+ }
2119
+ else {
2120
+ this.barElement.classList.add(activeClass);
2121
+ }
2122
+ });
2123
+ fromEvent(this.barElement, 'mouseleave')
2124
+ .pipe(takeUntil(this.destroy$))
2125
+ .subscribe(() => {
2126
+ if (!this.dragContainer.linkDraggingId) {
2127
+ this.barElement.classList.remove(activeClass);
2128
+ }
2129
+ else {
2130
+ this.dragContainer.emitLinkDragLeaved();
2131
+ }
2132
+ this.barElement.classList.remove(linkDropClass);
2133
+ });
2134
+ }
2135
+ createBarDrag() {
2136
+ const dragRef = this.dragDrop.createDrag(this.barElement);
2137
+ dragRef.lockAxis = 'x';
2138
+ dragRef.started.subscribe(() => {
2139
+ this.setDraggingStyles();
2140
+ this.dragContainer.dragStarted.emit({ item: this.item.origin });
2141
+ });
2142
+ dragRef.moved.subscribe((event) => {
2143
+ const x = this.item.refs.x + event.distance.x;
2144
+ const days = differenceInCalendarDays(this.item.end.value, this.item.start.value);
2145
+ const start = this.ganttUpper.view.getDateByXPoint(x);
2146
+ const end = start.addDays(days);
2147
+ this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(x), end);
2148
+ });
2149
+ dragRef.ended.subscribe((event) => {
2150
+ const days = differenceInCalendarDays(this.item.end.value, this.item.start.value);
2151
+ const start = this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x);
2152
+ const end = start.addDays(days);
2153
+ this.item.updateDate(start, end);
2154
+ this.clearDraggingStyles();
2155
+ this.closeDragBackdrop();
2156
+ event.source.reset();
2157
+ this.dragContainer.dragEnded.emit({ item: this.item.origin });
2158
+ });
2159
+ this.barDragRef = dragRef;
2160
+ return dragRef;
2161
+ }
2162
+ createBarHandleDrags() {
2163
+ const dragRefs = [];
2164
+ const handles = this.barElement.querySelectorAll('.drag-handles .handle');
2165
+ handles.forEach((handle, index) => {
2166
+ const isBefore = index === 0;
2167
+ const dragRef = this.dragDrop.createDrag(handle);
2168
+ dragRef.lockAxis = 'x';
2169
+ dragRef.withBoundaryElement(this.dom.root);
2170
+ dragRef.started.subscribe(() => {
2171
+ this.setDraggingStyles();
2172
+ this.dragContainer.dragStarted.emit({ item: this.item.origin });
2173
+ });
2174
+ dragRef.moved.subscribe((event) => {
2175
+ if (isBefore) {
2176
+ const x = this.item.refs.x + event.distance.x;
2177
+ const width = this.item.refs.width + event.distance.x * -1;
2178
+ if (width > dragMinWidth) {
2179
+ this.barElement.style.width = width + 'px';
2180
+ this.barElement.style.left = x + 'px';
2181
+ this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(x), this.ganttUpper.view.getDateByXPoint(x + width));
2182
+ }
2183
+ }
2184
+ else {
2185
+ const width = this.item.refs.width + event.distance.x;
2186
+ if (width > dragMinWidth) {
2187
+ this.barElement.style.width = width + 'px';
2188
+ this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(this.item.refs.x), this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width));
2189
+ }
2190
+ }
2191
+ event.source.reset();
2074
2192
  });
2075
- }
2076
- }
2077
- generatePath(source, target) {
2078
- if (source.before && source.after && target.before && target.after) {
2079
- const x1 = source.after.x;
2080
- const y1 = source.after.y;
2081
- const x4 = target.before.x;
2082
- const y4 = target.before.y;
2083
- const dx = Math.abs(x4 - x1) * this.bezierWeight;
2084
- const x2 = x1 - dx;
2085
- const x3 = x4 + dx;
2086
- const centerX = (x1 + x4) / 2;
2087
- const centerY = (y1 + y4) / 2;
2088
- let controlX = this.ganttUpper.styles.lineHeight / 2;
2089
- const controlY = this.ganttUpper.styles.lineHeight / 2;
2090
- if (x1 >= x4) {
2091
- if (y4 > y1) {
2092
- if (Math.abs(y4 - y1) <= this.ganttUpper.styles.lineHeight) {
2093
- return `M ${x1} ${y1}
2094
- C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 + controlX} ${x1} ${y1 + controlY}
2095
- L ${x1} ${y1 + controlY} ${centerX} ${centerY}
2096
-
2097
- M ${x4} ${y4}
2098
- C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 - controlX} ${x4} ${y4 - controlY}
2099
- L ${x4} ${y4 - controlY} ${centerX} ${centerY}`;
2193
+ dragRef.ended.subscribe((event) => {
2194
+ if (isBefore) {
2195
+ const width = this.item.refs.width + event.distance.x * -1;
2196
+ if (width > dragMinWidth) {
2197
+ this.item.updateDate(this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x), this.item.end);
2100
2198
  }
2101
2199
  else {
2102
- controlX = this.ganttUpper.styles.lineHeight;
2103
- return `M ${x1} ${y1}
2104
- C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 + controlX} ${centerX} ${centerY}
2105
-
2106
-
2107
- M ${x4} ${y4}
2108
- C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 - controlX} ${centerX} ${centerY}`;
2200
+ this.item.updateDate(this.item.end.startOfDay(), this.item.end);
2109
2201
  }
2110
2202
  }
2111
2203
  else {
2112
- if (Math.abs(y4 - y1) <= this.ganttUpper.styles.lineHeight) {
2113
- return `M ${x1} ${y1}
2114
- C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 - controlX} ${x1} ${y1 - controlY}
2115
- L ${x1} ${y1 - controlY} ${centerX} ${centerY}
2116
-
2117
- M ${x4} ${y4}
2118
- C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 + controlX} ${x4} ${y4 + controlY}
2119
- L ${x4} ${y4 + controlY} ${centerX} ${centerY}
2120
- `;
2204
+ const width = this.item.refs.width + event.distance.x;
2205
+ if (width > dragMinWidth) {
2206
+ this.item.updateDate(this.item.start, this.ganttUpper.view.getDateByXPoint(this.item.refs.x + this.item.refs.width + event.distance.x));
2121
2207
  }
2122
2208
  else {
2123
- controlX = this.ganttUpper.styles.lineHeight;
2124
- return `M ${x1} ${y1}
2125
- C ${x1 + controlX} ${y1} ${x1 + controlX} ${y1 - controlX} ${centerX} ${centerY}
2126
-
2127
- M ${x4} ${y4}
2128
- C ${x4 - controlX} ${y4} ${x4 - controlX} ${y4 + controlX} ${centerX} ${centerY}`;
2209
+ this.item.updateDate(this.item.start, this.item.start.endOfDay());
2129
2210
  }
2130
2211
  }
2131
- }
2132
- return `M ${x1} ${y1} C ${x2} ${y1} ${x3} ${y4} ${x4} ${y4}`;
2133
- }
2134
- }
2135
- buildLinks() {
2136
- this.computeItemPosition();
2137
- this.links = [];
2138
- this.linkItems.forEach((source) => {
2139
- if (source.origin.start || source.origin.end) {
2140
- source.links.forEach((linkId) => {
2141
- const target = this.linkItems.find((item) => item.id === linkId);
2142
- if (target && (target.origin.start || target.origin.end)) {
2143
- this.links.push({
2144
- path: this.generatePath(source, target),
2145
- source: source.origin,
2146
- target: target.origin,
2147
- color: source.end.getTime() > target.start.getTime() ? LinkColors.blocked : LinkColors.default
2148
- });
2149
- }
2150
- });
2151
- }
2152
- });
2153
- }
2154
- trackBy(index) {
2155
- return index;
2156
- }
2157
- onLineClick(event, link) {
2158
- this.lineClick.emit({
2159
- event,
2160
- source: link.source,
2161
- target: link.target
2212
+ this.clearDraggingStyles();
2213
+ this.closeDragBackdrop();
2214
+ this.dragContainer.dragEnded.emit({ item: this.item.origin });
2215
+ });
2216
+ dragRefs.push(dragRef);
2162
2217
  });
2218
+ return dragRefs;
2163
2219
  }
2164
- mouseEnterPath(link) {
2165
- if (link.color === LinkColors.default) {
2166
- link.color = LinkColors.active;
2167
- }
2168
- }
2169
- mouseLeavePath(link) {
2170
- if (link.color === LinkColors.active) {
2171
- link.color = LinkColors.default;
2172
- }
2173
- }
2174
- ngOnDestroy() {
2175
- this.unsubscribe$.next();
2176
- this.unsubscribe$.complete();
2177
- }
2178
- }
2179
- GanttLinksComponent.decorators = [
2180
- { type: Component, args: [{
2181
- selector: 'gantt-links-overlay',
2182
- template: "<svg [attr.width]=\"ganttUpper.view.width\" class=\"gantt-links-overlay-main\">\n <ng-container *ngFor=\"let link of links; let i = index; trackBy: trackBy\">\n <path [attr.d]=\"link.path\" fill=\"transparent\" stroke-width=\"2\" [attr.stroke]=\"link.color\" pointer-events=\"none\"></path>\n <g>\n <path\n class=\"link-line\"\n (click)=\"onLineClick($event, link)\"\n (mouseenter)=\"mouseEnterPath(link)\"\n (mouseleave)=\"mouseLeavePath(link)\"\n [attr.d]=\"link.path\"\n stroke=\"transparent\"\n stroke-width=\"9\"\n fill=\"none\"\n cursor=\"pointer\"\n ></path>\n </g>\n </ng-container>\n <line class=\"link-dragging-line\"></line>\n</svg>\n"
2183
- },] }
2184
- ];
2185
- GanttLinksComponent.ctorParameters = () => [
2186
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] },
2187
- { type: ChangeDetectorRef },
2188
- { type: ElementRef },
2189
- { type: GanttDragContainer }
2190
- ];
2191
- GanttLinksComponent.propDecorators = {
2192
- groups: [{ type: Input }],
2193
- items: [{ type: Input }],
2194
- lineClick: [{ type: Output }],
2195
- ganttLinksOverlay: [{ type: HostBinding, args: ['class.gantt-links-overlay',] }]
2196
- };
2197
-
2198
- class GanttPrintService {
2199
- constructor() { }
2200
- setInlineStyles(targetElem) {
2201
- const svgElements = Array.from(targetElem.getElementsByTagName('svg'));
2202
- for (const svgElement of svgElements) {
2203
- this.recursElementChildren(svgElement);
2204
- }
2205
- }
2206
- recursElementChildren(node) {
2207
- const transformProperties = [
2208
- 'fill',
2209
- 'color',
2210
- 'font-size',
2211
- 'stroke',
2212
- 'font',
2213
- 'text-anchor',
2214
- 'stroke-dasharray',
2215
- 'shape-rendering',
2216
- 'stroke-width'
2217
- ];
2218
- if (!node.style) {
2219
- return;
2220
- }
2221
- const styles = getComputedStyle(node);
2222
- for (const transformProperty of transformProperties) {
2223
- node.style[transformProperty] = styles[transformProperty];
2224
- }
2225
- for (const child of Array.from(node.childNodes)) {
2226
- this.recursElementChildren(child);
2227
- }
2228
- }
2229
- register(root) {
2230
- this.root = root.nativeElement;
2231
- this.mainContainer = this.root.getElementsByClassName('gantt-main-container')[0];
2232
- }
2233
- print(name = 'download', ignoreElementClass) {
2234
- const root = this.root;
2235
- const mainContainer = this.mainContainer;
2236
- // set print width
2237
- const printWidth = root.offsetWidth;
2238
- // set print height
2239
- const printHeight = root.offsetHeight - mainContainer.offsetHeight + mainContainer.scrollHeight;
2240
- html2canvas(root, {
2241
- logging: false,
2242
- allowTaint: true,
2243
- useCORS: true,
2244
- width: printWidth,
2245
- height: printHeight,
2246
- ignoreElements: (element) => {
2247
- if (ignoreElementClass && element.classList.contains(ignoreElementClass)) {
2248
- return true;
2249
- }
2250
- if (element.classList.contains('gantt-calendar-today-overlay')) {
2251
- return true;
2220
+ createLinkHandleDrags() {
2221
+ const dragRefs = [];
2222
+ const handles = this.barElement.querySelectorAll('.link-handles .handle');
2223
+ handles.forEach((handle, index) => {
2224
+ const isBefore = index === 0;
2225
+ const dragRef = this.dragDrop.createDrag(handle);
2226
+ dragRef.withBoundaryElement(this.dom.root);
2227
+ dragRef.beforeStarted.subscribe(() => {
2228
+ handle.style.pointerEvents = 'none';
2229
+ if (this.barDragRef) {
2230
+ this.barDragRef.disabled = true;
2252
2231
  }
2253
- },
2254
- onclone: (cloneDocument) => {
2255
- const ganttClass = root.className;
2256
- const cloneGanttDom = cloneDocument.querySelector(`.${ganttClass.replace(/\s+/g, '.')}`);
2257
- const cloneGanttContainerDom = cloneDocument.querySelector('.gantt-container');
2258
- const cloneCalendarOverlay = cloneDocument.querySelector('.gantt-calendar-overlay-main');
2259
- const cloneLinksOverlay = cloneDocument.querySelector('.gantt-links-overlay-main');
2260
- // change targetDom width
2261
- cloneGanttDom.style.width = `${printWidth}px`;
2262
- cloneGanttDom.style.height = `${printHeight}px`;
2263
- cloneGanttDom.style.overflow = `unset`;
2264
- cloneGanttContainerDom.style.backgroundColor = '#fff';
2265
- cloneCalendarOverlay.setAttribute('height', `${printHeight}`);
2266
- cloneCalendarOverlay.setAttribute('style', `background: transparent`);
2267
- if (cloneLinksOverlay) {
2268
- cloneLinksOverlay.setAttribute('height', `${printHeight}`);
2269
- cloneLinksOverlay.setAttribute('style', `height: ${printHeight}px`);
2232
+ this.createLinkDraggingLine();
2233
+ this.dragContainer.emitLinkDragStarted(isBefore ? 'target' : 'source', this.item);
2234
+ });
2235
+ dragRef.moved.subscribe(() => {
2236
+ const positions = this.calcLinkLinePositions(handle, isBefore);
2237
+ this.linkDraggingLine.setAttribute('x1', positions.x1.toString());
2238
+ this.linkDraggingLine.setAttribute('y1', positions.y1.toString());
2239
+ this.linkDraggingLine.setAttribute('x2', positions.x2.toString());
2240
+ this.linkDraggingLine.setAttribute('y2', positions.y2.toString());
2241
+ });
2242
+ dragRef.ended.subscribe((event) => {
2243
+ event.source.reset();
2244
+ handle.style.pointerEvents = '';
2245
+ if (this.barDragRef) {
2246
+ this.barDragRef.disabled = false;
2270
2247
  }
2271
- // setInlineStyles for svg
2272
- this.setInlineStyles(cloneGanttDom);
2273
- }
2274
- }).then((canvas) => {
2275
- const link = document.createElement('a');
2276
- const dataUrl = canvas.toDataURL('image/png');
2277
- link.download = `${name}.png`;
2278
- link.href = dataUrl;
2279
- link.click();
2280
- });
2281
- }
2282
- }
2283
- GanttPrintService.decorators = [
2284
- { type: Injectable }
2285
- ];
2286
- GanttPrintService.ctorParameters = () => [];
2287
-
2288
- class NgxGanttRootComponent {
2289
- constructor(elementRef, ngZone, dom, dragContainer, ganttUpper, printService) {
2290
- this.elementRef = elementRef;
2291
- this.ngZone = ngZone;
2292
- this.dom = dom;
2293
- this.dragContainer = dragContainer;
2294
- this.ganttUpper = ganttUpper;
2295
- this.printService = printService;
2296
- this.ganttClass = true;
2297
- this.unsubscribe$ = new Subject();
2298
- this.ganttUpper.dragContainer = dragContainer;
2299
- }
2300
- get view() {
2301
- return this.ganttUpper.view;
2302
- }
2303
- ngOnInit() {
2304
- this.ngZone.onStable.pipe(take(1)).subscribe(() => {
2305
- this.dom.initialize(this.elementRef);
2306
- if (this.printService) {
2307
- this.printService.register(this.elementRef);
2308
- }
2309
- this.setupScrollClass();
2310
- this.setupResize();
2311
- this.setupViewScroll();
2312
- // 优化初始化时Scroll滚动体验问题,通过透明度解决,默认透明度为0,滚动结束后恢复
2313
- this.elementRef.nativeElement.style.opacity = '1';
2314
- this.ganttUpper.viewChange.pipe(startWith(null)).subscribe(() => {
2315
- this.scrollToToday();
2248
+ this.barElement.classList.remove(activeClass);
2249
+ this.destroyLinkDraggingLine();
2250
+ this.dragContainer.emitLinkDragEnded();
2316
2251
  });
2252
+ dragRefs.push(dragRef);
2317
2253
  });
2254
+ return dragRefs;
2318
2255
  }
2319
- setupViewScroll() {
2320
- if (this.ganttUpper.disabledLoadOnScroll) {
2321
- return;
2256
+ openDragBackdrop(dragElement, start, end) {
2257
+ const dragMaskElement = this.dom.root.querySelector('.gantt-drag-mask');
2258
+ const dragBackdropElement = this.dom.root.querySelector('.gantt-drag-backdrop');
2259
+ const rootRect = this.dom.root.getBoundingClientRect();
2260
+ const dragRect = dragElement.getBoundingClientRect();
2261
+ const left = dragRect.left - rootRect.left - this.dom.side.clientWidth;
2262
+ const width = dragRect.right - dragRect.left;
2263
+ dragMaskElement.style.left = left + 'px';
2264
+ dragMaskElement.style.width = width + 'px';
2265
+ dragMaskElement.querySelector('.start').innerHTML = start.format('MM-dd');
2266
+ dragMaskElement.querySelector('.end').innerHTML = end.format('MM-dd');
2267
+ dragMaskElement.style.display = 'block';
2268
+ dragBackdropElement.style.display = 'block';
2269
+ }
2270
+ closeDragBackdrop() {
2271
+ const dragMaskElement = this.dom.root.querySelector('.gantt-drag-mask');
2272
+ const dragBackdropElement = this.dom.root.querySelector('.gantt-drag-backdrop');
2273
+ dragMaskElement.style.display = 'none';
2274
+ dragBackdropElement.style.display = 'none';
2275
+ }
2276
+ setDraggingStyles() {
2277
+ this.barElement.style.pointerEvents = 'none';
2278
+ this.barElement.classList.add('gantt-bar-draggable-drag');
2279
+ }
2280
+ clearDraggingStyles() {
2281
+ this.barElement.style.pointerEvents = '';
2282
+ this.barElement.classList.remove('gantt-bar-draggable-drag');
2283
+ }
2284
+ calcLinkLinePositions(target, isBefore) {
2285
+ const rootRect = this.dom.root.getBoundingClientRect();
2286
+ const targetRect = target.getBoundingClientRect();
2287
+ const layerRect = target.parentElement.parentElement.getBoundingClientRect();
2288
+ return {
2289
+ x1: layerRect.left + (isBefore ? 0 : layerRect.width) - rootRect.left,
2290
+ y1: layerRect.top + layerRect.height / 2 - rootRect.top,
2291
+ x2: targetRect.left - rootRect.left + targetRect.width / 2,
2292
+ y2: targetRect.top - rootRect.top + targetRect.height / 2
2293
+ };
2294
+ }
2295
+ createLinkDraggingLine() {
2296
+ if (!this.linkDraggingLine) {
2297
+ const svgElement = createSvgElement('svg', 'gantt-link-drag-container');
2298
+ const linElement = createSvgElement('line', 'link-dragging-line');
2299
+ svgElement.appendChild(linElement);
2300
+ this.dom.root.appendChild(svgElement);
2301
+ this.linkDraggingLine = linElement;
2322
2302
  }
2323
- this.dom
2324
- .getViewerScroll()
2325
- .pipe(takeUntil(this.unsubscribe$))
2326
- .subscribe((event) => {
2327
- if (event.direction === ScrollDirection.LEFT) {
2328
- const dates = this.view.addStartDate();
2329
- if (dates) {
2330
- event.target.scrollLeft += this.view.getDateRangeWidth(dates.start, dates.end);
2331
- this.ngZone.run(() => {
2332
- this.ganttUpper.loadOnScroll.emit({ start: dates.start.getUnixTime(), end: dates.end.getUnixTime() });
2333
- });
2334
- }
2335
- }
2336
- if (event.direction === ScrollDirection.RIGHT) {
2337
- const dates = this.view.addEndDate();
2338
- if (dates) {
2339
- this.ngZone.run(() => {
2340
- this.ganttUpper.loadOnScroll.emit({ start: dates.start.getUnixTime(), end: dates.end.getUnixTime() });
2341
- });
2342
- }
2343
- }
2344
- });
2345
2303
  }
2346
- setupResize() {
2347
- this.dom
2348
- .getResize()
2349
- .pipe(takeUntil(this.unsubscribe$))
2350
- .subscribe(() => {
2351
- this.setupScrollClass();
2352
- });
2304
+ destroyLinkDraggingLine() {
2305
+ if (this.linkDraggingLine) {
2306
+ this.linkDraggingLine.parentElement.remove();
2307
+ this.linkDraggingLine = null;
2308
+ }
2353
2309
  }
2354
- setupScrollClass() {
2355
- const mainContainer = this.dom.mainContainer;
2356
- const height = mainContainer.offsetHeight;
2357
- const scrollHeight = mainContainer.scrollHeight;
2358
- if (scrollHeight > height) {
2359
- this.elementRef.nativeElement.className = 'gantt gantt-scroll';
2310
+ createDrags(elementRef, item, ganttUpper) {
2311
+ this.item = item;
2312
+ this.barElement = elementRef.nativeElement;
2313
+ this.ganttUpper = ganttUpper;
2314
+ if (!item.draggable || (this.dragDisabled && this.linkDragDisabled)) {
2315
+ return;
2360
2316
  }
2361
2317
  else {
2362
- this.elementRef.nativeElement.className = 'gantt';
2318
+ this.createMouseEvents();
2319
+ if (!this.dragDisabled) {
2320
+ const dragRef = this.createBarDrag();
2321
+ const dragHandlesRefs = this.createBarHandleDrags();
2322
+ this.dragRefs.push(dragRef, ...dragHandlesRefs);
2323
+ }
2324
+ if (!this.linkDragDisabled) {
2325
+ const linkDragRefs = this.createLinkHandleDrags();
2326
+ this.dragRefs.push(...linkDragRefs);
2327
+ }
2363
2328
  }
2364
2329
  }
2365
- scrollToToday() {
2366
- const x = this.view.getTodayXPoint();
2367
- this.dom.scrollMainContainer(x);
2330
+ ngOnDestroy() {
2331
+ this.closeDragBackdrop();
2332
+ this.dragRefs.forEach((dragRef) => dragRef.dispose());
2333
+ this.destroy$.next();
2334
+ this.destroy$.complete();
2368
2335
  }
2369
2336
  }
2370
- NgxGanttRootComponent.decorators = [
2371
- { type: Component, args: [{
2372
- selector: 'ngx-gantt-root',
2373
- template: "<div class=\"gantt-side\" [style.width.px]=\"sideWidth\">\n <div class=\"gantt-side-container\">\n <ng-template [ngTemplateOutlet]=\"sideTemplate\"></ng-template>\n </div>\n</div>\n<div class=\"gantt-container\">\n <gantt-calendar-overlay></gantt-calendar-overlay>\n <gantt-drag-backdrop></gantt-drag-backdrop>\n <div class=\"gantt-main\">\n <ng-template [ngTemplateOutlet]=\"mainTemplate\"></ng-template>\n </div>\n</div>\n",
2374
- providers: [GanttDomService, GanttDragContainer]
2375
- },] }
2376
- ];
2377
- NgxGanttRootComponent.ctorParameters = () => [
2378
- { type: ElementRef },
2379
- { type: NgZone },
2380
- { type: GanttDomService },
2381
- { type: GanttDragContainer },
2382
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] },
2383
- { type: GanttPrintService, decorators: [{ type: Optional }] }
2384
- ];
2385
- NgxGanttRootComponent.propDecorators = {
2386
- sideWidth: [{ type: Input }],
2387
- ganttClass: [{ type: HostBinding, args: ['class.gantt',] }],
2388
- sideTemplate: [{ type: ContentChild, args: ['sideTemplate', { static: true },] }],
2389
- mainTemplate: [{ type: ContentChild, args: ['mainTemplate', { static: true },] }]
2390
- };
2337
+ GanttBarDrag.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttBarDrag, deps: [{ token: i1.DragDrop }, { token: GanttDomService }, { token: GanttDragContainer }], target: i0.ɵɵFactoryTarget.Injectable });
2338
+ GanttBarDrag.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttBarDrag });
2339
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttBarDrag, decorators: [{
2340
+ type: Injectable
2341
+ }], ctorParameters: function () { return [{ type: i1.DragDrop }, { type: GanttDomService }, { type: GanttDragContainer }]; } });
2391
2342
 
2392
- class NgxGanttRangeComponent extends GanttItemUpper {
2393
- constructor(elementRef, ganttUpper) {
2343
+ function linearGradient(sideOrCorner, color, stop) {
2344
+ return `linear-gradient(${sideOrCorner},${color} 0%,${stop} 40%)`;
2345
+ }
2346
+ class NgxGanttBarComponent extends GanttItemUpper {
2347
+ constructor(dragContainer, drag, elementRef, ganttUpper) {
2394
2348
  super(elementRef, ganttUpper);
2395
- this.ganttRangeClass = true;
2349
+ this.dragContainer = dragContainer;
2350
+ this.drag = drag;
2351
+ this.ganttUpper = ganttUpper;
2352
+ this.barClick = new EventEmitter();
2353
+ this.ganttItemClass = true;
2354
+ this.color = 'red';
2396
2355
  }
2397
2356
  ngOnInit() {
2398
2357
  super.onInit();
2358
+ this.dragContainer.dragEnded.pipe(takeUntil(this.unsubscribe$)).subscribe(() => {
2359
+ this.setContentBackground();
2360
+ });
2361
+ }
2362
+ ngAfterViewInit() {
2363
+ this.drag.createDrags(this.elementRef, this.item, this.ganttUpper);
2364
+ this.setContentBackground();
2399
2365
  }
2400
2366
  ngOnChanges() {
2401
2367
  super.onChanges();
2402
2368
  }
2369
+ onBarClick(event) {
2370
+ this.barClick.emit({ event, item: this.item.origin });
2371
+ }
2372
+ setContentBackground() {
2373
+ const contentElement = this.contentElementRef.nativeElement;
2374
+ const color = this.item.color || barBackground;
2375
+ const style = this.item.barStyle || {};
2376
+ if (this.item.origin.start && this.item.origin.end) {
2377
+ style.background = color;
2378
+ style.borderRadius = '';
2379
+ }
2380
+ if (this.item.origin.start && !this.item.origin.end) {
2381
+ style.background = linearGradient('to left', hexToRgb(color, 0.55), hexToRgb(color, 1));
2382
+ style.borderRadius = '4px 12.5px 12.5px 4px';
2383
+ }
2384
+ if (!this.item.origin.start && this.item.origin.end) {
2385
+ style.background = linearGradient('to right', hexToRgb(color, 0.55), hexToRgb(color, 1));
2386
+ style.borderRadius = '12.5px 4px 4px 12.5px';
2387
+ }
2388
+ if (this.item.progress >= 0) {
2389
+ const contentProgressElement = contentElement.querySelector('.gantt-bar-content-progress');
2390
+ style.background = hexToRgb(color, 0.3);
2391
+ style.borderRadius = '';
2392
+ contentProgressElement.style.background = color;
2393
+ }
2394
+ for (const key in style) {
2395
+ if (style.hasOwnProperty(key)) {
2396
+ contentElement.style[key] = style[key];
2397
+ }
2398
+ }
2399
+ }
2400
+ stopPropagation(event) {
2401
+ event.stopPropagation();
2402
+ }
2403
2403
  ngOnDestroy() {
2404
2404
  super.onDestroy();
2405
2405
  }
2406
2406
  }
2407
- NgxGanttRangeComponent.decorators = [
2408
- { type: Component, args: [{
2409
- selector: 'ngx-gantt-range,gantt-range',
2410
- template: "<ng-container *ngIf=\"item.start && item.end\">\n <div class=\"gantt-range-main\">\n <div class=\"gantt-range-main-progress\" *ngIf=\"item.progress >= 0\" [style.width.%]=\"item.progress * 100\"></div>\n </div>\n <div class=\"gantt-range-triangle left\"></div>\n <div class=\"gantt-range-triangle right\"></div>\n <ng-template [ngTemplateOutlet]=\"template\" [ngTemplateOutletContext]=\"{ item: item.origin, refs: item.refs }\"></ng-template>\n</ng-container>\n"
2411
- },] }
2412
- ];
2413
- NgxGanttRangeComponent.ctorParameters = () => [
2414
- { type: ElementRef },
2415
- { type: GanttUpper, decorators: [{ type: Inject, args: [GANTT_UPPER_TOKEN,] }] }
2416
- ];
2417
- NgxGanttRangeComponent.propDecorators = {
2418
- ganttRangeClass: [{ type: HostBinding, args: ['class.gantt-range',] }]
2419
- };
2407
+ NgxGanttBarComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttBarComponent, deps: [{ token: GanttDragContainer }, { token: GanttBarDrag }, { token: i0.ElementRef }, { token: GANTT_UPPER_TOKEN }], target: i0.ɵɵFactoryTarget.Component });
2408
+ NgxGanttBarComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: NgxGanttBarComponent, selector: "ngx-gantt-bar,gantt-bar", outputs: { barClick: "barClick" }, host: { properties: { "class.gantt-bar": "this.ganttItemClass" } }, providers: [GanttBarDrag], viewQueries: [{ propertyName: "contentElementRef", first: true, predicate: ["content"], descendants: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: "<div class=\"gantt-bar-layer\">\n <div *ngIf=\"item.draggable && ganttUpper.draggable\" class=\"drag-handles\">\n <ng-container>\n <span class=\"handle\" (mousedown)=\"stopPropagation($event)\"></span>\n <span class=\"handle\" (mousedown)=\"stopPropagation($event)\"></span>\n </ng-container>\n </div>\n <div *ngIf=\"item.linkable && ganttUpper.linkable\" class=\"link-handles\">\n <span class=\"handle\"><span class=\"point\"></span></span>\n <span class=\"handle\"> <span class=\"point\"></span></span>\n </div>\n</div>\n<div class=\"gantt-bar-border\"></div>\n<div #content class=\"gantt-bar-content\" (click)=\"onBarClick($event)\">\n <div class=\"gantt-bar-content-progress\" *ngIf=\"item.progress >= 0\" [style.width.%]=\"item.progress * 100\"></div>\n <ng-template [ngTemplateOutlet]=\"template\" [ngTemplateOutletContext]=\"{ item: item.origin, refs: item.refs }\"></ng-template>\n</div>\n", directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }] });
2409
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttBarComponent, decorators: [{
2410
+ type: Component,
2411
+ args: [{
2412
+ selector: 'ngx-gantt-bar,gantt-bar',
2413
+ templateUrl: './bar.component.html',
2414
+ providers: [GanttBarDrag]
2415
+ }]
2416
+ }], ctorParameters: function () { return [{ type: GanttDragContainer }, { type: GanttBarDrag }, { type: i0.ElementRef }, { type: GanttUpper, decorators: [{
2417
+ type: Inject,
2418
+ args: [GANTT_UPPER_TOKEN]
2419
+ }] }]; }, propDecorators: { barClick: [{
2420
+ type: Output
2421
+ }], contentElementRef: [{
2422
+ type: ViewChild,
2423
+ args: ['content']
2424
+ }], ganttItemClass: [{
2425
+ type: HostBinding,
2426
+ args: ['class.gantt-bar']
2427
+ }] } });
2420
2428
 
2421
- class IsGanttRangeItemPipe {
2422
- transform(value) {
2423
- return value === GanttItemType.range;
2429
+ class GanttMainComponent {
2430
+ constructor(ganttUpper) {
2431
+ this.ganttUpper = ganttUpper;
2432
+ this.barClick = new EventEmitter();
2433
+ this.lineClick = new EventEmitter();
2434
+ this.ganttMainClass = true;
2424
2435
  }
2425
- }
2426
- IsGanttRangeItemPipe.decorators = [
2427
- { type: Pipe, args: [{
2428
- name: 'isGanttRangeItem'
2429
- },] }
2430
- ];
2431
- class IsGanttBarItemPipe {
2432
- transform(value) {
2433
- return value === GanttItemType.bar;
2436
+ ngOnInit() { }
2437
+ trackBy(item, index) {
2438
+ return item.id || index;
2434
2439
  }
2435
2440
  }
2436
- IsGanttBarItemPipe.decorators = [
2437
- { type: Pipe, args: [{
2438
- name: 'isGanttBarItem'
2439
- },] }
2440
- ];
2441
- class IsGanttCustomItemPipe {
2442
- transform(value) {
2443
- return value === GanttItemType.custom;
2441
+ GanttMainComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttMainComponent, deps: [{ token: GANTT_UPPER_TOKEN }], target: i0.ɵɵFactoryTarget.Component });
2442
+ GanttMainComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: GanttMainComponent, selector: "gantt-main", inputs: { groups: "groups", items: "items", groupHeaderTemplate: "groupHeaderTemplate", itemTemplate: "itemTemplate", barTemplate: "barTemplate", rangeTemplate: "rangeTemplate" }, outputs: { barClick: "barClick", lineClick: "lineClick" }, host: { properties: { "class.gantt-main-container": "this.ganttMainClass" } }, ngImport: i0, template: "<gantt-links-overlay [groups]=\"groups\" [items]=\"items\" (lineClick)=\"lineClick.emit($event)\"></gantt-links-overlay>\n<!-- groups -->\n<div class=\"gantt-main-groups\" *ngIf=\"groups && groups.length > 0; else itemsTemplate\" [style.width.px]=\"ganttUpper.view.width\">\n <ng-container *ngFor=\"let group of groups; trackBy: trackBy\">\n <div class=\"gantt-group\" [ngClass]=\"group.class\">\n <ng-template [ngTemplateOutlet]=\"groupHeaderTemplate\" [ngTemplateOutletContext]=\"{ group: group }\"></ng-template>\n </div>\n <div *ngIf=\"group.expanded\" class=\"gantt-items\">\n <ng-template [ngTemplateOutlet]=\"ganttItems\" [ngTemplateOutletContext]=\"{ items: group.items }\"></ng-template>\n </div>\n </ng-container>\n</div>\n<!-- items -->\n<ng-template #itemsTemplate>\n <div class=\"gantt-main-items\" [style.width.px]=\"ganttUpper.view.width\">\n <ng-template [ngTemplateOutlet]=\"ganttItems\" [ngTemplateOutletContext]=\"{ items: items }\"></ng-template>\n </div>\n</ng-template>\n\n<ng-template #ganttItems let-items=\"items\">\n <ng-container *ngFor=\"let item of items; trackBy: trackBy\">\n <div class=\"gantt-item\" [style.height.px]=\"ganttUpper.styles.lineHeight\">\n <ng-container *ngIf=\"item.type | isGanttCustomItem\">\n <ng-template [ngTemplateOutlet]=\"itemTemplate\" [ngTemplateOutletContext]=\"{ item: item.origin, refs: item.refs }\"></ng-template>\n </ng-container>\n <gantt-range *ngIf=\"item.type | isGanttRangeItem\" [template]=\"rangeTemplate\" [item]=\"item\"></gantt-range>\n <gantt-bar *ngIf=\"item.type | isGanttBarItem\" [item]=\"item\" [template]=\"barTemplate\" (barClick)=\"barClick.emit($event)\"></gantt-bar>\n </div>\n <ng-template\n *ngIf=\"item.children && item.expanded\"\n [ngTemplateOutlet]=\"ganttItems\"\n [ngTemplateOutletContext]=\"{ items: item.children }\"\n ></ng-template>\n </ng-container>\n</ng-template>\n", components: [{ type: GanttLinksComponent, selector: "gantt-links-overlay", inputs: ["groups", "items"], outputs: ["lineClick"] }, { type: NgxGanttRangeComponent, selector: "ngx-gantt-range,gantt-range" }, { type: NgxGanttBarComponent, selector: "ngx-gantt-bar,gantt-bar", outputs: ["barClick"] }], directives: [{ type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }], pipes: { "isGanttCustomItem": IsGanttCustomItemPipe, "isGanttRangeItem": IsGanttRangeItemPipe, "isGanttBarItem": IsGanttBarItemPipe } });
2443
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: GanttMainComponent, decorators: [{
2444
+ type: Component,
2445
+ args: [{
2446
+ selector: 'gantt-main',
2447
+ templateUrl: './gantt-main.component.html'
2448
+ }]
2449
+ }], ctorParameters: function () { return [{ type: GanttUpper, decorators: [{
2450
+ type: Inject,
2451
+ args: [GANTT_UPPER_TOKEN]
2452
+ }] }]; }, propDecorators: { groups: [{
2453
+ type: Input
2454
+ }], items: [{
2455
+ type: Input
2456
+ }], groupHeaderTemplate: [{
2457
+ type: Input
2458
+ }], itemTemplate: [{
2459
+ type: Input
2460
+ }], barTemplate: [{
2461
+ type: Input
2462
+ }], rangeTemplate: [{
2463
+ type: Input
2464
+ }], barClick: [{
2465
+ type: Output
2466
+ }], lineClick: [{
2467
+ type: Output
2468
+ }], ganttMainClass: [{
2469
+ type: HostBinding,
2470
+ args: ['class.gantt-main-container']
2471
+ }] } });
2472
+
2473
+ class NgxGanttComponent extends GanttUpper {
2474
+ constructor(elementRef, cdr, ngZone, config) {
2475
+ super(elementRef, cdr, ngZone, config);
2476
+ this.maxLevel = 2;
2477
+ this.linkDragStarted = new EventEmitter();
2478
+ this.linkDragEnded = new EventEmitter();
2479
+ this.lineClick = new EventEmitter();
2480
+ this.ngUnsubscribe$ = new Subject();
2481
+ this.sideTableWidth = sideWidth;
2482
+ }
2483
+ ngOnInit() {
2484
+ super.onInit();
2485
+ this.ngZone.onStable.pipe(take(1)).subscribe(() => {
2486
+ this.dragContainer.linkDragStarted.pipe(takeUntil(this.ngUnsubscribe$)).subscribe((event) => {
2487
+ this.linkDragStarted.emit(event);
2488
+ });
2489
+ this.dragContainer.linkDragEnded.pipe(takeUntil(this.ngUnsubscribe$)).subscribe((event) => {
2490
+ this.linkDragEnded.emit(event);
2491
+ });
2492
+ });
2493
+ }
2494
+ ngAfterViewInit() {
2495
+ this.columns.changes.pipe(startWith(true), takeUntil(this.ngUnsubscribe$)).subscribe(() => {
2496
+ this.columns.forEach((column) => {
2497
+ if (!column.columnWidth) {
2498
+ column.columnWidth = coerceCssPixelValue(defaultColumnWidth);
2499
+ }
2500
+ });
2501
+ this.cdr.detectChanges();
2502
+ });
2503
+ }
2504
+ ngOnChanges(changes) {
2505
+ super.onChanges(changes);
2506
+ }
2507
+ expandChildren(item) {
2508
+ if (!item.expanded) {
2509
+ item.setExpand(true);
2510
+ if (this.async && this.childrenResolve && item.children.length === 0) {
2511
+ item.loading = true;
2512
+ this.childrenResolve(item.origin)
2513
+ .pipe(take(1), finalize(() => {
2514
+ item.loading = false;
2515
+ this.expandChange.emit();
2516
+ this.cdr.detectChanges();
2517
+ }))
2518
+ .subscribe((items) => {
2519
+ item.addChildren(items);
2520
+ this.computeItemsRefs(...item.children);
2521
+ });
2522
+ }
2523
+ else {
2524
+ this.computeItemsRefs(...item.children);
2525
+ this.expandChange.emit();
2526
+ }
2527
+ }
2528
+ else {
2529
+ item.setExpand(false);
2530
+ this.expandChange.emit();
2531
+ }
2532
+ }
2533
+ ngOnDestroy() {
2534
+ super.onDestroy();
2444
2535
  }
2445
2536
  }
2446
- IsGanttCustomItemPipe.decorators = [
2447
- { type: Pipe, args: [{
2448
- name: 'isGanttCustomItem'
2449
- },] }
2450
- ];
2537
+ NgxGanttComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttComponent, deps: [{ token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: GANTT_GLOBAL_CONFIG }], target: i0.ɵɵFactoryTarget.Component });
2538
+ NgxGanttComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.1.2", type: NgxGanttComponent, selector: "ngx-gantt", inputs: { maxLevel: "maxLevel", async: "async", childrenResolve: "childrenResolve", linkable: "linkable" }, outputs: { linkDragStarted: "linkDragStarted", linkDragEnded: "linkDragEnded", lineClick: "lineClick" }, providers: [
2539
+ {
2540
+ provide: GANTT_UPPER_TOKEN,
2541
+ useExisting: NgxGanttComponent
2542
+ },
2543
+ {
2544
+ provide: GANTT_ABSTRACT_TOKEN,
2545
+ useExisting: forwardRef(() => NgxGanttComponent)
2546
+ }
2547
+ ], queries: [{ propertyName: "table", first: true, predicate: NgxGanttTableComponent, descendants: true }, { propertyName: "tableEmptyTemplate", first: true, predicate: ["tableEmpty"], descendants: true, static: true }, { propertyName: "columns", predicate: NgxGanttTableColumnComponent, descendants: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: "<ngx-gantt-root>\n <ng-template #sideTemplate>\n <gantt-table [groups]=\"groups\" [items]=\"items\" [columns]=\"columns\" [groupTemplate]=\"groupTemplate\" [emptyTemplate]=\"tableEmptyTemplate\"></gantt-table>\n </ng-template>\n <ng-template #mainTemplate>\n <gantt-main\n [groups]=\"groups\"\n [items]=\"items\"\n [groupHeaderTemplate]=\"groupHeaderTemplate\"\n [itemTemplate]=\"itemTemplate\"\n [barTemplate]=\"barTemplate\"\n [rangeTemplate]=\"rangeTemplate\"\n (barClick)=\"barClick.emit($event)\"\n (lineClick)=\"lineClick.emit($event)\"\n >\n </gantt-main>\n </ng-template>\n</ngx-gantt-root>\n", components: [{ type: NgxGanttRootComponent, selector: "ngx-gantt-root", inputs: ["sideWidth"] }, { type: GanttTableComponent, selector: "gantt-table", inputs: ["groups", "items", "columns", "groupTemplate", "emptyTemplate"] }, { type: GanttMainComponent, selector: "gantt-main", inputs: ["groups", "items", "groupHeaderTemplate", "itemTemplate", "barTemplate", "rangeTemplate"], outputs: ["barClick", "lineClick"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2548
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttComponent, decorators: [{
2549
+ type: Component,
2550
+ args: [{
2551
+ selector: 'ngx-gantt',
2552
+ templateUrl: './gantt.component.html',
2553
+ changeDetection: ChangeDetectionStrategy.OnPush,
2554
+ providers: [
2555
+ {
2556
+ provide: GANTT_UPPER_TOKEN,
2557
+ useExisting: NgxGanttComponent
2558
+ },
2559
+ {
2560
+ provide: GANTT_ABSTRACT_TOKEN,
2561
+ useExisting: forwardRef(() => NgxGanttComponent)
2562
+ }
2563
+ ]
2564
+ }]
2565
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: undefined, decorators: [{
2566
+ type: Inject,
2567
+ args: [GANTT_GLOBAL_CONFIG]
2568
+ }] }]; }, propDecorators: { maxLevel: [{
2569
+ type: Input
2570
+ }], async: [{
2571
+ type: Input
2572
+ }], childrenResolve: [{
2573
+ type: Input
2574
+ }], linkable: [{
2575
+ type: Input
2576
+ }], linkDragStarted: [{
2577
+ type: Output
2578
+ }], linkDragEnded: [{
2579
+ type: Output
2580
+ }], lineClick: [{
2581
+ type: Output
2582
+ }], table: [{
2583
+ type: ContentChild,
2584
+ args: [NgxGanttTableComponent]
2585
+ }], columns: [{
2586
+ type: ContentChildren,
2587
+ args: [NgxGanttTableColumnComponent, { descendants: true }]
2588
+ }], tableEmptyTemplate: [{
2589
+ type: ContentChild,
2590
+ args: ['tableEmpty', { static: true }]
2591
+ }] } });
2451
2592
 
2452
2593
  class NgxGanttModule {
2453
2594
  }
2454
- NgxGanttModule.decorators = [
2455
- { type: NgModule, args: [{
2456
- imports: [CommonModule, DragDropModule],
2457
- exports: [NgxGanttComponent, NgxGanttTableComponent, NgxGanttTableColumnComponent, NgxGanttRootComponent, NgxGanttBarComponent],
2458
- declarations: [
2459
- NgxGanttComponent,
2460
- NgxGanttTableComponent,
2461
- NgxGanttTableColumnComponent,
2462
- GanttTableComponent,
2463
- GanttMainComponent,
2464
- GanttCalendarComponent,
2465
- GanttLinksComponent,
2466
- NgxGanttBarComponent,
2467
- GanttIconComponent,
2468
- GanttDragBackdropComponent,
2469
- NgxGanttRangeComponent,
2470
- NgxGanttRootComponent,
2471
- IsGanttRangeItemPipe,
2472
- IsGanttBarItemPipe,
2473
- IsGanttCustomItemPipe
2474
- ],
2475
- providers: []
2476
- },] }
2477
- ];
2595
+ NgxGanttModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2596
+ NgxGanttModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttModule, declarations: [NgxGanttComponent,
2597
+ NgxGanttTableComponent,
2598
+ NgxGanttTableColumnComponent,
2599
+ GanttTableComponent,
2600
+ GanttMainComponent,
2601
+ GanttCalendarComponent,
2602
+ GanttLinksComponent,
2603
+ NgxGanttBarComponent,
2604
+ GanttIconComponent,
2605
+ GanttDragBackdropComponent,
2606
+ NgxGanttRangeComponent,
2607
+ NgxGanttRootComponent,
2608
+ IsGanttRangeItemPipe,
2609
+ IsGanttBarItemPipe,
2610
+ IsGanttCustomItemPipe], imports: [CommonModule, DragDropModule], exports: [NgxGanttComponent,
2611
+ NgxGanttTableComponent,
2612
+ NgxGanttTableColumnComponent,
2613
+ NgxGanttRootComponent,
2614
+ NgxGanttBarComponent,
2615
+ NgxGanttRangeComponent] });
2616
+ NgxGanttModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttModule, providers: [
2617
+ {
2618
+ provide: GANTT_GLOBAL_CONFIG,
2619
+ useValue: defaultConfig
2620
+ }
2621
+ ], imports: [[CommonModule, DragDropModule]] });
2622
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0, type: NgxGanttModule, decorators: [{
2623
+ type: NgModule,
2624
+ args: [{
2625
+ imports: [CommonModule, DragDropModule],
2626
+ exports: [
2627
+ NgxGanttComponent,
2628
+ NgxGanttTableComponent,
2629
+ NgxGanttTableColumnComponent,
2630
+ NgxGanttRootComponent,
2631
+ NgxGanttBarComponent,
2632
+ NgxGanttRangeComponent
2633
+ ],
2634
+ declarations: [
2635
+ NgxGanttComponent,
2636
+ NgxGanttTableComponent,
2637
+ NgxGanttTableColumnComponent,
2638
+ GanttTableComponent,
2639
+ GanttMainComponent,
2640
+ GanttCalendarComponent,
2641
+ GanttLinksComponent,
2642
+ NgxGanttBarComponent,
2643
+ GanttIconComponent,
2644
+ GanttDragBackdropComponent,
2645
+ NgxGanttRangeComponent,
2646
+ NgxGanttRootComponent,
2647
+ IsGanttRangeItemPipe,
2648
+ IsGanttBarItemPipe,
2649
+ IsGanttCustomItemPipe
2650
+ ],
2651
+ providers: [
2652
+ {
2653
+ provide: GANTT_GLOBAL_CONFIG,
2654
+ useValue: defaultConfig
2655
+ }
2656
+ ]
2657
+ }]
2658
+ }] });
2478
2659
 
2479
2660
  /*
2480
2661
  * Public API Surface of gantt
@@ -2484,5 +2665,5 @@ NgxGanttModule.decorators = [
2484
2665
  * Generated bundle index. Do not edit.
2485
2666
  */
2486
2667
 
2487
- export { GANTT_UPPER_TOKEN, GanttBarClickEvent, GanttDate, GanttDatePoint, GanttDragEvent, GanttGroupInternal, GanttItemInternal, GanttItemType, GanttItemUpper, GanttLineClickEvent, GanttLinkDragEvent, GanttLoadOnScrollEvent, GanttPrintService, GanttTableEvent, GanttUpper, GanttView, GanttViewType, IsGanttBarItemPipe, IsGanttCustomItemPipe, IsGanttRangeItemPipe, NgxGanttComponent, NgxGanttModule, NgxGanttRootComponent, NgxGanttTableColumnComponent, NgxGanttTableComponent, defaultColumnWidth, minColumnWidth, primaryDatePointTop, secondaryDatePointTop, GanttDomService as ɵa, GanttDragContainer as ɵb, NgxGanttBarComponent as ɵc, GanttBarDrag as ɵd, GanttTableComponent as ɵe, GanttMainComponent as ɵf, GanttCalendarComponent as ɵg, GanttLinksComponent as ɵh, GanttIconComponent as ɵi, GanttDragBackdropComponent as ɵj, NgxGanttRangeComponent as ɵk };
2668
+ export { GANTT_GLOBAL_CONFIG, GANTT_UPPER_TOKEN, GanttBarClickEvent, GanttDate, GanttDatePoint, GanttDragEvent, GanttGroupInternal, GanttItemInternal, GanttItemType, GanttItemUpper, GanttLineClickEvent, GanttLinkDragEvent, GanttLoadOnScrollEvent, GanttPrintService, GanttTableEvent, GanttUpper, GanttView, GanttViewType, IsGanttBarItemPipe, IsGanttCustomItemPipe, IsGanttRangeItemPipe, NgxGanttBarComponent, NgxGanttComponent, NgxGanttModule, NgxGanttRangeComponent, NgxGanttRootComponent, NgxGanttTableColumnComponent, NgxGanttTableComponent, defaultConfig, primaryDatePointTop, secondaryDatePointTop };
2488
2669
  //# sourceMappingURL=worktile-gantt.js.map