@@ -10,11 +10,10 @@ define([
1010 this . _markForDeletion = { } ; // id -> node
1111 this . _oldMetadataByName = { } ; // name -> id
1212 this . createdMetadataIds = { } ;
13-
14- this . plotLines = { } ;
13+ this . createIdToMetadataId = { } ;
1514 } ;
1615
17- // I think I should convert these to just a single 'update graph' command
16+ // TODO: Add tests
1817 ExecuteJob . prototype [ CONSTANTS . PLOT_UPDATE ] = async function ( job , state ) {
1918 const jobId = this . core . getPath ( job ) ;
2019
@@ -23,86 +22,53 @@ define([
2322 let id = jobId + '/' + state . id ;
2423 let graph = this . getExistingMetadataById ( job , 'Graph' , id ) ;
2524 if ( ! graph ) {
26- graph = this . createNode ( 'Graph' , job ) ;
27- this . setAttribute ( graph , 'id' , id ) ;
28-
29- this . createIdToMetadataId [ graph ] = id ;
25+ graph = this . core . createNode ( {
26+ base : this . META . Graph ,
27+ parent : job
28+ } ) ;
29+ this . core . setAttribute ( graph , 'id' , id ) ;
30+ this . _metadata [ id ] = graph ;
3031 }
3132
3233 // Apply whatever updates are needed
3334 // Set the plot title
3435 // Only support a single axes for now
3536 const axes = state . axes [ 0 ] ;
36- this . setAttribute ( graph , 'name' , axes . title ) ;
37- this . setAttribute ( graph , 'xlabel' , axes . xlabel ) ;
38- this . setAttribute ( graph , 'ylabel' , axes . ylabel ) ;
37+ this . core . setAttribute ( graph , 'name' , axes . title ) ;
38+ this . core . setAttribute ( graph , 'xlabel' , axes . xlabel ) ;
39+ this . core . setAttribute ( graph , 'ylabel' , axes . ylabel ) ;
3940 this . logger . info ( `Updating graph named ${ axes . title } ` ) ;
4041
41- // Delete current line nodes
42- if ( ! this . isCreateId ( graph ) ) {
43- //const children = await this.core.loadChildren(graph);
44- const childIds = this . core . getChildrenPaths ( graph ) ;
45- childIds . forEach ( id => this . deleteNode ( id ) ) ;
46- }
47-
48- if ( this . plotLines [ id ] ) {
49- this . plotLines [ id ] . forEach ( lineId => {
50- if ( this . _metadata [ lineId ] ) {
51- const nodeId = this . core . getPath ( this . _metadata [ lineId ] ) ;
52- this . deleteNode ( nodeId ) ;
53- } else {
54- const createId = Object . keys ( this . createIdToMetadataId )
55- . find ( createId => this . createIdToMetadataId [ createId ] === lineId ) ;
56-
57- if ( createId ) {
58- this . deleteNode ( createId ) ;
59- }
60- }
61- } ) ;
62- }
63- this . plotLines [ id ] = [ ] ;
42+ const children = await this . core . loadChildren ( graph ) ;
43+ children . forEach ( node => this . core . deleteNode ( node ) ) ;
6444
6545 // Update the points for each of the lines
6646 axes . lines . forEach ( ( line , index ) => {
67- let lineId = id + '/' + index ;
68- let node = this . createNode ( ' Line' , graph ) ;
69- this . plotLines [ id ] . push ( lineId ) ;
70- this . createIdToMetadataId [ node ] = lineId ;
47+ let node = this . core . createNode ( {
48+ base : this . META . Line ,
49+ parent : graph ,
50+ } ) ;
7151
72- this . setAttribute ( node , 'name' , line . label || `line ${ index + 1 } ` ) ;
52+ this . core . setAttribute ( node , 'name' , line . label || `line ${ index + 1 } ` ) ;
7353 let points = line . points . map ( pts => pts . join ( ',' ) ) . join ( ';' ) ;
74- this . setAttribute ( node , 'points' , points ) ;
54+ this . core . setAttribute ( node , 'points' , points ) ;
7555 } ) ;
7656 } ;
7757
78- ExecuteJob . prototype [ CONSTANTS . GRAPH_CREATE_LINE ] = function ( job , graphId , id ) {
79- var jobId = this . core . getPath ( job ) ,
80- graph = this . _metadata [ jobId + '/' + graphId ] ,
81- name = Array . prototype . slice . call ( arguments , 3 ) . join ( ' ' ) ,
82- line ;
83-
84- // Create a 'line' node in the given Graph metadata node
85- name = name . replace ( / \s + $ / , '' ) ;
86- line = this . createNode ( 'Line' , graph ) ;
87- this . setAttribute ( line , 'name' , name ) ;
88- this . _metadata [ jobId + '/' + id ] = line ;
89- this . createIdToMetadataId [ line ] = jobId + '/' + id ;
90- } ;
91-
9258 ExecuteJob . prototype [ CONSTANTS . IMAGE . BASIC ] =
9359 ExecuteJob . prototype [ CONSTANTS . IMAGE . UPDATE ] =
9460 ExecuteJob . prototype [ CONSTANTS . IMAGE . CREATE ] = function ( job , hash , imgId ) {
9561 var name = Array . prototype . slice . call ( arguments , 3 ) . join ( ' ' ) ,
9662 imageNode = this . _getImageNode ( job , imgId , name ) ;
9763
98- this . setAttribute ( imageNode , 'data' , hash ) ;
64+ this . core . setAttribute ( imageNode , 'data' , hash ) ;
9965 } ;
10066
10167 ExecuteJob . prototype [ CONSTANTS . IMAGE . NAME ] = function ( job , imgId ) {
10268 var name = Array . prototype . slice . call ( arguments , 2 ) . join ( ' ' ) ,
10369 imageNode = this . _getImageNode ( job , imgId , name ) ;
10470
105- this . setAttribute ( imageNode , 'name' , name ) ;
71+ this . core . setAttribute ( imageNode , 'name' , name ) ;
10672 } ;
10773
10874 ExecuteJob . prototype . _getImageNode = function ( job , imgId , name ) {
@@ -116,9 +82,11 @@ define([
11682 imageNode = this . _getExistingMetadata ( jobId , 'Image' , name ) ;
11783 if ( ! imageNode ) {
11884 this . logger . info ( `Creating image ${ id } named ${ name } ` ) ;
119- imageNode = this . createNode ( 'Image' , job ) ;
120- this . setAttribute ( imageNode , 'name' , name ) ;
121- this . createIdToMetadataId [ imageNode ] = id ;
85+ imageNode = this . core . createNode ( {
86+ base : this . META . Image ,
87+ parent : job ,
88+ } ) ;
89+ this . core . setAttribute ( imageNode , 'name' , name ) ;
12290 }
12391 this . _metadata [ id ] = imageNode ;
12492 }
@@ -147,7 +115,7 @@ define([
147115 if ( this . isMetaTypeOf ( child , this . META . Metadata ) ) {
148116 id = this . core . getPath ( child ) ;
149117 base = this . core . getBase ( child ) ;
150- type = this . getAttribute ( base , 'name' ) ;
118+ type = this . core . getAttribute ( base , 'name' ) ;
151119
152120 this . _markForDeletion [ nodeId ] [ id ] = child ;
153121 // namespace by metadata type
@@ -166,7 +134,7 @@ define([
166134 // make the deletion ids relative to the job node
167135 this . logger . debug ( `About to delete ${ idsToDelete . length } : ${ idsToDelete . join ( ', ' ) } ` ) ;
168136 for ( i = idsToDelete . length ; i -- ; ) {
169- this . deleteNode ( idsToDelete [ i ] ) ;
137+ this . core . deleteNode ( idsToDelete [ i ] ) ;
170138 }
171139 } ) ;
172140 } ;
@@ -182,14 +150,14 @@ define([
182150 this . logger . debug ( `About to delete ${ nodeIds . length } : ${ nodeIds . join ( ', ' ) } ` ) ;
183151 for ( var i = nodeIds . length ; i -- ; ) {
184152 const node = this . _markForDeletion [ nodeId ] [ nodeIds [ i ] ] ;
185- this . deleteNode ( this . core . getPath ( node ) ) ;
153+ this . core . deleteNode ( this . core . getPath ( node ) ) ;
186154 }
187155 delete this . lastAppliedCmd [ nodeId ] ;
188156 delete this . createdMetadataIds [ nodeId ] ;
189157 delete this . _markForDeletion [ nodeId ] ;
190158 }
191159
192- this . delAttribute ( job , 'jobInfo' ) ;
160+ this . core . delAttribute ( job , 'jobInfo' ) ;
193161 } ;
194162
195163 ExecuteJob . prototype . resultMsg = function ( msg ) {
@@ -198,21 +166,14 @@ define([
198166 } ;
199167
200168 ExecuteJob . prototype . getExistingMetadataById = function ( job , type , id ) {
201- const createId = Object . keys ( this . createIdToMetadataId )
202- . find ( createId => this . createIdToMetadataId [ createId ] === id ) ;
203-
204- if ( createId ) { // on the queue to be created
205- return createId ;
206- }
207-
208- if ( this . _metadata [ id ] ) { // already created
169+ if ( this . _metadata [ id ] ) {
209170 return this . _metadata [ id ] ;
210171 }
211172
212- return this . _getExistingMetadata ( // exists from prev run
173+ return this . _getExistingMetadata ( // exists from prev run
213174 this . core . getPath ( job ) ,
214175 type ,
215- node => this . getAttribute ( node , 'id' ) === id
176+ node => this . core . getAttribute ( node , 'id' ) === id
216177 ) ;
217178 } ;
218179
@@ -271,5 +232,11 @@ define([
271232 } ;
272233 } ;
273234
235+ ExecuteJob . prototype . onNodeCreated = async function ( tmpId , node ) {
236+ const id = this . createIdToMetadataId [ tmpId ] ;
237+ delete this . createIdToMetadataId [ tmpId ] ;
238+ this . _metadata [ id ] = node ;
239+ } ;
240+
274241 return ExecuteJob ;
275242} ) ;
0 commit comments