Skip to content

Commit

Permalink
showing tests output
Browse files Browse the repository at this point in the history
  • Loading branch information
gcpdev committed Jan 9, 2018
1 parent 5ffaaba commit 259f380
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 60 deletions.
6 changes: 6 additions & 0 deletions guidelines/web/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,10 @@ div#questionnaire div input[type="text"] {

/** Unhide lightbox **/
display: block;
}
.col-sm-8, .col-sm-4 {
font-size: 10px;
position: relative;
top: -10px;
left: -15px;
}
3 changes: 2 additions & 1 deletion guidelines/web/guideline_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
" $this rdfs:subClassOf owl:Thing .",
" FILTER($this NOT IN (",
" <$input$>,",
" ))."
" )) .",
" } "
]
},
{
Expand Down
90 changes: 55 additions & 35 deletions guidelines/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,54 +130,74 @@ <h2>Test results</h2>
</div>
<div class="panel-body" id="results">
<ul class="list-group">
<a data-toggle="collapse" href="#list-success" aria-expanded="false" aria-controls="collapseExample">
<!-- a data-toggle="collapse" href="#list-success" aria-expanded="false" aria-controls="collapseExample">
<li class="list-group-item list-group-item-success">
<h2>3 tests passed</h2>
<h2 id="num-success"></h2>
</li>
</a>
<div class="collapse" id="list-success">
<ul>
<li class="list-group-item list-group-item-success">Success item</li>
<li class="list-group-item list-group-item-success">Success item</li>
<li class="list-group-item list-group-item-success">Success item</li>
<li class="list-group-item list-group-item-success">Success item</li>
<li class="list-group-item list-group-item-success">Success item</li>
<li class="list-group-item list-group-item-success">Success item</li>
<li class="list-group-item list-group-item-success">Success item</li>
<li class="list-group-item list-group-item-success">
<h3>Success item</h3>
</li>
<li class="list-group-item list-group-item-success">
<h3>Success item</h3>
</li>
<li class="list-group-item list-group-item-success">
<h3>Success item</h3>
</li>
<li class="list-group-item list-group-item-success">
<h3>Success item</h3>
</li>
<li class="list-group-item list-group-item-success">
<h3>Success item</h3>
</li>
<li class="list-group-item list-group-item-success">
<h3>Success item</h3>
</li>
<li class="list-group-item list-group-item-success">
<h3>Success item</h3>
</li>
</ul>
</div>
<a data-toggle="collapse" href="#list-warning" aria-expanded="false" aria-controls="collapseExample">
<li class="list-group-item list-group-item-warning">
<h2>4 warnings found</h2>
<h2 id="num-warning"></h2>
</li>
</a>
<div class="collapse" id="list-warning">
<ul>
<li class="list-group-item list-group-item-warning">Warn item</li>
<li class="list-group-item list-group-item-warning">Warn item</li>
<li class="list-group-item list-group-item-warning">Warn item</li>
<li class="list-group-item list-group-item-warning">Warn item</li>
<li class="list-group-item list-group-item-warning">Warn item</li>
<li class="list-group-item list-group-item-warning">Warn item</li>
<li class="list-group-item list-group-item-warning">Warn item</li>
<li class="list-group-item list-group-item-warning">
<h3>Warn item</h3>
</li>
<li class="list-group-item list-group-item-warning">
<h3>Warn item</h3>
</li>
<li class="list-group-item list-group-item-warning">
<h3>Warn item</h3>
</li>
<li class="list-group-item list-group-item-warning">
<h3>Warn item</h3>
</li>
<li class="list-group-item list-group-item-warning">
<h3>Warn item</h3>
</li>
<li class="list-group-item list-group-item-warning">
<h3>Warn item</h3>
</li>
<li class="list-group-item list-group-item-warning">
<h3>Warn item</h3>
</li>
</ul>
</div>
<a data-toggle="collapse" href="#list-error" aria-expanded="false" aria-controls="collapseExample">
<li class="list-group-item list-group-item-danger">
<h2>2 errors found</h2>
</li>
</a>
<div class="collapse" id="list-error">
<ul>
<li class="list-group-item list-group-item-danger">Error item</li>
<li class="list-group-item list-group-item-danger">Error item</li>
<li class="list-group-item list-group-item-danger">Error item</li>
<li class="list-group-item list-group-item-danger">Error item</li>
<li class="list-group-item list-group-item-danger">Error item</li>
<li class="list-group-item list-group-item-danger">Error item</li>
<li class="list-group-item list-group-item-danger">Error item</li>
</ul>
</div>
</div -->
<a data-toggle="collapse" href="#list-error" aria-expanded="false" aria-controls="collapseError">
<li class="list-group-item list-group-item-danger">
<h2 id="num-error"></h2>
</li>
</a>
<div class="collapse" id="list-error">

</div>

</ul>

Expand Down Expand Up @@ -211,7 +231,7 @@ <h4 class="modal-title" id="uploadModal">Upload ontology</h4>
<div class="modal-body">

<!-- Standar Form -->
<h4>Select files from your computer</h4>
<h4>Select an ontology in turtle format</h4>
<!-- form action="" method="post" enctype="multipart/form-data" id="js-upload-form" -->
<form action="" id="js-upload-ontology">
<div class="form-inline">
Expand Down
111 changes: 87 additions & 24 deletions guidelines/web/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ $(document).ready(function () {
$('#complete-step-1').prop("disabled", true);

$('form').on('change', ':checkbox', function () {
//console.log('checkbox ' + this.name + ' toggled');
console.log('checkbox ' + this.name + ' toggled');

//checks whether the checkbox was activated or deactivated and
//inserts or removes the test from SHACL_selected
Expand All @@ -80,7 +80,7 @@ $(document).ready(function () {
yield* SHACL_selected_prop;
}());
if (SHACL_selected.size === 0) document.getElementById('js-upload-submit').disabled = true;
//console.log(SHACL_selected);
console.log(SHACL_selected);
});

$('form').on('change, focusout', 'input[id$="-textbox"]', function (event) {
Expand Down Expand Up @@ -111,7 +111,8 @@ $(document).ready(function () {
regex = /^.*(<\$input\$>).*$/gm;
query = query.replace(regex, "");

//console.log(query);
console.log(query);
SHACL_selected_class.set(id, query);
});

});
Expand All @@ -124,6 +125,57 @@ function prevTab(elem) {
$(elem).prev().find('a[data-toggle="tab"]').click();
}

let error = [];
let error2 = new Map();

function listTestResults(res) {

let sev, msg, resource; //severity, message and resource
for (let i of res) {
let testResults = [];
let test1 = [];
msg = i.message.trim();
resource = i.failingresource.trim();
if (!error2.has(msg)) {
test1.push(resource);
error2.set(msg, test1);
} else {
test1 = error2.get(msg);
test1.push(resource);
error2.set(msg, test1);
}
for (let k of i.propertyValuePairs) {
if (k.property == "http://www.w3.org/ns/shacl#resultSeverity") {
sev = k.values[0];
break;
} else continue;
}
testResults.push(msg);
testResults.push(sev);
testResults.push(resource);
if (sev == "http://www.w3.org/ns/shacl#Violation") error.push(testResults);
else if (sev == "http://www.w3.org/ns/shacl#Warning") warning.push(testResults);
else info.push(testResults);
}
//$("#num-success").html(info.length + " tests passed");
//$("#num-warning").html(warning.length + " tests has warnings");
$("#num-error").html(error2.size + " tests failed, " + error.length + " violations");

let errorHtml = `<ul>
`;
for (let i of error) {
errorHtml += `<div class="list-group-item list-group-item-danger">
<div class="col-sm-8">` + i[0].replace("<", "").replace(">", "").replace("\\", "") + `</div>
<div class="col-sm-4"><a href="` + i[2] + `">` + i[2] + `</a></div>
</div>
`;

}
errorHtml += `
</ul>`;
$("#list-error").html(errorHtml);
}

/**
* Replace last occurrence of a string with another string
* x - the initial string
Expand Down Expand Up @@ -192,22 +244,26 @@ function ($) {
`;

//if at least one class test was selected, then insert the class shape prefixes
if (SHACL_selected_class.size > 0) shaclFile += SHACL_prefix_class;
//insert classes tests
for (let [k, v] of SHACL_selected_class) {
shaclFile += v;
if (SHACL_selected_class.size > 0) {
shaclFile += SHACL_prefix_class;
//insert classes tests
for (let [k, v] of SHACL_selected_class) {
shaclFile += v;
}
shaclFile = replaceLast(shaclFile, ";", " .");
}
shaclFile = replaceLast(shaclFile, ";", " .");
//if at least one property test was selected, then insert the property shape prefixes
if (SHACL_selected_prop.size > 0) shaclFile += SHACL_prefix_prop;
//insert properties tests
for (let [k, v] of SHACL_selected_prop) {
shaclFile += v;
if (SHACL_selected_prop.size > 0) {
shaclFile += SHACL_prefix_prop;
//insert properties tests
for (let [k, v] of SHACL_selected_prop) {
shaclFile += v;
}
shaclFile = replaceLast(shaclFile, ";", " .");
}
shaclFile = replaceLast(shaclFile, ";", " .");

shaclFile = shaclFile.replace('\"', '"');
//console.log(shaclFile);
console.log(shaclFile);

e.preventDefault();

Expand Down Expand Up @@ -237,8 +293,15 @@ function ($) {
cache: false,
async: false,
success: function (r) {
var response = JSON.parse(r);
console.log(response);
// console.dir(r);
//$("#results").append(r);
if (r) {
var response = JSON.parse(r);
console.log(response);
listTestResults(response);
} else {
$("#num-error").html("0 tests failed, 0 violations");
}
},
xhr: function () {
let xhr = new window.XMLHttpRequest();
Expand Down Expand Up @@ -270,6 +333,8 @@ let SHACL_questions_prop = new Map();
let SHACL_prefix_class;
let SHACL_prefix_prop;



//the following function generates the questionnaire HTML from JSON
jQuery(function ($) {

Expand All @@ -282,12 +347,12 @@ jQuery(function ($) {
let SHACL_tests_group = '';

$.getJSON("guideline_form.json", function (loadedJson) {
//console.log(loadedJson); // debug: output json to console
console.log(loadedJson); // debug: output json to console
let groups = $.parseJSON(JSON.stringify(loadedJson[0]));

for (let [index, group] of entries(groups)) {
//console.log(index);
//console.log(group);
console.log(index);
console.log(group);

SHACL_tests_group = `
Expand Down Expand Up @@ -352,7 +417,7 @@ jQuery(function ($) {
break;
}
let thisSHACL = `${questions[i].shacl} [
sh:message: "${questions[i].label}";
sh:message "${questions[i].label}";
`;
switch (questions[i].shacl) {
case "sh:sparql":
Expand All @@ -368,8 +433,8 @@ jQuery(function ($) {
break;
case "sh:property":
let prop = questions[i].test.join('\n');
thisSHACL += `${prop}
];
thisSHACL += replaceLast(prop, '.', ';');
thisSHACL += ` ];
`;
break;
Expand All @@ -390,8 +455,6 @@ jQuery(function ($) {
$("#questionnaire").append(renderGroup);

}
//console.log(SHACL_questions);


});

Expand Down

0 comments on commit 259f380

Please sign in to comment.