advanced_search.js 38 KB

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