DummyService.js 2.7 KB

12
  1. import React from'react';import Module from'../Module';import Extendable from'../base/ExtendableContainer';import{InputLink,OutputLink}from'../ModuleUtilities';import{FontAwesomeIcon}from'@fortawesome/react-fontawesome';import{Col,TextInput as Input}from'react-materialize';import ReactJson from'react-json-view';import'./DummyService.css';class DummyService extends Module{constructor(a){super(a);let b=JSON.parse(localStorage.getItem('dummyData')||'{}');this.state={text:this.input.value||{},object:b.object||{},string:b.string||''},this.input.onUpdate(()=>{let a=this.input.value;this.setState({text:a})}),this.string.set(this.state.string),this.object.set(this.state.object)}send(a){if('Enter'===a.key){let b=a.target.value;this.string.set(b),this.save()}}save(){let a={string:this.string.value,object:this.object.value};localStorage.setItem('dummyData',JSON.stringify(a))}sendJSON(a){if('Enter'===a.key){let b=a.target.value;try{let a=JSON.parse(b);this.object.set(a),this.save()}catch(a){return void console.log('Not JSON',a)}}}render(){// console.log(this.object);
  2. return React.createElement('div',{className:'',key:'DummyService'+Math.random()},React.createElement('div',{className:'row'},this.__renderID()),React.createElement('div',{className:'row'},React.createElement(Col,{s:12,className:'JSONViewer'},'Input',React.createElement(ReactJson,{src:this.state.text,theme:'apathy',displayDataTypes:!1,collapsed:!1,collapseStringsAfterLength:7})),React.createElement(Col,{s:12,className:'JSONViewer'},'Object',React.createElement(ReactJson,{src:this.state.object,onAdd:a=>{this.object.set(a.new_value),this.save(),this.setState({object:a.new_value})},theme:'apathy',onEdit:a=>{this.object.set(a.updated_src),this.save(),this.setState({object:a.updated_src})},onDelete:a=>{this.object.set(a.updated_src),this.save(),this.setState({object:a.updated_src})},displayDataTypes:!1,enableClipboard:!1,collapsed:!0,collapseStringsAfterLength:7})),React.createElement(Col,{s:12,className:'input-field'},'String',React.createElement('textarea',{type:'textarea',className:'white materialize-textarea',onKeyPress:a=>this.send(a),defaultValue:this.state.string}))),React.createElement('div',{className:'row'},React.createElement('div',{className:'col s12'},'Connections'),React.createElement('div',{className:'col s12'},React.createElement(OutputLink,{output:this.object})),React.createElement('div',{className:'col s12'},React.createElement(OutputLink,{output:this.string})),React.createElement('div',{className:'col s12'},React.createElement(InputLink,{input:this.input}))),React.createElement('div',{className:'row'}),super.render())}}DummyService.Outputs={object:{},string:{}},DummyService.Inputs={input:{type:Module.Types.Link}},DummyService.Category='Services';export default DummyService;