results.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. function handle_Letters(json, mittente, destinatario){
  2. thead = '<div class="row def_res"> \
  3. <div class="col-4">Documento</div> \
  4. <div class="col-2">Data di partenza</div> \
  5. <div class="col-2">Data di arrivo</div> \
  6. <div class="col-2">Luogo di partenza</div> \
  7. <div class="col-2">Luogo di arrivo</div> \
  8. </div>';
  9. var EventsTable = thead;
  10. $.each(
  11. json['results']['bindings'],
  12. function (index, value) {
  13. var uri_document = "";
  14. var doc = "";
  15. var time_span_from = "";
  16. var time_span_to = "";
  17. var uri_place_from = "";
  18. var place_from = "";
  19. var uri_place_to = "";
  20. var place_to = "";
  21. if(value.hasOwnProperty('uri_document')) {
  22. uri_document = value['uri_document']['value'];
  23. }
  24. if(value.hasOwnProperty('document')) {
  25. doc = value['document']['value'];
  26. }
  27. if(value.hasOwnProperty('time_span_from')) {
  28. time_span_from = value['time_span_from']['value'];
  29. }
  30. if(value.hasOwnProperty('time_span_to')) {
  31. time_span_to = value['time_span_to']['value'];
  32. }
  33. if(value.hasOwnProperty('uri_place_from')) {
  34. uri_place_from = value['uri_place_from']['value'];
  35. }
  36. if(value.hasOwnProperty('place_from')) {
  37. place_from = value['place_from']['value'];
  38. }
  39. if(value.hasOwnProperty('uri_place_to')) {
  40. uri_place_to = value['uri_place_to']['value'];
  41. }
  42. if(value.hasOwnProperty('place_to')) {
  43. place_to = value['place_to']['value'];
  44. }
  45. EventsTable += '<div class="row res">' +
  46. '<div id="' + uri_document + '" class="col-4 object">' + doc + '</div>' +
  47. '<div class="col-2">' + time_span_from + '</div>' +
  48. '<div class="col-2">' + time_span_to + '</div>' +
  49. '<div id="' + uri_place_from + '" class="col-2 luogo">' + place_from + '</div>' +
  50. '<div id="' + uri_place_to + '" class="col-2 luogo">' + place_to + '</div>' +
  51. '</div>';
  52. });
  53. document.getElementById("results_table").innerHTML = EventsTable;
  54. document.getElementById("results_title").innerHTML = "Lettere da " + mittente + " a " + destinatario;
  55. }
  56. function handleLemma(json, lemma) {
  57. let anni = [];
  58. thead = '<div class="row def_res"> \
  59. <div class="col-10">Documento</div> \
  60. <div class="col-2">Esplora</div> \
  61. </div>';
  62. var DocumentsTable = thead;
  63. var i = 0;
  64. var anno = "";
  65. $.each(
  66. json['results']['bindings'],
  67. function (index, value) {
  68. var document = value['document']['value'];
  69. var uri_document = value['uri_document']['value'];
  70. var uri_info = "";
  71. var type = "";
  72. var date = "";
  73. var year = "";
  74. var month = "";
  75. var day = "";
  76. var sigla = "";
  77. var text = "Nessun testo trovato";
  78. var object_button = "";
  79. if(value.hasOwnProperty('uri_infObj')) {
  80. uri_info = value['uri_infObj']['value'];
  81. }
  82. if(value.hasOwnProperty('types')) {
  83. type = value['types']['value'];
  84. }
  85. if(value.hasOwnProperty('time_span')) {
  86. date = value['time_span']['value'];
  87. }
  88. if(value.hasOwnProperty('year')) {
  89. year = value['year']['value'];
  90. }
  91. if(value.hasOwnProperty('month')) {
  92. month = value['month']['value'];
  93. }
  94. if(value.hasOwnProperty('day')) {
  95. day = value['day']['value'];
  96. }
  97. if(value.hasOwnProperty('text')) {
  98. text = value['text']['value'];
  99. }
  100. if(value.hasOwnProperty('sigla')) {
  101. sigla = value['sigla']['value'];
  102. }
  103. if (type.includes("lettera")) {
  104. object_button = '<button type="button" id="' + uri_info +
  105. '" class="lettera btn btn-default" alt="opera d\'arte" title="' + document +
  106. '"><i class="fa fa-envelope"></i><p class="btn-text">Lettera</p></button>';
  107. } else {
  108. object_button = '<button type="button" id="' + uri_document +
  109. '" class="object btn btn-default" alt="oggetto" title="' + document +
  110. '"><i class="fa fa-book"></i><p class="btn-text">Bene Culturale</p></button>';
  111. }
  112. DocumentsTable += '<div class="row res">' +
  113. '<div id="' + uri_document + '" class="col-10 object">' + document + '</div>' +
  114. '<div class="col-2">' + object_button + '</div>' +
  115. '</div>';
  116. var aaaa = "";
  117. if (anno != year) {
  118. anno = year;
  119. aaaa = year;
  120. createYearPoint(aaaa);
  121. }
  122. anni.push(year);
  123. querySigla = prefixes + (queryManager['queryRES']['queryTrovaSigla']).replace('<{SIGLA}>', sigla).replace('<{LEMMA}>', lemma);
  124. doJsonQuery(querySigla).done(function(r) { manageTimeline(r, date, aaaa, month, day, document, uri_document, text); });
  125. let element = [date, year, month, day, document, uri_document, text, uri_info];
  126. createTimelineNode(element);
  127. i++;
  128. });
  129. let uniqueyears = [...new Set(anni)];
  130. var AnniList = "<h3>Anni</h3><ul>";
  131. for (var i=0; i<uniqueyears.length; i++) {
  132. if (uniqueyears[i] != "") {
  133. AnniList += "<li><button class='btn btn-default anno' id=\""+ uniqueyears[i] + "\">" + uniqueyears[i] + "</button></li>";
  134. }
  135. }
  136. AnniList += "</ul>";
  137. document.getElementById("lemma_buttons").style.display = "flex";
  138. document.getElementById("anni").innerHTML = AnniList;
  139. document.getElementById("results_table").innerHTML = DocumentsTable;
  140. document.getElementById("results_title").innerHTML = titleCase(lemma);
  141. }
  142. function manageTimeline(json, date, year, month, day, document, uri_document, text) {
  143. num = "";
  144. $.each(
  145. json['results']['bindings'],
  146. function (index, value) {
  147. if(value.hasOwnProperty('id')) {
  148. num = value['id']['value'];
  149. }
  150. });
  151. var testo = text;
  152. /*if (num != "") {
  153. var toReplace = "n='" + num + "'";
  154. var toSearch = "<lem n='numero'\.* />[a-z]+";
  155. testo = text.replaceAll(toReplace, "class='highlight'");
  156. let rr = toSearch.replace("numero", num)
  157. let rer = new RegExp(rr);
  158. var pos = text.search(rer);
  159. var searchedString = text.match(rer);
  160. const regex = new RegExp(/<lem n=${testVar}.*>/);
  161. text.replace(regex, num);
  162. let regE = new RegExp("[0-9]+[]a$|[0-9]+[]" , 'g')
  163. var result = String("la tua stringa").match(regE );
  164. var ss = pos-150;
  165. var ee = pos+150;
  166. var start = 0;
  167. var end = ee;
  168. if (ss<0) {
  169. start = 0;
  170. } else {
  171. start = ss;
  172. }
  173. testo = text.substring(start, end)
  174. console.log([start, end, testo]);
  175. } else {
  176. testo = text;
  177. }*/
  178. }
  179. function createTimelineNode(array) {
  180. var data = array[0];
  181. var anno = array[1];
  182. var mese = array[2];
  183. var giorno = array[3];
  184. var titolo = array[4];
  185. var testo = array[6];
  186. var link = array[5];
  187. var infObj = array[7]
  188. var TimelineNode = '<li>' +
  189. '<div class="timeline-time">' +
  190. '<span class="time">'+ data +'</span>' +
  191. '</div>' +
  192. '<div class="timeline-icon">' +
  193. '<a href="javascript:;">&nbsp;</a>' +
  194. '</div>' +
  195. '<div class="timeline-body">' +
  196. '<div class="timeline-header">' +
  197. '<span id="' + infObj + '" class="lettera username">' + titolo + '</span>' +
  198. '</div>' +
  199. '<div class="timeline-content">' +
  200. '<p>' + testo + '</p>' +
  201. '</div>' +
  202. '</div></li>';
  203. document.getElementById("docTimeline").innerHTML += TimelineNode;
  204. }
  205. function createYearPoint(anno) {
  206. var TimelineNode = '<li>' +
  207. '<div class="timeline-icon">' +
  208. '<span id="anno_' + anno + '">' + anno + '</span>' +
  209. '</div></li>';
  210. document.getElementById("docTimeline").innerHTML += TimelineNode;
  211. }
  212. function handle_map(json) {
  213. console.log(json);
  214. const locations = [];
  215. const place_names = [];
  216. var lat = 0;
  217. var long = 0;
  218. var i=0;
  219. var myPlaces = "";
  220. $.each(
  221. json['results']['bindings'],
  222. function (index, value) {
  223. const loc = []
  224. var uri = value['place']['value'];
  225. var label = value['label']['value'];
  226. var coord = value['coordinates']['value'];
  227. const coordinates = coord.split(", ");
  228. loc.push(label);
  229. //myPlaces += "<div class='row'><div class='clickPlace col-10' data-point='"+ coordinates + "'>" + label + "</div><div class='luogo col' id='" +
  230. //uri + "'><i class='far fa-map' style='cursor:pointer'></i></div></div>";
  231. loc.push(coordinates[0]);
  232. lat += parseInt(coordinates[0]);
  233. loc.push(coordinates[1]);
  234. long += parseInt(coordinates[1].replace(/^(\.)/,"0.").replace("-.", "-0."));
  235. locations.push(loc);
  236. i++;
  237. });
  238. console.log(locations);
  239. var latitude = lat/i;
  240. var longitude = long/i;
  241. //document.getElementById("list_places_person").innerHTML = myPlaces;
  242. var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
  243. cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade, Points &copy 2012 LINZ',
  244. cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 17, attribution: cloudmadeAttribution}),
  245. latlng = new L.LatLng(latitude, longitude);
  246. var map = new L.Map('map', {center: latlng, zoom: 5, layers: [cloudmade]});
  247. mapLink = '<a href="https://openstreetmap.org">OpenStreetMap</a>';
  248. var markers = new L.MarkerClusterGroup();
  249. var markerList = [];
  250. var geo = new L.tileLayer(
  251. 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  252. attribution: '&copy; ' + mapLink + ' Contributors',
  253. maxZoom: 18,
  254. }).addTo(map);
  255. function populate() {
  256. for (var i = 0; i < locations.length; i++) {
  257. var a = locations[i];
  258. var title = a[0];
  259. var marker = new L.Marker(new L.LatLng(a[1], a[2]), { title: title });
  260. marker.bindPopup(title);
  261. markers.addLayer(marker);
  262. markerList.push(marker);
  263. }
  264. }
  265. populate();
  266. map.addLayer(markers);
  267. $('.clickPlace').on('click', function(){
  268. // parse lat and lng from the divs data attribute
  269. var latlng = $(this).data().point.split(',');
  270. var lat = latlng[0];
  271. var lng = latlng[1];
  272. var zoom = 10;
  273. // set the view
  274. map.setView([lat, lng], zoom);
  275. });
  276. }
  277. // Mini-utility per formattare liste
  278. function formatListAsLi(thisList){
  279. toRet = "";
  280. thisList.forEach(value => toRet += "<li>" + value + "</li>");
  281. return toRet;
  282. }
  283. // Buttons
  284. function createButton(buttonClass, text, onClickFunction){
  285. htmlCode = '\
  286. <button class="btn btn-default" type="button" onclick="<FUNCTION>">\
  287. <i class="<CLASS>" aria-hidden="true">\
  288. <p class="btn-text"><TEXT></p>\
  289. </i>\
  290. </button>\
  291. '.replace("<CLASS>", buttonClass).replace("<TEXT>", text).replace("<FUNCTION>", onClickFunction);
  292. return htmlCode;
  293. }
  294. function createButtonEVT(sigla){
  295. htmlCode = '\
  296. <button type="button" class="btn btn-secondary" onclick="loadPageEVT(\'<SIGLA>\')">\
  297. Button EVT</button>\
  298. '.replace("<SIGLA>", sigla);
  299. return htmlCode;
  300. }
  301. //<button type="button" class="btn btn-secondary" onclick="loadPageLOD()">Button LOD</button>
  302. function loadPageEVT(sigla)
  303. {
  304. window.location="http://restore.ovi.cnr.it/mockup/evt/#/imageText?p=" + sigla + "_01&el=diplomatic";
  305. }
  306. function createEmbed(link) {
  307. image = link.replace("scheda", "imageView") + "/#main";
  308. htmlCode = '\
  309. <embed id="imageEmb" src="<LINK>"> \
  310. '.replace("<LINK", image);
  311. return htmlCode;
  312. }
  313. function schedaPersona(info){
  314. window.open("Persona.html?link="+info);
  315. }
  316. function schedaMappa(info){
  317. window.open("Luogo.html?link="+info);
  318. }
  319. function schedaASPO(info){
  320. window.open(info);
  321. }
  322. function schedaEdizione(info){
  323. $("#myModal").empty();
  324. $("#myModal").css("display", "block");
  325. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  326. info + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  327. }
  328. function show_OVI(){
  329. document.getElementById("OVI_info").style.display = "block";
  330. document.getElementById("ASPO_info").style.display = "none";
  331. }
  332. function show_ASPO(){
  333. document.getElementById("OVI_info").style.display = "none";
  334. document.getElementById("ASPO_info").style.display = "block";
  335. }
  336. $(document).on("click", ".close", function (ev) {
  337. var link = this.id;
  338. //alert(nome_autore);
  339. //$('#myModal').text("");
  340. $("#myModal").css("display", "none");
  341. });
  342. $(document).on("click", ".hyp", function (ev) {
  343. var baseurl = window.location.origin+window.location.pathname;
  344. let slash = baseurl.lastIndexOf("/");
  345. var type = $(this).val() + '.html';
  346. var link = this.id;
  347. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  348. var link = this.id;
  349. $("#myModal").empty();
  350. $("#myModal").css("display", "block");
  351. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  352. url + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  353. });
  354. $(document).on("click", ".cit", function (ev) {
  355. var author ="RESTORE. smart access to digital heritage and memory"
  356. var year = new Date().getFullYear()
  357. var today = new Date();
  358. var dd = String(today.getDate()).padStart(2, '0');
  359. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  360. var yyyy = today.getFullYear();
  361. today = dd + '/' + mm + '/' + yyyy;
  362. var baseurl = window.location.origin+window.location.pathname;
  363. let slash = baseurl.lastIndexOf("/");
  364. var type = $(this).val() + '.html';
  365. var link = this.id;
  366. var url = baseurl.substr(0, slash+1) + type + "?link="+link;
  367. //alert(nome_autore);
  368. //$('#myModal').text("");
  369. $("#myModal").empty();
  370. $("#myModal").css("display", "block");
  371. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  372. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + url + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  373. });
  374. function copyToClipboard(text) {
  375. var sampleTextarea = document.createElement("textarea");
  376. document.body.appendChild(sampleTextarea);
  377. sampleTextarea.value = text; //save main text in it
  378. sampleTextarea.select(); //select textarea contenrs
  379. document.execCommand("copy");
  380. document.body.removeChild(sampleTextarea);
  381. }
  382. function myFunction(){
  383. var copy = document.getElementById("myInput");
  384. copyText = copy.textContent;
  385. copyToClipboard(copyText);
  386. //copyToClipboard(copyText.value);
  387. }
  388. $(document).on("click", ".luogo", function (ev) {
  389. var link = this.id;
  390. //alert(nome_autore);
  391. //$('#myModal').text("");
  392. window.open("Luogo.html?link="+this.id);
  393. });
  394. $(document).on("click", ".persona", function (ev) {
  395. var link = this.id;
  396. window.open("Persona.html?link="+this.id);
  397. });
  398. $(document).on("click", ".lettera", function (ev) {
  399. var link = this.id;
  400. //alert(nome_autore);
  401. //$('#myModal').text("");
  402. window.open("lettera.html?link="+this.id);
  403. });
  404. $(document).on("click", ".object", function (ev) {
  405. var link = this.id;
  406. //alert(nome_autore);
  407. //$('#myModal').text("");
  408. window.open("object.html?link="+this.id);
  409. });
  410. function scrollPos(point) {
  411. alert("helo");
  412. var div = document.getElementById(point).scrollTop;
  413. document.getElementById("pos").innerHTML = div;
  414. }
  415. $(document).on("click", ".anno", function (ev) {
  416. var link = this.id;
  417. var point = "#anno_" + link;
  418. $('html, body').animate({
  419. scrollTop: $(point).offset().top
  420. }, 2000);
  421. });
  422. function titleCase(str) {
  423. var splitStr = str.toLowerCase().split(' ');
  424. for (var i = 0; i < splitStr.length; i++) {
  425. // You do not need to check if i is larger than splitStr length, as your for does that for you
  426. // Assign it back to the array
  427. splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
  428. }
  429. // Directly return the joined string
  430. return splitStr.join(' ');
  431. }
  432. function show_list(){
  433. document.getElementById("res_container").style.display = "block";
  434. document.getElementById("lemmiMappa").style.display = "none";
  435. document.getElementById("lemmiTimeline").style.display = "none";
  436. }
  437. function show_timeline(){
  438. document.getElementById("res_container").style.display = "none";
  439. document.getElementById("lemmiMappa").style.display = "none";
  440. document.getElementById("lemmiTimeline").style.display = "block";
  441. }
  442. function show_map(){
  443. document.getElementById("res_container").style.display = "none";
  444. document.getElementById("lemmiMappa").style.display = "block";
  445. document.getElementById("lemmiTimeline").style.display = "none";
  446. }