method.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. $(document).ready(function () {
  2. //#######################################
  3. const graphArray = [
  4. ["ASPO - Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/datini"],
  5. ["ASPO - Ospedale", "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale"],
  6. ["ASPO - Marcovaldi", "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi"],
  7. ["ASPO - Gettatelli", "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli"],
  8. ["ASPO - Autori ASPO", "http://dev.restore.ovi.cnr.it:8890/aspo/actors"],
  9. ["MPP - Collezione Martini", "http://dev.restore.ovi.cnr.it:8890/mpp/martini"],
  10. ["MPP - Collezione Ospedale", "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale"],
  11. ["MPP - Collezione Datini", "http://dev.restore.ovi.cnr.it:8890/mpp/datini"],
  12. ["MPP - Autori MPP", "http://dev.restore.ovi.cnr.it:8890/mpp/authors"],
  13. ["OVI - Lettere", "http://dev.restore.ovi.cnr.it:8890/ovi/datini"],
  14. ["Luoghi", "http://dev.restore.ovi.cnr.it:8890/mpp/places"]
  15. ];
  16. var graph_selector = document.getElementById("graph_selector");
  17. let x = graphArray.length;
  18. for(var i=0; i<x; i++) {
  19. var opt = document.createElement("option");
  20. opt.value= graphArray[i][1];
  21. opt.innerHTML = graphArray[i][0]; // whatever property it has
  22. // then append it to the select element
  23. graph_selector.add(opt);
  24. }
  25. const entityArray = [
  26. ["Oggetti fisici", "http://www.cidoc-crm.org/cidoc-crm/E22_Man-Made_Object"],
  27. ["Contenuti Informativi", "http://www.cidoc-crm.org/cidoc-crm/E73_Information_Object"],
  28. ["Titoli", "http://www.cidoc-crm.org/cidoc-crm/E35_Title"],
  29. ["Persone", "http://www.cidoc-crm.org/cidoc-crm/E21_Person"]
  30. ];
  31. var entity_selector = document.getElementById("entity_selector");
  32. let y = entityArray.length;
  33. for(var i=0; i<y; i++) {
  34. var opt = document.createElement("option");
  35. opt.value= entityArray[i][1];
  36. opt.innerHTML = entityArray[i][0]; // whatever property it has
  37. // then append it to the select element
  38. entity_selector.add(opt);
  39. }
  40. var search_name = "";
  41. var testo = "";
  42. function autori_retrieveData() {
  43. search_name = testo;
  44. var g = document.getElementById("graph_selector");
  45. var graph = g.value;
  46. var search_graph = "";
  47. if (graph != "") {
  48. search_graph = '<' + graph + '>';
  49. } else {
  50. search_graph = '?g';
  51. }
  52. var e = document.getElementById("entity_selector");
  53. var entity = e.value;
  54. var search_entity = "";
  55. if (entity != "") {
  56. search_entity = '<' + entity + '>';
  57. } else {
  58. search_entity = '?type';
  59. }
  60. //var query='SELECT DISTINCT ?nome WHERE { ?autore <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.cidoc-crm.org/cidoc-crm/E39_Actor> . ?autore <http://www.cidoc-crm.org/cidoc-crm/P1_is_identified_by> ?nomeid. ?nomeid <http://www.w3.org/2000/01/rdf-schema#label> ?nome . FILTER regex(?nome, "'+ search_name +'") }' ;
  61. query = 'SELECT DISTINCT '+ search_graph +' AS ?graph ?link ?label ?entity ?object ?objLab WHERE { GRAPH '+ search_graph +' { ?link <http://www.w3.org/2000/01/rdf-schema#label> ?label ; <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> '+ search_entity +' . ?label bif:contains "\'' + search_name + '\'" .} '+ search_entity +' <http://www.w3.org/2000/01/rdf-schema#label> ?entity . FILTER (langMatches( lang(?entity), "en" )) OPTIONAL {?link <http://www.cidoc-crm.org/cidoc-crm/P2_has_type> ?object } OPTIONAL {?link <http://www.cidoc-crm.org/cidoc-crm/P2_has_type> ?link_object . ?link_object <http://www.w3.org/2000/01/rdf-schema#label> ?objLab }} limit 100';
  62. //query = 'select distinct ?nome ?link where {?link <http://www.w3.org/2000/01/rdf-schema#label> ?nome . ?nome bif:contains "'+ search_name +'"}'
  63. //query = 'select distinct ?nome where {?nome <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.cidoc-crm.org/cidoc-crm/E39_Actor> FILTER regex(?nome, "'+ search_name +'")}';
  64. var autori_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json';
  65. $.ajax({
  66. url: autori_url + '&callback=?',
  67. dataType: "json",
  68. success: function (data) {
  69. autori_handle_json(data);
  70. },
  71. error: function (e) {}
  72. });
  73. }
  74. function autori_handle_json(json) {
  75. console.log(json);
  76. $('#wb_Shape1').text("");
  77. $('#wb_Image1').text("");
  78. var i = 0;
  79. $.each(
  80. json['results']['bindings'],
  81. function (index, value) {
  82. var autore = ""; /*Inserisci VALUE TIPOLOGIA*/
  83. var tipo = "";
  84. var button_type = "";
  85. if (value.hasOwnProperty('object')) {
  86. if (value['object']['type'] == "literal") {
  87. tipo = value['object']['value'];
  88. }
  89. }
  90. if (value.hasOwnProperty('objLab')) {
  91. if (value['objLab']['type'] == "literal") {
  92. tipo = value['objLab']['value'];
  93. }
  94. }
  95. if (tipo == "lettera" || tipo == "Testo annotato OVI") {
  96. button_type += '<td><button type="button" id="' + value['link']['value'] + '" class="lettera btn btn-default" alt="lettera" title="' + value['label']['value'] + '"><i class="fa fa-info"></i><p class="btn-text">Info</p></button></td>';
  97. }
  98. autore += /*INIZIO DIV*/ '<tr><td style="width: 70%;">' /*DA QUA AUTORE ->*/ +
  99. '<div style="width:100%; height:auto; border:transparent;">' + value['graph']['value'] + '<br /><a href="' + value['link']['value'] + '" target="_blank">' + value['label']['value'] + '</a>' + '<br />' + value['entity']['value'] + '</td>' +
  100. button_type +
  101. /*DA QUI SCHEDA ->*/'<td><button type="button" id="' + value['link']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button>' + '</td><td>' +
  102. /*DA QUI CITAZIONE ->*/'<button type="button" id="' + value['link']['value'] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' + '</td><td>' +
  103. /*DA QUI HYPERLINK ->*/'<button type="button" id="' + value['link']['value'] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' + '</td><td>' +
  104. /*DA QUI LOD ->*/'<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['link']['value'] + '" target="_blank"><button type="button" id="lod ' + value['link']['value'] + '"class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></td>'
  105. + '</tr>';/*FINE DIV*/
  106. i++;
  107. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  108. $('#wb_Shape1').append(autore);
  109. });
  110. if (i==0) {
  111. var message = '<tr id="error"><td><p>Questa ricerca non ha prodotto risultati</p></td></tr>';
  112. $('#wb_Shape1').append(message);
  113. }
  114. }
  115. $('#ClipArt1').click(function () {
  116. testo = $('input#TextArea1').val();
  117. autori_retrieveData();
  118. search_name = "";
  119. });
  120. $('input#TextArea1').keypress(function(e) {
  121. var key = e.which;
  122. if (key == 13) // the enter key code
  123. {
  124. $('#ClipArt1').click();
  125. return false;
  126. }
  127. });
  128. //onlick hyperlink button
  129. $(document).on("click", ".hyp", function (ev) {
  130. var link = this.id;
  131. //alert(nome_autore);
  132. //$('#myModal').text("");
  133. $("#myModal").empty();
  134. $("#myModal").css("display", "block");
  135. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  136. link + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  137. });
  138. $(document).on("click", ".lettera", function (ev) {
  139. var link = this.id;
  140. //alert(nome_autore);
  141. //$('#myModal').text("");
  142. window.open("lettera.html?link="+this.id);
  143. });
  144. $(document).on("click", ".close", function (ev) {
  145. var link = this.id;
  146. //alert(nome_autore);
  147. //$('#myModal').text("");
  148. $("#myModal").css("display", "none");
  149. });
  150. $(document).on("click", ".back", function (ev) {
  151. $("#myTab").css("display", "none");
  152. });
  153. $(document).on("click", ".cit", function (ev) {
  154. var author ="RESTORE. smart access to digital heritage and memory"
  155. var year = new Date().getFullYear()
  156. var today = new Date();
  157. var dd = String(today.getDate()).padStart(2, '0');
  158. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  159. var yyyy = today.getFullYear();
  160. today = dd + '/' + mm + '/' + yyyy;
  161. var link = this.id;
  162. //alert(nome_autore);
  163. //$('#myModal').text("");
  164. $("#myModal").empty();
  165. $("#myModal").css("display", "block");
  166. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  167. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + link + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  168. });
  169. $(document).on("click", ".scheda", function (ev) {
  170. var link = this.id;
  171. var title = this.title;
  172. //alert(nome_autore);
  173. $("#myTab").empty();
  174. $("#myTab").css("display", "block");
  175. $('#myTab').append("<div class='tab-content'><span class='back'>&lt; Indietro</span><br /><h2><a href='" + link + "' target='_blank'>" + title + "</a></h2><div id='tab_container'><h3>Relazioni dirette</h3><br /><table id='info_link' class='table table-hover'></table><br /><table id='info_ico' class='table table-hover'></table><br /><h3>Relazioni inverse</h3><br /><table id='info_obj' class='table table-hover'></table></div></div>");
  176. /*var query_a = 'SELECT DISTINCT ?label WHERE { {<' + link +
  177. '> ?p ?object. OPTIONAL {?object ?property ?label . FILTER(?property = <http://www.w3.org/2004/02/skos/core#prefLabel> || ?property = <http://www.w3.org/2000/01/rdf-schema#label>) FILTER (langMatches( lang(?label), "en" )) } } UNION {<'+ link +
  178. '> ?p ?object. OPTIONAL {?p <http://www.w3.org/2000/01/rdf-schema#label> ?propertyLabel .?object <http://www.w3.org/2000/01/rdf-schema#label> ?label } FILTER (?p != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>) FILTER (langMatches( lang(?propertyLabel), "en" )) }}';
  179. */
  180. var query_a = 'SELECT DISTINCT ?propLab ?object ?label WHERE {{<' + link +
  181. '> ?property ?object. ?property <http://www.w3.org/2000/01/rdf-schema#label> ?propLab . OPTIONAL {?object <http://www.w3.org/2000/01/rdf-schema#label> ?label . } FILTER (?property != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> && ?property != <http://www.cidoc-crm.org/cidoc-crm/P62_depicts>) FILTER (langMatches( lang(?propLab), "en" ))} UNION {<' + link +
  182. '> ?property ?object. ?property <http://www.w3.org/2000/01/rdf-schema#label> ?propLab . OPTIONAL {?object <http://www.w3.org/2000/01/rdf-schema#label> ?label . } FILTER (?property != <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> && ?property != <http://www.w3.org/2000/01/rdf-schema#label>) FILTER(!regex(?property, "cidoc"))}}';
  183. var object_url_a = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_a) + '&output=json';
  184. var query_b = 'SELECT DISTINCT ?subject ?label ?property ?propertyLabel WHERE {?subject ?property <' + link +
  185. '> ; <http://www.w3.org/2000/01/rdf-schema#label> ?label . ?property <http://www.w3.org/2000/01/rdf-schema#label> ?propertyLabel . FILTER (langMatches( lang(?propertyLabel), "en" ))}';
  186. var object_url_b = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_b) + '&output=json';
  187. var query_c = 'SELECT DISTINCT ?object ?label WHERE {{<' + link + '> <http://www.cidoc-crm.org/cidoc-crm/P62_depicts> ?object . ?object <http://www.w3.org/2000/01/rdf-schema#label> ?label .} UNION {<' + link +
  188. '> <http://www.cidoc-crm.org/cidoc-crm/P62_depicts> ?object . ?object <http://www.w3.org/2004/02/skos/core#prefLabel> ?label . FILTER (langMatches(lang(?label), "it" )) }}';
  189. var object_url_c = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query_c) + '&output=json';
  190. $.ajax({//SOGGETTO
  191. url: object_url_a + '&callback=?',
  192. dataType: "json",
  193. success: function (data_a) {
  194. object_info_a(data_a);
  195. },
  196. error: function (e) {}
  197. });
  198. $.ajax({//OGGETTO
  199. url: object_url_b + '&callback=?',
  200. dataType: "json",
  201. success: function (data_b) {
  202. object_info_b(data_b);
  203. },
  204. error: function (e) {}
  205. });
  206. $.ajax({//ICONCLASS
  207. url: object_url_c + '&callback=?',
  208. dataType: "json",
  209. success: function (data_c) {
  210. object_info_c(data_c);
  211. },
  212. error: function (e) {}
  213. });
  214. });
  215. function object_info_a(json) {
  216. console.log(json);
  217. var j = 0;
  218. $('#info_link').text("");
  219. $.each(
  220. json['results']['bindings'],
  221. function (index, value) {
  222. var autore_a = "";
  223. var object = "";
  224. var object_type = value['object']['type'];
  225. if (object_type == "typed-literal" || object_type == "literal"){
  226. object = '<td>'+ value['object']['value'] + '</td>';
  227. }
  228. else{
  229. object = '<td style="width:60%;"><a href="'+ value['object']['value'] +'" target="_blank">'+ value['label']['value'] +'</a></td><td>' +
  230. '<button type="button" id="' + value['object']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button></td><td>' +
  231. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['object']['value'] + '" target="_blank"><button type="button" id="lod " class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></td>';
  232. }
  233. autore_a += /*INIZIO DIV*/ '<tr><td style="width:25%;">' + value['propLab']['value'] + '</td>' + object + '</tr>';/*FINE DIV*/
  234. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  235. j++;
  236. $('#info_link').append(autore_a);
  237. });
  238. if (j==0) {
  239. var message_a = '<tr id="error"><td><p>Non sono presenti relazioni dirette per questa risorsa</p></td></tr>';
  240. $('#info_link').append(message_a);
  241. }
  242. }
  243. function object_info_b(json) {
  244. console.log(json);
  245. var k = 0;
  246. $('#info_obj').text("");
  247. $.each(
  248. json['results']['bindings'],
  249. function (index, value) {
  250. var autore_b = "";
  251. autore_b += /*INIZIO DIV*/ '<tr><td style="width:60%;"><a href="' + value['subject']['value'] + '" target="_blank">' + value['label']['value'] + '</a></td><td style="width:25%;">' + value['propertyLabel']['value'] + '</td><td>' +
  252. '<button type="button" id="' + value['subject']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button></td><td>' +
  253. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['subject']['value'] + '" target="_blank"><button type="button" id="lod " class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></td></tr>';
  254. /*FINE DIV*/
  255. k++;
  256. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  257. $('#info_obj').append(autore_b);
  258. });
  259. if (k==0) {
  260. var message_b = '<tr id="error"><td><p>Non sono presenti relazioni inverse per questa risorsa</p></td></tr>';
  261. $('#info_obj').append(message_b);
  262. }
  263. }
  264. function object_info_c(json) {
  265. console.log(json);
  266. $('#info_ico').text("");
  267. $.each(
  268. json['results']['bindings'],
  269. function (index, value) {
  270. var autore_c = "";
  271. autore_c += /*INIZIO DIV*/ '<tr><td style="width:25%;">depicts</td><td style="width:60%;"><a href="' + value['object']['value'] + '">' + value['label']['value'] + '</a></td><td>' +
  272. '<button type="button" id="' + value['object']['value'] + '" class="scheda btn btn-default" alt="scheda" title="' + value['label']['value'] + '"><i class="fa fa-bars"></i><p class="btn-text">Scheda</p></button></td><td>' +
  273. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + value['object']['value'] + '" target="_blank"><button type="button" id="lod " class="btn btn-default info" alt="scheda" title="Info"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></td></tr>';
  274. /*FINE DIV*/
  275. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  276. $('#info_ico').append(autore_c);
  277. });
  278. }
  279. //VISUALIZZAZIONI DATI DELL'AUTORE
  280. //FUNZIONE LETTURA LUNGHEZZA FILE JSON
  281. /*
  282. function objLength(obj){
  283. var i=0;
  284. for (var x in obj){
  285. if(obj.hasOwnProperty(x)){
  286. i++;
  287. }
  288. }
  289. return i;
  290. }
  291. */
  292. //#######################################
  293. });
  294. function copyToClipboard(text) {
  295. var sampleTextarea = document.createElement("textarea");
  296. document.body.appendChild(sampleTextarea);
  297. sampleTextarea.value = text; //save main text in it
  298. sampleTextarea.select(); //select textarea contenrs
  299. document.execCommand("copy");
  300. document.body.removeChild(sampleTextarea);
  301. }
  302. function myFunction(){
  303. var copy = document.getElementById("myInput");
  304. copyText = copy.textContent;
  305. copyToClipboard(copyText);
  306. //copyToClipboard(copyText.value);
  307. }