Skip to content

Commit

Permalink
refactor: update species settings input handling and prediction logic
Browse files Browse the repository at this point in the history
- Replaced 'allSpecies' with 'allowedSpecies' to filter species based on prepared settings.
- Simplified the 'updatePredictions' method to utilize 'allowedSpecies' for generating predictions.
- Updated input fields to use a unified datalist for species suggestions, enhancing user experience.
- Removed unnecessary parameters from the prediction update function, streamlining the code.
  • Loading branch information
tphakala committed Jan 8, 2025
1 parent ce400bf commit 02cf0fe
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions views/settings/speciesSettings.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
editValue: '',
showTooltip: null,
hasChanges: false,
allSpecies: {{.AllSpecies | toJSON}},
filteredSpecies: [],
predictions: [],
allowedSpecies: {{.PreparedSpecies | toJSON}},
speciesSettingsOpen: false,
showActionsModal: false,
currentSpecies: '',
Expand Down Expand Up @@ -75,17 +75,15 @@
this.hasChanges = true;
this.closeActionsModal();
},
updatePredictions(input, list) {
if (!input) {
this.filteredSpecies = [];
updatePredictions(input) {
if (!input || !this.allowedSpecies) {
this.predictions = [];
return;
}
const currentList = this.speciesSettings[list] || [];
this.filteredSpecies = this.allSpecies
this.predictions = this.allowedSpecies
.filter(species =>
species.toLowerCase().includes(input.toLowerCase()) &&
!currentList.includes(species)
species.toLowerCase().includes(input.toLowerCase())
)
.slice(0, 5);
},
Expand Down Expand Up @@ -139,12 +137,12 @@
<div class="flex items-center mt-2">
<input type="text"
x-model="newIncludeSpecies"
@input="updatePredictions(newIncludeSpecies, 'Include')"
list="include-species-suggestions"
@input="updatePredictions(newIncludeSpecies)"
list="species-suggestions"
placeholder="Add species to include"
class="input input-bordered input-sm w-full" />
<datalist id="include-species-suggestions">
<template x-for="species in filteredSpecies" :key="species">
<datalist id="species-suggestions">
<template x-for="species in predictions" :key="species">
<option :value="species"></option>
</template>
</datalist>
Expand Down Expand Up @@ -184,12 +182,12 @@
<div class="flex items-center mt-2">
<input type="text"
x-model="newExcludeSpecies"
@input="updatePredictions(newExcludeSpecies, 'Exclude')"
list="exclude-species-suggestions"
@input="updatePredictions(newExcludeSpecies)"
list="species-suggestions"
placeholder="Add species to exclude"
class="input input-bordered input-sm w-full" />
<datalist id="exclude-species-suggestions">
<template x-for="species in filteredSpecies" :key="species">
<datalist id="species-suggestions">
<template x-for="species in predictions" :key="species">
<option :value="species"></option>
</template>
</datalist>
Expand Down Expand Up @@ -241,12 +239,12 @@
<div class="flex items-center mt-2">
<input type="text"
x-model="newThresholdSpecies"
@input="updatePredictions(newThresholdSpecies, 'Thresholds')"
list="threshold-species-suggestions"
@input="updatePredictions(newThresholdSpecies)"
list="species-suggestions"
placeholder="Species"
class="input input-bordered input-sm flex-grow" />
<datalist id="threshold-species-suggestions">
<template x-for="species in filteredSpecies" :key="species">
<datalist id="species-suggestions">
<template x-for="species in predictions" :key="species">
<option :value="species"></option>
</template>
</datalist>
Expand Down

0 comments on commit 02cf0fe

Please sign in to comment.