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

Fixes artifact drawing (now in POST rather than in GET mode). Fixes Regexp...

Fixes artifact drawing (now in POST rather than in GET mode). Fixes Regexp syntax for Json. No more info on nodes.
parent 1528d2ae
<?php
/*
<!DOCTYPE html>
<html>
<head>
......@@ -44,9 +48,26 @@
//left: 0px;
}
</style>
</head>
<body>
*/
// TODO here convert into drawArtifact function
function drawArtifact($conn,$artifactid){
global $VIEW;
$stmt_artifact = $conn->query("select definition from Artifact, ArtifactClass where Artifact.id=$artifactid and Artifact.classid=ArtifactClass.id")->fetch();
$artifact_file = $stmt_artifact['definition'];
// lire le fichier, l'encoder en JSON avec mise en forme, et affichage dans une balise PRE
//$jsonString=htmlentities(json_encode(load_artifact($artifact_file),JSON_PRETTY_PRINT));
//$jsonString=json_encode(load_artifact($artifact_file),JSON_PRETTY_PRINT);
$jsonString=json_encode(load_artifact($artifact_file));
//$jsonString='{"author":"bob"}';
$VIEW['MAIN'].=<<<EOF
<div class="container">
<div class="row">
<div class="col bg-secondary text-white">
......@@ -69,87 +90,23 @@
</div>
</div>
</div>
<script>
<script type="text/javascript">
/*window.onerror = function (msg, url, line) {
alert("Message : " + msg );
alert("url : " + url );
alert("Line number : " + line );
}
*/
EOF;
$VIEW['MAIN'].="var jsonString=`".$jsonString."`;";
$VIEW['MAIN'].=<<<'EOF'
const queryString = window.location.search;
console.log('query string '+queryString);
const urlParams = new URLSearchParams(queryString);
var jsonString = urlParams.get('json')
//console.log('json input '+jsonInput);
/*var jsonString = `{"author" : "le nom de l'auteur",
"doc" : "un texte html qui explique le .sca",
"1": {
"2": {
"guard": "select true from dual",
"actions": [
"-- tout ce qui commence par -- doit etre affiché <b>comme</b> de l'HTML",
"-- <h3>ceci devrait etre un titre</h3>",
"-- et <a href='http://www.irisa.fr'>ca</a> un lien",
"-- et les autres, qui ne commence pas par --, doivent être entre balises <pre> ou <code>",
"select @TEMPLATE:=body from Template where id='headwork-step1'",
"insert into Task(title,description,body,checker,checkermsg,artifact,ajax) values ('demo','Step 1: What is Headwork ?',@TEMPLATE,'REGEXP '''^-?[0-9]+$''','please, enter an integer',1000,false)",
"insert into Profile (select id,1 from Task)"
]
}
}
,"2": {
"3": {
"guard": "select count(*)>=1 from Answer",
"actions": [
"-- delete from profile",
"delete from Task where artifact=1000",
"select @TEMPLATE:=body from Template where id='headwork-step2'",
"insert into Task(title,description,body,type,artifact) select 'demo','Step 2: Making decisions',replace(@TEMPLATE,'TAG1',if(value='2','right!','wrong, sorry')),0,1000 from Answer",
"insert into Profile (select id,1 from Task)"
]
},
"4": {}
}
,"3": {
"4": {
"guard": "select count(*)>=2 from Answer",
"actions": [
"-- delete from profile",
"delete from Task where artifact=1000",
"insert into Task(title,description,body,type,checker,checkermsg,artifact) values ('demo','Step 3: Skills','Congratulations ! You are now aware of the basics of Headwork. You were granted this specific skill in your SKILL TREE (skills top menu). Look inside to see your score. This score is used to rank the tasks proposed to you (relevance score).',0,null,'',1000)",
"insert into Profile (select id,1 from Task)"
]
}
},
"4": {
"5": {
"guard": "select count(*)>=3 from Answer",
"actions": [
"delete from Task where artifact=1000",
"delete from Skills where iduser=SESSION_USER and idskill=1004",
"insert into Skills values (SESSION_USER,1004,5gg0)",
"insert into Skills values (SESSION_USER,1003,20)"
]
}
},
"5":{}
}`;
*/
var json= (jsonString.replace("\\","qqq"));
//var json = JSON.stringify(jsonString);
var obj;
try {
obj = JSON.parse(jsonString);
} catch(e) {
console.log("error"+jsonString);
alert(e); // error in the above string (in this case, yes)!
}
//{"1":{"2":{"guard":"none","actions":["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","use 'Please enter the letter A' as checker message","forget profile for current artifact","offer task to anyone","skill 1004 is relevant for the task","install task"]}},"2":{"3":{"guard":"task 1 is answered","actions":["delete from Task where artifact=CURRENT_ARTIFACT","prepare task 2 as message","select @TEMPLATE:=body from Template where id='headwork-gui-2'","select @TITLE:='Generic HTML questions'","select @CHECKER:=NULL","select @CHECKERMSG:=NULL","insert into Task(id,artifact,title,description,body,checker,checkermsg,type) values (@TASKID,CURRENT_ARTIFACT,'demo',@TITLE,@TEMPLATE,@CHECKER,@CHECKERMSG,@TYPE)","delete from Profile where idartifact=CURRENT_ARTIFACT","insert into Profile values (2,CURRENT_ARTIFACT,1)"]}},"3":{"4":{"guard":"select true from Answered where artifact=CURRENT_ARTIFACT and id=2","actions":["prepare task 3 as multi-line input","delete from Task where artifact=CURRENT_ARTIFACT","select @TEMPLATE:=body from Template where id='headwork-gui-3'","select @TITLE:='Multi-line input'","select @CHECKER:=NULL","select @CHECKERMSG:=NULL","select @LIST:='add several inputs, separated by a return'","insert into Task(id,artifact,title,description,body,checker,checkermsg,type,arg1) values (@TASKID,CURRENT_ARTIFACT,'demo',@TITLE,@TEMPLATE,@CHECKER,@CHECKERMSG,@TYPE,@LIST)","delete from Profile where idartifact=CURRENT_ARTIFACT","insert into Profile values (3,CURRENT_ARTIFACT,1)"]}},"4":{"5":{"guard":"select true from Answered where artifact=CURRENT_ARTIFACT and id=3","actions":["delete from Task where artifact=CURRENT_ARTIFACT","select @TEMPLATE:=body from Template where id='headwork-gui-4'","select @TITLE:='Drowpdown list'","select @CHECKER:=NULL","select @CHECKERMSG:=NULL","select @LIST:='select value as value,value as text from Answer where user=SESSION_USER and idtask=3'","select @TYPE:=1","insert into Task(id,artifact,title,description,body,checker,checkermsg,type,arg1) values (4,CURRENT_ARTIFACT,'demo',@TITLE,@TEMPLATE,@CHECKER,@CHECKERMSG,@TYPE,@LIST)","delete from Profile where idartifact=CURRENT_ARTIFACT","insert into Profile values (4,CURRENT_ARTIFACT,1)"]}},"5":{"6":{"guard":"select true from Answered where artifact=CURRENT_ARTIFACT and id=4","actions":["delete from Task where artifact=CURRENT_ARTIFACT","select @TEMPLATE:=body from Template where id='headwork-gui-5'","select @TITLE:='Radio buttons'","select @CHECKER:=NULL","select @CHECKERMSG:=NULL","select @LIST:='select value as value,value as text from Answer where user=SESSION_USER and idtask=3'","select @TYPE:=2","insert into Task(id,artifact,title,description,body,checker,checkermsg,type,arg1) values (5,CURRENT_ARTIFACT,'demo',@TITLE,@TEMPLATE,@CHECKER,@CHECKERMSG,@TYPE,@LIST)","delete from Profile where idartifact=CURRENT_ARTIFACT","insert into Profile values (5,CURRENT_ARTIFACT,1)"]}},"6":{"7":{"guard":"select true from Answered where artifact=CURRENT_ARTIFACT and id=5","actions":["delete from Task where artifact=CURRENT_ARTIFACT","select @TEMPLATE:=body from Template where id='headwork-gui-6'","select @TITLE:='Radio buttons with alternative free input'","select @CHECKER:=NULL","select @CHECKERMSG:=NULL","select @LIST:='select value as value,value as text from Answer where user=SESSION_USER and idtask=3'","select @TYPE:=4","insert into Task(id,artifact,title,description,body,checker,checkermsg,type,arg1) values (6,CURRENT_ARTIFACT,'demo',@TITLE,@TEMPLATE,@CHECKER,@CHECKERMSG,@TYPE,@LIST)","delete from Profile where idartifact=CURRENT_ARTIFACT","insert into Profile values (6,CURRENT_ARTIFACT,1)"]}},"7":{"9":{"guard":"select true from A
//console.log(jsonString);
console.log(json);
//console.log(json);
//console.log(obj);
//console.log(obj['3']);
......@@ -231,6 +188,7 @@ document.getElementById("hw-artefact-info").innerHTML = obj['doc'];
document.getElementById("hw-artefact-author").innerHTML = 'Author: '+obj['author'];
/*
cy.on('mouseover', 'node', function(evt){
var node = evt.target;
......@@ -238,7 +196,7 @@ cy.on('mouseover', 'node', function(evt){
});
*/
cy.on('mouseover', 'edge', function(evt){
cy.on('click', 'edge', function(evt){
var edge = evt.target;
console.log("source id"+edge.id());
split = edge.id().split("-");
......@@ -263,13 +221,18 @@ cy.on('mouseover', 'edge', function(evt){
actionString+='<p class="font-monospace bg-info">'+actions[i]+'</p>';
}
document.getElementById("info").innerHTML = `
<h1>Transition from state ${source} to state ${target}</h1>
<h1>State ${source} -> State ${target}</h1>
<h2>Guard</h2>
<p class="font-monospace bg-info">${obj[source][target]['guard']}</p>
<h2>Actions</h2>
${actionString}`;
});
</script>
EOF;
}
/* cy.layout({
name: 'cose',
animate:'end',
......@@ -278,6 +241,7 @@ cy.on('mouseover', 'edge', function(evt){
}).run();
*/
/*
cy.resize();
cy.fit();
......@@ -285,3 +249,5 @@ cy.fit();
</script>
</body>
</html>
*/
......@@ -22,6 +22,7 @@ require("connection.php");
require("show-pages.php");
require("artifacts.php");
require("show-artifact.php");
require("drawArtifact.php");
session_start();
......@@ -138,6 +139,9 @@ switch ($mode) {
case "showArtifact":
showArtifact($conn,$_GET['artifactid']);
break;
case "drawArtifact":
drawArtifact($conn,$_GET['artifactid']);
break;
case "Home":
showTasks($conn);
break;
......
......@@ -6,7 +6,7 @@
"guard": "select true from dual",
"actions": [
"select @TEMPLATE:=body from Template where id='headwork-belief-step1'",
"insert into Task(id,title,modality,description,body,checker,checkermsg,artifact,ajax) values (1,'demo','belief','Step 1: Using uncertain answers',@TEMPLATE,'REGEXP \"^-?[0-9]+$\"','please, enter an integer',CURRENT_ARTIFACT,false)",
"insert into Task(id,title,modality,description,body,checker,checkermsg,artifact,ajax) values (1,'demo','belief','Step 1: Using uncertain answers',@TEMPLATE,'REGEXP ''^-?[0-9]+$''','please, enter an integer',CURRENT_ARTIFACT,false)",
"delete from Profile where idartifact=CURRENT_ARTIFACT",
"insert into Profile values (1,CURRENT_ARTIFACT,1)"
]
......
......@@ -7,7 +7,7 @@
"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",
"use 'REGEXP ''^A$''' as checker",
"use 'Please enter the letter A' as checker message",
"forget profile for current artifact",
"offer task to anyone",
......
......@@ -5,7 +5,7 @@
"actions": [
"select @TEMPLATE:=body from Template where id='headwork-gui-1'",
"select @TITLE:='Simple question, simple checking'",
"select @CHECKER:='REGEXP \"^A$\"'",
"select @CHECKER:='REGEXP ''^A$'''",
"select @CHECKERMSG:='Please enter the letter A'",
"select @TYPE:=NULL",
"insert into Task(id,modality,artifact,title,description,body,checker,checkermsg,type) values (1,'belief',CURRENT_ARTIFACT,'demo',@TITLE,@TEMPLATE,@CHECKER,@CHECKERMSG,@TYPE)",
......
......@@ -5,7 +5,7 @@
"actions": [
"select @TEMPLATE:=body from Template where id='headwork-step1'",
"select @TITLE:='Voting with 2 users'",
"select @CHECKER:='REGEXP \"^[0-9]$\"'",
"select @CHECKER:='REGEXP ''^[0-9]$'''",
"select @CHECKERMSG:='Please enter an numerical digit'",
"select @TYPE:=NULL",
"select @ARTIFACT:=CURRENT_ARTIFACT",
......
{
"doc":"Demo of a Wirk service call",
"author":"David Gross-Amblard, Léo Jacoboni",
"1": {
"2": {
"guard": "select true from dual",
"actions": [
"select @TEMPLATE:='Give the URL of a picture, I will guess its content!'",
"select @TITLE:='Image Oracle'",
"select @CHECKER:='REGEXP \"^(https?://|www\\\\.)[\\.A-Za-z0-9/\\-]+\\\\.[a-zA-Z]{2,4}\"'",
"select @CHECKER:='REGEXP ''^(https?://|www[.period.])[A-Za-z0-9-]+[.period.][a-zA-Z]{2,4}'''",
"select @CHECKERMSG:='Please enter a valid URL (http://, https://, ...)'",
"select @TYPE:=NULL",
"select @ARTIFACTID:=CURRENT_ARTIFACT",
......
......@@ -3,16 +3,15 @@
"2": {
"guard": "select true from dual",
"actions": [
"select @TEMPLATE:='Donnez l\\'URL de l\\'image d\\'un Totoro (Miyazaki). Le fond de l\\'image doit etre uni. Voici un exemple : <br/><img width=\\'200px\\' src=\\'https://www.telerama.fr/sites/tr_master/files/styles/simplecrop1000/public/1_24.jpg?itok=WoHiE0hI\\'/>'",
"select @TEMPLATE:='Donnez l''URL de l''image d''un Totoro (Miyazaki). Le fond de l''image doit etre uni. Voici un exemple : <br/><img width=''200px'' src=''https://www.telerama.fr/sites/tr_master/files/styles/simplecrop1000/public/1_24.jpg?itok=WoHiE0hI''/>'",
"select @TITLE:='Trouvez un Totoro'",
"select @CHECKER:='REGEXP \"^(https?://|www\\\\.)[\\.A-Za-z0-9/\\-]+\\\\.[a-zA-Z]{2,4}\"'",
"select @CHECKER:='REGEXP ''^(https?://|www[.period.])[A-Za-z0-9-]+[.period.][a-zA-Z]{2,4}'''",
"select @CHECKERMSG:='Entrez une URL valide (http://, https://, ...)'",
"select @TYPE:=NULL",
"select @ARTIFACTID:=CURRENT_ARTIFACT",
"insert into Task(id,title,description,body,checker,checkermsg,type,artifact) values (1,'demo',@TITLE,@TEMPLATE,@CHECKER,@CHECKERMSG,@TYPE,@ARTIFACTID)",
"insert into Profile values (1,CURRENT_ARTIFACT,1)"
]
}
},
"2": {
......
......@@ -8,6 +8,7 @@
* @param $artifactid: the id of a running artifact
*/
function showArtifact($conn,$artifactid)
{
......@@ -20,7 +21,8 @@ function showArtifact($conn,$artifactid)
// lire le fichier, l'encoder en JSON avec mise en forme, et affichage dans une balise PRE
$jsonString=htmlentities(json_encode(load_artifact($artifact_file),JSON_PRETTY_PRINT));
$VIEW['MAIN'].='</p></p></p><a class="btn btn-dark" role="button" target="_blank" href="http://localhost:8888/headwork-master/showArtifact.html?json='.$jsonString.'">View automaton</a><p/>';
$VIEW['MAIN'].='</p></p></p><a class="btn btn-dark" role="button" href="http://localhost:8888/headwork-master/index.php?mode=drawArtifact&artifactid='.$artifactid.'">View automaton</a><p/>';
// TODO reusing targer=_blank ?
$VIEW['MAIN'] .= HTMLpre($jsonString);
......
......@@ -599,9 +599,6 @@ function showTasks($conn, $displayAlert = false)
and Artifact.state='running'
and Artifact.ownerid=" . $_SESSION['id'] . " order by Artifact.classid,Artifact.id";
// TODO in progress query to add relevance score
// still problem in regression test with primary keys.
$query = "SELECT Task.id, Task.description, sum(Skills.level) as level From Task,Artifact,ArtifactClass, Profile,Skills
where
Artifact.classid=ArtifactClass.id
......@@ -1048,6 +1045,7 @@ function showQueryAnswerAsString($conn, $title, $query, $exception = null)
/**
* showArtifactsTable
* TODO unused ?
*
* Display the list of artifacts
*
......
......@@ -35,6 +35,17 @@
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<script src='cytoscape.min.js'></script>
<style>
#cy {
width: 600px;
height: 600px;
//position: absolute;
//top: 0px;
//left: 0px;
}
</style>
</head>
<?php if(!in_array($_SESSION['mode'],array("showTasks","answer","startArtifact","answer","insertAnswer"))):?>
<body>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment