Bläddra i källkod

Update advanced search

Alessia 2 år sedan
förälder
incheckning
9e7c57b44c
1 ändrade filer med 86 tillägg och 54 borttagningar
  1. 86 54
      js/advanced_search.js

+ 86 - 54
js/advanced_search.js

@@ -1,5 +1,5 @@
 const choiceArray = [
-	["Nome risorsa", "Object, OA, Person, Letter, Place", "label"],
+	["Nome risorsa", "Object, OA", "label"],
 	["Identificatore", "Object, OA, Person, Letter, Place", "identifier"], 
 	["Materia", "Object, OA", "material"],
 	["Istituto di conservazione", "Object, OA", "localization"],
@@ -26,9 +26,9 @@ const choiceArray = [
 	["Lingua", "Letter", "language"],
 	["Area linguistica", "Letter", "languageArea"],
 	["Edizione", "Letter", "edition"],
-	["Antroponimo", "Letter", "antroponym"],
-	["Toponimo", "Letter", "toponym"],
-	["Data", "Object, OA", "date"]
+	["Data", "Object", "date"],
+	["Lemma", "Letter", "lemma"],
+	["Testo libero", "Letter", "keyword"]
 	];
 
 const typeArray = [
@@ -154,22 +154,61 @@ function populateOptions(selector, myArray) {
 		}
 
 	$('#' + selector).on( "change", function() {
-		
-		var numberId= selector.split("-")[1]
+		var numberId= selector.split("-")[1];
 		var inputText=  $( this ).find(":selected").text();
+		var inp = "";
+		if (inputText == "Genere") {
+			inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
+			<option>F</option> \
+			<option>M</option> \
+			</select>';
+		} else if (inputText == "Materia"){
+			inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
+			<option>Pittura a tempera</option> \
+			<option>Tavola</option> \
+			<option>Stucco</option> \
+			<option>Rame</option> \
+			<option>Carta</option> \
+			<option>Tela</option> \
+			</select>';
+		} else if (inputText == "Tecnica"){
+			inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
+			<option>Pittura</option> \
+			<option>Doratura</option> \
+			</select>';
+		} else if (inputText == "Tipo di risorsa"){
+			inp = '<select class="advanced-form-select form-control" id="inputchoiceSelector_'+ numberId +'"> \
+			<option>Documento</option> \
+			<option>Carteggio</option> \
+			<option>Lettera</option> \
+			<option>Libro</option> \
+			<option>Documenti diversi</option> \
+			</select>';
+		} else if (inputText == "Data") {
+			inp = '<div id="inputchoiceSelector_'+ numberId +'"><input type="date" id="start" value="1300-01-01"><input type="date" id="end" value="1300-12-31">';
+		}else {
+			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">';
+		
+		}
+		var sect = 'sect-' + String(numberId);
+		var inDiv = document.getElementById(sect);
+		inDiv.innerHTML = inp;
+		
+		
 		/*$('#inputchoiceSelector_' +  numberId).val(inputText);
 		$('#inputchoiceSelector_' +  numberId).id(inputText);*/
 	});
 }
 
+
+
 var val = 0;
 
 function addToList() {
 	val = val+1;
 	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"> \
 			  <option selected value="0">Scegli un\'opzione</option> \
-			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
-			</select></div></div>';
+			</select><div id="sect-' + val + '"></div></div></div>';
 	$('#drop-down-content').append(sel);
 	var selector = 'choice_selector-' + val;
 	populateOptions(selector, choiceArray);
@@ -179,8 +218,7 @@ function addToListObject() {
 	val = val+100;
 	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"> \
 			  <option selected value="0">Scegli un\'opzione</option> \
-			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
-			</select></div></div>';
+			  </select><div id="sect-' + val + '"></div></div></div>';
 	$('#drop-down-content-Object').append(sel);
 	var selector = 'choice_selector-' + val;
 	populateOptions(selector, objectArray);
@@ -190,8 +228,7 @@ function addToListOA() {
 	val = val+200;
 	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"> \
 			  <option selected value="0">Scegli un\'opzione</option> \
-			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
-			</select></div></div>';
+			  </select><div id="sect-' + val + '"></div></div></div>';
 	$('#drop-down-content-OA').append(sel);
 	var selector = 'choice_selector-' + val;
 	populateOptions(selector, oaArray);
@@ -201,8 +238,7 @@ function addToListPerson() {
 	val = val+300;
 	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"> \
 			  <option selected value="0">Scegli un\'opzione</option> \
-			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
-			</select></div></div>';
+			  </select><div id="sect-' + val + '"></div></div></div>';
 	$('#drop-down-content-Person').append(sel);
 	var selector = 'choice_selector-' + val;
 	populateOptions(selector, personArray);
@@ -212,8 +248,7 @@ function addToListLetter() {
 	val = val+400;
 	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"> \
 			  <option selected value="0">Scegli un\'opzione</option> \
-			  <input type="text" id="inputchoiceSelector_'+ val +'" class="selected_option form-control" placeholder="Enter search terms" aria-label="Enter search terms" aria-describedby="button-addon2"> \
-			</select></div></div>';
+			  </select><div id="sect-' + val + '"></div></div></div>';
 	$('#drop-down-content-Letter').append(sel);
 	var selector = 'choice_selector-' + val;
 	populateOptions(selector, letterArray);
@@ -243,9 +278,13 @@ function getParameters() {
 			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);
+			if (!!document.getElementById(inputId)) {
+				var inputText = document.getElementById(inputId).value;
+				var el = [e, inputText];
+				console.log([inputText, el]);
+				arr.push(el);
+			}
+			
 		}
 		constructQuery(arr); 
 	}
@@ -291,6 +330,9 @@ function constructQuery(params) {
 		crm:P2_has_type 'Segnatura' .";
 	}
 	if (choosen_type == "Letter") {
+		search_type = "?subject crm:P128_carries ?information_object . \
+		?information_object crm:P2_has_type ?uri_letter . \
+		?uri_letter rdfs:label 'lettera' ."
 		search_identifier = "?subject crm:P1_is_identified_by ?uri_identifier . \
 		?uri_identifier rdfs:label ?identifier ; \
 		crm:P2_has_type 'Segnatura' .";
@@ -338,8 +380,8 @@ function constructQuery(params) {
 	var lingua = ""; //
 	var area_linguistica = ""; //
 	var edizione = ""; //
-	var antroponimo = ""; //
-	var toponimo = ""; //
+	var lemma = ""; //
+	var testo = ""; //
 	var data = ""; //
 	var letter_event = ""; //
 	var infObj = ""; //
@@ -375,8 +417,8 @@ function constructQuery(params) {
 	var lin = ""; //
 	var alin = ""; //
 	var ed = ""; //
-	var antr = ""; //
-	var topo = ""; //
+	var lem = ""; //
+	var ttx = ""; //
 	var dt = ""; //
 
 	for (let i = 0; i < params.length; i++) {
@@ -412,7 +454,7 @@ function constructQuery(params) {
 		if(params[i][0] == "Tecnica" && (params[i][1] != "")) {
 			tec = " ?technique";
 
-			tecnica = "?subject ?property ?event . \
+			tecnica = "?event ?pp ?subject . \
 			?event crm:P32_used_general_technique ?uri_technique . \
 			?uri_technique rdfs:label ?technique . \
 			?technique bif:contains \"\'"+ params[i][1] +"\'\" . "
@@ -624,8 +666,6 @@ function constructQuery(params) {
 		if (params[i][0] == "Lingua" && (params[i][1] != "")) {
 			lin = " ?lingua";
 
-			infObj = "?subject crm:P128_carries ?information_object .";
-
 			lingua = "?information_object crm:P72_has_language ?language . \
 			?language rdfs:label ?lingua . \
 			?lingua bif:contains \"\'"+ params[i][1] +"\'\" ."
@@ -633,8 +673,6 @@ function constructQuery(params) {
 		if (params[i][0] == "Area linguistica" && (params[i][1] != "")) {
 			alin = " ?area_linguistica";
 
-			infObj = "?subject crm:P128_carries ?information_object .";
-
 			area_linguistica = "?information_object crm:P72_has_language ?language . \
 			?language crm:P3_has_note ?area . \
 			?area rdfs:label ?area_linguistica .\
@@ -643,32 +681,23 @@ function constructQuery(params) {
 		if (params[i][0] == "Edizione" && (params[i][1] != "")) {
 			ed = " ?edizione";
 
-			infObj = "?subject crm:P128_carries ?information_object .";
-
 			edizione = "?edition crm:P70_documents ?information_object ; \
 			crm:P1_is_identified_by ?edition_id . \
 			?edition_id rdfs:label ?edizione . \
 			?edizione bif:contains \"\'"+ params[i][1] +"\'\" ."
 		}
-		if (params[i][0] == "Toponimo" && (params[i][1] != "")) {
-			topo = " ?toponimo";
-
-			infObj = "?subject crm:P128_carries ?information_object .";
+		if (params[i][0] == "Lemma" && (params[i][1] != "")) {
+			lem = " ?lemma";
 
-			toponimo = "?information_object crm:P67_refers_to ?link_toponimo . \
-			?link_toponimo rdfs:label ?toponimo ; \
-			crm:P2_has_type 'Toponimo' . \
-			?toponimo bif:contains \"\'"+ params[i][1] +"\'\" ."
+			lemma = "?information_object crm:P67_refers_to ?link_lemma . \
+			?link_lemma rdfs:label ?lemma. \
+			?lemma bif:contains \"\'"+ params[i][1] +"\'\" ."
 		}
-		if (params[i][0] == "Antroponimo" && (params[i][1] != "")) {
-			antr = " ?antroponimo";
+		if (params[i][0] == "Testo libero" && (params[i][1] != "")) {
+			ttx = " ?testo";
 
-			infObj = "?subject crm:P128_carries ?information_object .";
-
-			antroponimo = "?information_object crm:P67_refers_to ?link_antroponimo . \
-			?link_antroponimo rdfs:label ?antroponimo; \
-			crm:P2_has_type 'Antroponimo' . \
-			?antroponimo bif:contains \"\'"+ params[i][1] +"\'\" ."
+			testo = "?information_object crm:P190_has_symbolic_content ?testo . \
+			?testo bif:contains \"\'"+ params[i][1] +"\'\" ."
 		}
 		if (params[i][0] == "Data" && (params[i][1] != "")) {
 			dt = " ?date";
@@ -692,7 +721,7 @@ function constructQuery(params) {
 
 	query = prefixes + " SELECT DISTINCT ?subject ?label ?identifier " + dm + mt + locl + tec + at
 	+ sg + tt + tp + nt + rf + np + nf + pt + ln + lm + gr + dn + dts + oc + qf + ga + mit 
-	+ des + lp + la + dp + da + lin + alin + ed + antr + topo + dt + " \
+	+ des + lp + la + dp + da + lin + alin + ed + lem + dt + ttx + " \
 	WHERE {GRAPH " + search_graph + " {?subject ?property ?object } \
 	?subject rdfs:label ?label . " 
 	+ search_identifier + infObj + letter_event + label + search_type + dimensione + materia + localizzazione + tecnica 
@@ -700,7 +729,7 @@ function constructQuery(params) {
 	+ patronimico + luogo_di_Nascita + luogo_di_Morte + genere + data_di_Nascita 
 	+ data_di_Morte + qualifica + occupazione + gruppi_di_appartenenza + mittente + destinatario 
 	+luogo_di_Partenza + luogo_di_Arrivo + data_partenza + data_arrivo + lingua 
-	+ area_linguistica + edizione + toponimo + antroponimo + data + identificatore + "}"
+	+ area_linguistica + edizione + lemma + data + identificatore + testo + "}"
 
 	var query_url = 'http://dev.restore.ovi.cnr.it:8890/sparql/?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json';
 
@@ -895,13 +924,13 @@ function query_handle_json(json, choosen_type) {
 		          edizione = value['edizione']['value'];
 		          object += '<div class="col-auto">' + edizione + '</div>';
 		        }
-		        if (value.hasOwnProperty('toponimo')) {
-		          toponimo = value['toponimo']['value'];
-		          object += '<div class="col-auto">' + toponimo + '</div>';
+		        if (value.hasOwnProperty('lemma')) {
+		          lemma = value['lemma']['value'];
+		          object += '<div class="col-auto">' + lemma + '</div>';
 		        }
-		        if (value.hasOwnProperty('antroponimo')) {
-		          antroponimo = value['antroponimo']['value'];
-		          object += '<div class="col-auto">' + antroponimo + '</div>';
+		        if (value.hasOwnProperty('testo')) {
+		          testo = value['testo']['value'];
+		          object += '<div class="col-auto">' + testo + '</div>';
 		        }
 		        if (value.hasOwnProperty('date')) {
 		          date = value['date']['value'];
@@ -1051,6 +1080,9 @@ function renameCol(param) {
 	else if (param == "lemma") {
 		return ("Lemma");
 	}
+	else if (param == "testo") {
+		return ("Testo");
+	}
 	else if (param == "date") {
 		return ("Data");
 	}