-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathdiagram-row.component.ts
83 lines (72 loc) · 2.51 KB
/
diagram-row.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
HostBinding,
Input,
OnChanges,
Output,
SimpleChanges,
} from '@angular/core';
import { CdkDragDrop, CdkDrag } from '@angular/cdk/drag-drop';
import { DiagramAction, DiagramSelection, TaskTile, Tile, TileType } from '../interfaces';
import { actionEventFactory } from '../action-event-factory';
import { RowIndexService } from '../shared';
import { rowAnimations } from './diagram-row.animations';
import { trackTileByFn } from '../tiles/track-tile-by';
import { DragTileService, TilesGroupedByZone } from '../drag-tiles';
@Component({
selector: 'flogo-diagram-row',
templateUrl: './diagram-row.component.html',
styleUrls: ['./diagram-row.component.less'],
animations: rowAnimations,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DiagramRowComponent implements OnChanges {
@Input() row: Tile[];
@Input() selection: DiagramSelection;
@Input() rowIndex: number;
@HostBinding('class.is-readonly') @Input() isReadOnly = false;
@Output() action = new EventEmitter<DiagramAction>();
tileTypes = TileType;
groupedTiles: TilesGroupedByZone<Tile>;
trackTileBy = trackTileByFn;
constructor(
private rowIndexService: RowIndexService,
private dragService: DragTileService
) {}
ngOnChanges({ row: rowChange }: SimpleChanges) {
if (rowChange) {
this.groupedTiles = this.dragService.groupTilesByZone(this.row);
}
}
calculateBranchSpan(taskTile: TaskTile) {
const [parentId] = taskTile.task.parents;
const parentRowIndex = this.rowIndexService.getRowIndexForTask(parentId);
return this.rowIndex - parentRowIndex;
}
onInsertSelected(parentId: string) {
this.action.emit(actionEventFactory.insert(parentId));
}
onTaskSelected(taskTile: TaskTile) {
this.action.emit(actionEventFactory.select(taskTile.task.id));
}
onTaskAction(action: DiagramAction) {
this.action.emit(action);
}
moveTile(event: CdkDragDrop<Tile[]>) {
const dropActionData = this.dragService.prepareDropActionData(event, () => {
const branchTile: TaskTile = this.groupedTiles.preDropZone.find(
(tile: TaskTile) => tile.type === TileType.Task
) as TaskTile;
return branchTile?.task.id;
});
if (dropActionData) {
const { itemId, parentId } = dropActionData;
this.action.emit(actionEventFactory.move(itemId, parentId));
}
}
restrictTileDrop = (dragEvent: CdkDrag) => {
return this.dragService.isTileAllowedToDropInRow(dragEvent.data, this.rowIndex);
};
}