object.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. var link = thisUrlParams.link;
  2. prefixes = queryManager['prefixes']['all'];
  3. queryURL = prefixes + (queryManager['querySchedaOggetto']['queryInfo']).replace('{URI}', link);
  4. console.log(queryURL);
  5. doJsonQuery(queryURL).done(function(data) { handle_objectData(data); });
  6. queryINF = prefixes + (queryManager['querySchedaOggetto']['queryContent']).replace('{URI}', link);
  7. doJsonQuery(queryINF).done(function(data) { handle_objectInfo(data); });
  8. queryGT = prefixes + (queryManager['querySchedaOggetto']['queryContrassegni']).replace('{URI}', link);
  9. doJsonQuery(queryGT).done(function(data) { handle_contrassegni(data); });
  10. queryOVI = prefixes + (queryManager['querySchedaOggetto']['queryOviLetter']).replace('{URI}', link);
  11. doJsonQuery(queryOVI).done(function(data) { handle_oviLetter(data); });
  12. queryPERS = prefixes + (queryManager['querySchedaOggetto']['queryPersone']).replace('{URI}', link);
  13. doJsonQuery(queryPERS).done(function(data) { handle_citedPeople(data); });
  14. queryLG = prefixes + (queryManager['querySchedaOggetto']['queryLuoghiGT']).replace('{URI}', link);
  15. doJsonQuery(queryLG).done(function(data) { handle_luoghiDocumento(data); });
  16. queryTR = prefixes + (queryManager['querySchedaOggetto']['queryTree']).replace('{URI}', link);
  17. doJsonQuery(queryTR).done(function(data) { handle_treeview(data, link); });
  18. function handle_objectData(json) {
  19. console.log(json);
  20. $.each(
  21. json['results']['bindings'],
  22. function (index, value) {
  23. var graph = value['graph']['value'];
  24. var label = value['label']['value'];
  25. var uri = value['uri']['value'];
  26. var siglaRegistro = "";
  27. var identifier = "";
  28. var dimensions = "";
  29. var consistence = "";
  30. var materials = "";
  31. var description = "";
  32. var button_ext = "";
  33. var button_owner = "";
  34. var current_owner = "";
  35. var uri_owner = "";
  36. var dates = "";
  37. var uri_composed = "";
  38. var composed = "";
  39. var button_doc = "";
  40. var treeList = "";
  41. var dataset = get_graph_name(graph);
  42. if (value.hasOwnProperty('id')) {
  43. $("#ID").css("display", "flex");
  44. identifier = value['id']['value'];
  45. }
  46. if (value.hasOwnProperty('dimension')) {
  47. $("#dimensione").css("display", "flex");
  48. dimensions = value['dimensions']['value'];
  49. }
  50. if (value.hasOwnProperty('consistency')) {
  51. $("#consistenza").css("display", "flex");
  52. consistence = value['consistency']['value'];
  53. }
  54. if (value.hasOwnProperty('sigla_registro')) {
  55. $("#IDreg").css("display", "flex");
  56. siglaRegistro = value['sigla_registro']['value'];
  57. }
  58. if (value.hasOwnProperty('condition')) {
  59. $("#STCC").css("display", "flex");
  60. condition = value['condition']['value'];
  61. }
  62. if (value.hasOwnProperty('material')) {
  63. $("#materia").css("display", "flex");
  64. materials = value['material']['value'];
  65. }
  66. if (value.hasOwnProperty('uri_owner')) {
  67. $("#current_owner").css("display", "flex");
  68. current_owner = value['owner']['value'];
  69. uri_owner = value['uri_owner']['value'];
  70. }
  71. if (value.hasOwnProperty('time_span')) {
  72. if (value['time_span']['value'] != ""){
  73. $("#time_span_object").css("display", "flex");
  74. dates = value['time_span']['value'];
  75. }
  76. }
  77. if (value.hasOwnProperty('note')) {
  78. $("#notes").css("display", "flex");
  79. description = value['note']['value'];
  80. }
  81. if (value.hasOwnProperty('uri_document')) {
  82. uri_composed = value['uri_document']['value'];
  83. }
  84. if (value.hasOwnProperty('document')) {
  85. //$("#composed").css("display", "flex");
  86. composed = value['document']['value'];
  87. }
  88. if (identifier != "") {
  89. button_ext = '<a title="Apri risorsa originale" href= "' + uri + '">' + identifier + '</a>';
  90. }
  91. if (uri_composed != "") {
  92. /*button_doc = '<button title="Apri risorsa di livello superiore" id="' + uri_composed + '" class="object btn btn-default" type="button" > \
  93. <i class="fa fa-book" aria-hidden="true"> <p class="btn-text">Livello superiore</p></i></button>';
  94. */
  95. treeList = '<li class="upLevel"><span id="' + uri_composed + '" class="object"><i class="fa fa-folder-open"></i>' +
  96. '<w class="link">' + composed + '</w></span><ul><li><span class="tree_label"><i class="fa fa-file-alt"></i>' + label + '<li></span><ul></li>'
  97. }
  98. if (owner != "") {
  99. button_owner = '<a title="Vai al sito dell\'Istituto" href= "' + uri_owner + '">' + current_owner + '</a>';
  100. }
  101. var Buttons = '<button title="Apri risorsa originale" class="btn btn-default" type="button" onclick="schedaASPO(\'' + uri + '\')"> \
  102. <i class="fas fa-external-link-alt" aria-hidden="true"></i></button> \
  103. <button title="Citazione" type="button" value="object" id="' + uri + '" class="cit btn btn-default" alt="scheda" title="Citazione"><i class="fa fa-quote-right"></i></button> \
  104. <button title="Permalink" type="button" value="object" id="' + uri + '" class="hyp btn btn-default" alt="scheda" title="Hyperlink"><i class="fa fa-link"></i></button> \
  105. <a href="http://dev.restore.ovi.cnr.it/lodlive/?' + uri + '" target="_blank"><button type="button" title="Naviga il grafo" class="btn btn-default info" alt="LOD" title="LodLive"><i class="fa fa-share-alt"></i></button></a></div></div>';
  106. document.getElementById("grafo").innerHTML = dataset;
  107. document.getElementById("nome_oggetto").innerHTML = label;
  108. document.getElementById("identifier").innerHTML = button_ext;
  109. document.getElementById("nota").innerHTML = description;
  110. document.getElementById("sigla_registro").innerHTML = siglaRegistro;
  111. document.getElementById("dimensions").innerHTML = dimensions;
  112. document.getElementById("materials").innerHTML = materials;
  113. document.getElementById("consistence").innerHTML = consistence;
  114. document.getElementById("owner").innerHTML = button_owner;
  115. document.getElementById("timeSpan").innerHTML = dates;
  116. document.getElementById("superDoc").innerHTML = composed;
  117. //document.getElementById("btn_superDoc").innerHTML = button_doc;
  118. document.getElementById("link_buttons").innerHTML = Buttons;
  119. document.getElementById("tree").innerHTML = treeList;
  120. });
  121. }
  122. function get_graph_name(graph) {
  123. var dataset = "Scheda Oggetto";
  124. if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale") {
  125. dataset = dataset + " / Ospedale";
  126. } else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/datini") {
  127. dataset = dataset + " / Datini";
  128. } else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi") {
  129. dataset = dataset + " / Marcovaldi";
  130. } else if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli") {
  131. dataset = dataset + " / Gettatelli";
  132. } else {
  133. dataset = dataset;
  134. }
  135. return dataset;
  136. }
  137. function handle_contrassegni(json) {
  138. console.log(json);
  139. var uri = "";
  140. var graph = "";
  141. var contrassegno = "";
  142. var immagine = "";
  143. var uri_gettatello = "";
  144. var gettatello = "";
  145. var Images = "";
  146. let markImg = [];
  147. $.each(
  148. json['results']['bindings'],
  149. function (index, value) {
  150. uri = value['uri']['value'];;
  151. contrassegno = value['contrassegno']['value'];
  152. immagine = value['image']['value'];
  153. uri_gettatello = value['uri_person']['value'];
  154. gettatello = value['gettatello']['value'];
  155. graph = value['g']['value'];
  156. });
  157. if (immagine != "") {
  158. $("#IMM").css("display", "flex");
  159. let imgs = immagine.split("_");
  160. const suffix = ["_a", "_b", "_c", "_a_2", "_a1", "_a2"];
  161. for (var k=0; k<suffix.length; k++) {
  162. var image_url = "img/contrassegni/" + imgs[0] + suffix[k] + ".jpg";
  163. markImg.push(image_url);
  164. createImage(image_url);
  165. }
  166. }
  167. if ((gettatello != "") && (uri_gettatello != "")) {
  168. $("#GT").css("display", "flex");
  169. var gt_btn = '<button type="button" id="' + uri_gettatello +
  170. '" class="persona btn btn-default" alt="persona"><i class="fa fa-user"></i><p class="btn-text">Persona</p></button>';
  171. document.getElementById('pp_gettatello').innerHTML = gettatello;
  172. document.getElementById('btn_gt').innerHTML = gt_btn;
  173. }
  174. var dataset = get_graph_name(graph);
  175. document.getElementById("nome_oggetto").innerHTML = contrassegno;
  176. document.getElementById("grafo").innerHTML = dataset;
  177. }
  178. function createImage(image) {
  179. checkIfImageExists(image, (exists) => {
  180. if (exists) {
  181. console.log(image);
  182. var Image = '<div class="singleImg"> \
  183. <img src="' + image + '" alt="contrassegno" style="width:100%" onclick="expandImg(this);"> \
  184. </div>';
  185. console.log(Image);
  186. $('#images').append(Image);
  187. } else {
  188. console.error('Image does not exists.')
  189. }
  190. });
  191. }
  192. function checkIfImageExists(url, callback) {
  193. const img = new Image();
  194. img.src = url;
  195. if (img.complete) {
  196. callback(true);
  197. } else {
  198. img.onload = () => {
  199. callback(true);
  200. };
  201. img.onerror = () => {
  202. callback(false);
  203. };
  204. }
  205. }
  206. function expandImg(imgs) {
  207. var expandImg = document.getElementById("expandedImg");
  208. var imgText = document.getElementById("imgtext");
  209. expandImg.src = imgs.src;
  210. imgText.innerHTML = imgs.alt;
  211. expandImg.parentElement.style.display = "block";
  212. }
  213. function handle_objectInfo(json) {
  214. console.log(json['results']['bindings']);
  215. $.each(
  216. json['results']['bindings'],
  217. function (index, value) {
  218. var title = "";
  219. var type = "";
  220. var subject = "";
  221. if (value.hasOwnProperty('titolo')) {
  222. $("#titolo").css("display", "flex");
  223. title = value['titolo']['value'];
  224. }
  225. if (value.hasOwnProperty('tipo')) {
  226. $("#tipo").css("display", "flex");
  227. type = value['tipo']['value'];
  228. }
  229. if (value.hasOwnProperty('ref')) {
  230. if (value['ref']['value'] != "") {
  231. $("#argomento").css("display", "flex");
  232. subject = value['ref']['value'];
  233. }
  234. }
  235. document.getElementById("title").innerHTML = title;
  236. document.getElementById("type").innerHTML = type;
  237. document.getElementById("subject").innerHTML = subject;
  238. });
  239. }
  240. function handle_oviLetter(json) {
  241. console.log(json['results']['bindings']);
  242. $.each(
  243. json['results']['bindings'],
  244. function (index, value) {
  245. var other_id = "";
  246. var uri = "";
  247. var button_letter = "";
  248. if (value.hasOwnProperty('otherId')) {
  249. $("#IDbis").css("display", "flex");
  250. other_id = value['otherId']['value'];
  251. }
  252. if (value.hasOwnProperty('InfObj')) {
  253. uri = value['InfObj']['value'];
  254. }
  255. if (uri != "") {
  256. button_letter = '<button type="button" id="' + uri +
  257. '" class="lettera btn btn-default" alt="lettera"><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  258. }
  259. document.getElementById("other_identifier").innerHTML = other_id;
  260. document.getElementById("btn_other_identifier").innerHTML = button_letter;
  261. });
  262. }
  263. function handle_citedPeople(json) {
  264. console.log(json);
  265. const people = [];
  266. $.each(
  267. json['results']['bindings'],
  268. function (index, value) {
  269. var uri = value['uri_person']['value'];
  270. var name = value['name']['value'];
  271. var tipo1 = "";
  272. var tipo2 = "";
  273. var nota = "";
  274. if (value.hasOwnProperty('types')) {
  275. if (value['types']['value'] != "") {
  276. tipo1 = value['types']['value'];
  277. }
  278. }
  279. if (value.hasOwnProperty('types2')) {
  280. if (value['types2']['value'] != "") {
  281. tipo2 = value['types2']['value'];
  282. }
  283. }
  284. if (value.hasOwnProperty('note')) {
  285. nota = value['note']['value'];
  286. }
  287. var tipo = "";
  288. if (tipo2 != "") {
  289. tipo = tipo2;
  290. } else {
  291. tipo = tipo1;
  292. }
  293. people.push([uri, name, tipo, nota]);
  294. });
  295. var Person = "";
  296. for (var i=0; i<people.length; i++) {
  297. var object = '<div class="col-8"><p><span id="' + people[i][0] + '" class="title_doc persona">'+ titleCase(people[i][1]) + '</span>';
  298. if (people[i][2] != "") {
  299. object = object + "<br />Ruoli documentati: " + people[i][2];
  300. }
  301. if (people[i][3] != "") {
  302. object = object + "<br />Nota: " + people[i][3];
  303. }
  304. object = object + '</p></div>';
  305. Person += '<div class="row res">' + object +
  306. '<div class="col d-flex align-items-start justify-content-end"><button type="button" id="' + people[i][0] + '" class="persona btn btn-default" alt="persona" title="' +
  307. people[i][1] + '"><i class="fa fa-user"></i><p class="btn-text">Persona</p></button>' +
  308. '<button type="button" value="Persona" id="' + people[i][0] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  309. '<button value="Persona" type="button" id="' + people[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  310. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + people[i][0] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  311. }
  312. document.getElementById("n_pp").innerHTML = people.length;
  313. document.getElementById("cited_people").innerHTML = Person;
  314. if (people.length==0) {
  315. var messaggio = "<p class='no-results'>Questa ricerca non ha prodotto risultati</p>";
  316. document.getElementById("cited_people").innerHTML = messaggio;
  317. }
  318. }
  319. function handle_treeview(json, uri_subject) {
  320. console.log(json);
  321. var upLevel = "";
  322. var uri_up = "";
  323. var tree_doc = "";
  324. $.each(
  325. json['results']['bindings'],
  326. function (index, value) {
  327. upLevel = value['label']['value'];
  328. uri_up = value['uri']['value'];
  329. var uri = value['uri_document']['value'];
  330. var document = value['document']['value'];
  331. tree_doc += '<li class="tree_el"><i class="fa fa-file-alt"></i><span id="' + uri + '" class="tree_seed link object">' + document + '</span><li>'
  332. });
  333. if (tree_doc != "") {
  334. var tree_list = '<li class="upLevelTree"><span style="cursor:pointer;" class="caret"><i class="fa fa-folder-open"></i>' +
  335. '<w>' + upLevel + '</w></span><ul id="nested" style="display: none;">' + tree_doc + '</ul></li>';
  336. document.getElementById("treeView").innerHTML = tree_list;
  337. }
  338. }
  339. function handle_luoghiDocumento(json) {
  340. console.log(json);
  341. const places = [];
  342. $.each(
  343. json['results']['bindings'],
  344. function (index, value) {
  345. var uri = value['uri_place']['value'];
  346. var label = value['place']['value'];
  347. places.push([uri, label]);
  348. });
  349. var Luoghi = "";
  350. for (var i=0; i<places.length; i++) {
  351. var object = '<div class="col-8"><p><span id="' + places[i][0] + '" class="title_doc luogo">'+ places[i][1] + '</span></p></div>';
  352. var object_button = '<button type="button" id="' + places[i][0] +
  353. '" class="luogo btn btn-default" alt="oggetto" title="' + places[i][1] +
  354. '"><i class="fa fa-map"></i><p class="btn-text">luogo</p></button>';
  355. Luoghi += '<div class="row res">'+ object +
  356. '<div class="col d-flex align-items-start justify-content-end">' + object_button +
  357. '<button type="button" value="luogo" id="' + places[i][0] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  358. '<button type="button" value="luogo" id="' + places[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  359. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + places[i][0] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  360. }
  361. document.getElementById("n_pl").innerHTML = places.length;
  362. document.getElementById("section_places").innerHTML = Luoghi;
  363. if (places.length==0) {
  364. var messaggio = "<p class='no-results'>Questa ricerca non ha prodotto risultati</p>";
  365. document.getElementById("section_places").innerHTML = messaggio;
  366. }
  367. }
  368. function createDivRelazione(type, id){
  369. htmlCode = '\
  370. <div class="row mb-2"> \
  371. <div class="col-sm-4"> \
  372. <span class="label"><RELATIONSHIP></span> \
  373. </div> \
  374. <div class="col record_box" id="<ID_RELATIONSHIP>"></div> \
  375. </div> \
  376. '.replace("<RELATIONSHIP>", type).replace("<ID_RELATIONSHIP>", id);
  377. return htmlCode;
  378. }
  379. function createColRelazione(text, link, tipo, fa, tab, decl) {
  380. htmlCode = '\
  381. <div class="row"> \
  382. <div class="col <CLASS>"><NAME></div> \
  383. <div class="col-auto"> \
  384. <button class="<TIPO> btn btn-default" type="button" id="<URI>">\
  385. <i class="<BUTTON>" aria-hidden="true">\
  386. <p class="btn-text"><TAB></p>\
  387. </i>\
  388. </button>\</div> \
  389. </div>\
  390. '.replace("<NAME>", text).replace("<URI>", link).replace("<TIPO>", tipo).replace("<BUTTON>", fa).replace("<TAB>", tab).replace("<CLASS>", decl);
  391. return htmlCode;
  392. }
  393. $(document).on("click", ".caret", function (ev) {
  394. $("#nested").toggle();
  395. //$("#nested").css("display", "block");
  396. });