Commit ea08550f authored by GROSS-AMBLARD David's avatar GROSS-AMBLARD David
Browse files

Glue blocky generator with real artifacts.

parent 608aa87c
......@@ -1257,18 +1257,6 @@ function searchForum($getArray)
}
}
/**
* Show the Embark page
* @param A valid PDO connection
*/
function embark($conn){
global $VIEW;
$VIEW['MAIN']=file_get_contents("templates/template-embark.tmpl");
// TODO: insert new artifact class from code. Check json encoding first
}
/**
* Display Tasks Viewer page.
*
......
<h1>Embark others!</h1>
<p>
Do not hesitate to ask you own questions! Many contributors may give you intersesting insights!
</p>
<p>
Fill in your query. The ongoing task will appear in the project "My own project"
</p>
<p>
UNDER DEVELOPMENT: COMING SOON!
</p>
<pre>
Ask to anyone "If I should see only one, which cyberpunk movie should I see?"
</pre>
<form action="index.php?mode=addArtifact" method="POST">
<input type="hidden" id="artifact" name="artifact" value='
{
"doc":"My own activity",
"author":"You",
"1": {
"2": {
"guard": "none",
"actions": [
"prepare task 1 as basic",
"use &apos;If I should see only one, which cyberpunk movie should I see?&apos; as title",
"use &apos;If I should see only one, which cyberpunk movie should I see?&apos; as description",
"select @CHECKER:=NULL",
"select @CHECKERMSG:=NULL",
"forget profile for current artifact",
"offer task to anyone",
"install task"
]
}
},
"2": {
"3": {
"guard": "task 1 is answered",
"actions": ["delete from Task where artifact=CURRENT_ARTIFACT"]
}
},
"3":{}
}
'>
<input type="submit" value="submit">
</form>
<h1>Embark others!</h1>
<p>
Do not hesitate to ask you own questions.Many contributors may give you interesting insights!
Create your activity for the crowd by assembling some block below.The ongoing task will appear in project "My own project".
</p>
<form action="index.php?mode=addArtifact" method="POST">
<input type="hidden" id="artifact" name="artifact" value=''>
<div class="container">
<div class="row">
<div class="col bg-secondary text-white">
<div id="hw-artefact-info">
</div>
</div>
</div>
</div>
<!--Création de l'html nécessaire à l'injection de blockly-->
<div id="blocklyArea" style="height: 700px; width: 1150px;"></div>
<div id="blocklyDiv" style="position: absolute"></div>
<textarea id="textarea" style="height: 700px; width: 1150px;"></textarea>
<!--Récupération des scripts de node_modules utiles pour blockly-->
<script type ="module", src="node_modules">import Blockly from 'blockly';</script>
<script src="node_modules/blockly/blockly_compressed.js"></script>
<script src="node_modules/blockly/javascript_compressed.js"></script>
<script src="node_modules/blockly/blocks_compressed.js"></script>
<script src="node_modules/blockly/msg/en.js"></script>
<script>
/*Blockly.Blocks['answers'] = {
init: function() {
this.appendValueInput("commande")
.setCheck(null)
.appendField("Do")
.appendField(new Blockly.FieldTextInput("commande"), "commande")
.appendField("awaiting")
.appendField(new Blockly.FieldNumber(0), "answers")
.appendField("answers");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};
*/
Blockly.Blocks['do_count'] = {
init: function() {
this.appendDummyInput()
.appendField(" Do");
this.appendStatementInput("com")
.setCheck(null)
.appendField("Awaiting")
.appendField(new Blockly.FieldNumber(1), "reponse")
.appendField("answers");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};
/*Blockly.JavaScript['answers'] = function(block) {
var text_commande = block.getFieldValue('commande');
var number_answers = block.getFieldValue('answers');
var value_commande = Blockly.JavaScript.valueToCode(block, 'commande', Blockly.JavaScript.ORDER_ATOMIC);
// TODO: Assemble JavaScript into code variable.
var json = "Do " + text_commande + " awaiting " + number_answers + " answers "
var code = JSON.stringify(json, null, '\t');
return code;
};
*/
Blockly.JavaScript['do_count'] = function(block) {
var number_reponse = block.getFieldValue('reponse');
var statements_com = Blockly.JavaScript.statementToCode(block, 'com');
/* if(statements_com != null) {
var res = statements_com.replaceAll("\"","'")
}
*/
var res=statements_com;
var json = `
{
"1": {
"2":{
"guard":"none",
"actions":`+res+`
}
},
"2": {
"3":{
"guard":"task 1 is answered",
"actions":["delete from Task where artifact=CURRENT_ARTIFACT"]
}
},
"3": {}
}
`;
return json;
};
Blockly.Blocks['ask_dropdown'] = {
init: function() {
this.appendDummyInput()
.appendField("Ask to anyone ")
.appendField(new Blockly.FieldTextInput("question"), "question")
.appendField(new Blockly.FieldDropdown([["yes/no","yes/no"], ["free input","free input"], ["list","list"], ["integer","integer"], ["picture","picture"], ["real","real"], ["URL","URL"] ]), "type");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(20);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['ask_dropdown'] = function(block) {
var question = block.getFieldValue('question');
var type = block.getFieldValue('type');
var checker=".*";
var checkermsg="free input"
if (type=="yes/no"){
checker="yes|no";
checkermsg="Please answer yes or no";
}
var json = `[
"prepare task 1 as basic",
"use 'headwork-gui-1' as template",
"use 'Simple question, simple checking' as title",
"use 'Simple question, simple checking' as description",
"use 'REGEXP ''^A$''' as checker",
"forget profile for current artifact",
"offer task to anyone",
"skill 1004 is relevant for the task",
"install task"
]`;
//var code = json;//JSON.stringify(json, null, '\t');
json=`[
\"prepare task 1 as basic\",
\"use '`+question+`' as title\",
\"use '`+question+`' as description\",
\"use 'REGEXP ''`+ checker + `''' as checker\",
\"use '`+ checkermsg+`' as checker message\",
\"offer task to anyone\",
\"install task\"
]`;
// TODO try to add commands here
var code=json;
return code;
};
Blockly.Blocks['take_majority'] = {
init: function() {
this.appendDummyInput()
.appendField("Take majority");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(120);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['take_majority'] = function(block) {
// TODO: Assemble JavaScript into code variable.
var json = "Take majority"
var code = JSON.stringify(json, null, '\t');
return code;
};
Blockly.Blocks['take_average'] = {
init: function() {
this.appendDummyInput()
.appendField("Take average");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(65);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['take_average'] = function(block) {
// TODO: Assemble JavaScript into code variable.
var json = "Take average"
var code = JSON.stringify(json, null, '\t');
return code;
};
Blockly.Blocks['do_abs_majority'] = {
init: function() {
this.appendDummyInput()
.appendField("Do");
this.appendStatementInput("NAME")
.setCheck(null)
.appendField("Task has reached absolute majority out of")
.appendField(new Blockly.FieldNumber(0), "NAME");
this.setColour(20);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['do_abs_majority'] = function(block) {
var number_name = block.getFieldValue('NAME');
var statements_name = Blockly.JavaScript.statementToCode(block, 'NAME');
// TODO: Assemble JavaScript into code variable.
if(statements_name != null) {
var res = statements_name.replaceAll("\"","'")
}
var json = " Do" + res +" Task has reached absolute majority out of " + number_name
var code = JSON.stringify(json, null, '\t');
return code;
};
Blockly.Blocks['do_consensus'] = {
init: function() {
this.appendDummyInput()
.appendField("Do");
this.appendStatementInput("NAME")
.setCheck(null)
.appendField("Task has reached consensus out of")
.appendField(new Blockly.FieldNumber(0), "NAME");
this.setColour(290);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['do_consensus'] = function(block) {
var number_name = block.getFieldValue('NAME');
var statements_name = Blockly.JavaScript.statementToCode(block, 'NAME');
// TODO: Assemble JavaScript into code variable.
if(statements_name != null) {
var res = statements_name.replaceAll("\"","'")
}
var json = "Do" + res + " Task has reached consensus out of " + number_name
var code = JSON.stringify(json, null, '\t');
return code;
};
</script>
<!--Création de la toolbox de blockly-->
<!--<block type="answers"></block> -->
<xml id="toolbox" style="display: none">
<category name ="Click to build your activity for the crowd" colour="210">
<block type="do_count"></block>
<block type="ask_dropdown"></block>
<!--
<block type="take_majority"></block>
<block type="take_average"></block>
<block type="do_abs_majority"></block>
<block type="do_consensus"></block>
-->
</category>
</xml>
<!--Script de Redimmensionnement de la div contenant le workspace de blockly-->
<script>
var blocklyArea = document.getElementById('blocklyArea');
var blocklyDiv = document.getElementById('blocklyDiv');
var workspace = Blockly.inject(blocklyDiv,
{toolbox: document.getElementById('toolbox'),
grid:
{spacing: 20,
length: 3,
colour: '#ccc',
snap: true},
trashcan: true});
var onresize = function(e) {
// Compute the absolute coordinates and dimensions of blocklyArea.
var element = blocklyArea;
var x = 0;
var y = 0;
do {
x += element.offsetLeft;
y += element.offsetTop;
element = element.offsetParent;
} while (element);
// Position blocklyDiv over blocklyArea.
blocklyDiv.style.left = x + 'px';
blocklyDiv.style.top = y + 'px';
blocklyDiv.style.width = blocklyArea.offsetWidth + 'px';
blocklyDiv.style.height = blocklyArea.offsetHeight + 'px';
Blockly.svgResize(workspace);
};
window.addEventListener('resize', onresize, false);
onresize();
Blockly.svgResize(workspace);
var code = Blockly.JavaScript.workspaceToCode(workspace);
</script>
<!--Création du code Javascript à partir du workspace de blocky-->
<script>
function myUpdateFunction(event) {
var code = Blockly.JavaScript.workspaceToCode(workspace);
document.getElementById('textarea').value = code;
document.getElementById('artifact').value = code;
}
workspace.addChangeListener(myUpdateFunction);
</script>
<!--Permet de récupérer la valeur du code saisie par l'utilisateur-->
<script>
function getValue() {
var input = document.getElementById("textarea").value;
var tb_str = input.split('\'');
if(tb_str[2] != null) {
var res = tb_str[2].replaceAll("\"","")
}
var json = {"1":{"2":{ "guard": "none", "actions": [ tb_str[1] ]} }, "2": { "3": { "guard": res , "actions": "" } }, "3": {} } ;
alert(JSON.stringify(json, null, ' '));
}
</script>
</br>
<input type="submit" value="submit">
</form>
<?php
/**
* workflowdesign
*
* Displays a custom blockly component for artifact design.
* $conn: database connection
*/
function workflowdesign($conn){
global $VIEW;
$VIEW['MAIN'].=<<<EOF
<div class="container">
<div class="row">
<div class="col bg-secondary text-white">
<div id="hw-artefact-info">Enter your workflow
</div>
</div>
</div>
</div>
<!--Création de l'html nécessaire à l'injection de blockly-->
<div id="blocklyArea" style="height: 700px; width: 1150px;"></div>
<div id="blocklyDiv" style="position: absolute"></div>
<textarea id="textarea" style="height: 700px; width: 1150px;"></textarea>
<!--Récupération des scripts de node_modules utiles pour blockly-->
<script type ="module", src="node_modules">import Blockly from 'blockly';</script>
<script src="node_modules/blockly/blockly_compressed.js"></script>
<script src="node_modules/blockly/javascript_compressed.js"></script>
<script src="node_modules/blockly/blocks_compressed.js"></script>
<script src="node_modules/blockly/msg/en.js"></script>
<script>
Blockly.Blocks['answers'] = {
init: function() {
this.appendValueInput("commande")
.setCheck(null)
.appendField("Do")
.appendField(new Blockly.FieldTextInput("commande"), "commande")
.appendField("awaiting")
.appendField(new Blockly.FieldNumber(0), "answers")
.appendField("answers");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.Blocks['do_commande'] = {
init: function() {
this.appendDummyInput()
.appendField(" Do");
this.appendStatementInput("com")
.setCheck(null)
.appendField("Awaiting")
.appendField(new Blockly.FieldNumber(0), "reponse")
.appendField("answers");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['answers'] = function(block) {
var text_commande = block.getFieldValue('commande');
var number_answers = block.getFieldValue('answers');
var value_commande = Blockly.JavaScript.valueToCode(block, 'commande', Blockly.JavaScript.ORDER_ATOMIC);
// TODO: Assemble JavaScript into code variable.
var json = "Do " + text_commande + " awaiting " + number_answers + " answers "
var code = JSON.stringify(json, null, '\t');
return code;
};
Blockly.JavaScript['do_commande'] = function(block) {
var number_reponse = block.getFieldValue('reponse');
var statements_com = Blockly.JavaScript.statementToCode(block, 'com');
if(statements_com != null) {
var res = statements_com.replaceAll("\"","'")
}
// TODO: Assemble JavaScript into code variable.
var json = " Do " + res + " Awaiting " + number_reponse + " answers "
var code = JSON.stringify(json, null, '\t');
return code;
};
Blockly.Blocks['ask_dropdown'] = {
init: function() {
this.appendDummyInput()
.appendField("Ask to anyone ")
.appendField(new Blockly.FieldTextInput("question"), "NAME")
.appendField(new Blockly.FieldDropdown([["yes/no","yes/no"], ["free input","free input"], ["list","list"], ["integer","integer"], ["picture","picture"], ["real","real"], ["URL","URL"] ]), "DROP");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(20);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['ask_dropdown'] = function(block) {
var text_name = block.getFieldValue('NAME');
var dropdown_name = block.getFieldValue('DROP');
// TODO: Assemble JavaScript into code variable.
var json ="Ask to anyone " + text_name + " " + dropdown_name
var code = JSON.stringify(json, null, '\t');
return code;
};
Blockly.Blocks['take_majority'] = {
init: function() {
this.appendDummyInput()
.appendField("Take majority");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(120);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['take_majority'] = function(block) {
// TODO: Assemble JavaScript into code variable.
var json = "Take majority"
var code = JSON.stringify(json, null, '\t');
return code;
};
Blockly.Blocks['take_average'] = {
init: function() {
this.appendDummyInput()
.appendField("Take average");
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(65);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['take_average'] = function(block) {
// TODO: Assemble JavaScript into code variable.
var json = "Take average"
var code = JSON.stringify(json, null, '\t');
return code;
};
Blockly.Blocks['task_has_reached'] = {
init: function() {
this.appendDummyInput()
.appendField("Do");
this.appendStatementInput("NAME")
.setCheck(null)
.appendField("Task has reached absolute majority out of")
.appendField(new Blockly.FieldNumber(0), "NAME");
this.setColour(20);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['task_has_reached'] = function(block) {
var number_name = block.getFieldValue('NAME');
var statements_name = Blockly.JavaScript.statementToCode(block, 'NAME');
// TODO: Assemble JavaScript into code variable.
if(statements_name != null) {
var res = statements_name.replaceAll("\"","'")
}
var json = " Do" + res +" Task has reached absolute majority out of " + number_name
var code = JSON.stringify(json, null, '\t');
return code;
};
Blockly.Blocks['task_has_consensus'] = {
init: function() {
this.appendDummyInput()
.appendField("Do");
this.appendStatementInput("NAME")
.setCheck(null)
.appendField("Task has reached consensus out of")
.appendField(new Blockly.FieldNumber(0), "NAME");
this.setColour(290);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['task_has_consensus'] = function(block) {
var number_name = block.getFieldValue('NAME');
var statements_name = Blockly.JavaScript.statementToCode(block, 'NAME');
// TODO: Assemble JavaScript into code variable.
if(statements_name != null) {
var res = statements_name.replaceAll("\"","'")
}
var json = "Do" + res + " Task has reached consensus out of " + number_name
var code = JSON.stringify(json, null, '\t');
return code;
};
</script>
<!--Création de la toolbox de blockly-->
<xml id="toolbox" style="display: none">
<category name ="Blocs customs" colour="210">
<block type="answers"></block>
<block type="do_commande"></block>
<block type="ask_dropdown"></block>
<block type="take_majority"></block>
<block type="take_average"></block>
<block type="task_has_reached"></block>
<block type="task_has_consensus"></block>
</category>
</xml>
<!--Script de Redimmensionnement de la div contenant le workspace de blockly-->
<script>
var blocklyArea = document.getElementById('blocklyArea');
var blocklyDiv = document.getElementById('blocklyDiv');