@@ -9,7 +9,7 @@ import { ConstraintService } from './constraintService';
99import { TransitionLogic } from '../common/TransitionLogic' ;
1010
1111@Injectable ( )
12- export class NodeService {
12+ export abstract class NodeService {
1313 private transitionResults = { } ;
1414 private chooseTransitionPromises = { } ;
1515 private nodeSubmitClickedSource : Subject < any > = new Subject < any > ( ) ;
@@ -18,83 +18,33 @@ export class NodeService {
1818 public doneRenderingComponent$ = this . doneRenderingComponentSource . asObservable ( ) ;
1919
2020 constructor (
21+ protected dataService : DataService ,
2122 protected dialog : MatDialog ,
2223 protected configService : ConfigService ,
2324 protected constraintService : ConstraintService ,
24- protected projectService : ProjectService ,
25- protected dataService : DataService
25+ protected projectService : ProjectService
2626 ) { }
2727
2828 setCurrentNode ( nodeId : string ) : void {
2929 this . dataService . setCurrentNodeByNodeId ( nodeId ) ;
3030 }
3131
3232 goToNextNode ( ) : Promise < string > {
33- return this . getNextNodeId ( ) . then ( ( nextNodeId ) => {
33+ return this . getNextNodeId ( ) . then ( ( nextNodeId : string ) => {
3434 if ( nextNodeId != null ) {
3535 this . setCurrentNode ( nextNodeId ) ;
3636 }
3737 return nextNodeId ;
3838 } ) ;
3939 }
4040
41- /**
42- * This function should be implemented by the child service classes
43- */
44- getNextNodeId ( currentId ?: string ) : Promise < any > {
45- return null ;
46- }
41+ abstract getNextNodeId ( currentId ?: string ) : Promise < any > ;
4742
48- goToPrevNode ( ) {
49- const prevNodeId = this . getPrevNodeId ( ) ;
50- this . setCurrentNode ( prevNodeId ) ;
43+ goToPrevNode ( ) : void {
44+ this . setCurrentNode ( this . getPrevNodeId ( ) ) ;
5145 }
5246
53- /**
54- * Get the previous node in the project sequence
55- * @param currentId (optional)
56- */
57- getPrevNodeId ( currentId ?: string ) : string {
58- let prevNodeId = null ;
59- const currentNodeId = currentId ?? this . dataService . getCurrentNodeId ( ) ;
60- if ( currentNodeId ) {
61- if ( [ 'author' , 'classroomMonitor' ] . includes ( this . configService . getMode ( ) ) ) {
62- const currentNodeOrder = this . projectService . getNodeOrderById ( currentNodeId ) ;
63- if ( currentNodeOrder ) {
64- const prevId = this . projectService . getNodeIdByOrder ( currentNodeOrder - 1 ) ;
65- if ( prevId ) {
66- prevNodeId = this . projectService . isApplicationNode ( prevId )
67- ? prevId
68- : this . getPrevNodeId ( prevId ) ;
69- }
70- }
71- } else {
72- // get all the nodes that transition to the current node
73- const nodeIdsByToNodeId = this . projectService
74- . getNodesByToNodeId ( currentNodeId )
75- . map ( ( node ) => node . id ) ;
76- if ( nodeIdsByToNodeId . length === 1 ) {
77- // there is only one node that transitions to the current node
78- prevNodeId = nodeIdsByToNodeId [ 0 ] ;
79- } else if ( nodeIdsByToNodeId . length > 1 ) {
80- // there are multiple nodes that transition to the current node
81-
82- const stackHistory = this . dataService . getStackHistory ( ) ;
83-
84- // loop through the stack history node ids from newest to oldest
85- for ( let s = stackHistory . length - 1 ; s >= 0 ; s -- ) {
86- const stackHistoryNodeId = stackHistory [ s ] ;
87- if ( nodeIdsByToNodeId . indexOf ( stackHistoryNodeId ) != - 1 ) {
88- // we have found a node that we previously visited that transitions to the current node
89- prevNodeId = stackHistoryNodeId ;
90- break ;
91- }
92- }
93- }
94- }
95- }
96- return prevNodeId ;
97- }
47+ abstract getPrevNodeId ( currentId ?: string ) : string ;
9848
9949 /**
10050 * Close the current node (and open the current node's parent group)
@@ -159,7 +109,7 @@ export class NodeService {
159109 * they last chose and not ask them again
160110 */
161111 } else {
162- this . letUserChooseTransition ( availableTransitions , nodeId , resolve ) ;
112+ this . letUserChooseTransition ( availableTransitions , resolve ) ;
163113 }
164114 } else {
165115 transitionResult = this . chooseTransitionAutomatically (
@@ -184,28 +134,18 @@ export class NodeService {
184134 ) ;
185135 }
186136
187- private letUserChooseTransition (
188- availableTransitions : any [ ] ,
189- nodeId : string ,
190- resolve : ( value : any ) => void
191- ) : void {
192- const paths = [ ] ;
193- for ( const availableTransition of availableTransitions ) {
194- const toNodeId = availableTransition . to ;
195- const path = {
196- nodeId : toNodeId ,
197- nodeTitle : this . projectService . getNodePositionAndTitle ( toNodeId ) ,
198- transition : availableTransition
199- } ;
200- paths . push ( path ) ;
201- }
202- const dialogRef = this . dialog . open ( ChooseBranchPathDialogComponent , {
203- data : paths ,
204- disableClose : true
205- } ) ;
206- dialogRef . afterClosed ( ) . subscribe ( ( result ) => {
207- resolve ( result ) ;
208- } ) ;
137+ private letUserChooseTransition ( transitions : any [ ] , resolve : ( value : any ) => void ) : void {
138+ this . dialog
139+ . open ( ChooseBranchPathDialogComponent , {
140+ data : transitions . map ( ( transition ) => ( {
141+ nodeId : transition . to ,
142+ nodeTitle : this . projectService . getNodePositionAndTitle ( transition . to ) ,
143+ transition : transition
144+ } ) ) ,
145+ disableClose : true
146+ } )
147+ . afterClosed ( )
148+ . subscribe ( ( result ) => resolve ( result ) ) ;
209149 }
210150
211151 private chooseTransitionAutomatically (
0 commit comments