diff --git a/js/script_Luk_Q.js b/js/script_Luk_Q.js index 7c68cd7..59adf19 100644 --- a/js/script_Luk_Q.js +++ b/js/script_Luk_Q.js @@ -12,6 +12,7 @@ $(document).ready(function() { $("#copiaTesto").prop("disabled", true); + // Evento: click sul bottone di copia dei risultati testuali $("#copiaTesto").on("click", function(){ $("#risultatitesto").copy2clipboard(); }); @@ -107,84 +108,31 @@ $(document).ready(function() { var addClaN = $(this).attr('id'); switch (addClaN) { case "Grammaticale": - tabID++; - var clone = document.getElementById("tipogrammaticaleN").cloneNode(true); - clone.setAttribute("id","cla" + tabID); - clone.setAttribute("aria-labelledby","cla" + tabID + "-tab"); - clone.removeAttribute("style"); - $('#cla-TabContent').append(clone); - // se non cambio l'id della select react non rileva l'evento onchange: - $('#cla' + tabID + " #grammtypes").attr("id","grammtypes" + tabID); - claListLen++; - $('#tab-list').append($('')); + addGramCla(); $('#cla' + tabID + '-tab').tab('show'); break; case "Sintattico": - tabID++; - var clone = document.getElementById("tiposintatticoN").cloneNode(true); - clone.setAttribute("id","cla" + tabID); - clone.setAttribute("aria-labelledby","cla" + tabID + "-tab"); - clone.removeAttribute("style"); - $('#cla-TabContent').append(clone); - claListLen++; - $('#tab-list').append($('')); + addSyntCla(); $('#cla' + tabID + '-tab').tab('show'); break; case "Metafore": - tabID++; - $('#cla-TabContent').append($('
' + iconCheckAndClose + '
Clausola Metafore - non ancora implementata
')); - claListLen++; - $('#tab-list').append($('')); + addMetaCla(); $('#cla' + tabID + '-tab').tab('show'); break; case "Dialoghi": - tabID++; - $('#cla-TabContent').append($('
' + iconCheckAndClose + '
Clausola Dialoghi - non ancora implementata
')); - claListLen++; - $('#tab-list').append($('')); + addDialCla(); $('#cla' + tabID + '-tab').tab('show'); break; case "Struttura": - tabID++; - $('#cla-TabContent').append($('
' + iconCheckAndClose + '
Clausola Struttura testo - non ancora implementata
')); - claListLen++; - $('#tab-list').append($('')); + addStruCla(); $('#cla' + tabID + '-tab').tab('show'); break; case "andCond": - condListLen++; - var LItext = condLIpart1 + condListLen + condLIpart2and + condListLen + condLIpart3and + condListLen + condLIpart4; - if ($("#H-cla0")[0]) { - $("#H-cla0")[0].remove(); - }; - $("#sortable0").append(LItext); - $("#sortable" + condListLen).sortable(); - $("#sortable" + condListLen).sortable( "option", "appendTo", document.body ); - $("#sortable" + condListLen).sortable({ - items: "> li", - handle: ".handle", - opacity: 0.6, - cursor: 'move', - update: function() {refreshSortables();} - }); + addLogicCond("AND") refreshConnectWith(); break; case "orCond": - condListLen++; - var LItext = condLIpart1 + condListLen + condLIpart2or + condListLen + condLIpart3or + condListLen + condLIpart4; - if ($("#H-cla0")[0]) { - $("#H-cla0")[0].remove(); - }; - $("#sortable0").append(LItext); - $("#sortable" + condListLen).sortable(); - $("#sortable" + condListLen).sortable( "option", "appendTo", document.body ); - $("#sortable" + condListLen).sortable({ - items: "> li", - handle: ".handle", - opacity: 0.6, - cursor: 'move', - update: function() {refreshSortables();} - }); + addLogicCond("OR") refreshConnectWith(); break; default: @@ -239,12 +187,11 @@ $(document).ready(function() { $("#apriFile").on('change', function() { var file = $(this).prop('files')[0]; - //console.log(file); var reader = new FileReader(); reader.onload = function(data){ queryJson = JSON.parse(data.target.result) - console.log(queryJson); $("#sparqlquery").val(data.target.result); + makeUpGui(queryJson); }; if (file) {reader.readAsText(file);} }); @@ -574,7 +521,7 @@ $(document).ready(function() { var logicExprString = ``; var execQuery = ``; var queryFields = []; // Contiene le intestazioni di colonna della tabella dei risultati - var c0 = JSON.parse('{"queryText": "", "lemma_forma": "lemma", "Tipo": "0", "Attiva": "0"}'); + var c0 = JSON.parse('{"queryText": "", "lemma_forma": "lemma", "TipoClausola": "0", "Attiva": "0"}'); var queryJson = JSON.parse('{"EsprLogica":""}'); queryJson.LiDaVersion = "1.0"; queryJson.Clausola0 = c0; @@ -587,8 +534,6 @@ $(document).ready(function() { async function executeQuery(){ - //execQuery = sparqlQuery3; - //queryFields = queryFields3; $("#loader").show(); bindingsStream = await myEngine.queryBindings(execQuery, { sources: [ { type: 'sparql', value: sparqlEndpoint }, ], }); $("#sparqlquery").val(execQuery); @@ -600,6 +545,7 @@ $(document).ready(function() { var resultTablePart4 = ''; var resultTablePart5 = ''; var resultTable = ''; + var latestVerso = ''; var latestResult = ''; var rowNum = 1; for (var i = 0; i < queryFields.length; i++) { @@ -609,11 +555,10 @@ $(document).ready(function() { $('#resultsId1').empty(); $('#resultsId1').addClass("small pb-2") $("#risultatitesto").empty(); - //$("#risultatitesto").append("[\n"); bindingsStream.on('data', (binding) => { //console.log(binding.toString()); // Quick way to print bindings for testing //console.log(binding.has('sub')); // Will be true - var latestVerso = binding.get('Verso').value + latestVerso = binding.get('Verso').value latestResult = rowNum + '. "' + latestVerso.replace(binding.get('Forma').value, '*' + binding.get('Forma').value + '*') + '" (' + binding.get('Cantica').value + ', ' + binding.get('Canto').value + ', Verso ' + binding.get('NumeroVerso').value + ')\n'; $("#risultatitesto").append(latestResult); resultTablePart4 = '' + rowNum++ + ''; @@ -621,18 +566,12 @@ $(document).ready(function() { resultTablePart4 = resultTablePart4 + '' + binding.get(queryFields[i]).value + ""; }; resultTable = resultTable + resultTablePart4 + ''; - //$("#risultatitesto").append(binding.toString() + ",\n"); $("#loader").hide(); - //console.log(binding.get('Verso').value); - //console.log(binding.get('form').termType); - //console.log(binding.get('pred').value); - //console.log(binding.get('obj').value); }); bindingsStream.on('end', () => { $("#loader").hide(); resultTable = resultTable + resultTablePart5; $("#resultsId1").append(resultTable); - //$("#risultatitesto").append("]"); $("#copiaTesto").prop("disabled", false); $('#resultTable').DataTable( { colReorder: true, @@ -649,7 +588,80 @@ $(document).ready(function() { },300); }); }; - + + // Funzione di creazione del tab delle clausole grammaticali + function addGramCla(){ + tabID++; + var clone = document.getElementById("tipogrammaticaleN").cloneNode(true); + clone.setAttribute("id","cla" + tabID); + clone.setAttribute("aria-labelledby","cla" + tabID + "-tab"); + clone.removeAttribute("style"); + $('#cla-TabContent').append(clone); + // se non cambio l'id della select react non rileva l'evento onchange: + $('#cla' + tabID + " #grammtypes").attr("id","grammtypes" + tabID); + claListLen++; + $('#tab-list').append($('')); + } + + // Funzione di creazione del tab delle clausole sintattiche + function addSyntCla(){ + tabID++; + var clone = document.getElementById("tiposintatticoN").cloneNode(true); + clone.setAttribute("id","cla" + tabID); + clone.setAttribute("aria-labelledby","cla" + tabID + "-tab"); + clone.removeAttribute("style"); + $('#cla-TabContent').append(clone); + claListLen++; + $('#tab-list').append($('')); + } + + // Funzione di creazione del tab delle clausole metafore + function addMetaCla(){ + tabID++; + $('#cla-TabContent').append($('
' + iconCheckAndClose + '
Clausola Metafore - non ancora implementata
')); + claListLen++; + $('#tab-list').append($('')); + } + + // Funzione di creazione del tab delle clausole dialoghi + function addDialCla(){ + tabID++; + $('#cla-TabContent').append($('
' + iconCheckAndClose + '
Clausola Dialoghi - non ancora implementata
')); + claListLen++; + $('#tab-list').append($('')); + } + + // Funzione di creazione del tab delle clausole struttura + function addStruCla(){ + tabID++; + $('#cla-TabContent').append($('
' + iconCheckAndClose + '
Clausola Struttura testo - non ancora implementata
')); + claListLen++; + $('#tab-list').append($('')); + } + + // Funzione di creazione del LI delle condizioni logiche + function addLogicCond(condtype){ + condListLen++; + if (condtype == "AND") { + var LItext = condLIpart1 + condListLen + condLIpart2and + condListLen + condLIpart3and + condListLen + condLIpart4; + } else { + var LItext = condLIpart1 + condListLen + condLIpart2or + condListLen + condLIpart3or + condListLen + condLIpart4; + } + if ($("#H-cla0")[0]) { + $("#H-cla0")[0].remove(); + }; + $("#sortable0").append(LItext); + $("#sortable" + condListLen).sortable(); + $("#sortable" + condListLen).sortable( "option", "appendTo", document.body ); + $("#sortable" + condListLen).sortable({ + items: "> li", + handle: ".handle", + opacity: 0.6, + cursor: 'move', + update: function() {refreshSortables();} + }); + } + // Funzione di refresh della lista delle tab delle clausole function refreshTabList(){ var tabs=$("#tab-list li:not(:first)"); @@ -694,7 +706,7 @@ $(document).ready(function() { var tabsC=$("#cla-TabContent").find(".tab-pane:not(:first)"); var clausoleText = ""; var len=0; - queryJson.Clausola0 = JSON.parse('{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "Tipo": "0", "Attiva": "' + claActive + '"}'); + queryJson.Clausola0 = JSON.parse('{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "TipoClausola": "0", "Attiva": "' + claActive + '"}'); if ($(tabsC).length) { $(tabsC).each(function(){ if ($("#H-cla0")[0]) { @@ -710,12 +722,12 @@ $(document).ready(function() { if (claActive > 0) { checkInsert = '" checked="checked"'; }; - var jsonTextToParse = '{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "Tipo": "' + claType + '", "Attiva": "' + claActive + '"'; + var jsonTextToParse = '{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "TipoClausola": "' + claType + '", "Attiva": "' + claActive + '"'; switch (claType) { case "Grammaticale": - var graSelect = $(this).find(".catgram"); - claText = len + ". Categoria grammaticale: " + graSelect[0].options[graSelect[0].selectedIndex].text + '
'; - jsonTextToParse = jsonTextToParse + ', "' + graSelect.attr('name') + '": "' + graSelect[0].options[graSelect[0].selectedIndex].value + '"'; + var gramSelect = $(this).find(".catgram"); + claText = len + ". Categoria grammaticale: " + gramSelect[0].options[gramSelect[0].selectedIndex].text + '
'; + jsonTextToParse = jsonTextToParse + ', "' + gramSelect.attr('name') + '": "' + gramSelect[0].options[gramSelect[0].selectedIndex].value + '"'; var claSubParList = $(this).children(".dettaglifiltri").find("select, fieldset"); claSubParList.each(function(){ var claSubParType = $(this)[0].type; @@ -836,7 +848,6 @@ $(document).ready(function() { logicExprString = parseCond("#sortable0", "AND"); $("#sparqlquery").val(logicExprString); queryJson.EsprLogica = logicExprString.split(' '); - //console.log(queryJson); }; // Funzione di refresh dei collegamenti tra elementi sortable @@ -906,22 +917,76 @@ $(document).ready(function() { $(this).after('
Copiati nella clipboard
'); }; - - function cambio(event) { - var file = event.target.files[0]; - var reader = new FileReader(); - reader.onload = function(e) { - // The file's text will be printed here - console.log(e.target.result) + function makeUpGui(queryJson) { + // 1. verifica json legit + // 2. pulire interfaccia + // 3. contare clausole, ricrearle in ordine e popolarle + // 4. ricreare condizioni logiche + // 5. ricreare albero logico + // 6. ??? + var logicExpr = queryJson.EsprLogica; + var clauCount = 0; + var clau2Make = ""; + console.log(logicExpr); + for (var i=0; i < logicExpr.length; i++) { + //console.log("- " + logicExpr[i]); + switch (logicExpr[i]) { + case "(": + console.log("("); + break; + case ")": + console.log(")"); + break; + case "OR": + console.log("OR"); + break; + case "AND": + console.log("AND"); + break; + default: + clauCount++ + }; }; - reader.readAsText(file); + console.log(clauCount + " clausole:"); + for (var i=1; i <= clauCount; i++) { + clau2Make = queryJson["Clausola" + i].TipoClausola; + console.log(clau2Make); + switch (clau2Make) { + case "Grammaticale": + addGramCla(); + //$('#cla' + tabID + '-tab').tab('show'); + break; + case "Sintattico": + addSyntCla(); + //$('#cla' + tabID + '-tab').tab('show'); + break; + case "Metafore": + addMetaCla(); + //$('#cla' + tabID + '-tab').tab('show'); + break; + case "Dialoghi": + addDialCla(); + //$('#cla' + tabID + '-tab').tab('show'); + break; + case "Struttura": + addStruCla(); + //$('#cla' + tabID + '-tab').tab('show'); + break; + case "andCond": + addLogicCond("AND") + refreshConnectWith(); + break; + case "orCond": + addLogicCond("OR") + refreshConnectWith(); + break; + default: + }; + }; + refreshTabList(); + refreshClaList(); }; - function cloneClaSint(clone,tabID){ - var original = document.getElementById("tiposintatticoX"); - clone = original.cloneNode(true); - clone.setAttribute("id","tiposintattico" + tabID); - } });