11import { h , Component } from 'preact'
22import { bind } from 'decko'
3+ import _ from 'lodash'
34import nodeStore from '../../redux/store'
45import { ACTION } from '../../redux/actions'
56import getNodeTypeComponent from './../../constants/node-type-components'
67import NodeResize from './node-resize'
8+ import Attributes from './attributes'
9+ import Portal from 'preact-portal'
710
811class Node extends Component {
912 constructor ( { nodeId, nodeName, x, y} ) {
@@ -308,6 +311,43 @@ class Node extends Component {
308311 event . preventDefault ( )
309312 }
310313
314+ @bind
315+ open ( ) {
316+ this . setState ( { open : true } )
317+ }
318+
319+ @bind
320+ close ( ) {
321+ this . setState ( { open : false } )
322+ }
323+
324+ @bind
325+ submit ( event ) {
326+ event . preventDefault ( )
327+
328+ let attributeName = event . target [ 0 ] . value
329+ let attributeType = event . target [ 1 ] . value
330+ let attributeIsPrimary = event . target [ 2 ] . checked
331+
332+ if ( _ . isEmpty ( attributeName ) ) {
333+ this . close ( )
334+ return
335+ }
336+
337+ nodeStore . dispatch ( { type : ACTION . ADD_ATTRIBUTE ,
338+ value : {
339+ nodeId : this . nodeId ,
340+ attribute : {
341+ name : attributeName ,
342+ type : attributeType ,
343+ isPrimary : attributeIsPrimary
344+ }
345+ }
346+ } )
347+
348+ this . close ( )
349+ }
350+
311351 render ( props , state ) {
312352 let rootStyle = {
313353 transform : `translate(${ state . dragX } px, ${ state . dragY } px) scale(${ props . zoom } )`
@@ -320,15 +360,14 @@ class Node extends Component {
320360 { /* */ }
321361 div >
322362
323- { props . selected && < NodeResize onStartNodeResize = { this . startNodeResize } /> }
363+ { < NodeResize onStartNodeResize = { this . startNodeResize } ng-if = 'props.selected' /> }
324364
325365 < div id = 'svg-rect' style = { { width : state . width , height : state . height } }
326366 onMouseDown = { this . onMouseDown }
327367 onMouseEnter = { this . onConnectionEnterDestination }
328368 onMouseLeave = { this . onConnectionLeaveDestination }
329369 onClick = { this . selectNode }
330370 >
331-
332371 { getNodeTypeComponent ( props . type , { width : state . width , height : state . height , color : props . color } ) }
333372
334373 {
@@ -344,6 +383,50 @@ class Node extends Component {
344383 div >
345384 }
346385 div >
386+
387+ < div class = 'attributes-wrapper' >
388+ < Attributes attributes = { props . attributes } />
389+
390+ { props . selected && props . type !== 'inheritance' && < button class = 'button-add-attribute' onClick = { this . open } > Add propertybutton > }
391+ div >
392+
393+ {
394+ state . open &&
395+ < Portal into = 'body' >
396+ < div class = 'modal' >
397+ < form class = 'modal-form' name = 'attributeForm' onSubmit = { this . submit } style = 'z-index: 101' >
398+ { /* */ }
399+ < input type = 'text' value = '' name = 'attributeName' onChange = { this . preventDefault } placeholder = 'type name...' />
400+
401+ < select name = 'attributeType' >
402+ < option value = 'CHAR' > CHARoption >
403+ < option value = 'INTEGER' > INTEGERoption >
404+ < option value = 'FLOAT' > FLOAToption >
405+ < option value = 'TIMESTAMP' > TIMESTAMPoption >
406+ select >
407+
408+ < label class = 'label--checkbox' >
409+ < input type = 'checkbox' class = 'checkbox' name = 'attributeIsKey' />
410+ < span > Is primary keyspan >
411+ label >
412+
413+ < div style = 'text-align: right; margin: 30px 5px 0px;' >
414+ < input type = 'submit' value = 'Submit' />
415+ < input type = 'button' value = 'Cancel' onClick = { this . close } />
416+ div >
417+ form >
418+
419+ < div class = 'modal-mask' style = '
420+ width: 100vw;
421+ height: 100vh;
422+ position: absolute;
423+ top: 0;
424+ background: rgba(21, 21, 21, 0.32);
425+ z-index: 100;
426+ ' />
427+ div >
428+ Portal >
429+ }
347430 div >
348431 )
349432 }
0 commit comments