@@ -314,6 +314,7 @@ export default {
314
314
if (! this .supports (' editArguments' )) {
315
315
this .$on (' editArguments' , (... args ) => this .showParameterViewer (... args));
316
316
}
317
+ this .$on (' duplicate' , this .duplicate .bind (this ));
317
318
},
318
319
async mounted () {
319
320
Utils .loadFontAwesome (this );
@@ -442,6 +443,9 @@ export default {
442
443
let refs = PgUtils .getRefs (value, true , true ).filter (ref => typeof ref .from_parameter !== ' undefined' );
443
444
for (let ref of refs) {
444
445
try {
446
+ if (! process .$el ) {
447
+ continue ;
448
+ }
445
449
if (process .$el .isParameterScoped (argName, ref .from_parameter )) {
446
450
continue ; // Skip if the parameter usage is scoped (i.e. defined as process parameetr for the children)
447
451
}
@@ -598,7 +602,20 @@ export default {
598
602
return ;
599
603
}
600
604
if (this .hasSelection && this .clipboard ) {
601
- return ; // ToDo: Implement pasting for selected blocks
605
+ if (this .clipboard .edges .length > 0 ) {
606
+ this .$emit (' error' , ' Pasting edges is not supported yet.' );
607
+ return ;
608
+ }
609
+ if (this .clipboard .blocks .length > 0 ) {
610
+ this .clipboard .blocks .forEach (block => {
611
+ if (block .type === ' process' && block .origin !== ' schema' ) {
612
+ this .duplicate (Utils .pickFromObject (block, [" arguments" , " description" , " namespace" , " position" , " process_id" ]));
613
+ }
614
+ else {
615
+ this .$emit (' error' , ` Pasting block '${ block .id } ' is not supported.` );
616
+ }
617
+ });
618
+ }
602
619
}
603
620
else {
604
621
try {
@@ -876,6 +893,15 @@ export default {
876
893
return [x, y];
877
894
},
878
895
896
+ duplicate (data ) {
897
+ data = Utils .deepClone (data);
898
+ if (data .position ) {
899
+ data .position [1 ] += 100 ;
900
+ }
901
+ let block = this .addBlock (data);
902
+ this .$nextTick (() => this .createEdgesForArguments (block .id , data .arguments ));
903
+ },
904
+
879
905
addProcess (process_id , args = {}, position = [], namespace = null ) {
880
906
return this .addBlock ({
881
907
process_id,
@@ -1380,44 +1406,54 @@ export default {
1380
1406
1381
1407
async importEdges (pg ) {
1382
1408
var nodes = pg .getNodes ();
1383
- for (var node of Object .values (nodes)) {
1384
- var args = node .getArgumentNames ();
1385
- for (let i in args) {
1386
- var val = node .getRawArgument (args[i]);
1387
- switch (node .getArgumentType (args[i])) {
1388
- case ' result' :
1389
- await this .addEdgeByNames (' #' + pg .getNode (val .from_node ).id , " output" , ' #' + node .id , args[i], false );
1390
- break ;
1391
- case ' parameter' :
1392
- await this .addEdgeByNames (' $' + val .from_parameter , " output" , ' #' + node .id , args[i], false );
1393
- break ;
1394
- case ' object' :
1395
- case ' array' :
1396
- await this .importEdgeDeep (val, pg, node, args, i);
1397
- break ;
1398
- }
1409
+ return Promise .all (Object .values (nodes).map (node => this .importEdgesForNode (node)));
1410
+ },
1411
+
1412
+ async importEdgesForNode (node ) {
1413
+ var args = node .getArgumentNames ();
1414
+ for (let i in args) {
1415
+ let arg = args[i];
1416
+ let val = node .getRawArgument (arg);
1417
+ let ref = ' #' + node .id ;
1418
+ switch (node .getArgumentType (arg)) {
1419
+ case ' result' :
1420
+ await this .addEdgeByNames (' #' + val .from_node , " output" , ref, arg, false );
1421
+ break ;
1422
+ case ' parameter' :
1423
+ await this .addEdgeByNames (' $' + val .from_parameter , " output" , ref, arg, false );
1424
+ break ;
1425
+ case ' object' :
1426
+ case ' array' :
1427
+ await this .importEdgeDeep (val, ref, arg);
1428
+ break ;
1399
1429
}
1400
1430
}
1401
1431
},
1402
1432
1403
- async importEdgeDeep (val , pg , node , args , i ) {
1433
+ async importEdgeDeep (val , nodeId , arg ) {
1404
1434
for (let k in val) {
1405
1435
// k !== 'process_graph' prevents importing sub process graphs like in load_collection, see #118
1406
1436
if (val[k] && typeof val[k] === " object" && k !== ' process_graph' ) {
1407
- await this .importEdgeDeep (val[k], pg, node, args, i );
1437
+ await this .importEdgeDeep (val[k], nodeId, arg );
1408
1438
}
1409
1439
else if (! Utils .isRef (val)) {
1410
1440
continue ;
1411
1441
}
1412
1442
else if (val .from_node ) {
1413
- await this .addEdgeByNames (' #' + pg . getNode ( val .from_node ). id , " output" , ' # ' + node . id , args[i] , false );
1443
+ await this .addEdgeByNames (' #' + val .from_node , " output" , nodeId, arg , false );
1414
1444
}
1415
1445
else if (val .from_parameter ) {
1416
- await this .addEdgeByNames (' $' + val .from_parameter , " output" , ' # ' + node . id , args[i] , false );
1446
+ await this .addEdgeByNames (' $' + val .from_parameter , " output" , nodeId, arg , false );
1417
1447
}
1418
1448
}
1419
1449
},
1420
1450
1451
+ async createEdgesForArguments (nodeId , args ) {
1452
+ for (let arg in args) {
1453
+ await this .importEdgeDeep (args[arg], nodeId, arg);
1454
+ }
1455
+ },
1456
+
1421
1457
async importNodes (nodes , x = 0 , y = 0 , imported = []) {
1422
1458
let nextNodes = [];
1423
1459
let maxX = 0 ;
0 commit comments