From df305dfeafa82cf3bd46be951a2f792b235c7168 Mon Sep 17 00:00:00 2001 From: Luca Trupiano Date: Thu, 4 Aug 2022 18:15:40 +0200 Subject: [PATCH] Aggiunta struttura dati Json x i filtri, salva e carica files json --- index_Luk_Q.html | 5 +- js/script_Luk_Q.js | 113 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 94 insertions(+), 24 deletions(-) diff --git a/index_Luk_Q.html b/index_Luk_Q.html index cf378db..8fcddea 100644 --- a/index_Luk_Q.html +++ b/index_Luk_Q.html @@ -61,8 +61,8 @@ @@ -106,6 +106,7 @@
+
diff --git a/js/script_Luk_Q.js b/js/script_Luk_Q.js index 0e5e048..20fcfac 100644 --- a/js/script_Luk_Q.js +++ b/js/script_Luk_Q.js @@ -18,21 +18,30 @@ $(document).ready(function() { $("#copiaQuery").prop("disabled", true); - $("#copiaQuery").on("click", function(){ - $('#sparqlquery').copy2clipboard(); - }); - $( "#sortable0" ).sortable({ items: "> li", handle: ".handle" }); - + + // Evento: click sul bottone di copia della query + $("#copiaQuery").on("click", function(){ + $('#sparqlquery').copy2clipboard(); + }); + // Evento: click sull'area di navigazione delle tab delle clausole $('#tab-list').on('click', function() { refreshClaList(); refreshSortables(); }); + $("form #lemma_forma").on('change', function() { + refreshClaList(); + }); + + $("form #queryText").on('change', function() { + refreshClaList(); + }); + // Evento: click sull'icona check dentro il tab della clausola $('#cla-TabContent').on('click', '.return2Query', function() { var tabFirst = $('#tab-list a:first'); @@ -214,6 +223,32 @@ $(document).ready(function() { }; }); + // Evento: click sull'icona di save local + $('#cla-TabContent').on('click', 'ion-icon[name="save-outline"]', function() { + var fileA = document.createElement("a"); + fileA.href = window.URL.createObjectURL(new Blob([JSON.stringify(queryJson)], {type: "text/plain;charset=utf-8"})); + fileA.download = "LiDaQuery.txt"; + fileA.click(); + fileA.remove(); + }); + + // Evento: click sull'icona di load local + $('#cla-TabContent').on('click', 'ion-icon[name="folder-open-outline"]', function() { + $('#apriFile').click(); + }); + + $("#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); + }; + if (file) {reader.readAsText(file);} + }); + // Evento: SCELTA CATEGORIA GRAMMATICALE $('#cla-TabContent').on('change', 'select.catgram', function(e) { e.preventDefault(); @@ -537,7 +572,11 @@ $(document).ready(function() { var claListLen = 0; var condListLen = 0; var execQuery =``; - var queryFields = []; + var queryFields = []; // Contiene le intestazioni di colonna della tabella dei risultati + var c0 = JSON.parse('{"queryText": "", "lemma_forma": "lemma", "Tipo": "0", "Attiva": "0"}'); + var queryJson = JSON.parse('{"EsprLogica":""}'); + queryJson.LiDaVersion = "1.0"; + queryJson.Clausola0 = c0; const myEngine = new Comunica.QueryEngine(); const sparqlEndpoint2 = "https://hdnlab1.isti.cnr.it/fuseki/commediaontosintgra/query"; @@ -732,11 +771,19 @@ WHERE { }); } - // Funzione di refresh della lista clausole nella tab principale + // Funzione di refresh della lista clausole nella tab principale e del json della query function refreshClaList(){ + 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; 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 + '"}'); if ($(tabsC).length) { $(tabsC).each(function(){ if ($("#H-cla0")[0]) { @@ -745,37 +792,41 @@ WHERE { len++; var claText = ''; var checkInsert = '"'; - var claListItemID = "H-" + $(this).attr('id'); + var claId = $(this).attr('id'); + var claListItemID = "H-" + claId; var claType = $(this).attr('data-claType'); var claActive = $(this).attr('data-claActive'); if (claActive > 0) { checkInsert = '" checked="checked"'; }; + var jsonTextToParse = '{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "Tipo": "' + claType + '", "Attiva": "' + claActive + '"'; switch (claType) { case "Grammaticale": var graSelect = $(this).find(".catgram"); - var graText = graSelect[0].options[graSelect[0].selectedIndex].text; - claText = len + ". Categoria grammaticale: " + graText + '
'; + claText = len + ". Categoria grammaticale: " + graSelect[0].options[graSelect[0].selectedIndex].text + '
'; + jsonTextToParse = jsonTextToParse + ', "' + graSelect.attr('name') + '": "' + graSelect[0].options[graSelect[0].selectedIndex].value + '"'; var claSubParList = $(this).children(".dettaglifiltri").find("select, fieldset"); claSubParList.each(function(){ var claSubParType = $(this)[0].type; if (claSubParType == "fieldset" && $(this).find(":checked").length) { - var claSubParId = $(this).find(":checked")[0].id; - var claSubParText = $(this).find("[for='" + claSubParId + "']")[0].innerText; - claText = claText + claSubParText + "; "; + var claSubParName = $(this).find(":checked")[0].name + if (claSubParName.startsWith(claId)) { + claSubParName = claSubParName.replace(claId,''); + } + claText = claText + $(this).find("[for='" + $(this).find(":checked")[0].id + "']")[0].innerText + "; "; + jsonTextToParse = jsonTextToParse + ', "' + claSubParName + '": "' + $(this).find(":checked")[0].value + '"'; }; - if (claSubParType == "select-one") { - var claSubParText = $(this)[0].options[$(this)[0].selectedIndex].text; - claText = claText + claSubParText + "; " + if (claSubParType == "select-one" && $(this)[0].selectedIndex != 0) { + claText = claText + $(this)[0].options[$(this)[0].selectedIndex].text + "; "; + jsonTextToParse = jsonTextToParse + ', "' + $(this)[0].name + '": "' + $(this)[0].options[$(this)[0].selectedIndex].value + '"'; }; }); break; case "Sintattico": var syntSelect = $(this).find("#synttypes"); - var syntText = syntSelect[0].options[syntSelect[0].selectedIndex].text; - var funcSelect = $(this).find("#syntfunc"); - var funcText = funcSelect[0].options[funcSelect[0].selectedIndex].text; - claText = len + ". Tipo sintattico: " + syntText + ';
Livello di subordinazione: ' + funcText +; var funcSelect = $(this).find("#syntfunc"); + claText = len + ". Tipo sintattico: " + syntSelect[0].options[syntSelect[0].selectedIndex].text + ';
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(); @@ -787,10 +838,14 @@ WHERE { } else { $("#sortable0").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 = ""; } tabID = 0; }; @@ -867,7 +922,10 @@ WHERE { }; }; }); - $("#sparqlquery").val(parseCond("#sortable0", "AND")); + var logicExprString = parseCond("#sortable0", "AND"); + $("#sparqlquery").val(logicExprString); + queryJson.EsprLogica = logicExprString.split(' '); + //console.log(queryJson); }; // Funzione di refresh dei collegamenti tra elementi sortable @@ -906,7 +964,7 @@ WHERE { if ($(this).hasClass("claLI")) { if ($(this).find("input")[0].checked == true){ var claText = $(this).find(".clatext").text(); - var claNum = claText.substr(0,claText.indexOf('.')); + var claNum = "Clausola" + claText.substr(0,claText.indexOf('.')); itemsText.push(claNum); }; }; @@ -970,6 +1028,17 @@ WHERE { $(this).after('
Copiata 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) + }; + reader.readAsText(file); + }; + function cloneClaSint(clone,tabID){ var original = document.getElementById("tiposintatticoX"); clone = original.cloneNode(true);