Skip to content

Commit

Permalink
Fix for #33 and improvement for item 1,2 of #16
Browse files Browse the repository at this point in the history
  • Loading branch information
YusufZiyaOzgul committed Aug 15, 2024
1 parent 2b310df commit 05f91a5
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 81 deletions.
20 changes: 10 additions & 10 deletions public/js/main.menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ let applyErrorFix = async function () {
let errorId = event.currentTarget.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.id;
errorId = errorId.replace("rec", "");
errorId = parseInt( errorId ) - 1;
errors[errorId].fixChoice = event.delegateTarget.firstChild.value;
errors[errorId].selectedOption = event.delegateTarget.firstChild.value;
}
catch{
event.currentTarget.style.checked = true;
Expand Down Expand Up @@ -215,17 +215,17 @@ let applyErrorFix = async function () {
$('.ui.radio.checkbox').checkbox();
$('.ui.checkbox').checkbox();
for( let i = 0; i < error.fixCandidate.length; i++){
$( `#solutionField${error.errorNo}` ).append('<div class="field" style = "margin: 0.01em 0;"><div onchange = "" class="ui radio checkbox"><input onclick = "" type="radio" id = "' + 'resAlt' + error.errorNo + '-' + i + '"name="'+ 'fixFor' + error.errorNo + '" value="' + error.fixCandidate[i].id+ '"><label style = "font-size:1em !important;margin-top:0px">' + error.fixCandidate[i].label +'</label></div></div>');
if( (error.defaultOption ) === i){
console.log( error.errorNo + " " + error.defaultOption + " " + i);
$( `#solutionField${error.errorNo}` ).append('<div class="field" style = "margin: 0.01em 0;"><div onchange = "" class="ui radio checkbox"><input onclick = "" type="radio" id = "' + 'resAlt' + error.errorNo + '-' + i + '"name="'+ 'fixFor' + error.errorNo + '" value="' + i+ '"><label style = "font-size:1em !important;margin-top:0px">' + error.fixCandidate[i].label +'</label></div></div>');
if( (error.selectedOption ) === i){
console.log( error.errorNo + " " + error.selectedOption + " " + i);
$('.ui.radio.checkbox').on('click', event =>{

try {
console.log( "format or alternative event " + " " + event.currentTarget.parentElement.id);
let errorId = event.currentTarget.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.id;
errorId = errorId.replace("rec", "");
errorId = parseInt( errorId ) - 1;
errors[errorId].fixChoice = event.delegateTarget.firstChild.value;
errors[errorId].selectedOption = event.delegateTarget.firstChild.value;
}
catch{
event.currentTarget.style.checked = true;
Expand Down Expand Up @@ -255,7 +255,7 @@ let applyErrorFix = async function () {
let errorId = event.currentTarget.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.id;
errorId = errorId.replace("rec", "");
errorId = parseInt( errorId ) - 1;
errors[errorId].fixChoice = event.delegateTarget.firstChild.value;
errors[errorId].selectedOption = event.delegateTarget.firstChild.value;
}
catch{
event.currentTarget.style.checked = true;
Expand Down Expand Up @@ -430,9 +430,9 @@ let processValidation = async function () {
if( showResolutionAlternatives && error.fixCandidate !== undefined && error.fixCandidate.length > 0){
for( let i = 0; i < error.fixCandidate.length; i++){
//$( `#solutionField${error.errorNo}` ).append('<div class="field" style = "margin: 0.01em 0;"><div onchange = "" class="ui radio checkbox"><input onclick = "" type="radio" name="fixFor' + error.errorNo + '" value="' + error.fixCandidate[i].id+ '"><label style = "font-size:1em !important;margin-top:0px">' + error.fixCandidate[i].label +'</label></div></div>');
$( `#solutionField${error.errorNo}` ).append('<div class="active field" style = "margin: 0.01em 0;"><div onchange = "" class="ui radio checkbox"><input onclick = "" type="radio" id = "' + 'resAlt' + error.errorNo + '-' + i + '"name="'+ 'fixFor' + error.errorNo + '" value="' + error.fixCandidate[i].id+ '" clicked ><label style = "font-size:1em !important;margin-top:0px">' + error.fixCandidate[i].label +'</label></div></div>');
if( (error.defaultOption ) === i){
console.log( error.errorNo + " " + error.defaultOption + " " + i);
$( `#solutionField${error.errorNo}` ).append('<div class="active field" style = "margin: 0.01em 0;"><div onchange = "" class="ui radio checkbox"><input onclick = "" type="radio" id = "' + 'resAlt' + error.errorNo + '-' + i + '"name="'+ 'fixFor' + error.errorNo + '" value="' + i + '" clicked ><label style = "font-size:1em !important;margin-top:0px">' + error.fixCandidate[i].label +'</label></div></div>');
if( (error.selectedOption ) === i){
console.log( error.errorNo + " " + error.selectedOption + " " + i);
console.log( document.getElementById("resAlt" + error.errorNo + "-" + i));
$('#resAlt' + error.errorNo + '-' + i).click();

Expand All @@ -454,7 +454,7 @@ let processValidation = async function () {
let errorId = event.currentTarget.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.id;
errorId = errorId.replace("rec", "");
errorId = parseInt( errorId ) - 1;
errors[errorId].fixChoice = event.delegateTarget.firstChild.value;
errors[errorId].selectedOption = event.delegateTarget.firstChild.value;
}
catch {
event.currentTarget.style.checked = true;
Expand Down
51 changes: 37 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ function findCandidatesOrFix( errors, cy, isFix){
let currentLength = currentErrors.length;
previousErrorCode = currentErrors[check].pattern;
previousErrorRole = currentErrors[check].role;
if( currentErrors[check].status === "solved"){
check++;
continue;
}
currentErrors[check].status = "unsolved";
let errorFixParam = {};
if( isFix === false ){
Expand All @@ -103,7 +107,7 @@ function findCandidatesOrFix( errors, cy, isFix){
if (compartments[i].parent().length == 0){
if( isFix === false ){
currentErrors[check].fixCandidate.push( {label : getLabel(compartments[i]), id : compartments[i].data().id});
currentErrors[check].defaultOption = 0;
currentErrors[check].selectedOption = 0;
}
else {
listedNodes.push(compartments[i]);
Expand Down Expand Up @@ -133,7 +137,7 @@ function findCandidatesOrFix( errors, cy, isFix){
currentErrors[check].fixCandidate.push( {label:(getLabel(connectedEdges[i].source())
+ " - " + getLabel(connectedEdges[i].target())), id: connectedEdges[i].data().id});
if( selectedEdge.data().id === connectedEdges[i].data().id ){
currentErrors[check].defaultOption = i;
currentErrors[check].selectedOption = i;
}
}
check++;
Expand Down Expand Up @@ -183,7 +187,7 @@ function findCandidatesOrFix( errors, cy, isFix){
for( let i = 0; i < listedNodes.length; i++){
currentErrors[check].fixCandidate.push( {label: getLabel(listedNodes[i]), id: listedNodes[i].data().id});
if( listedNodes[i].data().id === selectedNode.data().id){
currentErrors[check].defaultOption = i;
currentErrors[check].selectedOption = i;
}
}
check++;
Expand Down Expand Up @@ -215,7 +219,7 @@ function findCandidatesOrFix( errors, cy, isFix){
for( let i = 0; i < listedNodes.length; i++){
currentErrors[check].fixCandidate.push( {label: getLabel(listedNodes[i]), id: listedNodes[i].data().id});
if( closestNode.data().id == listedNodes[i].data().id){
currentErrors[check].defaultOption = i;
currentErrors[check].selectedOption = i;
}
}
check++;
Expand Down Expand Up @@ -244,7 +248,7 @@ function findCandidatesOrFix( errors, cy, isFix){
for( let i = 0; i < listedNodes.length; i++){
currentErrors[check].fixCandidate.push( {label: getLabel(listedNodes[i]), id: listedNodes[i].data().id});
if( closestNode.data().id == listedNodes[i].data().id){
currentErrors[check].defaultOption = i;
currentErrors[check].selectedOption = i;
}
}
check++;
Expand Down Expand Up @@ -275,7 +279,7 @@ function findCandidatesOrFix( errors, cy, isFix){
currentErrors[check].fixCandidate.push( {label: getLabel(nodes[i]), id: nodes[i].data().id} );
}
if( selectedNode.id() === nodes[i].data().id){
currentErrors[check].defaultOption = i;
currentErrors[check].selectedOption = i;
}
}
check++;
Expand All @@ -300,7 +304,7 @@ function findCandidatesOrFix( errors, cy, isFix){
if( nodes[i].data().id != ele.id() && elementUtilities.isEPNClass( nodes[i].data().class )){
currentErrors[check].fixCandidate.push( {label: getLabel(nodes[i]), id: nodes[i].data().id} );
if( selectedNode.id() === nodes[i].data().id){
currentErrors[check].defaultOption = i;
currentErrors[check].selectedOption = i;
}
}
}
Expand Down Expand Up @@ -447,8 +451,13 @@ function findCandidatesOrFix( errors, cy, isFix){

if( isFix === false ){
currentErrors[check].fixCandidate = [];
let selectedNode = closestNodeForEdges( ele.source(), listedNodes);
for( let i = 0; i < listedNodes.length; i++){
currentErrors[check].fixCandidate.push( {label:getLabel(listedNodes[i]), id: listedNodes[i].data().id});
if( selectedNode.id() === listedNodes[i].id()){
currentErrors[check].selectedOption = i;
}

}
check++;
continue;
Expand All @@ -473,9 +482,13 @@ function findCandidatesOrFix( errors, cy, isFix){
let connectedEdges = cy.edges('[source = "' + ele.id() + '"]');
if( isFix === false ){
currentErrors[check].fixCandidate = [];
let selectedEdge = findClosestNode(ele, connectedEdges); // default , the selection of edge will be determined later.
for( let i = 0; i < connectedEdges.length; i++){
currentErrors[check].fixCandidate.push( {label:(getLabel(connectedEdges[i].source())
+ " - " + getLabel(connectedEdges[i].target())), id: connectedEdges[i].data().id});
if( connectedEdges[i].id() == selectedEdge.id()){
currentErrors[check].selectedOption = i;
}
}
check++;
continue;
Expand All @@ -498,16 +511,20 @@ function findCandidatesOrFix( errors, cy, isFix){
var connectedEdges = ele.connectedEdges().filter('[class="consumption"]');
if( isFix === false ){
currentErrors[check].fixCandidate = [];
let selectedEdge = findClosestNode(ele, connectedEdges); // default selection, it will be determined. closest one will be kept.
for( let i = 0; i < connectedEdges.length; i++){
currentErrors[check].fixCandidate.push( {label:(getLabel(connectedEdges[i].source())
+ " - " + getLabel(connectedEdges[i].target())), id: connectedEdges[i].data().id});
if( connectedEdges[i].id() == selectedEdge.id()){
currentErrors[check].selectedOption = i;
}
}
check++;
continue;
}
errorFixParam.nodes = [];
errorFixParam.edges = [];
selectedEdge = closestNode(ele, connectedEdges); // default selection, it will be determined. closest one will be kept.
let selectedEdge = findClosestNode(ele, connectedEdges); // default selection, it will be determined. closest one will be kept.
for (let i = 0; i < connectedEdges.size(); i++) {
if (connectedEdges[i].id() != selectedEdge.id()) {
errorFixParam.nodes.push(connectedEdges[i].source().id() == ele.id() ? connectedEdges[i].target() : connectedEdges[i].source());
Expand All @@ -523,9 +540,13 @@ function findCandidatesOrFix( errors, cy, isFix){
let connectedEdges = ele.connectedEdges().filter('[class = "production"]');
if( isFix === false ){
currentErrors[check].fixCandidate = [];
let selectedEdge = findClosestNode(ele, connectedEdges); // default selection, it will be determined. closest one will be kept.
for( let i = 0; i < connectedEdges.length; i++){
currentErrors[check].fixCandidate.push( {label:(getLabel(connectedEdges[i].source())
+ " - " + getLabel(connectedEdges[i].target())), id: connectedEdges[i].data().id});
if( connectedEdges[i].id() == selectedEdge.id()){
currentErrors[check].selectedOption = i;
}
}
check++;
continue;
Expand Down Expand Up @@ -935,6 +956,7 @@ app.use(async (req, res, next) => {

currentSbgn = data;
let duplicatedIds = [];
let preValidationData = {};
if( errors.length === 0){
fs.writeFileSync('./src/sbgnFile.sbgn', currentSbgn);
let result = SaxonJS.transform({
Expand All @@ -957,7 +979,8 @@ app.use(async (req, res, next) => {
error.setText(parsedResult["svrl:schematron-output"]["svrl:failed-assert"][i]["svrl:text"]);
error.setPattern(parsedResult["svrl:schematron-output"]["svrl:failed-assert"][i]["$"]["id"]);
error.setRole(parsedResult["svrl:schematron-output"]["svrl:failed-assert"][i]["svrl:diagnostic-reference"][0]["_"]);
if( error.pattern == "00001" || error.pattern == "00002"){
if( (error.pattern == "00001" || error.pattern == "00002" ) && preValidationData[ error.pattern + error.role] === undefined ){
preValidationData[error.pattern + error.role] = 1;
let ret ={};
// ret['errorMessage'] = "ID needs to be unique and an arc target should be a glyph defined in the diagram";
// return res.status(200).send(ret);
Expand Down Expand Up @@ -1222,8 +1245,8 @@ app.post('/fixError', (req, res) => {
let showResolutionAlternatives = res.locals.showResolutionAlternatives;
let fixData = {};
for( let i = 0; i < errors.length; i++){
if( errors[i].fixChoice !== undefined ){
fixData[errors[i].pattern + errors[i].role] = errors[i].fixChoice;
if( errors[i].selectedOption !== undefined ){
fixData[errors[i].pattern + errors[i].role] = errors[i].fixCandidate[errors[i].selectedOption].id;
}
}
//while(1);
Expand Down Expand Up @@ -1857,10 +1880,10 @@ function fixError(errorFixParam) {
elementUtilities.reverseEdge(errorFixParam.edge);
}
if (errorCode == "pd10108" || errorCode == "pd10104") {
for (let i = 0; i < errorFixParam.nodes.length(); i++) {
for (let i = 0; i < errorFixParam.nodes.length; i++) {
errorFixParam.nodes[i].remove();
}
for (let i = 0; i < errorFixParam.edges.length(); i++) {
for (let i = 0; i < errorFixParam.edges.length; i++) {
errorFixParam.edges[i].remove();
}
}
Expand Down Expand Up @@ -1910,7 +1933,7 @@ function fixError(errorFixParam) {
edge.remove();
});
errorFixParam.nodes.forEach(function (node) {
node.remove();
//node.remove();
});
}
if (errorCode == "pd10111") {
Expand Down
Loading

0 comments on commit 05f91a5

Please sign in to comment.