advanced_search.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. const choiceArray = [
  2. ["Nome risorsa", "Object, OA", "label"],
  3. ["Identificatore", "Object, OA, Person, Letter, Place", "identifier"],
  4. ["Materia", "Object, OA", "material"],
  5. ["Istituto di conservazione", "Object, OA", "localization"],
  6. ["Tecnica", "OA", "technique"],
  7. ["Artista", "OA", "artist"],
  8. ["Soggetto", "OA", "subject"],
  9. ["Titolo", "Object, Inf", "title"],
  10. ["Tipo di risorsa", "Object, Inf", "type"],
  11. ["Nome proprio", "Person", "givenName"],
  12. ["Nome di famiglia", "Person", "familyName"],
  13. ["Luogo di Nascita", "Person", "birthPlace"],
  14. ["Luogo di Morte", "Person", "deathPlace"],
  15. ["Genere", "Person", "sex"],
  16. ["Data di Nascita", "Person", "birthDate"],
  17. ["Data di Morte", "Person", "deathDate"],
  18. ["Occupazione", "Person", "occupation"],
  19. ["Qualifica", "Person", "qualification"],
  20. ["Mittente", "Letter", "sender"],
  21. ["Destinatario", "Letter", "receiver"],
  22. ["Luogo di Partenza", "Letter", "startPlace"],
  23. ["Luogo di Arrivo", "Letter", "endPlace"],
  24. ["Data partenza", "Letter", "startDate"],
  25. ["Data arrivo", "Letter", "endDate"],
  26. ["Lingua", "Letter", "language"],
  27. ["Area linguistica", "Letter", "languageArea"],
  28. ["Edizione", "Letter", "edition"],
  29. ["Data", "Object", "date"],
  30. ["Lemma", "Letter", "lemma"],
  31. ["Testo libero", "Letter", "keyword"]
  32. ];
  33. const typeArray = [
  34. ["Oggetto", "Object"],
  35. ["Lettera", "Letter"],
  36. ["Opera d'Arte", "OA"],
  37. ["Persona", "Person"]
  38. ];
  39. const graphArray = [
  40. ["ASPO - Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/datini", "Object"],
  41. ["ASPO - Ospedale", "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale", "Object"],
  42. ["ASPO - Marcovaldi", "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi", "Object"],
  43. ["ASPO - Onomastica Gettatelli", "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli", "Person"],
  44. ["ASPO - Onomastica Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/onomastica", "Person"],
  45. ["MPP - Artisti", "http://dev.restore.ovi.cnr.it:8890/mpp/autori", "Person"],
  46. ["MPP - Collezione Martini", "http://dev.restore.ovi.cnr.it:8890/mpp/martini", "Artwork"],
  47. ["MPP - Collezione Ospedale", "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale", "Artwork"],
  48. ["MPP - Collezione Datini", "http://dev.restore.ovi.cnr.it:8890/mpp/datini", "Artwork"],
  49. ["OVI - Lettere", "http://dev.restore.ovi.cnr.it:8890/ovi/datini", "Letter"]
  50. ];
  51. const objectArray = [];
  52. const personArray = [];
  53. const placeArray = [];
  54. const oaArray = [];
  55. const letterArray = [];
  56. $(document).ready(function () {
  57. //#######################################
  58. var type_selector = document.getElementById("type_selector");
  59. var collection_selector = document.getElementById("collection_selector");
  60. let x = typeArray.length;
  61. for(var i=0; i<x; i++) {
  62. var opt = document.createElement("option");
  63. opt.value= typeArray[i][1];
  64. opt.innerHTML = typeArray[i][0]; // whatever property it has
  65. // then append it to the select element
  66. type_selector.add(opt);
  67. }
  68. let z = choiceArray.length;
  69. for(var i=0; i<z; i++) {
  70. var cat = choiceArray[i][1];
  71. if (cat.includes("Object")) {
  72. objectArray.push(choiceArray[i]);
  73. }
  74. if (cat.includes("OA")) {
  75. oaArray.push(choiceArray[i]);
  76. }
  77. if (cat.includes("Person")) {
  78. personArray.push(choiceArray[i]);
  79. }
  80. if (cat.includes("Letter")) {
  81. letterArray.push(choiceArray[i]);
  82. }
  83. if (cat.includes("Place")) {
  84. placeArray.push(choiceArray[i]);
  85. }
  86. }
  87. $("#type_selector").change(function(){
  88. var selOpt = "";
  89. $(this).find("option:selected").each(function(){
  90. var optionValue = $(this).attr("value");
  91. selOpt = optionValue;
  92. if(optionValue){
  93. $(".box").not("." + optionValue).hide();
  94. $("." + optionValue).show();
  95. } else{
  96. $(".box").hide();
  97. }
  98. });
  99. $( ".container_choice" ).remove();
  100. if (selOpt == "Object") {
  101. addToListObject();
  102. populateSelGraph("Object");
  103. }
  104. else if (selOpt == "OA") {
  105. addToListOA();
  106. populateSelGraph("Artwork");
  107. }
  108. else if (selOpt == "Person") {
  109. addToListPerson();
  110. populateSelGraph("Person");
  111. }
  112. else if (selOpt == "Letter") {
  113. addToListLetter();
  114. populateSelGraph("Letter");
  115. }
  116. else {
  117. addToList();
  118. populateSelGraph("General");
  119. }
  120. }).change();
  121. /*$('[name=sel-parent]').on('change', function() {
  122. $(this).attr("id", 'example' + $(this).name());
  123. });*/
  124. });
  125. function populateOptions(selector, myArray) {
  126. var choice_selector = document.getElementById(selector);
  127. let k = myArray.length;
  128. for(var i=0; i<k; i++) {
  129. var opt = document.createElement("option");
  130. opt.value= myArray[i][1];
  131. opt.innerHTML = myArray[i][0]; // whatever property it has
  132. // then append it to the select element
  133. choice_selector.add(opt);
  134. }
  135. $('#' + selector).on( "change", function() {
  136. var numberId= selector.split("-")[1];
  137. var inputText= $( this ).find(":selected").text();
  138. var inp = "";
  139. if (inputText == "Genere") {
  140. inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
  141. <option>F</option> \
  142. <option>M</option> \
  143. </select>';
  144. } else if (inputText == "Materia"){
  145. inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
  146. <option>Pittura a tempera</option> \
  147. <option>Tavola</option> \
  148. <option>Stucco</option> \
  149. <option>Rame</option> \
  150. <option>Carta</option> \
  151. <option>Tela</option> \
  152. </select>';
  153. } else if (inputText == "Tecnica"){
  154. inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
  155. <option>Pittura</option> \
  156. <option>Doratura</option> \
  157. </select>';
  158. } else if (inputText == "Tipo di risorsa"){
  159. inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
  160. <option>Documento</option> \
  161. <option>Carteggio</option> \
  162. <option>Lettera</option> \
  163. <option>Libro</option> \
  164. <option>Documenti diversi</option> \
  165. </select>';
  166. } else if (inputText == "Data") {
  167. var inp = '<div id="box_' + numberId + 'a" class="container_choice"><div class="choice_box"><select id ="choice_selector-' + numberId + '_a" value=' + numberId + '_a" name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  168. <option selected value="0">Da</option> \
  169. <input type="date" id="inputchoiceSelector_'+ numberId +'_a" name="start" value="1300-01-01"> \
  170. </select></div></div> \
  171. <div id="box_' + numberId + '_b" class="container_choice"><div class="choice_box"><select id ="choice_selector-' + numberId + '_b" value=' + numberId + '_b" name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  172. <option selected value="0">A</option> \
  173. <input type="date" id="inputchoiceSelector_'+ numberId +'_b" name="end" value="1300-12-31"> \
  174. </select></div></div>';
  175. }
  176. else {
  177. inp = '<input type="text" id="inputchoiceSelector_'+ numberId +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2">';
  178. }
  179. var sect = 'sect-' + String(numberId);
  180. var inDiv = document.getElementById(sect);
  181. inDiv.innerHTML = inp;
  182. console.log(selector);
  183. /*$('#inputchoiceSelector_' + numberId).val(inputText);
  184. $('#inputchoiceSelector_' + numberId).id(inputText);*/
  185. });
  186. }
  187. var val = 0;
  188. function addToList() {
  189. val = val+1;
  190. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  191. <option selected value="0">Scegli un\'opzione</option> \
  192. </select><div id="sect-' + val + '"></div></div></div>';
  193. $('#drop-down-content').append(sel);
  194. var selector = 'choice_selector-' + val;
  195. populateOptions(selector, choiceArray);
  196. }
  197. function addToListObject() {
  198. val = val+100;
  199. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  200. <option selected value="0">Scegli un\'opzione</option> \
  201. </select><div id="sect-' + val + '"></div></div></div>';
  202. $('#drop-down-content-Object').append(sel);
  203. var selector = 'choice_selector-' + val;
  204. populateOptions(selector, objectArray);
  205. }
  206. function addToListOA() {
  207. val = val+200;
  208. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  209. <option selected value="0">Scegli un\'opzione</option> \
  210. </select><div id="sect-' + val + '"></div></div></div>';
  211. $('#drop-down-content-OA').append(sel);
  212. var selector = 'choice_selector-' + val;
  213. populateOptions(selector, oaArray);
  214. }
  215. function addToListPerson() {
  216. val = val+300;
  217. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  218. <option selected value="0">Scegli un\'opzione</option> \
  219. </select><div id="sect-' + val + '"></div></div></div>';
  220. $('#drop-down-content-Person').append(sel);
  221. var selector = 'choice_selector-' + val;
  222. populateOptions(selector, personArray);
  223. }
  224. function addToListLetter() {
  225. val = val+400;
  226. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  227. <option selected value="0">Scegli un\'opzione</option> \
  228. </select><div id="sect-' + val + '"></div></div></div>';
  229. $('#drop-down-content-Letter').append(sel);
  230. var selector = 'choice_selector-' + val;
  231. populateOptions(selector, letterArray);
  232. }
  233. function addToListPlace() {
  234. val = val+500;
  235. var sel = '<div id="box_' + val + '" class="container_choice"><div class="remove"><a onclick="removeElement(\'box_' + val + '\')"><i class="fa fa-trash" aria-hidden="true"></i></a></div><div class="choice_box"><select id ="choice_selector-' + val + '" value=' + val + ' name="sel-parent" class="advanced-form-select form-control" aria-label="Default select example"> \
  236. <option selected value="0">Scegli un\'opzione</option> \
  237. <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
  238. </select></div></div>';
  239. $('#drop-down-content-Place').append(sel);
  240. var selector = 'choice_selector-' + val;
  241. populateOptions(selector, placeArray);
  242. }
  243. //Get parameters from select and input options to build the query
  244. function getParameters() {
  245. var cc = document.getElementById("type_selector").value;
  246. if (cc != "General") {
  247. const arr = [];
  248. const collection = document.getElementsByClassName("advanced-form-select");
  249. for (let i = 0; i < collection.length; i++) {
  250. var x = collection[i].id;
  251. var t = document.getElementById(x);
  252. var e = t.options[t.selectedIndex].text;
  253. var numberId= x.split("-")[1]
  254. var inputId = "inputchoiceSelector_" + numberId;
  255. if (!!document.getElementById(inputId)) {
  256. var inputText = document.getElementById(inputId).value;
  257. var el = [e, inputText];
  258. console.log([inputText, el]);
  259. arr.push(el);
  260. }
  261. }
  262. constructQuery(arr);
  263. }
  264. else {
  265. alert("Seleziona una categoria")
  266. }
  267. /*$('#query_results').append(arr);
  268. testo = $('input#writeText').val();*/
  269. }
  270. function removeElement(id_element) {
  271. const element = document.getElementById(id_element);
  272. element.remove();
  273. }
  274. //Build query with harvested parametes
  275. function constructQuery(params) {
  276. var g = document.getElementById("collection_selector");
  277. var graph = g.value;
  278. var search_graph = "?g";
  279. if (graph != "") {
  280. search_graph = '<' + graph + '>';
  281. }
  282. var search_type = "";
  283. var ct = document.getElementById("type_selector");
  284. var choosen_type = ct.value;
  285. console.log(choosen_type);
  286. var search_identifier = "";
  287. if (choosen_type == "Object") {
  288. search_type = "?subject rdf:type crm:E22_Man-Made_Object . ";
  289. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  290. ?uri_identifier rdfs:label ?identifier ; \
  291. crm:P2_has_type 'Segnatura' .";
  292. }
  293. if (choosen_type == "Letter") {
  294. search_type = "?subject crm:P128_carries ?information_object . \
  295. ?information_object crm:P2_has_type ?uri_letter . \
  296. ?uri_letter rdfs:label 'lettera' ."
  297. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  298. ?uri_identifier rdfs:label ?identifier ; \
  299. crm:P2_has_type 'Segnatura' .";
  300. }
  301. if (choosen_type == "OA") {
  302. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  303. ?uri_identifier rdfs:label ?identifier ; \
  304. crm:P2_has_type 'Codice univoco del bene (NCT)' .";
  305. }
  306. if (choosen_type == "Person") {
  307. search_type = "?subject rdf:type crm:E21_Person . ";
  308. search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
  309. ?uri_identifier rdfs:label ?identifier .";
  310. }
  311. var label = ""; //
  312. var identificatore = ""; //
  313. var dimensione = ""; //
  314. var materia = ""; //
  315. var localizzazione = ""; //
  316. var tecnica = ""; //
  317. var artista = ""; //
  318. var soggetto = ""; //
  319. var titolo = ""; //
  320. var tipo = ""; //
  321. var note = ""; //
  322. var riferimenti = ""; //
  323. var nome_proprio = ""; //
  324. var nome_di_famiglia = ""; //
  325. var patronimico = ""; //
  326. var luogo_di_Nascita = ""; //
  327. var luogo_di_Morte = ""; //
  328. var genere = ""; //
  329. var data_di_Nascita = ""; //
  330. var data_di_Morte = ""; //
  331. var occupazione = ""; //
  332. var qualifica = ""; //
  333. var gruppi_di_appartenenza = ""; //
  334. var mittente = ""; //
  335. var destinatario = ""; //
  336. var luogo_di_Partenza = ""; //
  337. var luogo_di_Arrivo = ""; //
  338. var data_partenza = ""; //
  339. var data_arrivo = ""; //
  340. var lingua = ""; //
  341. var area_linguistica = ""; //
  342. var edizione = ""; //
  343. var lemma = ""; //
  344. var testo = ""; //
  345. var data = ""; //
  346. var letter_event = ""; //
  347. var infObj = ""; //
  348. var id = ""; //
  349. var dm = ""; //
  350. var mt = ""; //
  351. var locl = ""; //
  352. var tec = ""; //
  353. var at = ""; //
  354. var sg = ""; //
  355. var tt = ""; //
  356. var tp = ""; //
  357. var nt = ""; //
  358. var rf = ""; //
  359. var np = ""; //
  360. var nf = ""; //
  361. var pt = ""; //
  362. var ln = ""; //
  363. var lm = ""; //
  364. var gr = ""; //
  365. var dn = ""; //
  366. var dts = ""; //
  367. var oc = ""; //
  368. var qf = ""; //
  369. var ga = ""; //
  370. var mit = ""; //
  371. var des = ""; //
  372. var lp = ""; //
  373. var la = ""; //
  374. var dp = ""; //
  375. var da = ""; //
  376. var lin = ""; //
  377. var alin = ""; //
  378. var ed = ""; //
  379. var lem = ""; //
  380. var ttx = ""; //
  381. var dt = ""; //
  382. for (let i = 0; i < params.length; i++) {
  383. if(params[i][0] == "Nome risorsa" && (params[i][1] != "")) {
  384. label = "?label bif:contains \"\' "+ params[i][1] + " \'\" . ";
  385. }
  386. if(params[i][0] == "Identificatore" && (params[i][1] != "")) {
  387. id = " ?identifier";
  388. identificatore = "FILTER (CONTAINS(?identifier, \'"+ params[i][1] +"\'))";
  389. }
  390. if(params[i][0] == "Dimensione" && (params[i][1] != "")) {
  391. dm = " ?dimension";
  392. dimensione = "?subject crm:P43_has_dimension ?uri_dimension . \
  393. ?uri_dimension rdfs:label ?dimension . \
  394. ?dimension bif:contains \"\'"+ params[i][1] +"\'\" ."
  395. }
  396. if(params[i][0] == "Materia" && (params[i][1] != "")) {
  397. mt = " ?material";
  398. materia = "?subject crm:P45_consists_of ?uri_material . \
  399. ?uri_material rdfs:label ?material . \
  400. ?material bif:contains \"\'"+ params[i][1] +"\'\" ."
  401. }
  402. if(params[i][0] == "Istituto di conservazione" && (params[i][1] != "")) {
  403. locl = " ?location";
  404. localizzazione = "?subject crm:P52_has_current_owner ?uri_location . \
  405. ?uri_location rdfs:label ?location . \
  406. ?location bif:contains \"\'"+ params[i][1] +"\'\" ."
  407. }
  408. if(params[i][0] == "Tecnica" && (params[i][1] != "")) {
  409. tec = " ?technique";
  410. tecnica = "?event ?pp ?subject . \
  411. ?event crm:P32_used_general_technique ?uri_technique . \
  412. ?uri_technique rdfs:label ?technique . \
  413. ?technique bif:contains \"\'"+ params[i][1] +"\'\" . "
  414. }
  415. if (params[i][0] == "Artista" && (params[i][1] != "")) {
  416. at = " ?artist";
  417. artista = "?subject rdfs:label ?label . \
  418. ?production crm:P108_has_produced ?subject . \
  419. ?pc crm:P01_has_domain ?production . \
  420. ?pc crm:P02_has_range ?range . \
  421. ?range rdfs:label ?artist . \
  422. ?artist bif:contains \"\'"+ params[i][1] +"\'\" ."
  423. }
  424. if (params[i][0] == "Soggetto" && (params[i][1] != "")) {
  425. sg = " ?depiction";
  426. soggetto = "?subject crm:P62_depicts ?uri_depiction . \
  427. ?uri_depiction rdfs:label ?depiction . \
  428. ?depiction bif:contains \"\'"+ params[i][1] +"\'\" ."
  429. }
  430. if (params[i][0] == "Titolo" && (params[i][1] != "")) {
  431. tt = " ?title";
  432. infObj = "?subject crm:P128_carries ?information_object .";
  433. titolo = "?information_object crm:P1_is_identified_by ?uri_title . \
  434. ?uri_title rdfs:label ?title . \
  435. ?title bif:contains \"\'"+ params[i][1] +"\'\" ."
  436. }
  437. if (params[i][0] == "Tipo di risorsa" && (params[i][1] != "")) {
  438. tp = " ?type";
  439. infObj = "?subject crm:P128_carries ?information_object .";
  440. tipo = "?information_object crm:P2_has_type ?uri_type . \
  441. ?uri_type rdfs:label ?type . \
  442. ?type bif:contains \"\'"+ params[i][1] +"\'\" ."
  443. }
  444. if (params[i][0] == "Note" && (params[i][1] != "")) {
  445. nt = " ?note";
  446. note = "?subject crm:P3_has_note ?uri_note . \
  447. ?uri_note rdfs:label ?note . \
  448. ?note bif:contains \"\'"+ params[i][1] +"\'\" .";
  449. }
  450. if (params[i][0] == "Riferimenti" && (params[i][1] != "")) {
  451. rf = " ?ref";
  452. riferimenti = "?subject crm:P67_refers_to ?uri_ref . \
  453. ?uri_ref rdfs:label ?ref . \
  454. ?ref bif:contains \"\'"+ params[i][1] +"\'\" . "
  455. }
  456. if (params[i][0] == "Nome proprio" && (params[i][1] != "")) {
  457. np = " ?givenName";
  458. nome_proprio = "?subject foaf:givenName ?givenName . \
  459. ?givenName bif:contains \"\'"+ params[i][1] +"\'\" . "
  460. }
  461. if (params[i][0] == "Nome di famiglia" && (params[i][1] != "")) {
  462. nf = " ?familyName";
  463. nome_di_famiglia = "?subject foaf:familyName ?familyName . \
  464. ?familyName bif:contains \"\'"+ params[i][1] +"\'\" . "
  465. }
  466. if (params[i][0] == "Patronimico" && (params[i][1] != "")) {
  467. pt = " ?patronymic";
  468. patronimico = "?subject person:patronymicName ?patronymic . \
  469. ?patronymic bif:contains \"\'"+ params[i][1] +"\'\" . "
  470. }
  471. if (params[i][0] == "Luogo di Nascita" && (params[i][1] != "")) {
  472. ln = " ?birthPlace";
  473. luogo_di_Nascita = "?subject crm:P98i_was_born ?Birth . \
  474. ?Birth crm:P7_took_place_at ?uri_birthPlace . \
  475. ?uri_birthPlace rdfs:label ?birthPlace . \
  476. ?birthPlace bif:contains \""+ params[i][1] +"\" . "
  477. }
  478. if (params[i][0] == "Luogo di Morte" && (params[i][1] != "")) {
  479. lm = " ?deathPlace";
  480. luogo_di_Morte = "?subject crm:P100i_died_in ?Death . \
  481. ?Death crm:P7_took_place_at ?uri_deathPlace . \
  482. ?uri_deathPlace rdfs:label ?deathPlace \
  483. ?deathPlace bif:contains \""+ params[i][1] +"\" . "
  484. }
  485. if (params[i][0] == "Genere" && (params[i][1] != "")) {
  486. gr = "?genere";
  487. genere = "?subject foaf:gender ?genere . \
  488. ?genere bif:contains \""+ params[i][1] +"\" . "
  489. }
  490. if (params[i][0] == "Data di Nascita" && (params[i][1] != "")) {
  491. dn = " ?Birth_TS";
  492. data_di_Nascita = "?subject crm:P98i_was_born ?Birth . \
  493. ?Birth crm:P4_has_time-span ?Birth_TS . \
  494. ?Birth_TS rdfs:label \""+ params[i][1] +"\" ."
  495. }
  496. if (params[i][0] == "Data di Morte" && (params[i][1] != "")) {
  497. dts = " ?Death_TS";
  498. data_di_Morte = "?subject crm:P100i_died_in ?Death . \
  499. ?Death crm:P4_has_time-span ?Death_TS . \
  500. ?Death_TS rdfs:label \""+ params[i][1] +"\" . "
  501. }
  502. if (params[i][0] == "Qualifica" && (params[i][1] != "")) {
  503. qf = " ?qualification";
  504. qualifica = "?subject schema:honorificPrefix ?qualification . \
  505. ?qualification bif:contains \"\'"+ params[i][1] +"\'\" . "
  506. }
  507. if (params[i][0] == "Occupazione" && (params[i][1] != "")) {
  508. oc = " ?occupation";
  509. occupazione = "?subject schema:hasOccupation ?uriOccupation . \
  510. ?uriOccupation rdf:type schema:Occupation; \
  511. rdfs:label ?occupation . \
  512. ?occupation bif:contains \"\'"+ params[i][1] +"\'\" . "
  513. }
  514. if (params[i][0] == "Gruppi di appartenenza" && (params[i][1] != "")) {
  515. ga = " ?group";
  516. gruppi_di_appartenenza = "?subject crm:P107i_is_current_or_former_member_of ?uriGroup . \
  517. ?uriGroup rdfs:label ?group . \
  518. ?group bif:contains \"\'"+ params[i][1] +"\'\" . "
  519. }
  520. if (params[i][0] == "Mittente" && (params[i][1] != "")) {
  521. mit = " ?mittente";
  522. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  523. ?send rdfs:subClassOf ?mov_ev ; \
  524. rdf:type crm:EL2_Send_Letter . \
  525. ?receive rdfs:subClassOf ?mov_ev; \
  526. rdf:type crm:EL3_Receive_Letter . ";
  527. mittente = "?send crm:P01_has_domain ?pcS . \
  528. ?pcS crm:P02_has_range ?uriSender . \
  529. ?uriSender rdfs:label ?mittente . \
  530. ?mittente bif:contains \"\'"+ params[i][1] +"\'\" . "
  531. }
  532. if (params[i][0] == "Destinatario" && (params[i][1] != "")) {
  533. des = " ?destinatario";
  534. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  535. ?send rdfs:subClassOf ?mov_ev ; \
  536. rdf:type crm:EL2_Send_Letter . \
  537. ?receive rdfs:subClassOf ?mov_ev; \
  538. rdf:type crm:EL3_Receive_Letter . ";
  539. destinatario = "?receive crm:P01_has_domain ?pcR . \
  540. ?pcR crm:P02_has_range ?uriReceiver . \
  541. ?uriReceiver rdfs:label ?destinatario . \
  542. ?destinatario bif:contains \"\'"+ params[i][1] +"\'\" . "
  543. }
  544. if (params[i][0] == "Luogo di Partenza" && (params[i][1] != "")) {
  545. lp = " ?luogo_partenza";
  546. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  547. ?send rdfs:subClassOf ?mov_ev ; \
  548. rdf:type crm:EL2_Send_Letter . \
  549. ?receive rdfs:subClassOf ?mov_ev; \
  550. rdf:type crm:EL3_Receive_Letter . ";
  551. luogo_di_Partenza = "?send crm:P27_moved_from ?uriLuogoPartenza . \
  552. ?uriLuogoPartenza rdfs:label ?luogo_partenza . \
  553. ?luogo_partenza bif:contains \"\'"+ params[i][1] +"\'\" . "
  554. }
  555. if (params[i][0] == "Luogo di Arrivo" && (params[i][1] != "")) {
  556. la = " ?luogo_arrivo";
  557. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  558. ?send rdfs:subClassOf ?mov_ev ; \
  559. rdf:type crm:EL2_Send_Letter . \
  560. ?receive rdfs:subClassOf ?mov_ev; \
  561. rdf:type crm:EL3_Receive_Letter . ";
  562. luogo_di_Arrivo = "?receive crm:P26_moved_to ?uriLuogoArrivo . \
  563. ?uriLuogoArrivo rdfs:label ?luogo_arrivo . \
  564. ?luogo_arrivo bif:contains \"\'"+ params[i][1] +"\'\" . "
  565. }
  566. if (params[i][0] == "Data partenza" && (params[i][1] != "")) {
  567. dp = " ?timeSpanSend";
  568. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  569. ?send rdfs:subClassOf ?mov_ev ; \
  570. rdf:type crm:EL2_Send_Letter . \
  571. ?receive rdfs:subClassOf ?mov_ev; \
  572. rdf:type crm:EL3_Receive_Letter . ";
  573. data_partenza = "?send crm:P4_has_time-span ?time_spanS . \
  574. ?time_spanS rdfs:label ?timeSpanSend . \
  575. ?timeSpanSend bif:contains \"\'"+ params[i][1] +"\'\" . "
  576. }
  577. if (params[i][0] == "Data arrivo" && (params[i][1] != "")) {
  578. da = " ?timeSpanReceive";
  579. letter_event = "?subject crm:P25i_moved_by ?mov_ev . \
  580. ?send rdfs:subClassOf ?mov_ev ; \
  581. rdf:type crm:EL2_Send_Letter . \
  582. ?receive rdfs:subClassOf ?mov_ev; \
  583. rdf:type crm:EL3_Receive_Letter . ";
  584. data_arrivo = "?receive crm:P4_has_time-span ?time_spanR . \
  585. ?time_spanR rdfs:label ?timeSpanReceive .\
  586. ?timeSpanReceive bif:contains \"\'"+ params[i][1] +"\'\" . "
  587. }
  588. if (params[i][0] == "Lingua" && (params[i][1] != "")) {
  589. lin = " ?lingua";
  590. lingua = "?information_object crm:P72_has_language ?language . \
  591. ?language rdfs:label ?lingua . \
  592. ?lingua bif:contains \"\'"+ params[i][1] +"\'\" ."
  593. }
  594. if (params[i][0] == "Area linguistica" && (params[i][1] != "")) {
  595. alin = " ?area_linguistica";
  596. area_linguistica = "?information_object crm:P72_has_language ?language . \
  597. ?language crm:P3_has_note ?area . \
  598. ?area rdfs:label ?area_linguistica .\
  599. ?area_linguistica bif:contains \"\'"+ params[i][1] +"\'\" ."
  600. }
  601. if (params[i][0] == "Edizione" && (params[i][1] != "")) {
  602. ed = " ?edizione";
  603. edizione = "?edition crm:P70_documents ?information_object ; \
  604. crm:P1_is_identified_by ?edition_id . \
  605. ?edition_id rdfs:label ?edizione . \
  606. ?edizione bif:contains \"\'"+ params[i][1] +"\'\" ."
  607. }
  608. if (params[i][0] == "Lemma" && (params[i][1] != "")) {
  609. lem = " ?lemma";
  610. lemma = "?information_object crm:P67_refers_to ?link_lemma . \
  611. ?link_lemma rdfs:label ?lemma. \
  612. ?lemma bif:contains \"\'"+ params[i][1] +"\'\" ."
  613. }
  614. if (params[i][0] == "Testo libero" && (params[i][1] != "")) {
  615. ttx = " ?testo";
  616. testo = "?information_object crm:P190_has_symbolic_content ?testo . \
  617. ?testo bif:contains \"\'"+ params[i][1] +"\'\" ."
  618. }
  619. if (params[i][0] == "Data" && (params[i][1] != "")) {
  620. dt = " ?date";
  621. data = "?subject ?property ?event . \
  622. ?event crm:P4_has_time-span ?uri_date . \
  623. ?uri_date rdfs:label ?date . \
  624. ?date bif:contains \"\'"+ params[i][1] +"\'\" ."
  625. }
  626. }
  627. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  628. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  629. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  630. PREFIX owl: <http://www.w3.org/2002/07/owl#> \
  631. PREFIX schema: <http://schema.org/> \
  632. PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
  633. PREFIX person: <http://www.w3.org/ns/person#>"
  634. query = prefixes + " SELECT DISTINCT ?subject ?label ?identifier " + dm + mt + locl + tec + at
  635. + sg + tt + tp + nt + rf + np + nf + pt + ln + lm + gr + dn + dts + oc + qf + ga + mit
  636. + des + lp + la + dp + da + lin + alin + ed + lem + dt + ttx + " \
  637. WHERE {GRAPH " + search_graph + " {?subject ?property ?object } \
  638. ?subject rdfs:label ?label . "
  639. + search_identifier + infObj + letter_event + label + search_type + dimensione + materia + localizzazione + tecnica
  640. + artista + titolo + tipo + note + riferimenti + nome_proprio + nome_di_famiglia
  641. + patronimico + luogo_di_Nascita + luogo_di_Morte + genere + data_di_Nascita
  642. + data_di_Morte + qualifica + occupazione + gruppi_di_appartenenza + mittente + destinatario
  643. +luogo_di_Partenza + luogo_di_Arrivo + data_partenza + data_arrivo + lingua
  644. + area_linguistica + edizione + lemma + data + identificatore + testo + "}"
  645. var query_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json';
  646. console.log(query);
  647. $.ajax({
  648. url: query_url + '&callback=?',
  649. dataType: "json",
  650. success: function (data) {
  651. query_handle_json(data, choosen_type);
  652. },
  653. error: function (e) {}
  654. });
  655. }
  656. function query_handle_json(json, choosen_type) {
  657. console.log(json);
  658. var resulType = "";
  659. if (choosen_type == "Object") {
  660. resulType = "object";
  661. }
  662. if (choosen_type == "Letter") {
  663. resulType = "object";
  664. }
  665. if (choosen_type == "OA") {
  666. resulType = "artwork";
  667. }
  668. if (choosen_type == "Person") {
  669. resulType = "persona";
  670. }
  671. $('#query_results').text("");
  672. var i = 0;
  673. const first_row = [];
  674. $.each(
  675. json['head']['vars'],
  676. function (index, value) {
  677. first_row.push(value);
  678. });
  679. var t_head = '<div class="row t_head">';
  680. for (let k = 1; k < first_row.length; k++) {
  681. var param = renameCol(first_row[k]);
  682. t_head += '<div class="col-auto">' + param + '</div>';
  683. }
  684. t_head += '</div>';
  685. $('#query_results').append(t_head);
  686. $.each(
  687. json['results']['bindings'],
  688. function (index, value) {
  689. var object = "";
  690. var link = value['subject']['value'];
  691. var label = value['label']['value'];
  692. object += '<div class="row"><div id="' + link + '" class="col-auto link ' + resulType + '">' + label + '</div>';
  693. if (value.hasOwnProperty('identifier')) {
  694. identifier = value['identifier']['value'];
  695. object += '<div class="col-auto">' + identifier + '</div>';
  696. }
  697. if (value.hasOwnProperty('dimension')) {
  698. dimension = value['dimension']['value'];
  699. object += '<div class="col-auto">' + dimension + '</div>';
  700. }
  701. if (value.hasOwnProperty('material')) {
  702. material = value['material']['value'];
  703. object += '<div class="col-auto">' + material + '</div>';
  704. }
  705. if (value.hasOwnProperty('location')) {
  706. localization = value['location']['value'];
  707. object += '<div class="col-auto">' + localization + '</div>';
  708. }
  709. if (value.hasOwnProperty('technique')) {
  710. technique = value['technique']['value'];
  711. object += '<div class="col-auto">' + technique + '</div>';
  712. }
  713. if (value.hasOwnProperty('artist')) {
  714. artist = value['artist']['value'];
  715. object += '<div class="col-auto">' + artist + '</div>';
  716. }
  717. if (value.hasOwnProperty('depiction')) {
  718. depiction = value['depiction']['value'];
  719. object += '<div class="col-auto">' + depiction + '</div>';
  720. }
  721. if (value.hasOwnProperty('title')) {
  722. title = value['title']['value'];
  723. object += '<div class="col-auto">' + title + '</div>';
  724. }
  725. if (value.hasOwnProperty('type')) {
  726. type = value['type']['value'];
  727. object += '<div class="col-auto">' + type + '</div>';
  728. }
  729. if (value.hasOwnProperty('note')) {
  730. note = value['note']['value'];
  731. object += '<div class="col-auto">' + note + '</div>';
  732. }
  733. if (value.hasOwnProperty('ref')) {
  734. ref = value['ref']['value'];
  735. object += '<div class="col-auto">' + ref + '</div>';
  736. }
  737. if (value.hasOwnProperty('givenName')) {
  738. givenName = value['givenName']['value'];
  739. object += '<div class="col-auto">' + givenName + '</div>';
  740. }
  741. if (value.hasOwnProperty('familyName')) {
  742. familyName = value['familyName']['value'];
  743. object += '<div class="col-auto">' + familyName + '</div>';
  744. }
  745. if (value.hasOwnProperty('patronymic')) {
  746. patronymic = value['patronymic']['value'];
  747. object += '<div class="col-auto">' + patronymic + '</div>';
  748. }
  749. if (value.hasOwnProperty('birthPlace')) {
  750. birthPlace = value['birthPlace']['value'];
  751. object += '<div class="col-auto">' + birthPlace + '</div>';
  752. }
  753. if (value.hasOwnProperty('deathPlace')) {
  754. deathPlace = value['deathPlace']['value'];
  755. object += '<div class="col-auto">' + deathPlace + '</div>';
  756. }
  757. if (value.hasOwnProperty('genere')) {
  758. genere = value['genere']['value'];
  759. object += '<div class="col-auto">' + genere + '</div>';
  760. }
  761. if (value.hasOwnProperty('Birth_TS')) {
  762. Birth_TS = value['Birth_TS']['value'];
  763. object += '<div class="col-auto">' + Birth_TS + '</div>';
  764. }
  765. if (value.hasOwnProperty('Death_TS')) {
  766. Death_TS = value['Death_TS']['value'];
  767. object += '<div class="col-auto">' + Death_TS + '</div>';
  768. }
  769. if (value.hasOwnProperty('qualification')) {
  770. qualification = value['qualification']['value'];
  771. object += '<div class="col-auto">' + qualification + '</div>';
  772. }
  773. if (value.hasOwnProperty('occupation')) {
  774. occupation = value['occupation']['value'];
  775. object += '<div class="col-auto">' + occupation + '</div>';
  776. }
  777. if (value.hasOwnProperty('group')) {
  778. group = value['group']['value'];
  779. object += '<div class="col-auto">' + group + '</div>';
  780. }
  781. if (value.hasOwnProperty('mittente')) {
  782. mittente = value['mittente']['value'];
  783. object += '<div class="col-auto">' + mittente + '</div>';
  784. }
  785. if (value.hasOwnProperty('destinatario')) {
  786. destinatario = value['destinatario']['value'];
  787. object += '<div class="col-auto">' + destinatario + '</div>';
  788. }
  789. if (value.hasOwnProperty('luogo_partenza')) {
  790. luogo_partenza = value['luogo_partenza']['value'];
  791. object += '<div class="col-auto">' + luogo_partenza + '</div>';
  792. }
  793. if (value.hasOwnProperty('luogo_arrivo')) {
  794. luogo_arrivo = value['luogo_arrivo']['value'];
  795. object += '<div class="col-auto">' + luogo_arrivo + '</div>';
  796. }
  797. if (value.hasOwnProperty('timeSpanSend')) {
  798. timeSpanSend = value['timeSpanSend']['value'];
  799. object += '<div class="col-auto">' + timeSpanSend + '</div>';
  800. }
  801. if (value.hasOwnProperty('timeSpanReceive')) {
  802. timeSpanReceive = value['timeSpanReceive']['value'];
  803. object += '<div class="col-auto">' + timeSpanReceive + '</div>';
  804. }
  805. if (value.hasOwnProperty('lingua')) {
  806. lingua = value['lingua']['value'];
  807. object += '<div class="col-auto">' + lingua + '</div>';
  808. }
  809. if (value.hasOwnProperty('area_linguistica')) {
  810. area_linguistica = value['area_linguistica']['value'];
  811. object += '<div class="col-auto">' + area_linguistica + '</div>';
  812. }
  813. if (value.hasOwnProperty('edizione')) {
  814. edizione = value['edizione']['value'];
  815. object += '<div class="col-auto">' + edizione + '</div>';
  816. }
  817. if (value.hasOwnProperty('lemma')) {
  818. lemma = value['lemma']['value'];
  819. object += '<div class="col-auto">' + lemma + '</div>';
  820. }
  821. if (value.hasOwnProperty('testo')) {
  822. testo = value['testo']['value'];
  823. object += '<div class="col-auto">' + testo + '</div>';
  824. }
  825. if (value.hasOwnProperty('date')) {
  826. date = value['date']['value'];
  827. object += '<div class="col-auto">' + date + '</div>';
  828. }
  829. object += '</div>';
  830. i++;
  831. /*onclick=copy__Text("' + value['link']['value'] + '")*/
  832. $('#query_results').append(object);
  833. });
  834. if (i==0) {
  835. var message = '<p>Nessun risultato trovato</p>';
  836. $('#query_results').append(message);
  837. }
  838. document.getElementById("n_res").innerHTML = i;
  839. }
  840. function populateSelGraph(graphType) {
  841. let y = graphArray.length;
  842. collection_selector.innerHTML = "";
  843. if (graphType != "General") {
  844. collection_selector.style.color = '#202122';
  845. collection_selector.style.cursor = 'pointer';
  846. collection_selector.style.backgroundColor = '#f8f9fa';
  847. collection_selector.style.backgroundImage = 'linear-gradient(to top, #fff, #fff 33%)';
  848. } else {
  849. collection_selector.style.color = '#a1a1a1';
  850. collection_selector.style.cursor = 'not-allowed';
  851. collection_selector.style.backgroundColor = '#eee';
  852. collection_selector.style.backgroundImage = 'linear-gradient(to top, #ddd, #eee 33%)';
  853. }
  854. var genOpt = document.createElement("option");
  855. genOpt.value= "";
  856. genOpt.innerHTML = "Tutte le Collezioni";
  857. collection_selector.add(genOpt);
  858. for(var i=0; i<y; i++) {
  859. if (graphType == graphArray[i][2]) {
  860. var opt = document.createElement("option");
  861. opt.value= graphArray[i][1];
  862. opt.innerHTML = graphArray[i][0]; // whatever property it has
  863. // then append it to the select element
  864. collection_selector.add(opt);
  865. }
  866. }
  867. }
  868. function renameCol(param) {
  869. if (param == "label") {
  870. return ("Denominazione");
  871. }
  872. else if (param == "identifier") {
  873. return ("Identificatore");
  874. }
  875. else if (param == "dimension") {
  876. return ("Dimensioni");
  877. }
  878. else if (param == "material") {
  879. return ("Materiale");
  880. }
  881. else if (param == "location") {
  882. return ("Istituto di conservazione");
  883. }
  884. else if (param == "technique") {
  885. return ("Tecnica");
  886. }
  887. else if (param == "artist") {
  888. return ("Artista");
  889. }
  890. else if (param == "depiction") {
  891. return ("Soggetto");
  892. }
  893. else if (param == "title") {
  894. return ("Titolo");
  895. }
  896. else if (param == "type") {
  897. return ("Tipologia");
  898. }
  899. else if (param == "note") {
  900. return ("Note");
  901. }
  902. else if (param == "ref") {
  903. return ("Riferimenti");
  904. }
  905. else if (param == "givenName") {
  906. return ("Nome proprio");
  907. }
  908. else if (param == "familyName") {
  909. return ("Cognome");
  910. }
  911. else if (param == "birthPlace") {
  912. return ("Luogo di Nascita");
  913. }
  914. else if (param == "deathPlace") {
  915. return ("Luogo di morte");
  916. }
  917. else if (param == "genere") {
  918. return ("Genere");
  919. }
  920. else if (param == "Birth_TS") {
  921. return ("Data di nascita");
  922. }
  923. else if (param == "Death_TS") {
  924. return ("Data di morte");
  925. }
  926. else if (param == "qualification") {
  927. return ("Qualifica");
  928. }
  929. else if (param == "occupation") {
  930. return ("Occupazione");
  931. }
  932. else if (param == "mittente") {
  933. return ("Mittente");
  934. }
  935. else if (param == "destinatario") {
  936. return ("Destinatario");
  937. }
  938. else if (param == "luogo_partenza") {
  939. return ("Luogo di partenza");
  940. }
  941. else if (param == "luogo_arrivo") {
  942. return ("Luogo di arrivo");
  943. }
  944. else if (param == "timeSpanSend") {
  945. return ("Data partenza");
  946. }
  947. else if (param == "timeSpanReceive") {
  948. return ("Data arrivo");
  949. }
  950. else if (param == "area_linguistica") {
  951. return ("Area linguistica");
  952. }
  953. else if (param == "edizione") {
  954. return ("Edizione");
  955. }
  956. else if (param == "lemma") {
  957. return ("Lemma");
  958. }
  959. else if (param == "testo") {
  960. return ("Testo");
  961. }
  962. else if (param == "date") {
  963. return ("Data");
  964. }
  965. else {
  966. return (param);
  967. }
  968. }
  969. function download_table_as_csv(separator = ',') {
  970. // Select rows from table_id
  971. var rows = document.querySelectorAll('#query_results .row');
  972. // Construct csv
  973. var csv = [];
  974. for (var i = 0; i < rows.length; i++) {
  975. var row = [], cols = rows[i].querySelectorAll('.col-auto');
  976. for (var j = 0; j < cols.length; j++) {
  977. // Clean innertext to remove multiple spaces and jumpline (break csv)
  978. var data = cols[j].innerText.replace(/(\r\n|\n|\r)/gm, '').replace(/(\s\s)/gm, ' ')
  979. // Escape double-quote with double-double-quote (see https://stackoverflow.com/questions/17808511/properly-escape-a-double-quote-in-csv)
  980. data = data.replace(/"/g, '""');
  981. // Push escaped string
  982. row.push('"' + data + '"');
  983. }
  984. csv.push(row.join(separator));
  985. }
  986. var csv_string = csv.join('\n');
  987. // Download it
  988. var filename = 'export_queryResults_' + new Date().toLocaleDateString() + '.csv';
  989. var link = document.createElement('a');
  990. link.style.display = 'none';
  991. link.setAttribute('target', '_blank');
  992. link.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv_string));
  993. link.setAttribute('download', filename);
  994. document.body.appendChild(link);
  995. link.click();
  996. document.body.removeChild(link);
  997. }