Merge branch 'master' of

https://gitea-s2i2s.isti.cnr.it/concordia/LiDa_Search.git
This commit is contained in:
Luca Trupiano 2022-10-17 09:23:44 +02:00
parent 16e4d37b4b
commit c79fa58311
1 changed files with 103 additions and 105 deletions

View File

@ -129,11 +129,9 @@ $(document).ready(function() {
break; break;
case "andCond": case "andCond":
addLogicCond("AND","#sortable0") addLogicCond("AND","#sortable0")
refreshConnectWith();
break; break;
case "orCond": case "orCond":
addLogicCond("OR","#sortable0") addLogicCond("OR","#sortable0")
refreshConnectWith();
break; break;
default: default:
}; };
@ -658,6 +656,7 @@ $(document).ready(function() {
cursor: 'move', cursor: 'move',
update: function() {refreshSortables();} update: function() {refreshSortables();}
}); });
refreshConnectWith();
} }
// Funzione di refresh della lista delle tab delle clausole // Funzione di refresh della lista delle tab delle clausole
@ -694,38 +693,56 @@ $(document).ready(function() {
// Funzione di refresh della lista clausole nella tab principale e del json della query // Funzione di refresh della lista clausole nella tab principale e del json della query
function refreshClaList(){ function refreshClaList(){
var l_f = $("form #lemma_forma")[0].options[$("form #lemma_forma")[0].selectedIndex].value;
var qText = $("form #queryText")[0].value; var qText = $("form #queryText")[0].value;
if (qText == "") { //disattivo clausola 0 se il testo e' vuoto if (qText == "") { //disattivo clausola 0 se il testo e' vuoto
var claActive = 0 var claActive = 0
} else { } else {
var claActive = 1 var claActive = 1
}; };
var l_f = $("form #lemma_forma")[0].options[$("form #lemma_forma")[0].selectedIndex].value; queryJson.Clausola0 = JSON.parse('{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "TipoClausola": "0", "Attiva": "' + claActive + '"}');
var tabsContent=$("#cla-TabContent").find(".tab-pane:not(:first)"); var tabsContent=$("#cla-TabContent").find(".tab-pane:not(:first)");
var len=0; var len=0;
queryJson.Clausola0 = JSON.parse('{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "TipoClausola": "0", "Attiva": "' + claActive + '"}');
if ($(tabsContent).length) { if ($(tabsContent).length) {
$(tabsContent).each(function(){
if ($("#H-cla0")[0]) { if ($("#H-cla0")[0]) {
$("#H-cla0")[0].remove(); $("#H-cla0")[0].remove();
}; };
$(tabsContent).each(function(){
len++; len++;
var claId = $(this).attr('id');
createClaListItem(len, claId, "#sortable0");
});
if (queryJson["Clausola" + (len + 1)]) //se vengo dalla rimozione di una clausola
delete queryJson["Clausola" + (len + 1)];
} else {
if (claListLen == 0 && condListLen == 0) {
$('#sortable0').html(emptyClaList);
queryJson.EsprLogica = "";
queryJson.LogicaGui = "";
}
tabID = 0;
};
}
// Funzione di creazione del LI nella lista delle clausole nel tab principale
function createClaListItem(len, claId, sortableNum){
var claText = ''; var claText = '';
var checkInsert = '"'; var checkInsert = '"';
var claId = $(this).attr('id');
var claListItemID = "H-" + claId; var claListItemID = "H-" + claId;
var claType = $(this).attr('data-claType'); var claType = $("#" + claId).attr('data-claType');
var claActive = $(this).attr('data-claActive'); var claActive = $("#" + claId).attr('data-claActive');
if (claActive > 0) { if (claActive > 0) {
checkInsert = '" checked="checked"'; checkInsert = '" checked="checked"';
}; };
var l_f = $("form #lemma_forma")[0].options[$("form #lemma_forma")[0].selectedIndex].value;
var qText = $("form #queryText")[0].value;
var jsonTextToParse = '{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "TipoClausola": "' + claType + '", "Attiva": "' + claActive + '"'; var jsonTextToParse = '{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "TipoClausola": "' + claType + '", "Attiva": "' + claActive + '"';
switch (claType) { switch (claType) {
case "Grammaticale": case "Grammaticale":
var gramSelect = $(this).find(".catgram"); var gramSelect = $("#" + claId).find(".catgram");
claText = len + ". Categoria grammaticale: " + gramSelect[0].options[gramSelect[0].selectedIndex].text + '<br><span class="small ml-3">'; claText = len + ". Categoria grammaticale: " + gramSelect[0].options[gramSelect[0].selectedIndex].text + '<br><span class="small ml-3">';
jsonTextToParse = jsonTextToParse + ', "' + gramSelect.attr('name') + '": "' + gramSelect[0].options[gramSelect[0].selectedIndex].value + '"'; jsonTextToParse = jsonTextToParse + ', "' + gramSelect.attr('name') + '": "' + gramSelect[0].options[gramSelect[0].selectedIndex].value + '"';
var claSubParList = $(this).children(".dettaglifiltri").find("select, fieldset"); var claSubParList = $("#" + claId).children(".dettaglifiltri").find("select, fieldset");
claSubParList.each(function(){ claSubParList.each(function(){
var claSubParType = $(this)[0].type; var claSubParType = $(this)[0].type;
if (claSubParType == "fieldset" && $(this).find(":checked").length) { if (claSubParType == "fieldset" && $(this).find(":checked").length) {
@ -743,33 +760,23 @@ $(document).ready(function() {
}); });
break; break;
case "Sintattico": case "Sintattico":
var syntSelect = $(this).find("#synttypes"); var syntSelect = $("#" + claId).find("#synttypes");
; var funcSelect = $(this).find("#syntfunc"); ; var funcSelect = $("#" + claId).find("#syntfunc");
claText = len + ". Tipo sintattico: " + syntSelect[0].options[syntSelect[0].selectedIndex].text + '; <br><span class="ml-3"">Livello di subordinazione: ' + funcSelect[0].options[funcSelect[0].selectedIndex].text; claText = len + ". Tipo sintattico: " + syntSelect[0].options[syntSelect[0].selectedIndex].text + '; <br><span class="ml-3"">Livello di subordinazione: ' + funcSelect[0].options[funcSelect[0].selectedIndex].text;
jsonTextToParse = jsonTextToParse + ', "' + syntSelect.attr('name') + '": "' + syntSelect[0].options[syntSelect[0].selectedIndex].value + '", "' + funcSelect.attr('name') + '": "' + funcSelect[0].options[funcSelect[0].selectedIndex].value + '"'; jsonTextToParse = jsonTextToParse + ', "' + syntSelect.attr('name') + '": "' + syntSelect[0].options[syntSelect[0].selectedIndex].value + '", "' + funcSelect.attr('name') + '": "' + funcSelect[0].options[funcSelect[0].selectedIndex].value + '"';
break; break;
default: default:
claText = len + ". " + $(this).text(); claText = len + ". " + $("#" + claId).text();
checkInsert = '" disabled'; checkInsert = '" disabled';
}; };
var LItext = claLIpart1 + claListItemID + claLIpart2 + claText + claLIpart3 + len + checkInsert + claLIpart4 + len + claLIpart5; var LItext = claLIpart1 + claListItemID + claLIpart2 + claText + claLIpart3 + len + checkInsert + claLIpart4 + len + claLIpart5;
if ($("#" + claListItemID)[0]) { if ($("#" + claListItemID)[0]) {
$("#" + claListItemID).replaceWith(LItext); $("#" + claListItemID).replaceWith(LItext);
} else { } else {
$("#sortable0").append(LItext); $(sortableNum).append(LItext);
}; };
queryJson["Clausola" + len] = JSON.parse(jsonTextToParse + '}'); queryJson["Clausola" + len] = JSON.parse(jsonTextToParse + '}');
});
if (queryJson["Clausola" + (len + 1)]) //se vengo dalla rimozione di una clausola
delete queryJson["Clausola" + (len + 1)];
} else {
if (claListLen == 0 && condListLen == 0) {
$('#sortable0').html(emptyClaList);
queryJson.EsprLogica = "";
queryJson.LogicaGui = "";
}
tabID = 0;
};
} }
// Funzione di refresh dei placeholders e attivazione/disattivazione bottoni nelle liste sortable // Funzione di refresh dei placeholders e attivazione/disattivazione bottoni nelle liste sortable
@ -856,7 +863,6 @@ $(document).ready(function() {
$("#sparqlquery").val(logicExprString); $("#sparqlquery").val(logicExprString);
queryJson.EsprLogica = logicExprString.split(' '); queryJson.EsprLogica = logicExprString.split(' ');
queryJson.LogicaGui = guiLogicString.split(' '); queryJson.LogicaGui = guiLogicString.split(' ');
console.log(queryJson.LogicaGui);
}; };
// Funzione di refresh dei collegamenti tra elementi sortable // Funzione di refresh dei collegamenti tra elementi sortable
@ -933,14 +939,8 @@ $(document).ready(function() {
function makeUpGui(queryJson) { function makeUpGui(queryJson) {
$("#risultatitesto").val(queryJson["LogicaGui"]); $("#risultatitesto").val(queryJson["LogicaGui"]);
// 1. verifica json legit --> TO DO // 1. verifica json legit --> TO DO
// 2. pulire interfaccia --> OK
// 3. clausola0 --> OK
// 4. contare clausole, ricrearle in ordine e popolarle --> OK
// 5. ricreare condizioni logiche --> OK
// 6. ricreare albero logico --> TO DO
// 7. ???
// ------------------- // -------------------
// 2: // Pulizia interfaccia:
var tabsContent=$("#cla-TabContent").find(".tab-pane:not(:first)"); var tabsContent=$("#cla-TabContent").find(".tab-pane:not(:first)");
var tabs=$("#tab-list li:not(:first)"); var tabs=$("#tab-list li:not(:first)");
if ($(tabsContent).length) { if ($(tabsContent).length) {
@ -955,16 +955,17 @@ $(document).ready(function() {
condListLen = 0; condListLen = 0;
tabID = 0; tabID = 0;
$('#sortable0').html(emptyClaList); $('#sortable0').html(emptyClaList);
// 3: // Rigenerazione Clausola0:
if (queryJson["Clausola0"].Attiva) { if (queryJson["Clausola0"].Attiva) {
$("#cla0 #lemma_forma").val(queryJson["Clausola0"].lemma_forma); $("#cla0 #lemma_forma").val(queryJson["Clausola0"].lemma_forma);
$("#cla0 #queryText").val(queryJson["Clausola0"].queryText); $("#cla0 #queryText").val(queryJson["Clausola0"].queryText);
}; };
// 4 e 5: // Generazione lista clausole e condizioni con elementi padre:
guiLogicString = queryJson.LogicaGui; guiLogicString = queryJson.LogicaGui;
var clau2Make = ""; var clau2Make = "";
var treeLevel = []; var claParent = []; // array di coppie [elemento, elemento padre]
var claParent = []; var treeLevel = []; // pila di elementi padre
var condNum = 0;
for (var i=0; i < guiLogicString.length; i++) { for (var i=0; i < guiLogicString.length; i++) {
switch (guiLogicString[i]) { switch (guiLogicString[i]) {
case "(": case "(":
@ -973,48 +974,44 @@ $(document).ready(function() {
treeLevel.pop(); treeLevel.pop();
break; break;
case "OR": case "OR":
addLogicCond("OR",treeLevel[treeLevel.length - 1]); claParent.push([guiLogicString[i], treeLevel[treeLevel.length - 1]]);
treeLevel.push("#sortable" + condListLen); treeLevel.push("#sortable" + ++condNum);
guiLogicString[i] = "#sortable" + condListLen;
refreshConnectWith();
break; break;
case "AND": case "AND":
if (i > 1) { if (i > 1) {
addLogicCond("AND",treeLevel[treeLevel.length - 1]); claParent.push([guiLogicString[i], treeLevel[treeLevel.length - 1]]);
treeLevel.push("#sortable" + condListLen); treeLevel.push("#sortable" + ++condNum);
refreshConnectWith();
guiLogicString[i] = "#sortable" + condListLen;
} else { } else {
guiLogicString[1] = "#sortable0";
treeLevel.push("#sortable0"); treeLevel.push("#sortable0");
}; };
break; break;
default: default:
claParent.push(treeLevel[treeLevel.length - 1]); claParent.push([guiLogicString[i].replace("Clausola", ""), treeLevel[treeLevel.length - 1]]);
}; };
}; };
//console.log(claParent); $(claParent).each(function(){ // rigenero le clausole nei tab
for (var i=1; i <= claParent.length; i++) { var itm = $(this)[0]
clau2Make = queryJson["Clausola" + i].TipoClausola; if (itm != "OR" && itm != "AND") {
active = queryJson["Clausola" + i].Attiva clau2Make = queryJson["Clausola" + itm].TipoClausola;
active = queryJson["Clausola" + itm].Attiva
switch (clau2Make) { switch (clau2Make) {
case "Grammaticale": case "Grammaticale":
selectedValue = queryJson["Clausola" + i].typeGramm0; selectedValue = queryJson["Clausola" + itm].typeGramm0;
addGramCla(active); addGramCla(active);
if (selectedValue != "all") { if (selectedValue != "all") {
$("#cla" + tabID + " .catgram").val(selectedValue); $("#cla" + tabID + " .catgram").val(selectedValue);
addCatgramSubcla("cla" + tabID,selectedValue); addCatgramSubcla("cla" + tabID, selectedValue);
var ks = Object.keys(queryJson["Clausola" + i]); var ks = Object.keys(queryJson["Clausola" + itm]);
for (var j = 5; j < ks.length; j++) { for (var j = 5; j < ks.length; j++) {
var test="cla" + i + ks[j]; var melID = "cla" + tabID + ks[j];
var melement = document.getElementById(test); var melement = document.getElementById(melID);
switch (melement.type) { switch (melement.type) {
case "fieldset": case "fieldset":
var sval = queryJson["Clausola" + i][ks[j]] var sval = queryJson["Clausola" + itm][ks[j]]
$("#cla" + tabID + sval.replace(/\s/g, '')).attr("checked",true); $("#cla" + tabID + sval.replace(/\s/g, '')).attr("checked", true);
break; break;
case "select-one": case "select-one":
melement.value=([queryJson["Clausola" + i][ks[j]]]) melement.value = ([queryJson["Clausola" + itm][ks[j]]])
break; break;
default: default:
}; };
@ -1023,11 +1020,11 @@ $(document).ready(function() {
break; break;
case "Sintattico": case "Sintattico":
addSyntCla(active); addSyntCla(active);
if (queryJson["Clausola" + i].typeSyntax0 != ".+") { if (queryJson["Clausola" + itm].typeSyntax0 != ".+") {
$("#cla" + tabID + " #synttypes").val(queryJson["Clausola" + i].typeSyntax0); $("#cla" + tabID + " #synttypes").val(queryJson["Clausola" + itm].typeSyntax0);
} }
if (queryJson["Clausola" + i].functionSyntax != ".+") { if (queryJson["Clausola" + itm].functionSyntax != ".+") {
$("#cla" + tabID + " #syntfunc").val(queryJson["Clausola" + i].functionSyntax); $("#cla" + tabID + " #syntfunc").val(queryJson["Clausola" + itm].functionSyntax);
} }
break; break;
case "Metafore": case "Metafore":
@ -1041,16 +1038,17 @@ $(document).ready(function() {
break; break;
default: default:
}; };
var ind = guiLogicString.indexOf("Clausola" + i);
guiLogicString[ind] = "#cla" + tabID;
}; };
// 6: });
//console.log(guiLogicString); $(claParent).each(function(){ // rigenero le liste di clausole e condizioni logiche nel tab principale
refreshTabList(); if ($(this)[0] == "OR" || $(this)[0] == "AND") {
refreshClaList(); addLogicCond($(this)[0],$(this)[1]);
} else {
createClaListItem($(this)[0], "cla" + $(this)[0], $(this)[1]);
refreshSortables(); refreshSortables();
}; };
});
};
}); });