11import { Injectable } from '@angular/core' ;
22import { Router } from '@angular/router' ;
3+ import { Observable } from 'rxjs/Observable' ;
4+ import { tap } from 'rxjs/operators' ;
5+ import { of } from 'rxjs' ;
36
47import { Session , Node , NodeSchema } from './session' ;
58import { SessionsService } from './sessions.service' ;
@@ -135,7 +138,7 @@ export class ModificationsService {
135138 case 'bits' :
136139 case 'enumeration' :
137140 waiting = true ;
138- this . sessionsService . schemaValues ( activeSession . key , node ) . then ( result => {
141+ this . sessionsService . schemaValues ( activeSession . key , node ) . subscribe ( result => {
139142 if ( result [ 'success' ] ) {
140143 node [ 'info' ] [ 'values' ] = result [ 'data' ] ;
141144 }
@@ -330,7 +333,7 @@ export class ModificationsService {
330333 * @param schemas List of available schema nodes for the node's children.
331334 * @param node Parent node where a new children is supposed to be created.
332335 */
333- createOpen ( activeSession : Session , schemas : string [ ] , node : Node ) : void {
336+ createOpen ( activeSession : Session , schemas : NodeSchema [ ] , node : Node ) : void {
334337 //console.trace();
335338 node [ 'schemaChildren' ] = schemas ;
336339 node [ 'creatingChild' ] = { } ;
@@ -340,7 +343,7 @@ export class ModificationsService {
340343 if ( children . length ) {
341344 let last = children [ children . length - 1 ] ;
342345 if ( last [ 'info' ] [ 'type' ] == 16 ) {
343- let instances = this . treeService . getInstances ( activeSession , last )
346+ let instances = this . treeService . getInstances ( activeSession , last ) ;
344347 last = instances [ instances . length - 1 ] ;
345348 }
346349 delete last [ 'last' ] ;
@@ -371,7 +374,7 @@ export class ModificationsService {
371374 if ( children . length ) {
372375 let last = children [ children . length - 1 ] ;
373376 if ( last [ 'info' ] [ 'type' ] == 16 ) {
374- let instances = this . treeService . getInstances ( activeSession , last )
377+ let instances = this . treeService . getInstances ( activeSession , last ) ;
375378 last = instances [ instances . length - 1 ] ;
376379 }
377380 last [ 'last' ] = true ;
@@ -483,7 +486,7 @@ export class ModificationsService {
483486
484487 newNode [ 'children' ] = [ ] ;
485488 /* open creation dialog for nodes inside the created container */
486- this . sessionsService . childrenSchemas ( activeSession . key , newNode ) . then ( result => {
489+ this . sessionsService . childrenSchemas ( activeSession . key , newNode ) . subscribe ( result => {
487490 this . createOpen ( activeSession , result , newNode ) ;
488491 } ) ;
489492 break ;
@@ -493,7 +496,7 @@ export class ModificationsService {
493496 if ( 'default' in newNode [ 'info' ] ) {
494497 newNode [ 'value' ] = newNode [ 'info' ] [ 'default' ] ;
495498 }
496- this . setEdit ( activeSession , newNode , true )
499+ this . setEdit ( activeSession , newNode , true ) ;
497500 break ;
498501 case 8 : /* leaf-list */
499502 /* check number of instances, if first, mark this as the first leaf-list instance */
@@ -533,7 +536,7 @@ export class ModificationsService {
533536 }
534537 newNode [ 'children' ] = [ ] ;
535538 /* open creation dialog for nodes inside the created list */
536- this . sessionsService . childrenSchemas ( activeSession . key , newNode ) . then ( result => {
539+ this . sessionsService . childrenSchemas ( activeSession . key , newNode ) . subscribe ( result => {
537540 if ( result && result . length ) {
538541 this . createOpen ( activeSession , result , newNode ) ;
539542 }
@@ -808,7 +811,7 @@ export class ModificationsService {
808811 let err = this . resolveKeys ( activeSession . modifications [ mod ] [ 'data' ] ) ;
809812 if ( err ) {
810813 console . log ( err ) ;
811- return new Promise ( ( resolve , reject ) => { resolve ( { 'success' :false , 'error' : [ { 'message' :err } ] } ) } ) ;
814+ return of ( { 'success' : false , 'error' : [ { 'message' : err } ] } ) ;
812815 }
813816 }
814817
@@ -834,10 +837,10 @@ export class ModificationsService {
834837 /* eat distances to generate transactions */
835838 record [ 'transactions' ] = [ ] ;
836839 let pos = this . getHighestDistIndex ( nodes ) ;
837- while ( pos != - 1 ) {
840+ while ( pos != - 1 ) {
838841 if ( nodes [ pos ] [ 'dist' ] < 0 ) {
839842 /* moved to the left */
840- let offset = 1
843+ let offset = 1 ;
841844 for ( ; nodes [ pos ] [ 'dist' ] != 0 ; nodes [ pos ] [ 'dist' ] ++ , offset ++ ) {
842845 nodes [ pos + offset ] [ 'dist' ] -- ;
843846 }
@@ -894,13 +897,15 @@ export class ModificationsService {
894897 }
895898
896899 //console.log(JSON.stringify(activeSession.modifications));
897- return this . sessionsService . commit ( activeSession ) . then ( result => {
898- if ( result [ 'success' ] ) {
899- delete activeSession . modifications ;
900- } else {
901- console . log ( result ) ;
902- }
903- return result ;
904- } )
900+ return this . sessionsService . commit ( activeSession ) . pipe (
901+ tap ( result => {
902+ if ( result [ 'success' ] ) {
903+ delete activeSession . modifications ;
904+ } else {
905+ console . log ( result ) ;
906+ }
907+ return result ;
908+ } )
909+ )
905910 }
906911}
0 commit comments