Browse Source

New array for context request

Alessia 1 year ago
parent
commit
ff10c8b6bb
2 changed files with 34 additions and 6 deletions
  1. 1 0
      site2/index.html
  2. 33 6
      site2/js/ricerca.js

+ 1 - 0
site2/index.html

@@ -142,6 +142,7 @@
 
       <span id="params"></span><br />
       <div id="result"></div>
+      <button id="lauchSearchContext" class="btn btn-primary" onclick="checkContext()">Vai ai contesti</button>
 
    </div>
 

+ 33 - 6
site2/js/ricerca.js

@@ -12,7 +12,7 @@ function getData(queryDTO){
     return $.post(url,  {stringifiedDTO: JSON.stringify(queryDTO)});
 }
 
-
+let arrayResponse = [];
 // Separate function to handle response data -- could be moved to different file (a service)
 function processData(response){
     console.log(response)
@@ -20,16 +20,18 @@ function processData(response){
         alert('No results!')
     }
     else {
+      arrayResponse = response;
       var ll = response.length;
       for (var i=0; i<ll; i++) {
         let newRow = response[i];
         createRow(i, newRow);
       }
-      //$("#result").html(response.join('<br/>'));
     }
     //$("#result").append(response);
 }
 
+let queryDTO = {};
+
 function funzioneRicerca(){
   $("#result").html("");
   let collection_elementoDaRicercare = document.getElementsByClassName("barraDiRicerca");
@@ -62,6 +64,7 @@ function funzioneRicerca(){
     {
       formeLemmi = 1;
     }
+    
 
     if ((check_tipo == "forma") && (formeLemmi == 0)) {
       tipo = "forma";
@@ -93,10 +96,8 @@ function funzioneRicerca(){
   let cooccorrenze = {"distanza": distanza, "stesso_periodo": periodo, "ordinate": ordinate};
 
 
-
-  //
   // DTO: 'Data Transfer Object'
-  let queryDTO = {
+  queryDTO = {
       queryList: queryList,
       cooccorrenze: cooccorrenze
   }
@@ -109,6 +110,31 @@ function funzioneRicerca(){
   
 } 
 
+function checkContext() {
+  let resulTable = document.getElementById("result");
+  const checkBoxes = resulTable.querySelectorAll('input[type="checkbox"]');
+
+  var selected = [];
+  $('#result input:checked').each(function() {
+      //selected.push($(this).attr('id'));
+      var checkNum = $(this).attr('id');
+      selected.push(checkNum);
+  });
+
+  for (var i=0; i<arrayResponse.length; i++) {
+    for (var j=0; j<selected.length; j++) {
+      if (arrayResponse[i]["cod"] == selected[j]) {
+        arrayResponse[i]["selected"] = true;
+      }
+    }
+  }
+
+  queryDTO["listResults"] = arrayResponse; 
+
+  //INSERIRE QUI LA CHIAMATA PER LA RICERCA DEI CONTESTI (SENZA COOCCORRENZE)
+  console.log(queryDTO);
+}
+
 
 $( document ).ready(function() {
   $("select").on("change", function(event) {
@@ -158,6 +184,7 @@ function createRow(num, elem) {
   var forma = elem["forma"];
   var lemma = elem["lemma"];
   var occ = elem["occ"];
+  var cod = elem["cod"];
 
   var row = document.createElement('div');
   row.className = "row height d-flex justify-content-center align-items-center";
@@ -192,7 +219,7 @@ function createRow(num, elem) {
   colSel.className = "col seleziona_elemento";
   var inputSel = document.createElement('input');
   inputSel.className = "form-check-selected";
-  inputSel.id = "seleziona_" + num;
+  inputSel.id = cod;
   inputSel.type = "checkbox";
   colSel.append(inputSel);
   row.append(colSel);