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;
case "andCond":
addLogicCond("AND","#sortable0")
refreshConnectWith();
break;
case "orCond":
addLogicCond("OR","#sortable0")
refreshConnectWith();
break;
default:
};
@ -658,6 +656,7 @@ $(document).ready(function() {
cursor: 'move',
update: function() {refreshSortables();}
});
refreshConnectWith();
}
// 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
function refreshClaList(){
var l_f = $("form #lemma_forma")[0].options[$("form #lemma_forma")[0].selectedIndex].value;
var qText = $("form #queryText")[0].value;
if (qText == "") { //disattivo clausola 0 se il testo e' vuoto
var claActive = 0
} else {
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 len=0;
queryJson.Clausola0 = JSON.parse('{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "TipoClausola": "0", "Attiva": "' + claActive + '"}');
if ($(tabsContent).length) {
if ($("#H-cla0")[0]) {
$("#H-cla0")[0].remove();
};
$(tabsContent).each(function(){
if ($("#H-cla0")[0]) {
$("#H-cla0")[0].remove();
};
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 checkInsert = '"';
var claId = $(this).attr('id');
var claListItemID = "H-" + claId;
var claType = $(this).attr('data-claType');
var claActive = $(this).attr('data-claActive');
var claType = $("#" + claId).attr('data-claType');
var claActive = $("#" + claId).attr('data-claActive');
if (claActive > 0) {
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 + '"';
switch (claType) {
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">';
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(){
var claSubParType = $(this)[0].type;
if (claSubParType == "fieldset" && $(this).find(":checked").length) {
@ -743,33 +760,23 @@ $(document).ready(function() {
});
break;
case "Sintattico":
var syntSelect = $(this).find("#synttypes");
; var funcSelect = $(this).find("#syntfunc");
var syntSelect = $("#" + claId).find("#synttypes");
; 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;
jsonTextToParse = jsonTextToParse + ', "' + syntSelect.attr('name') + '": "' + syntSelect[0].options[syntSelect[0].selectedIndex].value + '", "' + funcSelect.attr('name') + '": "' + funcSelect[0].options[funcSelect[0].selectedIndex].value + '"';
break;
default:
claText = len + ". " + $(this).text();
claText = len + ". " + $("#" + claId).text();
checkInsert = '" disabled';
};
var LItext = claLIpart1 + claListItemID + claLIpart2 + claText + claLIpart3 + len + checkInsert + claLIpart4 + len + claLIpart5;
if ($("#" + claListItemID)[0]) {
$("#" + claListItemID).replaceWith(LItext);
} else {
$("#sortable0").append(LItext);
$(sortableNum).append(LItext);
};
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
@ -856,7 +863,6 @@ $(document).ready(function() {
$("#sparqlquery").val(logicExprString);
queryJson.EsprLogica = logicExprString.split(' ');
queryJson.LogicaGui = guiLogicString.split(' ');
console.log(queryJson.LogicaGui);
};
// Funzione di refresh dei collegamenti tra elementi sortable
@ -933,14 +939,8 @@ $(document).ready(function() {
function makeUpGui(queryJson) {
$("#risultatitesto").val(queryJson["LogicaGui"]);
// 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 tabs=$("#tab-list li:not(:first)");
if ($(tabsContent).length) {
@ -955,16 +955,17 @@ $(document).ready(function() {
condListLen = 0;
tabID = 0;
$('#sortable0').html(emptyClaList);
// 3:
// Rigenerazione Clausola0:
if (queryJson["Clausola0"].Attiva) {
$("#cla0 #lemma_forma").val(queryJson["Clausola0"].lemma_forma);
$("#cla0 #queryText").val(queryJson["Clausola0"].queryText);
};
// 4 e 5:
// Generazione lista clausole e condizioni con elementi padre:
guiLogicString = queryJson.LogicaGui;
var clau2Make = "";
var treeLevel = [];
var claParent = [];
var claParent = []; // array di coppie [elemento, elemento padre]
var treeLevel = []; // pila di elementi padre
var condNum = 0;
for (var i=0; i < guiLogicString.length; i++) {
switch (guiLogicString[i]) {
case "(":
@ -973,84 +974,81 @@ $(document).ready(function() {
treeLevel.pop();
break;
case "OR":
addLogicCond("OR",treeLevel[treeLevel.length - 1]);
treeLevel.push("#sortable" + condListLen);
guiLogicString[i] = "#sortable" + condListLen;
refreshConnectWith();
claParent.push([guiLogicString[i], treeLevel[treeLevel.length - 1]]);
treeLevel.push("#sortable" + ++condNum);
break;
case "AND":
if (i > 1) {
addLogicCond("AND",treeLevel[treeLevel.length - 1]);
treeLevel.push("#sortable" + condListLen);
refreshConnectWith();
guiLogicString[i] = "#sortable" + condListLen;
claParent.push([guiLogicString[i], treeLevel[treeLevel.length - 1]]);
treeLevel.push("#sortable" + ++condNum);
} else {
guiLogicString[1] = "#sortable0";
treeLevel.push("#sortable0");
};
break;
default:
claParent.push(treeLevel[treeLevel.length - 1]);
claParent.push([guiLogicString[i].replace("Clausola", ""), treeLevel[treeLevel.length - 1]]);
};
};
//console.log(claParent);
for (var i=1; i <= claParent.length; i++) {
clau2Make = queryJson["Clausola" + i].TipoClausola;
active = queryJson["Clausola" + i].Attiva
switch (clau2Make) {
case "Grammaticale":
selectedValue = queryJson["Clausola" + i].typeGramm0;
addGramCla(active);
if (selectedValue != "all") {
$("#cla" + tabID + " .catgram").val(selectedValue);
addCatgramSubcla("cla" + tabID,selectedValue);
var ks = Object.keys(queryJson["Clausola" + i]);
for (var j = 5; j < ks.length; j++) {
var test="cla" + i + ks[j];
var melement = document.getElementById(test);
switch (melement.type) {
case "fieldset":
var sval = queryJson["Clausola" + i][ks[j]]
$("#cla" + tabID + sval.replace(/\s/g, '')).attr("checked",true);
break;
case "select-one":
melement.value=([queryJson["Clausola" + i][ks[j]]])
break;
default:
$(claParent).each(function(){ // rigenero le clausole nei tab
var itm = $(this)[0]
if (itm != "OR" && itm != "AND") {
clau2Make = queryJson["Clausola" + itm].TipoClausola;
active = queryJson["Clausola" + itm].Attiva
switch (clau2Make) {
case "Grammaticale":
selectedValue = queryJson["Clausola" + itm].typeGramm0;
addGramCla(active);
if (selectedValue != "all") {
$("#cla" + tabID + " .catgram").val(selectedValue);
addCatgramSubcla("cla" + tabID, selectedValue);
var ks = Object.keys(queryJson["Clausola" + itm]);
for (var j = 5; j < ks.length; j++) {
var melID = "cla" + tabID + ks[j];
var melement = document.getElementById(melID);
switch (melement.type) {
case "fieldset":
var sval = queryJson["Clausola" + itm][ks[j]]
$("#cla" + tabID + sval.replace(/\s/g, '')).attr("checked", true);
break;
case "select-one":
melement.value = ([queryJson["Clausola" + itm][ks[j]]])
break;
default:
};
};
};
};
break;
case "Sintattico":
addSyntCla(active);
if (queryJson["Clausola" + i].typeSyntax0 != ".+") {
$("#cla" + tabID + " #synttypes").val(queryJson["Clausola" + i].typeSyntax0);
}
if (queryJson["Clausola" + i].functionSyntax != ".+") {
$("#cla" + tabID + " #syntfunc").val(queryJson["Clausola" + i].functionSyntax);
}
break;
case "Metafore":
addMetaCla(active);
break;
case "Dialoghi":
addDialCla(active);
break;
case "Struttura":
addStruCla(active);
break;
default:
};
var ind = guiLogicString.indexOf("Clausola" + i);
guiLogicString[ind] = "#cla" + tabID;
};
// 6:
//console.log(guiLogicString);
refreshTabList();
refreshClaList();
refreshSortables();
break;
case "Sintattico":
addSyntCla(active);
if (queryJson["Clausola" + itm].typeSyntax0 != ".+") {
$("#cla" + tabID + " #synttypes").val(queryJson["Clausola" + itm].typeSyntax0);
}
if (queryJson["Clausola" + itm].functionSyntax != ".+") {
$("#cla" + tabID + " #syntfunc").val(queryJson["Clausola" + itm].functionSyntax);
}
break;
case "Metafore":
addMetaCla(active);
break;
case "Dialoghi":
addDialCla(active);
break;
case "Struttura":
addStruCla(active);
break;
default:
};
};
});
$(claParent).each(function(){ // rigenero le liste di clausole e condizioni logiche nel tab principale
if ($(this)[0] == "OR" || $(this)[0] == "AND") {
addLogicCond($(this)[0],$(this)[1]);
} else {
createClaListItem($(this)[0], "cla" + $(this)[0], $(this)[1]);
refreshSortables();
};
});
};
});