Dynamic blocks
This commit is contained in:
		
							
								
								
									
										4
									
								
								client/src/blocks/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								client/src/blocks/index.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | module.exports = { | ||||||
|  |   input: require("./input.js"), | ||||||
|  |   output: require("./output.js") | ||||||
|  | } | ||||||
							
								
								
									
										13
									
								
								client/src/blocks/input.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								client/src/blocks/input.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | module.exports =  { | ||||||
|  |   name: "Input", | ||||||
|  |   inputs: { | ||||||
|  |   }, | ||||||
|  |   output: true, | ||||||
|  |   execute: function({}, block){ | ||||||
|  |     block.find("input[name='input']").val(); | ||||||
|  |   }, | ||||||
|  |   pageBlock: { | ||||||
|  |     html: "<input type='text' name='input'></input>", | ||||||
|  |     js: function(){} | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										14
									
								
								client/src/blocks/output.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								client/src/blocks/output.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | |||||||
|  | module.exports =  { | ||||||
|  |   name: "Output", | ||||||
|  |   inputs: { | ||||||
|  |     input: "Input" | ||||||
|  |   }, | ||||||
|  |   output: false, | ||||||
|  |   execute: function({input}, block){ | ||||||
|  |     $(elem).find("div.output").html(input1); | ||||||
|  |   }, | ||||||
|  |   pageBlock: { | ||||||
|  |     html: "<span class='output'></span>", | ||||||
|  |     js: function(){} | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										15
									
								
								client/src/blocks/template.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								client/src/blocks/template.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | module.exports =  { | ||||||
|  |   name: "Example Block", | ||||||
|  |   inputs: { | ||||||
|  |     input1: "Input 1" | ||||||
|  |   }, | ||||||
|  |   output: true, | ||||||
|  |   execute: function({input1}, elem){ | ||||||
|  |     $(elem).find("div.input1").html(input1); | ||||||
|  |     return (output = parseInt(input1) + 1).toString(); | ||||||
|  |   }, | ||||||
|  |   pageBlock: { | ||||||
|  |     html: "<div class='input1'></div>", | ||||||
|  |     js: function(){} | ||||||
|  |   } | ||||||
|  | } | ||||||
							
								
								
									
										1
									
								
								client/src/document.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								client/src/document.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | module.exports = {}; | ||||||
| @@ -7,38 +7,8 @@ | |||||||
|       Header will go here |       Header will go here | ||||||
|     </div> |     </div> | ||||||
|     <div id="blocks"> |     <div id="blocks"> | ||||||
|       <div class="block"> |  | ||||||
|         <div class="inputs"> |  | ||||||
|           <div id="input1">Input 1</div> |  | ||||||
|           <div id="input2">Input 2</div> |  | ||||||
|         </div> |  | ||||||
|         <div class="main"> |  | ||||||
|           <div> |  | ||||||
|             <div class="title">Test Block</div> |  | ||||||
|             <div class="content">Custom code will go here</div> |  | ||||||
|           </div> |  | ||||||
|         </div> |  | ||||||
|         <div class="output"> |  | ||||||
|           Output |  | ||||||
|         </div> |  | ||||||
|       </div> |  | ||||||
|     </div> |     </div> | ||||||
|     <div id="workspace"> |     <div id="workspace"> | ||||||
|       <div class="block"> |  | ||||||
|         <div class="inputs"> |  | ||||||
|           <div id="input1">Input 1</div> |  | ||||||
|           <div id="input2">Input 2</div> |  | ||||||
|         </div> |  | ||||||
|         <div class="main"> |  | ||||||
|           <div> |  | ||||||
|             <div class="title">Test Block</div> |  | ||||||
|             <div class="content">Custom code will go here</div> |  | ||||||
|           </div> |  | ||||||
|         </div> |  | ||||||
|         <div class="output"> |  | ||||||
|           Output |  | ||||||
|         </div> |  | ||||||
|       </div> |  | ||||||
|     </div> |     </div> | ||||||
|   </body> |   </body> | ||||||
| </html> | </html> | ||||||
|   | |||||||
| @@ -1 +1,2 @@ | |||||||
| require("./styles.scss"); | require("./styles.scss"); | ||||||
|  | require("./pageInteraction"); | ||||||
|   | |||||||
							
								
								
									
										18
									
								
								client/src/pageInteraction/block.hbs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								client/src/pageInteraction/block.hbs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | |||||||
|  | <div class="block"> | ||||||
|  |   <div class="inputs"> | ||||||
|  |     {{#each inputs as |desc name|}} | ||||||
|  |       <div id="{{name}}">{{desc}}</div> | ||||||
|  |     {{/each}} | ||||||
|  |   </div> | ||||||
|  |   <div class="main"> | ||||||
|  |     <div> | ||||||
|  |       <div class="title">{{name}}</div> | ||||||
|  |       {{{pageBlock.html}}} | ||||||
|  |     </div> | ||||||
|  |   </div> | ||||||
|  |   {{#if output}} | ||||||
|  |     <div class="output"> | ||||||
|  |       Output | ||||||
|  |     </div> | ||||||
|  |   {{/if}} | ||||||
|  | </div> | ||||||
							
								
								
									
										0
									
								
								client/src/pageInteraction/dragDrop.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								client/src/pageInteraction/dragDrop.js
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										1
									
								
								client/src/pageInteraction/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								client/src/pageInteraction/index.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | require("./setupBlocks.js"); | ||||||
							
								
								
									
										5
									
								
								client/src/pageInteraction/setupBlocks.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								client/src/pageInteraction/setupBlocks.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | |||||||
|  | var $ = require("jquery"); | ||||||
|  | var blocks = require("../blocks"); | ||||||
|  | for(var block of Object.keys(blocks)){ | ||||||
|  |   $("#blocks").append(require("./block.hbs")(blocks[block])); | ||||||
|  | } | ||||||
| @@ -9,6 +9,14 @@ body{ | |||||||
|   flex-direction: column; |   flex-direction: column; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #blocks{ | ||||||
|  |   display: flex; | ||||||
|  |   flex-direction: row; | ||||||
|  |   .block{ | ||||||
|  |     margin: 10px; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| .block{ | .block{ | ||||||
|   width: 200px; |   width: 200px; | ||||||
|   height: 200px; |   height: 200px; | ||||||
| @@ -19,6 +27,7 @@ body{ | |||||||
|     display: flex; |     display: flex; | ||||||
|     flex-direction: row; |     flex-direction: row; | ||||||
|     >div{ |     >div{ | ||||||
|  |       font-weight: bold; | ||||||
|       border: 1px solid black; |       border: 1px solid black; | ||||||
|       flex-grow: 1; |       flex-grow: 1; | ||||||
|       text-align: center; |       text-align: center; | ||||||
| @@ -37,6 +46,7 @@ body{ | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   >.output{ |   >.output{ | ||||||
|  |     font-weight: bold; | ||||||
|     border: 1px solid black; |     border: 1px solid black; | ||||||
|     text-align: center; |     text-align: center; | ||||||
|     padding-top: 5px; |     padding-top: 5px; | ||||||
| @@ -48,7 +58,5 @@ body{ | |||||||
|   position: relative; |   position: relative; | ||||||
|   .block{ |   .block{ | ||||||
|     position: absolute; |     position: absolute; | ||||||
|     top: 40px; |  | ||||||
|     left: 40px; |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -24,6 +24,14 @@ module.exports = { | |||||||
|         }, { |         }, { | ||||||
|           loader: "sass-loader" |           loader: "sass-loader" | ||||||
|         }] |         }] | ||||||
|  |       }, | ||||||
|  |       { | ||||||
|  |         test: /\.hbs$/, | ||||||
|  |         use: [ | ||||||
|  |           { | ||||||
|  |             loader: "handlebars-loader" | ||||||
|  |           } | ||||||
|  |         ] | ||||||
|       } |       } | ||||||
|     ] |     ] | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -19,7 +19,10 @@ | |||||||
|   "homepage": "https://github.com/TimStallard/CryptoAssist#readme", |   "homepage": "https://github.com/TimStallard/CryptoAssist#readme", | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|     "css-loader": "^0.26.1", |     "css-loader": "^0.26.1", | ||||||
|  |     "handlebars": "^4.0.6", | ||||||
|  |     "handlebars-loader": "^1.4.0", | ||||||
|     "html-webpack-plugin": "^2.28.0", |     "html-webpack-plugin": "^2.28.0", | ||||||
|  |     "jquery": "^3.1.1", | ||||||
|     "node-sass": "^4.5.0", |     "node-sass": "^4.5.0", | ||||||
|     "sass-loader": "^6.0.1", |     "sass-loader": "^6.0.1", | ||||||
|     "style-loader": "^0.13.1", |     "style-loader": "^0.13.1", | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user