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