@@ -256,18 +256,7 @@ export class RenderService implements Flo.Renderer {
256
256
257
257
initializeNewLink ( link : dia . Link , viewerDescriptor : Flo . ViewerDescriptor ) {
258
258
link . set ( 'smooth' , true ) ;
259
- link . attr ( 'metadata/metadata/unselectable' , 'true' ) ;
260
- // var isTapLink = link.attr('props/isTapLink');
261
- // if (isTapLink === 'true') {
262
- // var linkView = paperAndGraph.paper.findViewByModel(link);
263
- // _.each(linkView.el.querySelectorAll('.connection, .marker-source, .marker-target'), function(connection) {
264
- // joint.V(connection).addClass('tapped-output-from-app');
265
- // });
266
- // }
267
- // TODO remove this on link delete !!
268
- // paperAndGraph.paper.findViewByModel(link).on('switch',function() {
269
- // handleLinkEvent(paperAndGraph.paper, 'switch', link);
270
- // });
259
+ link . attr ( 'metadata/metadata/unselectable' , true ) ;
271
260
}
272
261
273
262
isSemanticProperty ( propertyPath : string ) : boolean {
@@ -312,9 +301,9 @@ export class RenderService implements Flo.Renderer {
312
301
if ( changedPropertyPath === 'props/isTapLink' ) {
313
302
const isTapLink = link . attr ( 'props/isTapLink' ) ;
314
303
const linkView = paper . findViewByModel ( link ) ;
315
- console . log ( 'Adjusting link class isTapLink?' + isTapLink ) ;
304
+ console . log ( 'Adjusting link class isTapLink? ' + isTapLink ) ;
316
305
// TODO: Check if need to switch bacl to _.each(...)
317
- if ( isTapLink === 'true' ) {
306
+ if ( isTapLink ) {
318
307
linkView . el . querySelectorAll ( '.connection, .marker-source, .marker-target' )
319
308
. forEach ( connection => joint . V ( connection ) . addClass ( 'tapped-output-from-app' ) ) ;
320
309
} else {
@@ -356,15 +345,25 @@ export class RenderService implements Flo.Renderer {
356
345
return Promise . resolve ( layout ( paper ) ) ;
357
346
}
358
347
359
- handleLinkSourceChanged ( link : dia . Link , paper : dia . Paper ) {
360
- const graph = paper . model ;
348
+ handleLinkSourceChanged ( link : dia . Link , flo : Flo . EditorContext ) {
349
+ const graph = flo . getGraph ( ) ;
361
350
const newSourceId = link . get ( 'source' ) . id ;
362
351
const oldSourceId = link . previous ( 'source' ) . id ;
363
352
const targetId = link . get ( 'target' ) . id ;
364
353
if ( newSourceId !== oldSourceId ) {
365
354
const newSource = graph . getCell ( newSourceId ) ;
366
355
const oldSource = graph . getCell ( oldSourceId ) ;
367
356
const target = graph . getCell ( targetId ) ;
357
+
358
+ // If reconnecting source anchor to a shape with existing primary link switch the link to tap link
359
+ if ( newSource ) {
360
+ const outgoingLinks = graph . getConnectedLinks ( newSource , { outbound : true } ) ;
361
+ const primaryLink = outgoingLinks . find ( ol => ol !== link && ! ol . attr ( 'props/isTapLink' ) ) ;
362
+
363
+ link . attr ( 'props/isTapLink' , primaryLink ? true : false ) ;
364
+ this . refreshVisuals ( link , 'props/isTapLink' , flo . getPaper ( ) ) ;
365
+ }
366
+
368
367
// Show input port for 'destination' if outgoing links are gone
369
368
if ( oldSource && oldSource . attr ( 'metadata/name' ) === 'destination'
370
369
/*&& graph.getConnectedLinks(oldSource, {outbound: true}).length === 0*/ ) {
@@ -385,20 +384,19 @@ export class RenderService implements Flo.Renderer {
385
384
}
386
385
387
386
// If tap link has been reconnected update the stream-label for the target if necessary
388
- // TODO: Isn't tap port removed?
389
387
if ( target ) {
390
- if ( link . previous ( 'source' ) . port === 'tap' ) {
388
+ if ( link . attr ( 'props/isTapLink' ) ) {
391
389
target . attr ( '.stream-label/display' , 'none' ) ;
392
390
}
393
- if ( link . get ( 'source' ) . port === 'tap' ) {
391
+ if ( link . attr ( 'props/isTapLink' ) ) {
394
392
target . attr ( '.stream-label/display' , 'block' ) ;
395
393
}
396
394
}
397
395
}
398
396
}
399
397
400
- handleLinkTargetChanged ( link : dia . Link , paper : dia . Paper ) {
401
- const graph = paper . model ;
398
+ handleLinkTargetChanged ( link : dia . Link , flo : Flo . EditorContext ) {
399
+ const graph = flo . getGraph ( ) ;
402
400
const newTargetId = link . get ( 'target' ) . id ;
403
401
const oldTargetId = link . previous ( 'target' ) . id ;
404
402
if ( newTargetId !== oldTargetId ) {
@@ -428,8 +426,7 @@ export class RenderService implements Flo.Renderer {
428
426
}
429
427
430
428
// If tap link has been reconnected update the stream-label for the new target and old target
431
- // TODO: Isn't tap port removed?
432
- if ( link . get ( 'source' ) . port === 'tap' ) {
429
+ if ( link . attr ( 'props/isTapLink' ) ) {
433
430
if ( oldTarget ) {
434
431
oldTarget . attr ( '.stream-label/display' , 'none' ) ;
435
432
}
@@ -441,8 +438,8 @@ export class RenderService implements Flo.Renderer {
441
438
}
442
439
}
443
440
444
- handleLinkRemoved ( link : dia . Link , paper : dia . Paper ) {
445
- const graph = paper . model ;
441
+ handleLinkRemoved ( link : dia . Link , flo : Flo . EditorContext ) {
442
+ const graph = flo . getGraph ( ) ;
446
443
const source = graph . getCell ( link . get ( 'source' ) . id ) ;
447
444
const target = graph . getCell ( link . get ( 'target' ) . id ) ;
448
445
let view : dia . CellView ;
@@ -452,7 +449,7 @@ export class RenderService implements Flo.Renderer {
452
449
// Set silently, last attr call would refresh the view
453
450
( < any > source ) . attr ( '.stream-label/display' , 'none' , { silent : true } ) ;
454
451
source . removeAttr ( '.input-port/display' ) ;
455
- view = paper . findViewByModel ( source ) ;
452
+ view = flo . getPaper ( ) . findViewByModel ( source ) ;
456
453
if ( view ) {
457
454
( < any > view ) . update ( ) ;
458
455
}
@@ -463,14 +460,13 @@ export class RenderService implements Flo.Renderer {
463
460
// Set silently, last attr call would refresh the view
464
461
( < any > target ) . attr ( '.stream-label/display' , 'none' , { silent : true } ) ;
465
462
target . removeAttr ( '.output-port/display' ) ;
466
- view = paper . findViewByModel ( target ) ;
463
+ view = flo . getPaper ( ) . findViewByModel ( target ) ;
467
464
if ( view ) {
468
465
( < any > view ) . update ( ) ;
469
466
}
470
467
}
471
468
// If tap link is removed update stream-name value for the target, i.e. don't display stream anymore
472
- // TODO: Isn't tap port removed?
473
- if ( link . get ( 'source' ) . port === 'tap' && target ) {
469
+ if ( link . attr ( 'props/isTapLink' ) && target ) {
474
470
target . attr ( '.stream-label/display' , 'none' ) ;
475
471
}
476
472
}
@@ -481,115 +477,78 @@ export class RenderService implements Flo.Renderer {
481
477
return `${ source ? source . attr ( 'metadata/name' ) : '?' } -> ${ target ? target . attr ( 'metadata/name' ) : '?' } ` ;
482
478
}
483
479
484
- // TODO: Rewrite this! Should be creating elements on the graph manually!
485
480
// Should pass use Flo.EditorContext and pass metadata, props etc.
486
- handleLinkInsertChannel ( link : dia . Link , paper : dia . Paper ) {
487
- const graph = paper . model ;
481
+ handleLinkInsertChannel ( link : dia . Link , flo : Flo . EditorContext ) {
482
+ const graph = flo . getGraph ( ) ;
488
483
const source = graph . getCell ( link . get ( 'source' ) . id ) ;
489
484
const target = graph . getCell ( link . get ( 'target' ) . id ) ;
490
485
// Create a node
491
486
this . metamodelService . load ( ) . then ( mm => {
492
- const metadata = Flo . getMetadata ( mm , 'destination' , 'other' ) ;
493
- const newDestinationNode = new joint . shapes . flo . Destination (
494
- joint . util . deepSupplement ( {
495
- attrs : {
496
- '.box' : {
497
- 'fill' : '#eeeeff' ,
498
- 'stroke' : '#0000ff'
499
- } ,
500
- '.label1' : {
501
- 'text' : metadata . name
502
- } ,
503
- '.label2' : {
504
- 'text' : metadata . metadata . unicodeChar
505
- }
506
- }
507
- } , joint . shapes . flo . Destination . prototype . defaults )
508
- ) ;
509
487
510
488
let sourceName = source . attr ( 'metadata/name' ) ;
511
489
if ( sourceName === 'destination' ) {
512
- sourceName = source . attr ( 'props/name' ) ;
490
+ sourceName = source . attr ( 'props/name' ) ;
513
491
}
514
492
let targetName = target . attr ( 'metadata/name' ) ;
515
493
if ( targetName === 'destination' ) {
516
- targetName = target . attr ( 'props/name' ) ;
494
+ targetName = target . attr ( 'props/name' ) ;
517
495
}
518
496
519
- newDestinationNode . set ( 'type' , joint . shapes . flo . NODE_TYPE ) ;
520
- newDestinationNode . attr ( 'props' , { 'name' : sourceName + '-' + targetName } ) ;
521
- newDestinationNode . attr ( 'metadata' , metadata ) ;
522
- graph . addCell ( newDestinationNode ) ;
523
- const nodeView = paper . findViewByModel ( newDestinationNode ) ;
524
- this . initializeNewNode ( < dia . Element > nodeView . model , { 'paper' : paper , 'graph' : graph } ) ;
497
+ const newDestinationNode = flo . createNode ( Flo . getMetadata ( mm , 'destination' , 'other' ) ,
498
+ new Map < string , any > ( ) . set ( 'name' , sourceName + '-' + targetName ) ) ;
525
499
526
500
// Adjust existing link to hit this channel
527
501
const previousSource = link . get ( 'source' ) ;
528
- const existingIsTap = ( link . attr ( 'props/isTapLink' ) === 'true' ) ;
529
- link . set ( 'source' , { 'id' : newDestinationNode . id , 'port' : 'output' , 'selector' : '.output-port' } ) ;
502
+ const existingIsTap = link . attr ( 'props/isTapLink' ) ;
503
+ link . set ( 'source' , {
504
+ id : newDestinationNode . id ,
505
+ port : 'output' ,
506
+ selector : '.output-port'
507
+ } ) ;
530
508
531
509
// New link to connect original source to new target
532
- const newlink = this . createLink ( null , null ) ;
533
- newlink . set ( 'target' , { 'id' : newDestinationNode . id , 'port' : 'input' , 'selector' : '.input-port' } ) ;
534
- newlink . set ( 'source' , previousSource ) ;
535
- newlink . set ( 'type' , joint . shapes . flo . LINK_TYPE ) ;
536
- newlink . attr ( 'metadata' , { } ) ;
537
- graph . addCell ( newlink ) ;
538
- newlink . attr ( '.marker-vertices/display' , 'none' ) ;
539
- newlink . attr ( 'props/isTapLink' , existingIsTap ? 'true' : 'false' ) ;
540
- this . initializeNewLink ( newlink , { 'paper' : paper , 'graph' : graph } ) ;
541
- this . layout ( paper ) ;
510
+ flo . createLink ( previousSource ,
511
+ { 'id' : newDestinationNode . id , 'port' : 'input' , 'selector' : '.input-port' } ,
512
+ null ,
513
+ new Map < string , any > ( ) . set ( 'isTapLink' , existingIsTap ? true : false ) ) ;
514
+
515
+ flo . performLayout ( ) ;
542
516
} ) ;
543
517
}
544
518
545
- handleLinkSwitch ( link : dia . Link , paper : dia . Paper ) {
546
- const graph = paper . model ;
519
+ handleLinkSwitch ( link : dia . Link , flo : Flo . EditorContext ) {
520
+ const graph = flo . getGraph ( ) ;
547
521
const source = graph . getCell ( link . get ( 'source' ) . id ) ;
548
522
// var target = graph.getCell(link.get('target').id);
549
- const isTapLink = ( link . attr ( 'props/isTapLink' ) === 'true ') ;
523
+ const isTapLink = link . attr ( 'props/isTapLink' ) ;
550
524
if ( isTapLink ) {
551
525
console . log ( `Converting link ${ this . toLinkString ( graph , link ) } into a primary link` ) ;
552
- link . attr ( 'props/isTapLink' , ' false' ) ;
526
+ link . attr ( 'props/isTapLink' , false ) ;
553
527
// Need to ensure no other links are still primary, that isn't allowed
554
528
const primaryLink = graph . getConnectedLinks ( source , { outbound : true } )
555
- . find ( l => l !== link && l . attr ( 'props/isTapLink' ) !== 'true' ) ;
529
+ . find ( l => l !== link && l . attr ( 'props/isTapLink' ) ) ;
556
530
if ( primaryLink ) {
557
- primaryLink . attr ( 'props/isTapLink' , ' true' ) ;
558
- this . refreshVisuals ( primaryLink , 'props/isTapLink' , paper ) ;
531
+ primaryLink . attr ( 'props/isTapLink' , true ) ;
532
+ this . refreshVisuals ( primaryLink , 'props/isTapLink' , flo . getPaper ( ) ) ;
559
533
}
560
534
} else {
561
535
console . log ( `Converting link ${ this . toLinkString ( graph , link ) } into a tap link` ) ;
562
- link . attr ( 'props/isTapLink' , ' true' ) ;
536
+ link . attr ( 'props/isTapLink' , true ) ;
563
537
}
564
- this . refreshVisuals ( link , 'props/isTapLink' , paper ) ;
565
- // if (source) {
566
- // var outputLinks = graph.getConnectedLinks(source, {outbound: true});
567
- // var isPrimaryLink = true;
568
- // for (var i=0;i<outputLinks.length;i++) {
569
- // var ol = outputLinks[i];
570
- // if (ol === link || (ol.attr('props/isTapLink')==='true')) {
571
- // continue;
572
- // }
573
- // isPrimaryLink = false;
574
- // break;
575
- // }
576
- // console.log("marking primary? "+isPrimaryLink);
577
- // link.attr('props/isTapLink',isPrimaryLink?'false':'true');
578
- // refreshVisuals(link, 'props/isTapLink', paper);
579
- // }
538
+ this . refreshVisuals ( link , 'props/isTapLink' , flo . getPaper ( ) ) ;
580
539
}
581
540
582
- handleLinkAdded ( link : dia . Link , paper : dia . Paper ) {
583
- const graph = paper . model ;
541
+ handleLinkAdded ( link : dia . Link , flo : Flo . EditorContext ) {
542
+ const graph = flo . getGraph ( ) ;
584
543
const source = graph . getCell ( link . get ( 'source' ) . id ) ;
585
544
const target = graph . getCell ( link . get ( 'target' ) . id ) ;
586
545
console . log ( 'render-service.handleLinkAdded' ) ;
587
546
if ( source ) {
588
- const nonPrimaryLink = graph . getConnectedLinks ( source , { outbound : true } )
589
- . find ( ol => ol !== link && ol . attr ( 'props/isTapLink' ) !== 'true' ) ;
547
+ const outgoingLinks = graph . getConnectedLinks ( source , { outbound : true } ) ;
548
+ const primaryLink = outgoingLinks . find ( ol => ol !== link && ! ol . attr ( 'props/isTapLink' ) ) ;
590
549
591
- link . attr ( 'props/isTapLink' , nonPrimaryLink ? ' true' : ' false' ) ;
592
- this . refreshVisuals ( link , 'props/isTapLink' , paper ) ;
550
+ link . attr ( 'props/isTapLink' , primaryLink ? true : false ) ;
551
+ this . refreshVisuals ( link , 'props/isTapLink' , flo . getPaper ( ) ) ;
593
552
}
594
553
if ( source && source . attr ( 'metadata/name' ) === 'destination' && target ) {
595
554
// A link is added from a source destination to a target. In these cases the
@@ -605,27 +564,26 @@ export class RenderService implements Flo.Renderer {
605
564
// XXX target.attr('.output-port/display', 'none');
606
565
}
607
566
// If tap link has been added update the stream-label for the target
608
- // TODO: Tap port? Isn't it removed?
609
- if ( link . get ( 'source' ) . port === 'tap' && target ) {
567
+ if ( link . attr ( 'props/isTapLink' ) && target ) {
610
568
target . attr ( '.stream-label/display' , 'block' ) ;
611
569
}
612
570
}
613
571
614
- handleLinkEvent ( paper : dia . Paper , event : string , link : dia . Link ) {
572
+ handleLinkEvent ( flo : Flo . EditorContext , event : string , link : dia . Link ) {
615
573
if ( event === 'change:source' ) {
616
- this . handleLinkSourceChanged ( link , paper ) ;
574
+ this . handleLinkSourceChanged ( link , flo ) ;
617
575
} else if ( event === 'change:target' ) {
618
- this . handleLinkTargetChanged ( link , paper ) ;
576
+ this . handleLinkTargetChanged ( link , flo ) ;
619
577
} else if ( event === 'remove' ) {
620
- this . handleLinkRemoved ( link , paper ) ;
578
+ this . handleLinkRemoved ( link , flo ) ;
621
579
} else if ( event === 'add' ) {
622
- this . handleLinkAdded ( link , paper ) ;
623
- paper . findViewByModel ( link ) . on ( 'switch' , ( ) => this . handleLinkEvent ( paper , 'switch' , link ) ) ;
624
- paper . findViewByModel ( link ) . on ( 'insert-channel' , ( ) => this . handleLinkEvent ( paper , 'insert-channel' , link ) ) ;
580
+ this . handleLinkAdded ( link , flo ) ;
581
+ flo . getPaper ( ) . findViewByModel ( link ) . on ( 'switch' , ( ) => this . handleLinkEvent ( flo , 'switch' , link ) ) ;
582
+ flo . getPaper ( ) . findViewByModel ( link ) . on ( 'insert-channel' , ( ) => this . handleLinkEvent ( flo , 'insert-channel' , link ) ) ;
625
583
} else if ( event === 'switch' ) {
626
- this . handleLinkSwitch ( link , paper ) ;
584
+ this . handleLinkSwitch ( link , flo ) ;
627
585
} else if ( event === 'insert-channel' ) {
628
- this . handleLinkInsertChannel ( link , paper ) ;
586
+ this . handleLinkInsertChannel ( link , flo ) ;
629
587
}
630
588
}
631
589
0 commit comments