From 15e8377e484667f135a45aa409298b8cc07b4cbb Mon Sep 17 00:00:00 2001 From: cesare Date: Mon, 3 Feb 2025 14:17:23 +0100 Subject: [PATCH] query riferimenti,contesti --- js/dataMgr.js | 78 +++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/js/dataMgr.js b/js/dataMgr.js index f6cea2f..5412310 100644 --- a/js/dataMgr.js +++ b/js/dataMgr.js @@ -175,40 +175,20 @@ export async function queryRiferimenti(filtro, cid) { if (filtro.Testo_Nota != null && filtro.Testo_Nota.trim() != '') queryfi += " and Ann like '%" + filtro.Testo_Nota.trim() + "%'" - if (filtro.contesto!=null){ + if (filtro.contesto != null) { var marray = JSON.parse(filtro.contesto); - console.log(marray[0].every( (val, i, arr) => val === 1 )) - if (marray[0].every( (val, i, arr) => val === 1)){ - queryfi+=" and Cantica='Inferno'" - } - else{ - if (marray[0].some( (val, i, arr) => val === 1)){ - var tearr=marray[0].reduce(function(tearr, n, i) { if (n===1) tearr.push(i); return tearr; },[] ); - for (const ic in tearr){ - var canto=tearr[ic].toString() - if (tearr[ic] <10) - canto='0'+canto - if (ic==0) - queryfi+="and Cantica='Inferno' and (Canto='"+canto+"'" - else - queryfi+=" or Canto='"+canto+"'" - - } - if (tearr.length) - queryfi+=")" - console.log(queryfi) - } - } - // var array = [1, 2, 3, 4, 3].reduce(function(array, n, i) { if (n===3) array.push(i); return array; },[] ); - - if (marray[1].every( (val, i, arr) => val === 1)){ - - queryfi+=" and Cantica='Purgatorio'" - } - if (marray[2].every( (val, i, arr) => val === 1)){ - - queryfi+=" and Cantica='Paradiso'" - } + var oplog=' and ' + var tfi=filtroContesto(marray[0], 'Inferno', oplog) + queryfi+=tfi + if (tfi.trim()!='') + oplog=' or ' + tfi='' + tfi=filtroContesto(marray[1], 'Purgatorio', oplog) + if (tfi!=''){ + queryfi += tfi + oplog=' or ' + } + queryfi += filtroContesto(marray[2], 'Paradiso', oplog) } var rs = await tconn.query(querytl + queryfi) @@ -221,7 +201,7 @@ export async function queryRiferimenti(filtro, cid) { var numcid = cid.split('_')[1] for (var cantica in resxcantica) { var $nctags = $(' .navig-canto') - + console.log(resxcantica[cantica].length) var i = 1; if (cantica == 'Purgatorio') @@ -232,8 +212,8 @@ export async function queryRiferimenti(filtro, cid) { spanbadgecantica.attr('class', 'badge badge-warning badge-pill mx-2'); spanbadgecantica.append(resxcantica[cantica].length) spanbadgecantica.appendTo($('#cantica' + i + '-badge')) - - + + var tmp = resxcantica[cantica] var resxcanto = Object.groupBy(tmp, ({ Canto }) => Canto); for (var canto in resxcanto) { @@ -288,4 +268,28 @@ function opzioniRiferimenti() { }; }); -}; +}; + +function filtroContesto(marray, cantica, op) { + var filtrost = '' + if (marray.every((val, i, arr) => val === 1)) { + return " and Cantica='"+cantica+"'" + } + if (marray.some((val, i, arr) => val === 1)) { + var tearr = marray.reduce(function(tearr, n, i) { if (n === 1) tearr.push(i); return tearr; }, []); + for (const ic in tearr) { + var canto = (tearr[ic]+1).toString() + if ((tearr[ic]+1) < 10) + canto = '0' + canto + if (ic == 0) + filtrost += op+" (Cantica='"+cantica+"' and (Canto='" + canto + "'" + else + filtrost += " or Canto='" + canto + "'" + + } + if (tearr.length) + filtrost += "))" + console.log(filtrost) + } + return filtrost +}