11import React , { Component } from 'react' ;
22import * as FlexLayout from 'geppetto-client/js/components/interface/flexLayout2/src/index' ;
3- import Actions from 'geppetto-client/js/components/interface/flexLayout2/src/model/Actions' ;
3+ import Actions from '@geppettoengine/ geppetto-client/js/components/interface/flexLayout2/src/model/Actions' ;
44
55
66import { WidgetStatus } from '../../constants' ;
77import { isEqual } from '../../Utils' ;
88import WidgetFactory from './WidgetFactory' ;
99import TabsetIconFactory from './TabsetIconFactory'
1010import defaultLayoutConfiguration from './layoutConf.json' ;
11- import simulateLayoutConfiguration from './simulateLayoutConf.json' ;
1211import Icon from '@material-ui/core/Icon' ;
1312
1413import { withStyles } from '@material-ui/core/styles'
@@ -62,7 +61,7 @@ class LayoutManager extends Component {
6261
6362 this . cacheModels = {
6463 edit : FlexLayout . Model . fromJson ( layout ) ,
65- simulate : FlexLayout . Model . fromJson ( simulateLayoutConfiguration )
64+ simulate : FlexLayout . Model . fromJson ( layout )
6665 }
6766 }
6867
@@ -83,10 +82,6 @@ class LayoutManager extends Component {
8382 if ( newWidgets . length > 0 ) {
8483 this . addWidgets ( newWidgets ) ;
8584 }
86-
87- if ( ! this . props . editMode && ! this . cacheModels . simulate . getNodeById ( widgets . python . id ) ) {
88- this . addWidgets ( [ widgets . python ] ) ;
89- }
9085
9186 const updatedWidgets = this . findUpdatedWidgets ( widgets , oldWidgets ) ;
9287 if ( updatedWidgets ) {
@@ -136,7 +131,40 @@ class LayoutManager extends Component {
136131 }
137132
138133 addWidget ( widgetConfiguration ) {
139- this . refs . layout . addTabToTabSet ( widgetConfiguration . panelName , widget2Node ( widgetConfiguration ) ) ;
134+ const model = this . getModel ( )
135+ let tabset = model . getNodeById ( widgetConfiguration . panelName )
136+ if ( tabset === undefined ) {
137+ this . createTabSet ( widgetConfiguration . panelName )
138+ }
139+ this . refs . layout . addTabToTabSet ( widgetConfiguration . panelName , widget2Node ( widgetConfiguration ) )
140+ }
141+
142+ createTabSet ( tabsetID ) {
143+ // In case the tabset doesn't exist
144+ const model = this . getModel ( )
145+ const rootNode = model . getNodeById ( "root" )
146+
147+ const pyPanel = model . getNodeById ( 'consolePanel' )
148+ if ( pyPanel ) {
149+ pyPanel . _setWeight ( 20 )
150+ }
151+
152+ let hrow = new FlexLayout . RowNode ( model , { } ) ;
153+ hrow . _setWeight ( 100 )
154+
155+ const tabset = new FlexLayout . TabSetNode ( model , { id : tabsetID } ) ;
156+ tabset . _setWeight ( 80 )
157+
158+ hrow . _addChild ( tabset )
159+
160+ rootNode . getChildren ( ) . forEach ( child => hrow . _addChild ( child ) )
161+ rootNode . _removeAll ( )
162+ rootNode . _addChild ( hrow , 0 ) ;
163+ if ( ! this . props . editMode && tabsetID === 'plotPanel' ) {
164+ // We need to resize Geppetto 3D canvas to new panel sizes
165+ setTimeout ( ( ) => window . dispatchEvent ( new Event ( 'resize' ) ) , 1000 )
166+
167+ }
140168 }
141169
142170 updateWidgets ( widgets ) {
@@ -214,11 +242,31 @@ class LayoutManager extends Component {
214242 case Actions . MOVE_NODE :
215243 window . dispatchEvent ( new Event ( 'resize' ) ) ;
216244 break ;
245+ case Actions . ADD_NODE :{
246+ if ( this . props . editMode && action . data . toNode === 'hlsPanel' ) {
247+ action . data . index = this . findWidgetInsertionIndex ( action . data . json . config . pos )
248+ }
249+ break
250+ }
217251 }
218-
219252 model . doAction ( action ) ;
220253 }
221254
255+ findWidgetInsertionIndex ( position ) {
256+ const model = this . getModel ( )
257+ const tabset = model . getNodeById ( 'hlsPanel' )
258+
259+ const positions = tabset . getChildren ( ) . map ( node => node . getConfig ( ) . pos )
260+ var index = - 1
261+ for ( let i = 0 ; i < positions . length ; i ++ ) {
262+ if ( position < positions [ i ] ) {
263+ index = i
264+ break
265+ }
266+ }
267+ return index
268+ }
269+
222270 onActionMaximizeWidget ( action ) {
223271 const model = this . getModel ( )
224272 const { widgets } = this . props ;
@@ -270,7 +318,11 @@ class LayoutManager extends Component {
270318
271319 clickOnBordersAction ( node ) {
272320 const model = this . getModel ( )
273- model . doAction ( FlexLayout . Actions . moveNode ( node . getId ( ) , 'bottomPanel' , FlexLayout . DockLocation . CENTER , 0 ) ) ;
321+ let tabset = model . getNodeById ( 'consolePanel' )
322+ if ( tabset === undefined ) {
323+ this . createTabSet ( 'consolePanel' )
324+ }
325+ model . doAction ( FlexLayout . Actions . moveNode ( node . getId ( ) , 'consolePanel' , FlexLayout . DockLocation . CENTER , 0 ) ) ;
274326 }
275327
276328 onRenderTab ( node , renderValues ) {
0 commit comments