object.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // Raccatto i parametri dall'URL -- mi aspetto un parametro di nome 'link'!
  2. thisUrlParams = {};
  3. window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  4. thisUrlParams[key] = value;
  5. });
  6. console.log('URL get params: ', thisUrlParams);
  7. // Funzioni per eseguire le queries
  8. function prepareQueryURL(query){
  9. sparqlEndpoint = 'http://dev.restore.ovi.cnr.it:8890/sparql/';
  10. sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
  11. return sparqlEndpoint + sparqlUrlParams;
  12. }
  13. function doJsonQuery(query){
  14. queryURL = prepareQueryURL(query);
  15. response = $.ajax({//OGGETTO
  16. url: queryURL,
  17. dataType: "json",
  18. success: function (data){},
  19. error: function (e) {}
  20. });
  21. return response;
  22. }
  23. // Funzioni per raccattare + stringhificare l'output
  24. queryStringOutput = "";
  25. function stringifyResponse(val){
  26. resultArray = val['results']['bindings'];
  27. out = "";
  28. for(i = 0; i < resultArray.length; i++){
  29. out = out + JSON.stringify(resultArray[i])
  30. }
  31. queryStringOutput = (queryStringOutput + out).replace("}{",",");
  32. }
  33. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  34. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  35. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  36. PREFIX owl: <http://www.w3.org/2002/07/owl#> \
  37. PREFIX schema: <http://schema.org/> \
  38. PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
  39. PREFIX person: <http://www.w3.org/ns/person#>"
  40. queryInfo = prefixes + " SELECT DISTINCT ?g AS ?graph ?uri ?label ?dimension ?consistency ?id (group_concat(distinct ?dimension ; separator='<br />') as ?dimensions) ?material ?location ?note \
  41. WHERE { \
  42. VALUES ?uri {<" + thisUrlParams.link + ">} \
  43. GRAPH ?g { ?uri rdfs:label ?label } \
  44. OPTIONAL {?uri crm:P1_is_identified_by ?uri_id . \
  45. ?uri_id rdfs:label ?id ; \
  46. crm:P2_has_type 'Segnatura' .} \
  47. OPTIONAL { ?uri crm:P43_has_dimension ?uri_consistency . \
  48. ?uri_consistency crm:P2_has_type 'Consistenza carte' ; \
  49. rdfs:label ?consistency } \
  50. OPTIONAL { ?uri crm:P43_has_dimension ?uri_dimension . \
  51. ?uri_dimension crm:P2_has_type 'Dimensioni' ; \
  52. rdfs:label ?dimension } \
  53. OPTIONAL { ?uri crm:P45_consist_of ?uri_material . \
  54. ?uri_material rdfs:label ?material } \
  55. OPTIONAL { ?uri crm:P54_has_current_permanent_location ?uri_location . \
  56. ?uri_location rdfs:label ?location } \
  57. OPTIONAL { ?uri crm:P3_has_note ?uri_note . \
  58. ?uri_note rdfs:label ?note } \
  59. } "
  60. queryContent = prefixes + " SELECT DISTINCT ?g AS ?graph ?uri ?titolo ?tipo (group_concat(distinct ?ref ; separator='<br />') as ?ref) \
  61. WHERE { \
  62. VALUES ?object {<" + thisUrlParams.link + ">} \
  63. ?object crm:P128_carries ?uri . \
  64. ?uri rdf:type crm:E73_Information_Object . \
  65. GRAPH ?g { ?uri rdfs:label ?label } \
  66. OPTIONAL {?uri crm:P1_is_identified_by ?uri_titolo . \
  67. ?uri_titolo rdfs:label ?titolo ; \
  68. rdf:type crm:E35_Title . } \
  69. OPTIONAL { ?uri crm:P2_has_type ?uri_tipo . \
  70. ?uri_tipo rdfs:label ?tipo . } \
  71. OPTIONAL { ?uri crm:P67_refers_to ?uri_ref . \
  72. ?uri_ref rdfs:label ?ref . } \
  73. FILTER NOT EXISTS {GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini> { ?uri rdfs:label ?label }}. \
  74. }"
  75. queryOviLetter = prefixes + " SELECT DISTINCT ?otherId ?InfObj \
  76. WHERE { \
  77. VALUES ?uri {<" + thisUrlParams.link + ">} \
  78. ?uri crm:P1_is_identified_by ?uri_id . \
  79. ?uri_id crm:P2_has_type 'Segnatura' ; \
  80. crm:P139_has_alternative_form ?other_id . \
  81. ?other_id crm:P2_has_type ?uri_type ; \
  82. rdfs:label ?otherId . \
  83. ?uri_type rdfs:label 'Segnatura OVI' . \
  84. OPTIONAL { ?uri crm:P128_carries ?InfObj . \
  85. GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini> {?InfObj rdf:type crm:E73_Information_Object } } \
  86. } "
  87. queryURL = prepareQueryURL(queryInfo);
  88. queryINF = prepareQueryURL(queryContent);
  89. queryOVI = prepareQueryURL(queryOviLetter);
  90. response = $.ajax({
  91. url: queryURL,
  92. dataType: "json",
  93. success: function (data){
  94. handle_objectData(data);
  95. },
  96. error: function (e) {}
  97. });
  98. response_info = $.ajax({
  99. url: queryINF,
  100. dataType: "json",
  101. success: function (data){
  102. handle_objectInfo(data);
  103. },
  104. error: function (e) {}
  105. });
  106. response_info = $.ajax({
  107. url: queryOVI,
  108. dataType: "json",
  109. success: function (data){
  110. handle_oviLetter(data);
  111. },
  112. error: function (e) {}
  113. });
  114. function handle_objectData(json) {
  115. console.log(json['results']['bindings']);
  116. $.each(
  117. json['results']['bindings'],
  118. function (index, value) {
  119. var graph = value['graph']['value'];
  120. var label = value['label']['value'];
  121. var uri = value['uri']['value'];
  122. var identifier = "";
  123. var dimensions = "";
  124. var consistence = "";
  125. var materials = "";
  126. var current_location = "";
  127. var description = "";
  128. var button_ext = "";
  129. var dataset = get_graph_name(graph);
  130. if (value.hasOwnProperty('id')) {
  131. $("#ID").css("display", "flex");
  132. identifier = value['id']['value'];
  133. }
  134. if (value.hasOwnProperty('dimension')) {
  135. $("#dimensione").css("display", "flex");
  136. dimensions = value['dimensions']['value'];
  137. }
  138. if (value.hasOwnProperty('consistency')) {
  139. $("#consistenza").css("display", "flex");
  140. consistence = value['consistency']['value'];
  141. }
  142. if (value.hasOwnProperty('condition')) {
  143. $("#STCC").css("display", "flex");
  144. condition = value['condition']['value'];
  145. }
  146. if (value.hasOwnProperty('material')) {
  147. $("#materia").css("display", "flex");
  148. materials = value['material']['value'];
  149. }
  150. if (value.hasOwnProperty('location')) {
  151. $("#localizzazione").css("display", "flex");
  152. current_location = value['location']['value'];
  153. }
  154. if (value.hasOwnProperty('note')) {
  155. $("#notes").css("display", "flex");
  156. description = value['note']['value'];
  157. }
  158. if (identifier != "") {
  159. button_ext = '<button class="btn btn-default" type="button" onclick="schedaASPO(\'' + uri + '\')"> \
  160. <i class="fa fa-link" aria-hidden="true"> <p class="btn-text">Link</p></i></button>';
  161. }
  162. document.getElementById("grafo").innerHTML = dataset;
  163. document.getElementById("nome_oggetto").innerHTML = label;
  164. document.getElementById("identifier").innerHTML = identifier;
  165. document.getElementById("btn_identifier").innerHTML = button_ext;
  166. document.getElementById("location").innerHTML = current_location;
  167. document.getElementById("nota").innerHTML = description;
  168. document.getElementById("dimensions").innerHTML = dimensions;
  169. document.getElementById("consistence").innerHTML = consistence;
  170. document.getElementById("materials").innerHTML = materials;
  171. });
  172. }
  173. function get_graph_name(graph) {
  174. var dataset = "Scheda Oggetto";
  175. if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale") {
  176. dataset = dataset + " / Ospedale";
  177. } else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/datini") {
  178. dataset = dataset + " / Datini";
  179. } else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi") {
  180. dataset = dataset + " / Marcovaldi";
  181. } else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli") {
  182. dataset = dataset + " / Gettatelli";
  183. } else {
  184. dataset = dataset;
  185. }
  186. return dataset;
  187. }
  188. function handle_objectInfo(json) {
  189. console.log(json['results']['bindings']);
  190. $.each(
  191. json['results']['bindings'],
  192. function (index, value) {
  193. var title = "";
  194. var type = "";
  195. var subject = "";
  196. if (value.hasOwnProperty('titolo')) {
  197. $("#titolo").css("display", "flex");
  198. title = value['titolo']['value'];
  199. }
  200. if (value.hasOwnProperty('tipo')) {
  201. $("#tipo").css("display", "flex");
  202. type = value['tipo']['value'];
  203. }
  204. if (value.hasOwnProperty('ref')) {
  205. if (value['ref']['value'] != "") {
  206. $("#argomento").css("display", "flex");
  207. subject = value['ref']['value'];
  208. }
  209. }
  210. document.getElementById("title").innerHTML = title;
  211. document.getElementById("type").innerHTML = type;
  212. document.getElementById("subject").innerHTML = subject;
  213. });
  214. }
  215. function handle_oviLetter(json) {
  216. console.log(json['results']['bindings']);
  217. $.each(
  218. json['results']['bindings'],
  219. function (index, value) {
  220. var other_id = "";
  221. var uri = "";
  222. var button_letter = "";
  223. if (value.hasOwnProperty('otherId')) {
  224. $("#IDbis").css("display", "flex");
  225. other_id = value['otherId']['value'];
  226. }
  227. if (value.hasOwnProperty('InfObj')) {
  228. uri = value['InfObj']['value'];
  229. }
  230. if (uri != "") {
  231. button_letter = '<button type="button" id="' + uri +
  232. '" class="lettera btn btn-default" alt="lettera"><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  233. }
  234. document.getElementById("other_identifier").innerHTML = other_id;
  235. document.getElementById("btn_other_identifier").innerHTML = button_letter;
  236. });
  237. }
  238. $(document).on("click", ".lettera", function (ev) {
  239. var link = this.id;
  240. //alert(nome_autore);
  241. //$('#myModal').text("");
  242. window.open("lettera.html?link="+this.id);
  243. });
  244. $(document).on("click", ".luogo", function (ev) {
  245. var link = this.id;
  246. //alert(nome_autore);
  247. //$('#myModal').text("");
  248. window.open("Luogo.html?link="+this.id);
  249. });
  250. $(document).on("click", ".persona", function (ev) {
  251. var link = this.id;
  252. //alert(nome_autore);
  253. //$('#myModal').text("");
  254. window.open("Persona.html?link="+this.id);
  255. });
  256. function schedaASPO(info){
  257. window.open(info);
  258. }