@@ -6,6 +6,7 @@ import { InsertNodesService } from '../../../services/insertNodesService';
66import { TeacherProjectService } from '../../../services/teacherProjectService' ;
77import { InsertFirstNodeInBranchPathService } from '../../../services/insertFirstNodeInBranchPathService' ;
88import { AddStepTarget } from '../../../../../app/domain/addStepTarget' ;
9+ import { ensureDefaultIcon } from '../../../common/Node' ;
910
1011@Directive ( )
1112export abstract class AbstractImportStepComponent implements OnInit {
@@ -32,21 +33,36 @@ export abstract class AbstractImportStepComponent implements OnInit {
3233 this . submitting = true ;
3334 this . copyNodesService
3435 . copyNodes ( nodesToImport , this . importProjectId , this . configService . getProjectId ( ) )
35- . subscribe ( ( copiedNodes : any [ ] ) => {
36- const nodesWithNewNodeIds = this . projectService . getNodesWithNewIds ( copiedNodes ) ;
36+ . subscribe ( ( copiedNodesWithOldIds : any [ ] ) => {
37+ const copiedNodes = this . replaceNodesWithNewIds ( copiedNodesWithOldIds ) ;
38+ ensureDefaultIcon ( copiedNodes ) ;
3739 if ( this . target . type === 'firstStepInBranchPath' ) {
3840 this . insertFirstNodeInBranchPathService . insertNodes (
39- nodesWithNewNodeIds ,
41+ copiedNodes ,
4042 this . target . branchNodeId ,
4143 this . target . firstNodeIdInBranchPath
4244 ) ;
4345 } else {
44- this . insertNodesService . insertNodes ( nodesWithNewNodeIds , this . target . targetId ) ;
46+ this . setColor ( copiedNodes , this . target . targetId ) ;
47+ this . insertNodesService . insertNodes ( copiedNodes , this . target . targetId ) ;
4548 }
4649 this . projectService . checkPotentialStartNodeIdChangeThenSaveProject ( ) . then ( ( ) => {
4750 this . projectService . refreshProject ( ) ;
4851 this . router . navigate ( [ '../../..' ] , { relativeTo : this . route } ) ;
4952 } ) ;
5053 } ) ;
5154 }
55+
56+ private replaceNodesWithNewIds ( nodes : any [ ] ) : any [ ] {
57+ const oldToNewIds = this . projectService . getOldToNewIds ( nodes ) ;
58+ return nodes . map ( ( node : any ) => this . projectService . replaceOldIds ( node , oldToNewIds ) ) ;
59+ }
60+
61+ private setColor ( nodes : any [ ] , nodeId : string ) : void {
62+ const nodeToMatchColor = this . projectService . isGroupNode ( nodeId )
63+ ? this . projectService . getNodeById ( nodeId )
64+ : this . projectService . getParentGroup ( nodeId ) ;
65+ ensureDefaultIcon ( [ nodeToMatchColor ] ) ;
66+ nodes . forEach ( ( node : any ) => ( node . icon . color = nodeToMatchColor . icon . color ) ) ;
67+ }
5268}
0 commit comments