Skip to content

Commit

Permalink
Merge pull request #137 from nossas/fix/map-search-code
Browse files Browse the repository at this point in the history
Fix: Adiciona filter e comparação para código + título no Mapa
  • Loading branch information
miguelzinh3 authored Oct 23, 2023
2 parents 0f3ec25 + 04161d1 commit 790acb5
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions app/contrib/frontend/maps/static/maps/js/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,32 @@ if (mapWrapper) {
const api = mapWrapper.dataset.mapsGeojson;
return new Promise((resolve) => {
fetch(api)
.then((response) => response.json())
.then((data) => {
const result = data.features
.sort((a, b) =>
a.properties.title.localeCompare(b.properties.title)
)
.filter((element) => {
return element.properties.title.match(
.then((response) => response.json())
.then((data) => {
const result = data.features
.filter((element) => {
const lnCodigoMatch = element.properties.ln_codigo.toString().match(
new RegExp(currentValue, "gi")
);
const titleMatch = element.properties.title.match(
new RegExp(currentValue, "gi")
);
});
resolve(result);
})
.catch((error) => console.error(error));
);
return titleMatch || lnCodigoMatch;
})
.sort((a, b) => {
const aCombination = `${a.properties.ln_codigo} - ${a.properties.title}`;
const bCombination = `${b.properties.ln_codigo} - ${b.properties.title}`;

return aCombination.localeCompare(bCombination);
});
resolve(result);
})
.catch((error) => console.error(error))
});
},

onResults: ({ matches, template }) =>
matches === 0 ? template : matches.map((el) => `<li><div class="title">${el.properties.title}</div></li>`).join(""),
matches === 0 ? template : matches.map((el) => `<li><div class="title">${el.properties.ln_codigo} - ${el.properties.title}</div></li>`).join(""),

onSubmit: ({ object }) => {
const coordinates = object.geometry.coordinates;
Expand Down

0 comments on commit 790acb5

Please sign in to comment.