LiDa_Search/js/cesareBrowse.js

409 lines
11 KiB
JavaScript
Raw Normal View History

2022-11-06 17:12:56 +01:00
/**
*
*/
2022-11-08 10:44:20 +01:00
$(document).ready(function() {
2022-11-06 17:12:56 +01:00
const sparqlGenerator = sparqljs.Generator;
const myEngine = new Comunica.QueryEngine();
const sparqlEndpoint = "https://hdnlab1.isti.cnr.it/fuseki/commediaontosintgra/query";
2022-11-08 10:44:20 +01:00
var primaCanticaLoaded = false;
var secondaCanticaLoaded = false;
var terzaCanticaLoaded = false;
2022-11-06 17:12:56 +01:00
var listaVersi = new Set()
2022-11-11 22:11:22 +01:00
const ddmenus={"Inferno":"#dmc1",
"Purgatorio": "#dmc2",
"Paradiso": "#dmc3"}
var listarisultativersi=[];
var currentMinimap=''
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
//caricamento prima cantica
2022-11-06 17:12:56 +01:00
$('#cantica1').on('click', function() {
2022-11-11 22:11:22 +01:00
hideMinimap();
2022-11-08 10:44:20 +01:00
activateMenuItem('#cantica1')
if (!(primaCanticaLoaded)) {
2022-11-07 11:52:54 +01:00
jsonQuery = versiCantica("Inferno");
execQuery = new sparqlGenerator().stringify(jsonQuery);
2022-11-08 10:44:20 +01:00
executeQueryVersi(execQuery);
primaCanticaLoaded = true;
}
else {
//$("#InfernoCanto_1").attr('style', 'display:block')
2022-11-08 10:44:20 +01:00
$("#CantiInferno").attr('style', 'display:block')
2022-11-07 11:52:54 +01:00
}
2022-11-11 22:11:22 +01:00
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
});
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
//caricamento seconda cantica
$('#cantica2').on('click', function() {
2022-11-11 22:11:22 +01:00
hideMinimap();
2022-11-08 10:44:20 +01:00
activateMenuItem('#cantica2')
if (!(secondaCanticaLoaded)) {
2022-11-07 11:52:54 +01:00
jsonQuery = versiCantica("Purgatorio");
execQuery = new sparqlGenerator().stringify(jsonQuery);
2022-11-08 10:44:20 +01:00
executeQueryVersi(execQuery);
secondaCanticaLoaded = true;
2022-11-07 11:52:54 +01:00
}
2022-11-08 10:44:20 +01:00
else {
//$("#PurgatorioCanto_1").attr('style', 'display:block')
2022-11-08 10:44:20 +01:00
$("#CantiPurgatorio").attr('style', 'display:block')
}
2022-11-11 22:11:22 +01:00
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
});
2022-11-08 10:44:20 +01:00
2022-11-07 11:52:54 +01:00
//caricamento terza cantica
$('#cantica3').on('click', function() {
2022-11-11 22:11:22 +01:00
hideMinimap();
2022-11-08 10:44:20 +01:00
activateMenuItem('#cantica3')
if (!(terzaCanticaLoaded)) {
2022-11-07 11:52:54 +01:00
jsonQuery = versiCantica("Paradiso");
execQuery = new sparqlGenerator().stringify(jsonQuery);
2022-11-08 10:44:20 +01:00
executeQueryVersi(execQuery);
terzaCanticaLoaded = true;
2022-11-07 11:52:54 +01:00
}
2022-11-08 10:44:20 +01:00
else {
//$("#ParadisoCanto_1").attr('style', 'display:block')
2022-11-08 10:44:20 +01:00
$("#CantiParadiso").attr('style', 'display:block')
}
2022-11-11 22:11:22 +01:00
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
});
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
jQuery(document).delegate('.navig-canto', 'click', function(e) {
$('.canto').each(function() {
2022-11-08 10:44:20 +01:00
$(this).attr("style", 'display:none');
2022-11-06 17:12:56 +01:00
});
2022-11-08 10:44:20 +01:00
$("#" + $(this).attr('name').replace(" ", "_")).attr('style', 'display:block')
showMinimap($(this).attr('name').replace(" ", "_"))
2022-11-11 22:11:22 +01:00
currentMinimap=$(this).attr('name').replace(" ", "_");
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
});
2022-11-08 10:44:20 +01:00
2022-11-11 22:11:22 +01:00
//Query
//$('#searchcomm').on('click', function() {
jQuery(document).delegate('#searchcomm', 'click', function(e) {
cleanSearchResult()
esprlogica=[]
esprlogica.push('Clausola1')
condizioni={"EsprLogica": esprlogica}
clausola={}
clausola['typeGramm0']=$('#queryText').val()
clausola['queryText']=""
condizioni['Clausola1']=clausola
jsonQuery=buildSQ(condizioni)
myquery =new sparqlGenerator().stringify(jsonQuery)
executeQuerySearch(myquery)
2022-11-12 19:45:14 +01:00
2022-11-11 22:11:22 +01:00
2022-11-14 09:22:00 +01:00
});
//Reset
jQuery(document).delegate('#cleanresult', 'click', function(e) {
cleanSearchResult()
esprlogica=[]
$('#queryText').val("")
2022-11-11 22:11:22 +01:00
});
2022-11-06 17:12:56 +01:00
//Utility functions
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
//activate navigation menu items
2022-11-08 10:44:20 +01:00
function activateMenuItem(menuItem) {
2022-11-11 22:11:22 +01:00
//$('.blog-nav-item').each(function() {
// $(this).attr("class", $(this).attr("class").replace(' active', ''));
//});
//$(menuItem).attr("class", $(menuItem).attr("class") + ' active');
2022-11-06 17:12:56 +01:00
}
2022-11-08 10:44:20 +01:00
2022-11-11 22:11:22 +01:00
2022-11-08 10:44:20 +01:00
2022-11-11 22:11:22 +01:00
2022-11-08 12:25:59 +01:00
function managePunctuation(stringa) {
var tempstringa=stringa.replaceAll(" ,", ",")
tempstringa=tempstringa.replaceAll(" .", ".")
tempstringa=tempstringa.replaceAll(" :", ":")
tempstringa=tempstringa.replaceAll(" !", "!")
tempstringa=tempstringa.replaceAll(" ?", "?")
tempstringa=tempstringa.replaceAll(" ;", ";")
2022-11-12 19:45:14 +01:00
tempstringa=tempstringa.replaceAll("%20", " ")
2022-11-08 12:25:59 +01:00
return tempstringa
}
2022-11-11 22:11:22 +01:00
function cleanSearchResult(){
for (verso of listarisultativersi){
idverso='#'+verso
console.log(idverso)
2022-11-12 19:45:14 +01:00
//$(idverso).attr('class', $(idverso).attr('class').replace(" dark-blue", ""))
$(idverso).attr('class', 'f6 font-weight-lighter')
2022-11-11 22:11:22 +01:00
}
if (currentMinimap!='')
showMinimap(currentMinimap)
}
2022-11-08 10:44:20 +01:00
//minimap management
let minimap = document.createElement('div');
let minimapSize = document.createElement('div');
let viewer = document.createElement('div');
let minimapContent = document.createElement('iframe');
let scale=0.1;
let realScale;
function showMinimap(element) {
minimap.className = 'minimap_container'
minimapSize.className = 'minimap_size'
viewer.className = 'minimap_viewer'
viewer.id='minimapviewer'
2022-11-08 10:44:20 +01:00
minimapContent.className = 'minimap_content'
minimap.append(minimapSize, viewer, minimapContent);
document.body.appendChild(minimap)
let html = document.getElementById(element).innerHTML
2022-11-14 12:29:23 +01:00
console.log(html)
2022-11-08 10:44:20 +01:00
let iFrameDoc = minimapContent.contentWindow.document;
iFrameDoc.open();
iFrameDoc.write(html);
iFrameDoc.close();
getDimensions()
window.addEventListener('scroll', trackScroll)
window.addEventListener('resize', getDimensions)
}
2022-11-07 11:52:54 +01:00
2022-11-08 10:44:20 +01:00
function getDimensions(){
let bodyWidth = document.body.clientWidth;
let bodyRatio = document.body.clientHeight / bodyWidth;
let winRatio = window.innerHeight / window.innerWidth;
minimap.style.width = '10%';
realScale = minimap.clientWidth / (bodyWidth);
minimapSize.style.paddingTop = `${bodyRatio * 100}%`
viewer.style.paddingTop = `${winRatio * 100}%`;
minimapContent.style.transform = `scale(${realScale})`;
minimapContent.style.width = `${(100 / realScale)}%`
minimapContent.style.height = `${(100 / realScale)}%`
}
function trackScroll(){
viewer.style.transform=`translateY(${window.scrollY * realScale}px)`
2022-11-07 11:52:54 +01:00
}
2022-11-11 22:11:22 +01:00
function hideMinimap(){
$('.canto').each(function() {
$(this).attr("style", 'display:none');
});
$( ".minimap_container" ).remove();
currentMinimap=''
}
2022-11-08 10:44:20 +01:00
//end minimap management
async function executeQueryVersi(query) {
bindingsStream = await myEngine.queryBindings(query, { sources: [{ type: 'sparql', value: sparqlEndpoint },], });
2022-11-06 17:12:56 +01:00
alert(query)
try {
2022-11-11 22:11:22 +01:00
2022-11-06 17:12:56 +01:00
var listaCanti = new Set()
2022-11-11 22:11:22 +01:00
2022-11-06 17:12:56 +01:00
listaVersi = new Set()
2022-11-12 19:45:14 +01:00
listaForme = new Set()
2022-11-08 10:44:20 +01:00
let cantica = 0;
2022-11-06 17:12:56 +01:00
bindingsStream.on('data', (binding) => {
2022-11-11 22:11:22 +01:00
//cantica
cantica = binding.get('Cantica').value;
//la lista dei canti
listaCanti.add(binding.get('Canto').value)
//la lista dei versi
var obj = new Object();
2022-11-12 19:45:14 +01:00
var forma=new Object()
2022-11-11 22:11:22 +01:00
obj.numverso = binding.get('NumeroVerso').value;
obj.verso = binding.get('Verso').value;
obj.canto = binding.get('Canto').value;
2022-11-12 19:45:14 +01:00
//obj.pos = binding.get('pos').value;
//obj.form = binding.get('textform').value;
2022-11-11 22:11:22 +01:00
obj.cantica = cantica;
listaVersi.add(obj)
2022-11-12 19:45:14 +01:00
forma.numverso = binding.get('NumeroVerso').value;
forma.canto = binding.get('Canto').value;
forma.pos = binding.get('pos').value;
forma.form = binding.get('textform').value;
forma.cantica = cantica;
listaForme.add(forma)
2022-11-11 22:11:22 +01:00
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
});
bindingsStream.on('end', () => {
2022-11-11 22:11:22 +01:00
var orderedListaCanti = Array.from(listaCanti)
orderedListaCanti = orderedListaCanti.sort((a, b) => {
if (parseInt(a.split(" ")[1]) < parseInt(b.split(" ")[1])) {
return -1;
}
});
var orderedListaVersi = Array.from(listaVersi)
orderedListaVersi = orderedListaVersi.sort((a, b) => {
if (parseInt(a.numverso) < parseInt(b.numverso)) {
return -1;
}
2022-11-12 19:45:14 +01:00
});
orderedListaVersi = orderedListaVersi.filter((value, index, self) =>
index === self.findIndex((t) => (
t.numverso === value.numverso && t.canto === value.canto && t.cantica===value.cantica
))
)
var orderedListaForme = Array.from(listaForme)
orderedListaForme = orderedListaForme.sort((a, b) => {
if (parseInt(a.pos) < parseInt(b.pos)) {
return -1;
}
2022-11-11 22:11:22 +01:00
});
var divListaCanti = $('<DIV id="Canti' + cantica + '" />')
for (canto of orderedListaCanti) {
var licanto = $('<li class="navig-canto"/>')
licanto.attr('name', cantica + canto)
licanto.attr('href', "#")
licanto.attr("style", "line-height: 1.2em")
2022-11-14 12:29:23 +01:00
numcanto=canto.split(" ")[1]
licanto.append(numcanto)
2022-11-11 22:11:22 +01:00
//licanto.appendTo('#listacanti')
licanto.appendTo(divListaCanti)
var divcanto = $('<div />')
var titolocanto = $('<h1 class="f3 font-weight-lighter titolo-canto" />')
titolocanto.append(canto)
divcanto.attr('class', 'canto')
divcanto.attr('style', 'display:none')
divcanto.attr('id', (cantica + canto).replace(" ", "_"))
titolocanto.appendTo(divcanto)
divcanto.appendTo(' .blog-main')
2022-11-08 10:44:20 +01:00
}
2022-11-11 22:11:22 +01:00
//divListaCanti.appendTo('#listacanti')
divListaCanti.appendTo(ddmenus[cantica])
for (verso of orderedListaVersi) {
var elementoverso = $('<p />')
vartestoverso=verso.numverso;
elementoverso.append(verso.numverso + ". ")
//elementoverso.append(verso.numverso + ". " + managePunctuation(verso.verso))
elementoverso.attr("style", "line-height: 0.5em")
elementoverso.attr('class', 'f6 font-weight-lighter')
elementoverso.attr('id', verso.cantica+"_"+ verso.canto.replace(" ", "_")+"_"+verso.numverso)
elementoverso.appendTo('#' + cantica + verso.canto.replace(" ", "_"))
2022-11-08 10:44:20 +01:00
}
2022-11-12 19:45:14 +01:00
orderedListaForme.forEach((element) => {
var spanoccorrenza=$('<span />')
var pos=parseInt(element.pos)
spanoccorrenza.attr('id', element.cantica+"_"+ element.canto.replace(" ", "_")+"_"+element.numverso+"_"+pos)
spanoccorrenza.append(managePunctuation(element.form))
elementoverso=$('#'+element.cantica+"_"+ element.canto.replace(" ", "_")+"_"+element.numverso)
spanoccorrenza.appendTo(elementoverso)
elementoverso.append('&nbsp;')
})
2022-11-11 22:11:22 +01:00
2022-11-08 10:44:20 +01:00
2022-11-11 22:11:22 +01:00
});
}
catch (err) {
console.log(err.message);
$("#loader").hide();
};
};
//execute query
async function executeQuerySearch(query) {
seachbBindingsStream = await myEngine.queryBindings(query, { sources: [{ type: 'sparql', value: sparqlEndpoint },], });
2022-11-12 19:45:14 +01:00
//console.log(query)
2022-11-11 22:11:22 +01:00
alert(query)
try {
var resultVersi = new Set()
seachbBindingsStream.on('data', (binding) => {
//cantica
cantica = binding.get('Cantica').value;
//canto
canto=binding.get('Canto').value;
//numero del verso
numverso=binding.get('NumeroVerso').value;
2022-11-11 22:26:10 +01:00
//posizione delframmento
pos=binding.get('pos').value;
resultVersi.add(cantica+"_"+canto.replace(" ", "_")+"_"+numverso+"_"+pos)
2022-11-11 22:11:22 +01:00
});
seachbBindingsStream.on('end', () => {
listarisultativersi = Array.from(resultVersi)
for (verso of listarisultativersi){
idverso='#'+verso
2022-11-14 12:29:23 +01:00
//console.log(idverso)
2022-11-12 19:45:14 +01:00
$(idverso).attr('class', "f6 b dark-blue ")
}
if (currentMinimap!=''){
showMinimap(currentMinimap)
2022-11-06 17:12:56 +01:00
}
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
});
}
2022-11-08 10:44:20 +01:00
catch (err) {
console.log(err.message);
$("#loader").hide();
2022-11-06 17:12:56 +01:00
};
};
2022-11-08 10:44:20 +01:00
2022-11-06 17:12:56 +01:00
});