Mostly added import/export
This commit is contained in:
parent
f157a5aaa2
commit
69547f6114
@ -63,13 +63,11 @@ module.exports = {
|
|||||||
//first
|
//first
|
||||||
topGroups = topGroupsByFrequency(getFrequency(getFirstLetters(input, parseInt(block.properties.type))));
|
topGroups = topGroupsByFrequency(getFrequency(getFirstLetters(input, parseInt(block.properties.type))));
|
||||||
}
|
}
|
||||||
block.properties.chartTop.data.labels = topGroups.labels;
|
$(block.elem).data("chartTop").data.labels = topGroups.labels;
|
||||||
block.properties.chartTop.data.datasets[0] = {
|
$(block.elem).data("chartTop").data.datasets[0] = {
|
||||||
data: topGroups.values
|
data: topGroups.values
|
||||||
};
|
};
|
||||||
block.properties.chartTop.update();
|
$(block.elem).data("chartTop").update();
|
||||||
|
|
||||||
return input;
|
|
||||||
},
|
},
|
||||||
size: { //update static widths in HTML as well
|
size: { //update static widths in HTML as well
|
||||||
height: 400,
|
height: 400,
|
||||||
@ -78,10 +76,10 @@ module.exports = {
|
|||||||
pageBlock: {
|
pageBlock: {
|
||||||
html: `
|
html: `
|
||||||
<select>
|
<select>
|
||||||
<option value="1">Single Letters</option>
|
<option value="1">Single Letters</option>
|
||||||
<option value="2">Digraphs</option>
|
<option value="2">Digraphs</option>
|
||||||
<option value="3">Trigraphs</option>
|
<option value="3">Trigraphs</option>
|
||||||
<option value="first">1st Letter</option>
|
<option value="first">1st Letter</option>
|
||||||
</select>
|
</select>
|
||||||
<span class="topHidden">
|
<span class="topHidden">
|
||||||
<div class="canvasContainer">
|
<div class="canvasContainer">
|
||||||
@ -113,17 +111,17 @@ module.exports = {
|
|||||||
var standardFrequency = standardFrequencies[block.properties.type];
|
var standardFrequency = standardFrequencies[block.properties.type];
|
||||||
var standardGroups = topGroupsByFrequency(standardFrequency, true);
|
var standardGroups = topGroupsByFrequency(standardFrequency, true);
|
||||||
|
|
||||||
block.properties.chartBottom.data.labels = standardGroups.labels;
|
$(block.elem).data("chartBottom").data.labels = standardGroups.labels;
|
||||||
block.properties.chartBottom.data.datasets[0] = {
|
$(block.elem).data("chartBottom").data.datasets[0] = {
|
||||||
data: standardGroups.values
|
data: standardGroups.values
|
||||||
};
|
};
|
||||||
block.properties.chartBottom.update();
|
$(block.elem).data("chartBottom").update();
|
||||||
|
|
||||||
events.emit("inputChanged");
|
events.emit("inputChanged");
|
||||||
});
|
});
|
||||||
|
|
||||||
var Chart = require("chart.js");
|
var Chart = require("chart.js");
|
||||||
block.properties.chartTop = new Chart(
|
$(block.elem).data("chartTop", new Chart(
|
||||||
$(block.elem).find(".chart.top"),
|
$(block.elem).find(".chart.top"),
|
||||||
{
|
{
|
||||||
type: "bar",
|
type: "bar",
|
||||||
@ -137,8 +135,8 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
));
|
||||||
block.properties.chartBottom = new Chart(
|
$(block.elem).data("chartBottom", new Chart(
|
||||||
$(block.elem).find(".chart.bottom"),
|
$(block.elem).find(".chart.bottom"),
|
||||||
{
|
{
|
||||||
type: "bar",
|
type: "bar",
|
||||||
@ -158,7 +156,7 @@ module.exports = {
|
|||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
));
|
||||||
|
|
||||||
$(block.elem).find("select").change();
|
$(block.elem).find("select").change();
|
||||||
}
|
}
|
||||||
|
@ -6,12 +6,16 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
output: true,
|
output: true,
|
||||||
execute: function({}, block){
|
execute: function({}, block){
|
||||||
return block.elem.find("input[name='input']").val();
|
return block.properties.value;
|
||||||
},
|
},
|
||||||
pageBlock: {
|
pageBlock: {
|
||||||
html: "<input type='text' name='input'></input>",
|
html: "<input type='text' name='input'></input>",
|
||||||
js: function(block){
|
js: function(block){
|
||||||
|
if(block.properties.value){
|
||||||
|
block.elem.find("input[name='input']").val(block.properties.value);
|
||||||
|
}
|
||||||
$(block.elem).find("input[name='input']").keyup(function(){
|
$(block.elem).find("input[name='input']").keyup(function(){
|
||||||
|
block.properties.value = block.elem.find("input[name='input']").val();
|
||||||
events.emit("inputChanged");
|
events.emit("inputChanged");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ module.exports = {
|
|||||||
name: "Vigenere Decode",
|
name: "Vigenere Decode",
|
||||||
inputs: {
|
inputs: {
|
||||||
cipherText: "Ciphertext",
|
cipherText: "Ciphertext",
|
||||||
key: "key"
|
key: "Key"
|
||||||
},
|
},
|
||||||
output: true,
|
output: true,
|
||||||
execute: function({cipherText, key}, elem){
|
execute: function({cipherText, key}, elem){
|
||||||
|
9
client/src/diagram/export.js
Normal file
9
client/src/diagram/export.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
module.exports = function(){
|
||||||
|
var diagram = require("./index.js");
|
||||||
|
return JSON.stringify(diagram, function(key, value){
|
||||||
|
if(key == "elem"){
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
}
|
12
client/src/diagram/import.js
Normal file
12
client/src/diagram/import.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
var diagram = require("./index.js");
|
||||||
|
var events = require("../events.js");
|
||||||
|
var $ = require("jquery");
|
||||||
|
|
||||||
|
module.exports = function(newDiagram){
|
||||||
|
Object.assign(diagram, JSON.parse(newDiagram));
|
||||||
|
$("#workspace>*").remove();
|
||||||
|
for(var block of diagram.state){
|
||||||
|
require("../pageInteraction/addBlockToPage.js")(block);
|
||||||
|
}
|
||||||
|
events.emit("diagramImport");
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
name: "",
|
name: "New Diagram",
|
||||||
state: [],
|
state: [],
|
||||||
snapshots: []
|
snapshots: []
|
||||||
};
|
};
|
@ -4,7 +4,9 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="header">
|
<div id="header">
|
||||||
Header will go here
|
<a href="#" id="import">Open File</a>
|
||||||
|
<a href="#" id="export">Save</a>
|
||||||
|
<input type="file" id="importUpload"></input>
|
||||||
</div>
|
</div>
|
||||||
<div id="blocks">
|
<div id="blocks">
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
require("./styles.scss");
|
require("./styles.scss");
|
||||||
require("./pageInteraction");
|
require("./pageInteraction");
|
||||||
require("./outputCalculation.js");
|
require("./outputCalculation.js");
|
||||||
|
require("./menu.js");
|
||||||
|
|
||||||
//for lazy debugging, remove when done
|
//for lazy debugging, remove when done
|
||||||
window.diagram = require("./diagram.js");
|
window.diagram = require("./diagram");
|
||||||
window.$ = require("jquery");
|
window.$ = require("jquery");
|
||||||
|
window.exportDiagram = require("./diagram/export.js");
|
||||||
|
window.importDiagram = require("./diagram/import.js");
|
||||||
|
21
client/src/menu.js
Normal file
21
client/src/menu.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
var $ = require("jquery");
|
||||||
|
|
||||||
|
$("#header>a#export").click(function(){
|
||||||
|
var fileSaver = require("file-saver");
|
||||||
|
var exported = require("./diagram/export.js")();
|
||||||
|
var exportedBlob = new Blob([exported], {type: "text/plain;chartset=utf-8"})
|
||||||
|
fileSaver.saveAs(exportedBlob, diagram.name + ".json");
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#header>a#import").click(function(){
|
||||||
|
$("#header>#importUpload").click();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#header>#importUpload").change(function(){
|
||||||
|
var reader = new FileReader();
|
||||||
|
reader.onload = function(){
|
||||||
|
require("./diagram/import.js")(reader.result);
|
||||||
|
}
|
||||||
|
reader.readAsText(this.files[0]);
|
||||||
|
//console.log($("#header>#importUpload")[0].files[0])
|
||||||
|
})
|
@ -1,4 +1,4 @@
|
|||||||
var diagram = require("./diagram.js");
|
var diagram = require("./diagram");
|
||||||
var events = require("./events.js");
|
var events = require("./events.js");
|
||||||
var blocks = require("./blocks");
|
var blocks = require("./blocks");
|
||||||
|
|
||||||
@ -14,7 +14,10 @@ function resolveOutput(block, cache){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var output = blocks[block.type].execute(inputValues, block);
|
var output = "";
|
||||||
|
if(Object.keys(blocks[block.type].inputs).length == Object.keys(inputValues).length){
|
||||||
|
var output = blocks[block.type].execute(inputValues, block);
|
||||||
|
}
|
||||||
cache[block.id] = output;
|
cache[block.id] = output;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
@ -30,5 +33,6 @@ function calculateOutputBlocks(){
|
|||||||
|
|
||||||
events.subscribe("inputChanged", calculateOutputBlocks);
|
events.subscribe("inputChanged", calculateOutputBlocks);
|
||||||
events.subscribe("newJoin", calculateOutputBlocks);
|
events.subscribe("newJoin", calculateOutputBlocks);
|
||||||
|
events.subscribe("diagramImport", calculateOutputBlocks);
|
||||||
|
|
||||||
window.calculate = calculateOutputBlocks;
|
window.calculate = calculateOutputBlocks;
|
||||||
|
24
client/src/pageInteraction/addBlockToPage.js
Normal file
24
client/src/pageInteraction/addBlockToPage.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
var blocks = require("../blocks");
|
||||||
|
|
||||||
|
module.exports = function(newBlock){
|
||||||
|
var newBlockElement = $(
|
||||||
|
require("./block.hbs")({
|
||||||
|
block: blocks[newBlock.type],
|
||||||
|
instance: newBlock
|
||||||
|
})
|
||||||
|
).appendTo("#workspace");
|
||||||
|
newBlock.elem = newBlockElement;
|
||||||
|
if(blocks[newBlock.type].size){
|
||||||
|
newBlockElement.css({
|
||||||
|
height: blocks[newBlock.type].size.height,
|
||||||
|
width: blocks[newBlock.type].size.width
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if(newBlock.position){
|
||||||
|
newBlockElement.css({
|
||||||
|
top: newBlock.position.y,
|
||||||
|
left: newBlock.position.x
|
||||||
|
});
|
||||||
|
}
|
||||||
|
blocks[newBlock.type].pageBlock.js(newBlock);
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
var blocks = require("../blocks");
|
var blocks = require("../blocks");
|
||||||
var diagram = require("../diagram.js");
|
var diagram = require("../diagram");
|
||||||
var events = require("../events.js");
|
var events = require("../events.js");
|
||||||
var $ = require("jquery");
|
var $ = require("jquery");
|
||||||
var uuid = require("node-uuid");
|
var uuid = require("node-uuid");
|
||||||
@ -36,20 +36,7 @@ $("#blocks").on("mousedown", ".block>.main,.block>.inputs", function(event){
|
|||||||
properties: {}
|
properties: {}
|
||||||
}
|
}
|
||||||
diagram.state.push(newBlock);
|
diagram.state.push(newBlock);
|
||||||
var newBlockElement = $(
|
require("./addBlockToPage.js")(newBlock);
|
||||||
require("./block.hbs")({
|
|
||||||
block: blocks[newBlock.type],
|
|
||||||
instance: newBlock
|
|
||||||
})
|
|
||||||
).appendTo("#workspace");
|
|
||||||
newBlock.elem = newBlockElement;
|
|
||||||
if(blocks[newBlock.type].size){
|
|
||||||
newBlockElement.css({
|
|
||||||
height: blocks[newBlock.type].size.height,
|
|
||||||
width: blocks[newBlock.type].size.width
|
|
||||||
});
|
|
||||||
}
|
|
||||||
blocks[newBlock.type].pageBlock.js(newBlock);
|
|
||||||
blockPositionChange(event);
|
blockPositionChange(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
var blocks = require("../blocks");
|
var blocks = require("../blocks");
|
||||||
var diagram = require("../diagram.js");
|
var diagram = require("../diagram");
|
||||||
var events = require("../events.js");
|
var events = require("../events.js");
|
||||||
var $ = require("jquery");
|
var $ = require("jquery");
|
||||||
|
|
||||||
@ -58,6 +58,7 @@ $("#workspace").on("mouseup", ".block>.inputs>div", function(event){
|
|||||||
|
|
||||||
events.subscribe("blockMove", drawJoiningLines);
|
events.subscribe("blockMove", drawJoiningLines);
|
||||||
events.subscribe("blockDelete", drawJoiningLines);
|
events.subscribe("blockDelete", drawJoiningLines);
|
||||||
|
events.subscribe("diagramImport", drawJoiningLines);
|
||||||
|
|
||||||
function drawJoiningLines(){
|
function drawJoiningLines(){
|
||||||
$(".line").remove();
|
$(".line").remove();
|
||||||
|
@ -9,6 +9,12 @@ body{
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#header{
|
||||||
|
#importUpload{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#blocks{
|
#blocks{
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/TimStallard/CryptoAssist#readme",
|
"homepage": "https://github.com/TimStallard/CryptoAssist#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"chart.js": "^2.5.0",
|
||||||
"css-loader": "^0.26.1",
|
"css-loader": "^0.26.1",
|
||||||
|
"file-saver": "^1.3.3",
|
||||||
"handlebars": "^4.0.6",
|
"handlebars": "^4.0.6",
|
||||||
"handlebars-loader": "^1.4.0",
|
"handlebars-loader": "^1.4.0",
|
||||||
"html-webpack-plugin": "^2.28.0",
|
"html-webpack-plugin": "^2.28.0",
|
||||||
@ -29,7 +31,6 @@
|
|||||||
"style-loader": "^0.13.1",
|
"style-loader": "^0.13.1",
|
||||||
"uuid": "^3.0.1",
|
"uuid": "^3.0.1",
|
||||||
"webpack": "^2.2.1",
|
"webpack": "^2.2.1",
|
||||||
"webpack-dev-server": "^2.3.0",
|
"webpack-dev-server": "^2.3.0"
|
||||||
"chart.js": "^2.5.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user