Aggiunta struttura dati Json x i filtri, salva e carica files json

This commit is contained in:
Luca Trupiano 2022-08-04 18:15:40 +02:00
parent b8d49960f7
commit df305dfeaf
2 changed files with 94 additions and 24 deletions

View File

@ -61,8 +61,8 @@
<label class="input-group-text"><ion-icon name="document-text"></ion-icon></label> <label class="input-group-text"><ion-icon name="document-text"></ion-icon></label>
</div> </div>
<select class="form-control custom-select" id="lemma_forma"> <select class="form-control custom-select" id="lemma_forma">
<option>il lemma</option> <option value="lemma">il lemma</option>
<option>la forma</option> <option value="forma">la forma</option>
</select> </select>
<input type="text" class="form-control" id="queryText" placeholder="stelle" aria-describedby="name-desc" name="query"> <input type="text" class="form-control" id="queryText" placeholder="stelle" aria-describedby="name-desc" name="query">
</div> </div>
@ -106,6 +106,7 @@
</div> </div>
</div> </div>
<div class="col text-right px-3"> <div class="col text-right px-3">
<input style="display: none;" type="file" id="apriFile">
<span class="border rounded p-1 pt-2"><ion-icon name="save-outline"></ion-icon> <ion-icon name="folder-open-outline"></ion-icon> <span class="border rounded p-1 pt-2"><ion-icon name="save-outline"></ion-icon> <ion-icon name="folder-open-outline"></ion-icon>
<ion-icon name="cloud-upload-outline"></ion-icon> <ion-icon name="cloud-download-outline"></ion-icon></span> <ion-icon name="cloud-upload-outline"></ion-icon> <ion-icon name="cloud-download-outline"></ion-icon></span>
</div> </div>

View File

@ -18,21 +18,30 @@ $(document).ready(function() {
$("#copiaQuery").prop("disabled", true); $("#copiaQuery").prop("disabled", true);
$("#copiaQuery").on("click", function(){
$('#sparqlquery').copy2clipboard();
});
$( "#sortable0" ).sortable({ $( "#sortable0" ).sortable({
items: "> li", items: "> li",
handle: ".handle" 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 // Evento: click sull'area di navigazione delle tab delle clausole
$('#tab-list').on('click', function() { $('#tab-list').on('click', function() {
refreshClaList(); refreshClaList();
refreshSortables(); refreshSortables();
}); });
$("form #lemma_forma").on('change', function() {
refreshClaList();
});
$("form #queryText").on('change', function() {
refreshClaList();
});
// Evento: click sull'icona check dentro il tab della clausola // Evento: click sull'icona check dentro il tab della clausola
$('#cla-TabContent').on('click', '.return2Query', function() { $('#cla-TabContent').on('click', '.return2Query', function() {
var tabFirst = $('#tab-list a:first'); 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 // Evento: SCELTA CATEGORIA GRAMMATICALE
$('#cla-TabContent').on('change', 'select.catgram', function(e) { $('#cla-TabContent').on('change', 'select.catgram', function(e) {
e.preventDefault(); e.preventDefault();
@ -537,7 +572,11 @@ $(document).ready(function() {
var claListLen = 0; var claListLen = 0;
var condListLen = 0; var condListLen = 0;
var execQuery =``; 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 myEngine = new Comunica.QueryEngine();
const sparqlEndpoint2 = "https://hdnlab1.isti.cnr.it/fuseki/commediaontosintgra/query"; 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(){ 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 tabsC=$("#cla-TabContent").find(".tab-pane:not(:first)");
var clausoleText = ""; var clausoleText = "";
var len=0; var len=0;
queryJson.Clausola0 = JSON.parse('{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "Tipo": "0", "Attiva": "' + claActive + '"}');
if ($(tabsC).length) { if ($(tabsC).length) {
$(tabsC).each(function(){ $(tabsC).each(function(){
if ($("#H-cla0")[0]) { if ($("#H-cla0")[0]) {
@ -745,37 +792,41 @@ WHERE {
len++; len++;
var claText = ''; var claText = '';
var checkInsert = '"'; var checkInsert = '"';
var claListItemID = "H-" + $(this).attr('id'); var claId = $(this).attr('id');
var claListItemID = "H-" + claId;
var claType = $(this).attr('data-claType'); var claType = $(this).attr('data-claType');
var claActive = $(this).attr('data-claActive'); var claActive = $(this).attr('data-claActive');
if (claActive > 0) { if (claActive > 0) {
checkInsert = '" checked="checked"'; checkInsert = '" checked="checked"';
}; };
var jsonTextToParse = '{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "Tipo": "' + claType + '", "Attiva": "' + claActive + '"';
switch (claType) { switch (claType) {
case "Grammaticale": case "Grammaticale":
var graSelect = $(this).find(".catgram"); var graSelect = $(this).find(".catgram");
var graText = graSelect[0].options[graSelect[0].selectedIndex].text; claText = len + ". Categoria grammaticale: " + graSelect[0].options[graSelect[0].selectedIndex].text + '<br><span class="small ml-3">';
claText = len + ". Categoria grammaticale: " + graText + '<br><span class="small ml-3">'; jsonTextToParse = jsonTextToParse + ', "' + graSelect.attr('name') + '": "' + graSelect[0].options[graSelect[0].selectedIndex].value + '"';
var claSubParList = $(this).children(".dettaglifiltri").find("select, fieldset"); var claSubParList = $(this).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) {
var claSubParId = $(this).find(":checked")[0].id; var claSubParName = $(this).find(":checked")[0].name
var claSubParText = $(this).find("[for='" + claSubParId + "']")[0].innerText; if (claSubParName.startsWith(claId)) {
claText = claText + claSubParText + "; "; 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") { if (claSubParType == "select-one" && $(this)[0].selectedIndex != 0) {
var claSubParText = $(this)[0].options[$(this)[0].selectedIndex].text; claText = claText + $(this)[0].options[$(this)[0].selectedIndex].text + "; ";
claText = claText + claSubParText + "; " jsonTextToParse = jsonTextToParse + ', "' + $(this)[0].name + '": "' + $(this)[0].options[$(this)[0].selectedIndex].value + '"';
}; };
}); });
break; break;
case "Sintattico": case "Sintattico":
var syntSelect = $(this).find("#synttypes"); var syntSelect = $(this).find("#synttypes");
var syntText = syntSelect[0].options[syntSelect[0].selectedIndex].text; ; var funcSelect = $(this).find("#syntfunc");
var funcSelect = $(this).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;
var funcText = 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 + '"';
claText = len + ". Tipo sintattico: " + syntText + '; <br><span class="ml-3"">Livello di subordinazione: ' + funcText
break; break;
default: default:
claText = len + ". " + $(this).text(); claText = len + ". " + $(this).text();
@ -787,10 +838,14 @@ WHERE {
} else { } else {
$("#sortable0").append(LItext); $("#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 { } else {
if (claListLen == 0 && condListLen == 0) { if (claListLen == 0 && condListLen == 0) {
$('#sortable0').html(emptyClaList); $('#sortable0').html(emptyClaList);
queryJson.EsprLogica = "";
} }
tabID = 0; 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 // Funzione di refresh dei collegamenti tra elementi sortable
@ -906,7 +964,7 @@ WHERE {
if ($(this).hasClass("claLI")) { if ($(this).hasClass("claLI")) {
if ($(this).find("input")[0].checked == true){ if ($(this).find("input")[0].checked == true){
var claText = $(this).find(".clatext").text(); var claText = $(this).find(".clatext").text();
var claNum = claText.substr(0,claText.indexOf('.')); var claNum = "Clausola" + claText.substr(0,claText.indexOf('.'));
itemsText.push(claNum); itemsText.push(claNum);
}; };
}; };
@ -970,6 +1028,17 @@ WHERE {
$(this).after('<div class="mt-2 text-lida3" id="msgCopiata">Copiata nella clipboard</div>'); $(this).after('<div class="mt-2 text-lida3" id="msgCopiata">Copiata nella clipboard</div>');
}; };
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){ function cloneClaSint(clone,tabID){
var original = document.getElementById("tiposintatticoX"); var original = document.getElementById("tiposintatticoX");
clone = original.cloneNode(true); clone = original.cloneNode(true);