Skip to content

Commit

Permalink
Merge pull request #218 from Shrutihindocha/main
Browse files Browse the repository at this point in the history
scientific name filtering for flora/fauna occurrence dashboard
  • Loading branch information
xzzy authored Feb 9, 2024
2 parents 6287f14 + d3132e0 commit 2aab1b7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion boranga/components/occurrence/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def filter_queryset(self, request, queryset, view):

filter_scientific_name = request.GET.get('filter_scientific_name')
if filter_scientific_name and not filter_scientific_name.lower() == 'all':
queryset = queryset.filter(species__taxonomy__scientific_name=filter_scientific_name)
queryset = queryset.filter(species__taxonomy__id=filter_scientific_name)

filter_status = request.GET.get('filter_status')
if filter_status and not filter_status.lower() == 'all':
Expand Down
10 changes: 10 additions & 0 deletions boranga/components/species_and_communities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ def get(self, request, format=None):
return Response({"results": data_transform})
return Response()

class GetScientificNameByGroup(views.APIView):
def get(self, request, format=None):
search_term = request.GET.get('term', '')
if search_term:
group_type_id = request.GET.get('group_type_id', '')
queryset = Taxonomy.objects.values_list('scientific_name', flat=True)
queryset = queryset.filter(scientific_name__icontains=search_term, kingdom_fk__grouptype=group_type_id).distinct().values('id', 'scientific_name')[:10]
queryset = [{'id': taxon['id'], 'text': taxon['scientific_name']} for taxon in queryset]
return Response({"results": queryset})

class GetCommonName(views.APIView):
def get(self, request, format=None):
group_type_id = request.GET.get('group_type_id', '')
Expand Down
1 change: 1 addition & 0 deletions boranga/frontend/boranga/src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ module.exports = {
species_lookup:"/api/species_lookup",
communities_lookup:"/api/communities_lookup",
scientific_name_lookup:"/api/scientific_name_lookup",
scientific_name_lookup_by_groupname:"/api/scientific_name_lookup_by_groupname",
//taxon_name_lookup:"/api/taxon_name_lookup",
common_name_lookup:"/api/common_name_lookup",
family_lookup:"/api/family_lookup",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
</div>
</div>
<div class="col-md-4">
<div class="form-group" id="select_scientific_name">
<label for="or_scientific_name_lookup">Scientific Name:</label>
<div class="form-group" id="select_scientific_name_by_groupname">
<label for="or_scientific_name_lookup_by_groupname">Scientific Name:</label>
<select
id="or_scientific_name_lookup"
name="or_scientific_name_lookup"
ref="or_scientific_name_lookup"
id="or_scientific_name_lookup_by_groupname"
name="or_scientific_name_lookup_by_groupname"
ref="or_scientific_name_lookup_by_groupname"
class="form-control" />
</div>
</div>
Expand Down Expand Up @@ -480,7 +480,7 @@ export default {
"data": function ( d ) {
d.filter_group_type = vm.group_type_name;
d.filter_occurrence = vm.filterORFaunaOccurrence;
d.filter_species_scientific_name = vm.filterORFaunaScientificName;
d.filter_scientific_name = vm.filterORFaunaScientificName;
d.filter_submission_date_time = vm.filterORFaunaSubmissionDateTime;
d.filter_submitted_from_date = vm.filterORFaunaSubmittedFromDate;
d.filter_submitted_to_date = vm.filterORFaunaSubmittedToDate;
Expand Down Expand Up @@ -545,14 +545,14 @@ export default {
},
initialiseScientificNameLookup: function(){
let vm = this;
$(vm.$refs.or_scientific_name_lookup).select2({
$(vm.$refs.or_scientific_name_lookup_by_groupname).select2({
minimumInputLength: 2,
dropdownParent: $("#select_scientific_name"),
dropdownParent: $("#select_scientific_name_by_groupname"),
theme: 'bootstrap-5',
allowClear: true,
placeholder:"Select Scientific Name",
ajax: {
url: api_endpoints.scientific_name_lookup,
url: api_endpoints.scientific_name_lookup_by_groupname,
dataType: 'json',
data: function(params) {
var query = {
Expand All @@ -576,7 +576,7 @@ export default {
sessionStorage.setItem("filterORFaunaScientificNameText",'');
}).
on("select2:open",function (e) {
const searchField = $('[aria-controls="select2-or_scientific_name_lookup-results"]')
const searchField = $('[aria-controls="select2-or_scientific_name_lookup_by_groupname-results"]')
searchField[0].focus();
});
},
Expand Down Expand Up @@ -906,7 +906,7 @@ export default {
{
// contructor new Option(text, value, defaultSelected, selected)
var newOption = new Option(sessionStorage.getItem("filterORFaunaScientificNameText"), vm.filterORFaunaScientificName, false, true);
$('#or_scientific_name_lookup').append(newOption);
$('#or_scientific_name_lookup_by_groupname').append(newOption);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
</div>
</div>
<div class="col-md-4">
<div class="form-group" id="select_scientific_name">
<label for="or_scientific_name_lookup">Scientific Name:</label>
<div class="form-group" id="select_scientific_name_by_groupname">
<label for="or_scientific_name_lookup_by_groupname">Scientific Name:</label>
<select
id="or_scientific_name_lookup"
name="or_scientific_name_lookup"
ref="or_scientific_name_lookup"
id="or_scientific_name_lookup_by_groupname"
name="or_scientific_name_lookup_by_groupname"
ref="or_scientific_name_lookup_by_groupname"
class="form-control" />
</div>
</div>
Expand Down Expand Up @@ -479,7 +479,7 @@ export default {
"data": function ( d ) {
d.filter_group_type = vm.group_type_name;
d.filter_occurrence = vm.filterORFloraOccurrence;
d.filter_species_scientific_name = vm.filterORFloraScientificName;
d.filter_scientific_name = vm.filterORFloraScientificName;
d.filter_status = vm.filterORFloraStatus;
d.filter_submitted_from_date = vm.filterORFloraSubmittedFromDate;
d.filter_submitted_to_date = vm.filterORFloraSubmittedToDate;
Expand Down Expand Up @@ -544,14 +544,14 @@ export default {
},
initialiseScientificNameLookup: function(){
let vm = this;
$(vm.$refs.or_scientific_name_lookup).select2({
$(vm.$refs.or_scientific_name_lookup_by_groupname).select2({
minimumInputLength: 2,
dropdownParent: $("#select_scientific_name"),
dropdownParent: $("#select_scientific_name_by_groupname"),
theme: 'bootstrap-5',
allowClear: true,
placeholder:"Select Scientific Name",
ajax: {
url: api_endpoints.scientific_name_lookup,
url: api_endpoints.scientific_name_lookup_by_groupname,
dataType: 'json',
data: function(params) {
var query = {
Expand All @@ -575,7 +575,7 @@ export default {
sessionStorage.setItem("filterORFloraScientificNameText",'');
}).
on("select2:open",function (e) {
const searchField = $('[aria-controls="select2-or_scientific_name_lookup-results"]')
const searchField = $('[aria-controls="select2-or_scientific_name_lookup_by_groupname-results"]')
searchField[0].focus();
});
},
Expand Down Expand Up @@ -905,7 +905,7 @@ export default {
{
// contructor new Option(text, value, defaultSelected, selected)
var newOption = new Option(sessionStorage.getItem("filterORFloraScientificNameText"), vm.filterORFloraScientificName, false, true);
$('#or_scientific_name_lookup').append(newOption);
$('#or_scientific_name_lookup_by_groupname').append(newOption);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions boranga/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
url(r'^api/species_lookup$', species_communities_api.GetSpecies.as_view(), name='get-species'),
url(r'^api/communities_lookup$', species_communities_api.GetCommunities.as_view(), name='get-communities'),
url(r'^api/scientific_name_lookup$', species_communities_api.GetScientificName.as_view(), name='get-scientific-name'),
url(r'^api/scientific_name_lookup_by_groupname$', species_communities_api.GetScientificNameByGroup.as_view(), name='get-scientific-name-by-groupname'),
url(r'^api/common_name_lookup$', species_communities_api.GetCommonName.as_view(), name='get-common-name'),
url(r'^api/family_lookup$', species_communities_api.GetFamily.as_view(), name='get-family'),
url(r'^api/genera_lookup$', species_communities_api.GetGenera.as_view(), name='get-genera'),
Expand Down

0 comments on commit 2aab1b7

Please sign in to comment.