Adjust search controller (WIP)
This commit is contained in:
@@ -38,8 +38,8 @@ export default class extends Controller {
|
||||
const results = await response.json();
|
||||
|
||||
this.containerTarget.classList.remove('is-hidden');
|
||||
if (results.count) {
|
||||
this.#injectResults(results);
|
||||
if (results.length) {
|
||||
// Reset zoom level after successful search
|
||||
map.setZoom(INIT_ZOOM);
|
||||
this.#filterMap(results);
|
||||
@@ -48,7 +48,7 @@ export default class extends Controller {
|
||||
|
||||
// Should technique always be shown after a search?
|
||||
for (const key of Object.keys(techsMarkers)) {
|
||||
for (const record of results) {
|
||||
for (const record of results.sites) {
|
||||
// Adjust for non-site records!!
|
||||
if (techsMarkers[key].options.site === record.label
|
||||
&& techsMarkers[key].options.label === body.technique)
|
||||
@@ -80,7 +80,9 @@ export default class extends Controller {
|
||||
const output = this.resultsTarget;
|
||||
output.innerHTML = '';
|
||||
|
||||
if (results.length === 0) {
|
||||
console.debug(results);
|
||||
|
||||
if (results.count === 0) {
|
||||
output.innerHTML = html`
|
||||
<p class="has-background-white-bis p-4 mt-0 has-text-centered">
|
||||
Nessun risultato trovato per i parametri di ricerca
|
||||
@@ -88,12 +90,24 @@ export default class extends Controller {
|
||||
`;
|
||||
}
|
||||
|
||||
const sites = GisState.markers.sites;
|
||||
delete results.count;
|
||||
|
||||
for (const result of results) {
|
||||
let coordinates = ''
|
||||
for (let key of Object.keys(sites)) {
|
||||
if (sites[key].options.data.label === result.label) {
|
||||
for (const group of Object.keys(results)) {
|
||||
if (results[group].length) this.#populateResults(group, results[group], output);
|
||||
}
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {string} group
|
||||
* @param {Array<Object>} resultGroup
|
||||
* @param {HTMLOutputElement} output
|
||||
*/
|
||||
#populateResults(group, resultGroup, output) {
|
||||
const markers = GisState.markers[group];
|
||||
for (const result of resultGroup) {
|
||||
let coordinates = '';
|
||||
for (let key of Object.keys(markers)) {
|
||||
if (markers[key].options.data.label === result.label) {
|
||||
coordinates = key;
|
||||
}
|
||||
}
|
||||
@@ -108,7 +122,7 @@ export default class extends Controller {
|
||||
data-action="marker#go"
|
||||
data-marker-zoom-param="17"
|
||||
data-marker-coords-value="${coordinates}"
|
||||
data-marker-group-value="sites">
|
||||
data-marker-group-value="${resultGroup}">
|
||||
Vai
|
||||
<span class="ml-1 icon">
|
||||
<i class="fa fa-chevron-right"></i>
|
||||
@@ -123,12 +137,12 @@ export default class extends Controller {
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {Array<Object>} results
|
||||
* @param {Object} results
|
||||
*/
|
||||
#filterMap(results) {
|
||||
const map = GisState.map;
|
||||
const labels = [];
|
||||
results.forEach(r => labels.push(r.label));
|
||||
results.sites.forEach(r => labels.push(r.label));
|
||||
|
||||
// Remove all layer groups first
|
||||
for (const key of Object.keys(GisState.layers)) {
|
||||
|
||||
Reference in New Issue
Block a user