Преглед изворни кода

Update advanced search and bug fix

Alessia пре 1 година
родитељ
комит
9c1b9bff7a
5 измењених фајлова са 118 додато и 46 уклоњено
  1. 4 1
      css/advanced-search.css
  2. 105 39
      js/advanced_search.js
  3. 2 2
      js/lettera.js
  4. 3 3
      lettera.html
  5. 4 1
      ricerca_avanzata.html

+ 4 - 1
css/advanced-search.css

@@ -168,7 +168,6 @@
   display: table-cell;
 }
 
-
 .remove {
   float: right;
   margin-right: 10px;
@@ -176,3 +175,7 @@
   cursor: pointer;
 }
 
+#btn_dowload {
+  text-align: center;
+  margin-top:15px;
+}

+ 105 - 39
js/advanced_search.js

@@ -35,19 +35,20 @@ const typeArray = [
 	["Oggetto", "Object"], 
 	["Lettera", "Letter"],
 	["Opera d'Arte", "OA"],
-	["Persona", "Person"],
-	["Luogo", "Place"]
+	["Persona", "Person"]
 	];
 
 const graphArray = [
-	["ASPO - Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/datini"], 
-	["ASPO - Ospedale", "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale"],
-	["ASPO - Marcovaldi", "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi"],
-	["ASPO - Gettatelli", "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli"],
-	["MPP - Collezione Martini", "http://dev.restore.ovi.cnr.it:8890/mpp/martini"],
-	["MPP - Collezione Ospedale", "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale"],
-	["MPP - Collezione Datini", "http://dev.restore.ovi.cnr.it:8890/mpp/datini"],
-	["OVI - Lettere", "http://dev.restore.ovi.cnr.it:8890/ovi/datini"]
+	["ASPO - Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/datini", "Object"], 
+	["ASPO - Ospedale", "http://dev.restore.ovi.cnr.it:8890/aspo/ospedale", "Object"],
+	["ASPO - Marcovaldi", "http://dev.restore.ovi.cnr.it:8890/aspo/marcovaldi", "Object"],
+	["ASPO - Onomastica Ospedale", "http://dev.restore.ovi.cnr.it:8890/aspo/gettatelli", "Person"],
+	["ASPO - Onomastica Datini", "http://dev.restore.ovi.cnr.it:8890/aspo/onomastica", "Person"],
+	["MPP - Artisti", "http://dev.restore.ovi.cnr.it:8890/mpp/autori", "Person"],
+	["MPP - Collezione Martini", "http://dev.restore.ovi.cnr.it:8890/mpp/martini", "Artwork"],
+	["MPP - Collezione Ospedale", "http://dev.restore.ovi.cnr.it:8890/mpp/ospedale", "Artwork"],
+	["MPP - Collezione Datini", "http://dev.restore.ovi.cnr.it:8890/mpp/datini", "Artwork"],
+	["OVI - Lettere", "http://dev.restore.ovi.cnr.it:8890/ovi/datini", "Letter"]
 	];
 
 const objectArray = [];
@@ -73,16 +74,6 @@ $(document).ready(function () {
 		   type_selector.add(opt);
 		}
 
-	let y = graphArray.length;
-
-	for(var i=0; i<y; i++) {
-		   var opt = document.createElement("option");
-		   opt.value= graphArray[i][1];
-		   opt.innerHTML = graphArray[i][0]; // whatever property it has
-
-		   // then append it to the select element
-		   collection_selector.add(opt);
-		}
 
 	let z = choiceArray.length;
 
@@ -120,24 +111,30 @@ $(document).ready(function () {
 		$( ".container_choice" ).remove();
 		if (selOpt == "Object") {
 			addToListObject();
+			populateSelGraph("Object");
 		}
-		if (selOpt == "OA") {
+		else if (selOpt == "OA") {
 			addToListOA();
+			populateSelGraph("Artwork");
 		}
-		if (selOpt == "Person") {
+		else if (selOpt == "Person") {
 			addToListPerson();
+			populateSelGraph("Person");
 		}
-		if (selOpt == "Letter") {
+		else if (selOpt == "Letter") {
 			addToListLetter();
-		}	
+			populateSelGraph("Letter");
+		}
+		else {
+			addToList();
+			populateSelGraph("General");
+		} 
     }).change();
 
     /*$('[name=sel-parent]').on('change', function() {
 	   $(this).attr("id", 'example' + $(this).name());
 	});*/
 
-	addToList();
-
 });
 
 
@@ -236,20 +233,25 @@ function addToListPlace() {
 
 //Get parameters from select and input options to build the query
 function getParameters() {
-	const arr = [];
-	const collection = document.getElementsByClassName("advanced-form-select");
-	for (let i = 0; i < collection.length; i++) {
-	  var x = collection[i].id;
-	  var t = document.getElementById(x);
-	  var e = t.options[t.selectedIndex].text;
-	  var numberId= x.split("-")[1]
-	  var inputId = "inputchoiceSelector_" + numberId;
-	  var inputText = document.getElementById(inputId).value;
-	  var el = [e, inputText];
-	  arr.push(el);
+	var cc = document.getElementById("type_selector").value;
+	if (cc != "General") {
+		const arr = [];
+		const collection = document.getElementsByClassName("advanced-form-select");
+		for (let i = 0; i < collection.length; i++) {
+			var x = collection[i].id;
+			var t = document.getElementById(x);
+			var e = t.options[t.selectedIndex].text;
+			var numberId= x.split("-")[1]
+			var inputId = "inputchoiceSelector_" + numberId;
+			var inputText = document.getElementById(inputId).value;
+			var el = [e, inputText];
+			arr.push(el);
+		}
+		constructQuery(arr); 
+	}
+	else {
+		alert("Seleziona una categoria")
 	}
-
-	constructQuery(arr);
 	/*$('#query_results').append(arr);
 	testo = $('input#writeText').val();*/
 }
@@ -924,6 +926,40 @@ function query_handle_json(json, choosen_type) {
 		document.getElementById("n_res").innerHTML = i;
 }
 
+function populateSelGraph(graphType) {
+	let y = graphArray.length;
+
+	collection_selector.innerHTML = "";
+
+	if (graphType != "General") {
+		collection_selector.style.color = '#202122';
+		collection_selector.style.cursor = 'pointer';
+		collection_selector.style.backgroundColor = '#f8f9fa';
+		collection_selector.style.backgroundImage  = 'linear-gradient(to top, #fff, #fff 33%)';
+	} else {
+		collection_selector.style.color = '#a1a1a1';
+		collection_selector.style.cursor = 'not-allowed';
+		collection_selector.style.backgroundColor = '#eee';
+		collection_selector.style.backgroundImage = 'linear-gradient(to top, #ddd, #eee 33%)';
+	}
+
+	var genOpt = document.createElement("option");
+	genOpt.value= "";
+	genOpt.innerHTML = "Tutte le Collezioni";
+	collection_selector.add(genOpt);
+
+	for(var i=0; i<y; i++) {
+		if (graphType == graphArray[i][2]) {
+		   var opt = document.createElement("option");
+		   opt.value= graphArray[i][1];
+		   opt.innerHTML = graphArray[i][0]; // whatever property it has
+
+		   // then append it to the select element
+		   collection_selector.add(opt);
+		}
+	}
+}
+
 function renameCol(param) {
 	if (param == "label") {
 		return ("Denominazione");
@@ -1022,3 +1058,33 @@ function renameCol(param) {
 		return (param);
 	}
 }
+
+function download_table_as_csv(separator = ',') {
+    // Select rows from table_id
+    var rows = document.querySelectorAll('#query_results .row');
+    // Construct csv
+    var csv = [];
+    for (var i = 0; i < rows.length; i++) {
+        var row = [], cols = rows[i].querySelectorAll('.col-auto');
+        for (var j = 0; j < cols.length; j++) {
+            // Clean innertext to remove multiple spaces and jumpline (break csv)
+            var data = cols[j].innerText.replace(/(\r\n|\n|\r)/gm, '').replace(/(\s\s)/gm, ' ')
+            // Escape double-quote with double-double-quote (see https://stackoverflow.com/questions/17808511/properly-escape-a-double-quote-in-csv)
+            data = data.replace(/"/g, '""');
+            // Push escaped string
+            row.push('"' + data + '"');
+        }
+        csv.push(row.join(separator));
+    }
+    var csv_string = csv.join('\n');
+    // Download it
+    var filename = 'export_queryResults_' + new Date().toLocaleDateString() + '.csv';
+    var link = document.createElement('a');
+    link.style.display = 'none';
+    link.setAttribute('target', '_blank');
+    link.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(csv_string));
+    link.setAttribute('download', filename);
+    document.body.appendChild(link);
+    link.click();
+    document.body.removeChild(link);
+}

+ 2 - 2
js/lettera.js

@@ -146,8 +146,8 @@ function createButton(buttonClass, text, onClickFunction){
 
 function createButtonEVT(sigla){
 	htmlCode = '\
-		<button title="Edition Visualization Technology" type="button" class="btn btn-secondary" onclick="loadPageEVT(\'<SIGLA>\')">\
-		Apri EVT</button>\
+		<p>Per approfondire accedi a <button title="Edition Visualization Technology" type="button" class="btn btn-secondary" onclick="loadPageEVT(\'<SIGLA>\')">\
+		Edition Visualization Technology</button></p>\
 		'.replace("<SIGLA>", sigla);
 	return htmlCode;
 }

+ 3 - 3
lettera.html

@@ -261,14 +261,14 @@
 							<div class="col" id="container_lettera_1">
 								<div id="info_trascrizione">
 									<div class="headInfo" id="head_trascrizione">
-										<h2 id="trascrizione_titolo">Trascrizione</h2>
+										<h2 id="trascrizione_titolo">Trascrizione fornita da Opera del Vocabolario Italiano</h2>
 									</div>
 									<div id="trascrizione_id"></div>
 									<div class="row align-items-center justify-content-end" id="row_evt">
 										<div id="evt_button" class="col-auto"></div>
-										<div class="col-auto">
+										<!--<div class="col-auto">
 											<button title="Naviga il grafo" type="button" class="btn btn-secondary" onclick="loadPageLOD()">Apri LodLive</button>
-										</div>
+										</div>-->
 									</div>
 
 									<div class="row" id="row_pl">

+ 4 - 1
ricerca_avanzata.html

@@ -81,8 +81,8 @@
 					<p>Questa è l'interfaccia per la ricerca avanzata, dedicata a coloro i quali hanno già familiarità con i dataset del progetto e desiderano cercare una risorsa specifica. 
 						Per utilizzare al meglio la ricerca avanzata:
 						<ul>
+							<li><b>Seleziona la categoria della risorsa che stai cercando</b> (in caso contrario la ricerca non verrà eseguita)</li>
 							<li>Compila sempre almeno un parametro</li>
-							<li>Per restringere i parametri tra cui scegliere seleziona una categoria di risorsa dall'apposito menù a tendina</li>
 							<li>Per selezionare le risorse in base alla fonte originale seleziona una collezione dall'apposito menù a tendina</li>
 						</ul>
 						La ricerca avanzata simula un costruttore di query. Si può selezionare un numero a scelta di parametri, allo stesso 
@@ -195,6 +195,9 @@
 							<div id="query_results"></div>
 						</div>
 					</div>
+					<div id="btn_dowload">
+						<button onclick="download_table_as_csv();" class="btn btn-outline-dark"><i class="fa fa-download"></i> Download</button>
+					</div>
 				</div>
 			</div>
 		</section>