Skip to content

feat: ability to drag and drop tiles #1297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2600927
feat(lib-client): ability to drag the tiles
apandura-tibco Feb 27, 2020
95e350c
feat(lib-client): ability to drop tiles in another tile place
apandura-tibco Mar 26, 2020
a22f205
feat(lib-client): small improvement in calculating the previous index…
apandura-tibco Mar 26, 2020
89e95c3
feat(lib-client): Fixed alignment when sorting tiles in branched rows
apandura-tibco Mar 26, 2020
f3db398
feat(lib-client): Work in Progress. Updating state when the drop is done
apandura-tibco Mar 29, 2020
30fa0a8
feat(lib-client): Able to update the links in both state and database
apandura-tibco Apr 1, 2020
87bdcb7
refactor(lib-client): Moved the logic to update the links in the grap…
apandura-tibco Apr 13, 2020
05ab6fa
fix(lib-client): Fix a broken code when there is not change the posit…
apandura-tibco Apr 15, 2020
61d8b06
feature(stream-client): Enabled drag drop feature to the stream plugi…
apandura-tibco Apr 15, 2020
7c99282
refactor(stream-client|lib-client): Moved the common drag drop animat…
apandura-tibco Apr 15, 2020
70d0bca
fix(lib-client): Disabling the drag drop in read-only mode
apandura-tibco Apr 15, 2020
7a76ea4
feat(lib-client): revert drop when dropped in an empty area
ppaidi Apr 16, 2020
02dd52e
style(lib-client): code format
ppaidi Apr 17, 2020
47abf35
enhancement(lib-client): Implemented the tiles to group by zones wher…
apandura-tibco Apr 20, 2020
58f0c03
feature(lib-client): Disabling drag on a activity which cannot have a…
apandura-tibco Apr 20, 2020
07eb0f3
feature(lib-client): Moved common code to revert when dropping in emp…
apandura-tibco Apr 20, 2020
65ce039
feat(lib-client): restrict drop a parent tile in a row which is branc…
ppaidi Apr 23, 2020
c81bf82
fix: remove circular dependency
ppaidi Apr 23, 2020
bf7a110
fix: update row parents list if all rows are deleted
ppaidi Apr 24, 2020
e2ee893
refactor: remove input property bind dependency by maintaining data i…
ppaidi Apr 27, 2020
0c5fa6d
refactor: avoid parameters mutation in the moveItem action's reducer
ppaidi Apr 30, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libs/assets/styles/_drag-drop-animation.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.cdk-drop-list-dragging .cdk-drag {
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
}

.cdk-drop-list {
display: flex;
}
3 changes: 3 additions & 0 deletions libs/lib-client/diagram/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {
DiagramAction,
DiagramActionChild,
DiagramActionSelf,
DiagramActionMove,
Tile,
TaskTile,
TileType,
Expand All @@ -14,3 +15,5 @@ export { DiagramComponent } from './lib/diagram/diagram.component';
export { SELECTED_INSERT_TILE_CLASS, BUTTON_INSERT_CLASS } from './lib/constants';
export { DiagramModule } from './lib/diagram.module';
export { trackTileByFn } from './lib/tiles/track-tile-by';
export { updateLinks } from './lib/drag-tiles';
export { DragTileService } from './lib/drag-tiles';
9 changes: 8 additions & 1 deletion libs/lib-client/diagram/src/lib/action-event-factory.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DiagramActionType } from './interfaces';
import { DiagramActionType, DiagramActionMove } from './interfaces';
import { DiagramActionChild, DiagramActionSelf } from './interfaces';

export const actionEventFactory = {
Expand All @@ -8,6 +8,13 @@ export const actionEventFactory = {
parentId,
};
},
move(id: string, parentId: string): DiagramActionMove {
return {
type: DiagramActionType.Move,
id,
parentId: parentId || null,
};
},
branch(parentId: string): DiagramActionChild {
return {
type: DiagramActionType.Branch,
Expand Down
9 changes: 6 additions & 3 deletions libs/lib-client/diagram/src/lib/diagram.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { NgModule } from '@angular/core';
import { LanguageModule } from '@flogo-web/lib-client/language';
import { CommonModule } from '@angular/common';
import { DragDropModule } from '@angular/cdk/drag-drop';

import { LanguageModule } from '@flogo-web/lib-client/language';

import { DiagramComponent } from './diagram/diagram.component';
import { DiagramRowComponent } from './diagram/diagram-row.component';
Expand All @@ -9,9 +11,10 @@ import { TileTaskComponent } from './tiles/tile-task.component';

import { TileBranchComponent } from './tiles/tile-branch.component';
import { TileSsvgComponent } from './tiles/tiles-svg';
import { DragTileService } from './drag-tiles';

@NgModule({
imports: [CommonModule, LanguageModule],
imports: [CommonModule, LanguageModule, DragDropModule],

exports: [DiagramComponent, TileInsertComponent, TileTaskComponent, TileSsvgComponent],
declarations: [
Expand All @@ -22,6 +25,6 @@ import { TileSsvgComponent } from './tiles/tiles-svg';
TileTaskComponent,
TileSsvgComponent,
],
providers: [],
providers: [DragTileService],
})
export class DiagramModule {}
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
<ng-template ngFor let-tile [ngForOf]="tiles" [ngForTrackBy]="trackTileBy">
<div
*ngIf="tile.type === tileTypes.Padding || tile.type == tileTypes.Placeholder"
<ng-template
ngFor
let-tile
[ngForOf]="groupedTiles?.preDropZone"
[ngForTrackBy]="trackTileBy"
>
<div *ngIf="tile.type === tileTypes.Padding" @tileGeneric class="tile tile--slot"></div>
<flogo-diagram-tile-branch
*ngIf="tile.type === tileTypes.Task"
@tileGeneric
[@.disabled]="tile.type === tileTypes.Placeholder"
class="tile tile--slot"
[class.tile--placeholder]="tile.type === tileTypes.Placeholder"
></div>
<flogo-diagram-tile-insert
*ngIf="tile.type === tileTypes.Insert"
@tileInsert
class="tile--slot"
class="tile--branch"
[tile]="tile"
[currentSelection]="selection"
(select)="onInsertSelected($event)"
></flogo-diagram-tile-insert>
[isReadOnly]="isReadOnly"
[spanRows]="calculateBranchSpan(tile)"
(select)="onTaskSelected($event)"
(remove)="onTaskAction($event)"
></flogo-diagram-tile-branch>
</ng-template>
<div
cdkDropList
cdkDropListOrientation="horizontal"
[cdkDropListDisabled]="isReadOnly"
[cdkDropListEnterPredicate]="restrictTileDrop"
(cdkDropListDropped)="moveTile($event)"
>
<ng-template
ngFor
let-tile
[ngForOf]="groupedTiles?.dropZone"
[ngForTrackBy]="trackTileBy"
>
<flogo-diagram-tile-task
cdkDrag
cdkDragBoundary="flogo-diagram"
@tileTask
[tile]="tile"
[cdkDragData]="tile?.task?.id"
[currentSelection]="selection"
[isReadOnly]="isReadOnly"
(select)="onTaskSelected($event)"
(branch)="onTaskAction($event)"
(remove)="onTaskAction($event)"
(configure)="onTaskAction($event)"
></flogo-diagram-tile-task>
</ng-template>
</div>
<ng-template
ngFor
let-tile
[ngForOf]="groupedTiles?.postDropZone"
[ngForTrackBy]="trackTileBy"
>
<flogo-diagram-tile-task
*ngIf="tile.type === tileTypes.Task && tile.task?.type === nodeTypes.Task"
*ngIf="tile.type === tileTypes.Task"
@tileTask
[tile]="tile"
[currentSelection]="selection"
Expand All @@ -25,15 +62,19 @@
(remove)="onTaskAction($event)"
(configure)="onTaskAction($event)"
></flogo-diagram-tile-task>
<flogo-diagram-tile-branch
*ngIf="tile.type === tileTypes.Task && tile.task?.type === nodeTypes.Branch"
<div
*ngIf="tile.type == tileTypes.Placeholder"
@tileGeneric
class="tile--branch"
[@.disabled]="tile.type === tileTypes.Placeholder"
class="tile tile--slot"
[class.tile--placeholder]="tile.type === tileTypes.Placeholder"
></div>
<flogo-diagram-tile-insert
*ngIf="tile.type === tileTypes.Insert"
@tileInsert
class="tile--slot"
[tile]="tile"
[currentSelection]="selection"
[isReadOnly]="isReadOnly"
[spanRows]="calculateBranchSpan(tile)"
(select)="onTaskSelected($event)"
(remove)="onTaskAction($event)"
></flogo-diagram-tile-branch>
(select)="onInsertSelected($event)"
></flogo-diagram-tile-insert>
</ng-template>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../_styles';
@import '~@flogo-web/assets/styles/_drag-drop-animation';

:host {
.row();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import {
Output,
SimpleChanges,
} from '@angular/core';
import { CdkDragDrop, CdkDrag } from '@angular/cdk/drag-drop';

import { NodeType } from '@flogo-web/lib-client/core';

import { Tile, TaskTile, TileType, DiagramAction, DiagramSelection } from '../interfaces';
import { DiagramAction, DiagramSelection, TaskTile, Tile, TileType } from '../interfaces';
import { actionEventFactory } from '../action-event-factory';
import { RowIndexService, isTaskTile, isInsertTile } from '../shared';
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',
Expand All @@ -31,15 +32,17 @@ export class DiagramRowComponent implements OnChanges {
@Output() action = new EventEmitter<DiagramAction>();

tileTypes = TileType;
nodeTypes = NodeType;
tiles: Tile[];
groupedTiles: TilesGroupedByZone<Tile>;
trackTileBy = trackTileByFn;

constructor(private rowIndexService: RowIndexService) {}
constructor(
private rowIndexService: RowIndexService,
private dragService: DragTileService
) {}

ngOnChanges({ row: rowChange }: SimpleChanges) {
if (rowChange) {
this.tiles = this.row;
this.groupedTiles = this.dragService.groupTilesByZone(this.row);
}
}

Expand All @@ -60,4 +63,21 @@ export class DiagramRowComponent implements OnChanges {
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);
};
}
26 changes: 14 additions & 12 deletions libs/lib-client/diagram/src/lib/diagram/diagram.component.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<flogo-diagram-tiles-svg></flogo-diagram-tiles-svg>
<flogo-diagram-row
*ngFor="let row of tileMatrix; trackBy: trackRowBy; let rowIndex = index"
@diagramRow
[row]="row"
[rowIndex]="tileMatrix.length - rowIndex - 1"
[selection]="selection"
[isReadOnly]="isReadOnly"
(action)="onAction($event)"
class="diagram-row"
>
</flogo-diagram-row>
<div class="group" cdkDropListGroup>
<flogo-diagram-tiles-svg></flogo-diagram-tiles-svg>
<flogo-diagram-row
*ngFor="let row of tileMatrix; trackBy: trackRowBy; let rowIndex = index"
@diagramRow
[row]="row"
[rowIndex]="tileMatrix.length - rowIndex - 1"
[selection]="selection"
[isReadOnly]="isReadOnly"
(action)="onAction($event)"
class="diagram-row"
>
</flogo-diagram-row>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:host {
.group {
display: flex;
flex-direction: column-reverse;
position: relative;
Expand Down
13 changes: 12 additions & 1 deletion libs/lib-client/diagram/src/lib/diagram/diagram.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { EMPTY_MATRIX, RowIndexService } from '../shared';
import { makeRenderableMatrix, TileMatrix } from '../renderable-model';
import { diagramAnimations } from './diagram.animations';
import { diagramRowTracker } from './diagram-row-tracker';
import { DragTileService } from '../drag-tiles';

@Component({
// temporal name until old diagram implementation is removed
Expand All @@ -39,7 +40,10 @@ export class DiagramComponent implements OnChanges, OnDestroy {

trackRowBy: TrackByFunction<Tile[]>;

constructor(private rowIndexService: RowIndexService) {
constructor(
private rowIndexService: RowIndexService,
private dragService: DragTileService
) {
this.trackRowBy = diagramRowTracker(this);
}

Expand All @@ -66,8 +70,15 @@ export class DiagramComponent implements OnChanges, OnDestroy {
// matrix is reversed to make sure html stack order always goes from bottom to top
// i.e. top rows are rendered in front of bottom rows, this ensures branches don't display on top of the tiles above
this.tileMatrix = tileMatrix.reverse();
this.updateRowParents();
} else if (!this.isReadOnly) {
this.tileMatrix = EMPTY_MATRIX;
}
}

private updateRowParents() {
this.dragService.updateRowParents(this.tileMatrix, taskId =>
this.rowIndexService.getRowIndexForTask(taskId)
);
}
}
Loading