AdminModule.js 4.2 KB

123
  1. var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a};import React from'react';import Types from'./Types.js';import Logger from'../systems/Logger';import{FontAwesomeIcon}from'@fortawesome/react-fontawesome';import{Card,CardTitle,Icon,Input,Button}from'react-materialize';import ReactJson from'react-json-view';import{Resolver,RendererInput,RendererOutput,InputMarker,RemoveMarker}from'./ModuleUtilities';class AdminModule extends React.Component{constructor(a){super(a),this.dynamicProperties(),this.readOnly=a.readOnly,this._mode=a.__adminmode||'closed',a.withAdmin&&(this._mode='normal');let b=['onClick'];for(var c in this.disableEvents={},b)this.disableEvents[b[c]]=this._stopPropagation}_stopPropagation(a){a.stopPropagation(),a.preventDefault()}_addChild(a){console.log(a);let b=_extends({},a,{inputs:_extends({},a.inputs),outputs:_extends({},a.outputs),children:[...a.children]});b.id=this.__genRandom(),this.props.System.loadModule(b),this.props.System.addChild(this.getId(),b.id),this.props.System.__refresh(),this.onChildAdd&&this.onChildAdd(b.id)}_removeMe(){this.props.System.remove(this.getId()),this.props.System.__refresh()}_connect(a,b){// output!
  2. this.props.System.connect(a,b)}_change(a,b,c){let d=Resolver(c,b);this[a].update(b),this.props.System.change(this.getId(),a,d)}_changeID(a){a&&a!==this.getId()&&(this.props.System.rename(this.getId(),a),this.props.System.__refresh())}__factoryInput(a){return RendererInput(a,this._change.bind(this))}__factoryOutput(a){return RendererOutput(a)}__renderID(){return this.updateID&&!this.readOnly?React.createElement('input',{type:'text',onBlur:a=>this._changeID(a.target.value),defaultValue:this.__id}):React.createElement('span',{onClick:()=>{this.updateID=!0,this.forceUpdate()}},''+this.__id)}__reorder(a){this.props.System.reorder(this.getId(),a),this.props.System.__refresh()}__setAdminUIPosition(a){let b=['top-left','top-center','top-right','bottom-left','bottom','bottom-right'],c=b.indexOf(this.properties.EditPosition),d=this.properties.EditPosition;-1===c?d=b[1]:0<=c-a&&c-a<b.length&&(d=b[c-a]),this.properties.EditPosition=d}dynamicProperties(){this.properties={},this.properties.EditPosition=this.constructor.EditPosition,this.properties.Inputs=this.constructor.Inputs||{},this.properties.Outputs=this.constructor.Outputs||{}}render(){let a=this.properties.EditPosition,b=this.properties.Inputs,c=this.properties.Outputs,d='',e='';// analyze inputs!
  3. return this.props.inputs&&(d=Object.keys(b||{}).map((a,c)=>React.createElement('div',{key:this.getId()+c},this.__factoryInput(_extends({},b[a],this.props.inputs[a]))))),this.props.outputs&&(e=Object.keys(c||{}).map((a,b)=>React.createElement('div',{key:'out'+this.getId()+b},this.__factoryOutput(_extends({},c[a],this.props.outputs[a]))))),'closed'===this._mode?'':React.createElement(Card,_extends({className:`blue-grey darken-1 AdminModule semi Position-${a} ${'open'==this._mode?'top':''}`,key:'666999666999Admina'+this.getId(),onMouseEnter:()=>{this._mode='open',this.forceUpdate()},onMouseLeave:()=>{this._mode='normal',this.forceUpdate()}},this.disableEvents,{header:React.createElement('div',null,React.createElement('h6',null,React.createElement('b',null,'ID:'),this.__renderID(),React.createElement('span',null,React.createElement('i',{className:'material-icons cursor small',onClick:()=>this.__reorder(-1)},'arrow_drop_up'),React.createElement('i',{className:'material-icons cursor small',onClick:()=>this.__reorder(1)},'arrow_drop_down')),React.createElement('span',null,React.createElement('i',{className:'material-icons cursor small',onClick:()=>this.__setAdminUIPosition(-1)},'arrow_left'),React.createElement('i',{className:'material-icons cursor small',onClick:()=>this.__setAdminUIPosition(1)},'arrow_right'))))}),'open'==this._mode?React.createElement('div',null,React.createElement('div',{className:'row'},React.createElement(InputMarker,{onDrop:a=>this._addChild(a),name:'Add child',className:'col s12'})),''==d?'':React.createElement('div',{className:'bars'},d),''==e?'':React.createElement('div',{className:'bars'},e),React.createElement('div',null,React.createElement(RemoveMarker,{className:'col s12',onRemove:()=>this._removeMe()}))):'')}}export default AdminModule;