Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //------------------------------------------------------------------------------------------------------------------------------
  2. //Classes-----------------------------------------------------------------------------------------------------------------------
  3. //------------------------------------------------------------------------------------------------------------------------------
  4.  
  5.  
  6.  
  7. var Main = React.createClass(
  8. {
  9.   getInitialState: function() {
  10.     // return {
  11.     //   boards: [
  12.     //   {
  13.     //     type: 'teensy',
  14.     //     name: 'bela1'
  15.     //   },
  16.     //   {
  17.     //     type: 'photon',
  18.     //     name: 'jozsiasd'
  19.     //   },
  20.     //   {
  21.     //     type: 'arduino',
  22.     //     name: 'repa fozelek'
  23.     //   },
  24.     //   {
  25.     //     type: 'teensy',
  26.     //     name: 'krumplist teszta'
  27.     //   }]
  28.     // }
  29.     return {
  30.       boards: []
  31.     }
  32.   },
  33.  
  34.   addBoard: function(boardConfig) {
  35.     const newBoard = {
  36.       name: boardConfig.name,
  37.       type: boardConfig.type
  38.     }
  39.  
  40.     this.setState({
  41.       boards: [...this.state.boards, newBoard]
  42.     });
  43.   },
  44.  
  45.   renderElement: function(element) {
  46.     switch (element.type) {
  47.       case 'teensy':
  48.         return <Teensy name={element.name}/>
  49.       case 'photon':
  50.         return <Photon name={element.name}/>
  51.       case 'arduino':
  52.         return <Arduino name={element.name}/>
  53.     }
  54.   },
  55.  
  56.   render: function() {
  57.     console.log(this.state.boards);
  58.       return (
  59.             <div>
  60.           {this.state.boards.map( (element) => {
  61.             return this.renderElement(element);
  62.           })}
  63.             <AddButton onClickFunc={this.addBoard}/>
  64.             </div>
  65.       );
  66.   }
  67. });
  68. //Teensy class
  69. var Teensy=React.createClass(
  70. {
  71.     clickEve: function(data){
  72.         console.log("Onclick", data);
  73.     },
  74.     getInitialState: function () {
  75.           return {
  76.             opacity: 0
  77.           };
  78.         },
  79.     componentDidMount: function () {
  80.         var fadeTim = setInterval(fadeTimeout.bind(this), 100);
  81.         function fadeTimeout() {
  82.             var opacity = this.state.opacity;
  83.             opacity += .05;
  84.             if (opacity >= 1.0) {
  85.                 console.log("Interval cleared", opacity);
  86.               clearInterval(fadeTim);
  87.             }
  88.  
  89.             this.setState({
  90.               opacity: opacity
  91.             });
  92.           }
  93.         },
  94.  
  95.     render: function(){
  96.         console.log("Teensy created");
  97.         const v=1;
  98.         return(
  99.             <div style={{display:'inline-block', paddingLeft:'20', paddingRight:'20', opacity:this.state.opacity}}>
  100.                 <h2>Teensy: {this.props.name}</h2>
  101.                 <img onClick={this.clickEve} src="/pics/teensy_p.png" height="20" width="10"/>
  102.             </div>
  103.         );
  104.     }
  105. }
  106. );
  107. //Arduino class
  108. var Arduino=React.createClass(
  109. {
  110.     getInitialState: function () {
  111.           return {
  112.             opacity: 0
  113.           };
  114.         },
  115.     componentDidMount: function () {
  116.         var fadeTim = setInterval(fadeTimeout.bind(this), 100);
  117.         function fadeTimeout() {
  118.             var opacity = this.state.opacity;
  119.             opacity += .05;
  120.             if (opacity >= 1.0) {
  121.                 console.log("Interval cleared", opacity);
  122.               clearInterval(fadeTim);
  123.             }
  124.  
  125.             this.setState({
  126.               opacity: opacity
  127.             });
  128.           }
  129.         },
  130.     render: function(){
  131.         console.log("Arduino created");
  132.         return(
  133.         <div style={{display:'inline-block', paddingLeft:'20', paddingRight:'20', opacity: this.state.opacity}}>
  134.             <h2>Arduino: {this.props.name}</h2>
  135.             <img src="/pics/arduino-nano_p.png" height="500" width="200"/>
  136.         </div>
  137.         );
  138.     }
  139. }
  140. );
  141. //photon class
  142. var Photon=React.createClass(
  143. {
  144.     getInitialState: function () {
  145.           return {
  146.             opacity: 0
  147.           };
  148.         },
  149.     componentDidMount: function () {
  150.         var fadeTim = setInterval(fadeTimeout.bind(this), 100);
  151.         function fadeTimeout() {
  152.             var opacity = this.state.opacity;
  153.             opacity += .05;
  154.             if (opacity >= 1.0) {
  155.                 console.log("Interval cleared", opacity);
  156.               clearInterval(fadeTim);
  157.             }
  158.  
  159.             this.setState({
  160.               opacity: opacity
  161.             });
  162.           }
  163.         },
  164.     render: function(){
  165.         console.log("Photon created");
  166.         return(
  167.         <div style={{display:'inline-block', paddingLeft:'20', paddingRight:'20', opacity:this.state.opacity}}>
  168.             <h2>Photon: {this.props.name}</h2>
  169.             <img src="/pics/photon_p.png" height="400" width="200"/>
  170.         </div>
  171.         );
  172.     }
  173. }
  174. );
  175.  
  176. var Photon2=React.createClass(
  177. {
  178.     render: function(){
  179.         console.log("Photon2 created");
  180.         return(
  181.         <div style={{display:'inline-block', width:'200', height:'400', borderRadius:'25', paddingLeft:'20', paddingRight:'20', background:'#424242', margin:'20'}}>
  182.             <h2>Photon2: {this.props.name}</h2>
  183.             <PItem id='1' mode='In' value='Low'/>
  184.             <PItem id='2' mode='In' value='Low'/>
  185.             <PItem id='3' mode='In' value='Low'/>
  186.             <PItem id='4' mode='In' value='Low'/>
  187.         </div>
  188.         );
  189.     }
  190. }
  191. );
  192.  
  193. var PItem=React.createClass(
  194. {
  195.     click: function(data){
  196.         console.log("Click",data.target.id);
  197.     },
  198.     render: function(){
  199.         console.log("Photon2 created");
  200.         return(
  201.         <div>
  202.         {this.props.mode}
  203.         <div id={this.props.id} style={{display:'inline-block', width:'50', height:'50', borderRadius:'25', background:'#78909C', marginTop:'10'}} onClick={this.click}></div>
  204.         {this.props.value}
  205.         </div>
  206.         );
  207.     }
  208. }
  209. );
  210.  
  211. var AddButton=React.createClass({
  212.     getInitialState: function () {
  213.           return {
  214.             borderColor: '#2196F3'
  215.           };
  216.         },
  217.     clickEve: function(data){
  218.         console.log("Plus");
  219.     if (this.props.onClickFunc) {
  220.       this.props.onClickFunc({
  221.         type: 'teensy',
  222.         name: 'lofaszjoska' + Math.random(1000)
  223.       });
  224.     }
  225.     },
  226.     mouseE: function(){
  227.         console.log("MouseO");
  228.  
  229.         this.setState({
  230.               borderColor: '#BBDEFB'
  231.             });
  232.     },
  233.     mouseL: function(){
  234.         console.log("MouseO");
  235.  
  236.         this.setState({
  237.               borderColor: '#2196F3'
  238.             });
  239.     },
  240.     render: function(){
  241.         console.log("Addbutton created");
  242.         return(
  243.         <div style={{display:'inline-block', width:'300', height:'250', borderStyle:'solid', borderWidths:'10', borderColor:this.state.borderColor, borderRadius:'25', background:'#2196F3', position: 'absolute', top: '0', right: '0'}} onClick={this.clickEve} onMouseEnter={this.mouseE} onMouseLeave={this.mouseL}>
  244.             <img src="/pics/plus_p.png" style={{paddingTop:'60', paddingLeft:'80'}}/>
  245.         </div>
  246.         );
  247.     }
  248. }
  249. );
  250.  
  251. //------------------------------------------------------------------------------------------------------------------------------
  252. //Main--------------------------------------------------------------------------------------------------------------------------
  253. //------------------------------------------------------------------------------------------------------------------------------
  254. ReactDOM.render(<Main/>, document.getElementById('example'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement