From 27a4586e28a7c6ab8b8556c12c0a5d8577ffe2c1 Mon Sep 17 00:00:00 2001 From: Shruti Hindocha Date: Thu, 1 Feb 2024 16:23:22 +0800 Subject: [PATCH 1/3] fixed status fliter in occurrence dashboard for flora and fauna --- boranga/components/occurrence/api.py | 45 ++++++++++--------- .../occurrence_report_fauna_dashboard.vue | 9 +--- .../occurrence_report_flora_dashboard.vue | 10 +---- 3 files changed, 27 insertions(+), 37 deletions(-) diff --git a/boranga/components/occurrence/api.py b/boranga/components/occurrence/api.py index c7085734..b55ef339 100644 --- a/boranga/components/occurrence/api.py +++ b/boranga/components/occurrence/api.py @@ -112,28 +112,31 @@ class OccurrenceReportFilterBackend(DatatablesFilterBackend): def filter_queryset(self, request, queryset, view): total_count = queryset.count() - - flora = GroupType.GROUP_TYPE_FLORA - fauna = GroupType.GROUP_TYPE_FAUNA - community = GroupType.GROUP_TYPE_COMMUNITY filter_group_type = request.GET.get('filter_group_type') if filter_group_type and not filter_group_type.lower() == 'all': queryset = queryset.filter(group_type__name=filter_group_type) - - # filter_scientific_name is the species_id + + # To do - change group_type__name based on the relevant model + # filter_occurrence = request.GET.get('filter_occurrence') + # if filter_occurrence and not filter_occurrence.lower() == 'all': + # queryset = queryset.filter(group_type__name=filter_occurrence) + filter_scientific_name = request.GET.get('filter_scientific_name') if filter_scientific_name and not filter_scientific_name.lower() == 'all': - queryset = queryset.filter(species=filter_scientific_name) + queryset = queryset.filter(species__taxonomy__scientific_name=filter_scientific_name) - # filter_community_name is the community_id - filter_community_name = request.GET.get('filter_community_name') - if filter_community_name and not filter_community_name.lower() == 'all': - queryset = queryset.filter(community=filter_community_name) + filter_status = request.GET.get('filter_status') + if filter_status and not filter_status.lower() == 'all': + queryset = queryset.filter(processing_status=filter_status) - filter_application_status = request.GET.get('filter_application_status') - if filter_application_status and not filter_application_status.lower() == 'all': - queryset = queryset.filter(customer_status=filter_application_status) + filter_submitted_from = request.GET.get('filter_submitted_from') + if filter_submitted_from and not filter_submitted_from.lower() == 'all': + queryset = queryset.filter(submitter=filter_submitted_from) + + filter_submitted_to = request.GET.get('filter_submitted_to') + if filter_submitted_to and not filter_submitted_to.lower() == 'all': + queryset = queryset.filter(assigned_officer=filter_submitted_to) getter = request.query_params.get fields = self.get_fields(getter) @@ -193,14 +196,14 @@ def occurrence_report_external(self, request, *args, **kwargs): @list_route(methods=['GET',], detail=False) def occurrence_report_internal(self, request, *args, **kwargs): - qs = self.get_queryset() - qs = qs.filter(Q(internal_application=False)) - qs = self.filter_queryset(qs) + qs = self.get_queryset() + qs = qs.filter(Q(internal_application=False)) + qs = self.filter_queryset(qs) - self.paginator.page_size = qs.count() - result_page = self.paginator.paginate_queryset(qs, request) - serializer = ListInternalOccurrenceReportSerializer(result_page, context={'request': request}, many=True) - return self.paginator.get_paginated_response(serializer.data) + self.paginator.page_size = qs.count() + result_page = self.paginator.paginate_queryset(qs, request) + serializer = ListInternalOccurrenceReportSerializer(result_page, context={'request': request}, many=True) + return self.paginator.get_paginated_response(serializer.data) class OccurrenceReportViewSet(viewsets.ModelViewSet): queryset = OccurrenceReport.objects.none() diff --git a/boranga/frontend/boranga/src/components/common/occurrence_report_fauna_dashboard.vue b/boranga/frontend/boranga/src/components/common/occurrence_report_fauna_dashboard.vue index c8081e1b..97e11051 100644 --- a/boranga/frontend/boranga/src/components/common/occurrence_report_fauna_dashboard.vue +++ b/boranga/frontend/boranga/src/components/common/occurrence_report_fauna_dashboard.vue @@ -723,13 +723,6 @@ export default { },(error) => { console.log(error); }) - vm.$http.get(api_endpoints.region_district_filter_dict).then((response) => { - vm.filterRegionDistrict= response.body; - vm.region_list= vm.filterRegionDistrict.region_list; - vm.district_list= vm.filterRegionDistrict.district_list; - },(error) => { - console.log(error); - }) }, createFaunaOccurrenceReport: async function () { let newFaunaCSId = null @@ -920,7 +913,7 @@ export default { filter_scientific_name: vm.filterORFaunaScientificName, filter_status: vm.filterORFaunaStatus, filter_submitted_from: vm.filterORFaunaSubmittedFrom, - filter_submitted_from: vm.filterORFaunaSubmittedTo, + filter_submitted_to: vm.filterORFaunaSubmittedTo, is_internal: vm.is_internal, export_format: format }; diff --git a/boranga/frontend/boranga/src/components/common/occurrence_report_flora_dashboard.vue b/boranga/frontend/boranga/src/components/common/occurrence_report_flora_dashboard.vue index af3a56c9..ff058b26 100644 --- a/boranga/frontend/boranga/src/components/common/occurrence_report_flora_dashboard.vue +++ b/boranga/frontend/boranga/src/components/common/occurrence_report_flora_dashboard.vue @@ -485,6 +485,7 @@ export default { // adding extra GET params for Custom filtering "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_status = vm.filterORFloraStatus; @@ -722,13 +723,6 @@ export default { },(error) => { console.log(error); }) - vm.$http.get(api_endpoints.region_district_filter_dict).then((response) => { - vm.filterRegionDistrict= response.body; - vm.region_list= vm.filterRegionDistrict.region_list; - vm.district_list= vm.filterRegionDistrict.district_list; - },(error) => { - console.log(error); - }) }, createFloraOccurrenceReport: async function () { let newFloraCSId = null @@ -919,7 +913,7 @@ export default { filter_scientific_name: vm.filterORFloraScientificName, filter_status: vm.filterORFloraStatus, filter_submitted_from: vm.filterORFloraSubmittedFrom, - filter_submitted_from: vm.filterORFloraSubmittedTo, + filter_submitted_to: vm.filterORFloraSubmittedTo, is_internal: vm.is_internal, export_format: format }; From 47f6013972b3d93150fc6c7df648edb0e25127da Mon Sep 17 00:00:00 2001 From: Shruti Hindocha Date: Fri, 2 Feb 2024 15:48:24 +0800 Subject: [PATCH 2/3] submitted to and from date filters occurrence report dashboards --- boranga/components/occurrence/api.py | 23 ++- .../occurrence_report_fauna_dashboard.vue | 194 +++--------------- .../occurrence_report_flora_dashboard.vue | 193 +++-------------- 3 files changed, 65 insertions(+), 345 deletions(-) diff --git a/boranga/components/occurrence/api.py b/boranga/components/occurrence/api.py index b55ef339..fb2bfc25 100644 --- a/boranga/components/occurrence/api.py +++ b/boranga/components/occurrence/api.py @@ -9,7 +9,7 @@ from rest_framework.decorators import action as list_route from rest_framework.response import Response from rest_framework.renderers import JSONRenderer -from datetime import datetime +from datetime import datetime, time from ledger_api_client.settings_base import TIME_ZONE from boranga import settings from boranga import exceptions @@ -130,13 +130,22 @@ def filter_queryset(self, request, queryset, view): if filter_status and not filter_status.lower() == 'all': queryset = queryset.filter(processing_status=filter_status) - filter_submitted_from = request.GET.get('filter_submitted_from') - if filter_submitted_from and not filter_submitted_from.lower() == 'all': - queryset = queryset.filter(submitter=filter_submitted_from) + def get_date(filter_date): + date = request.GET.get(filter_date) + if date: + date = datetime.strptime(date,'%Y-%m-%d') + return date + + filter_submitted_from_date = get_date('filter_submitted_from_date') + filter_submitted_to_date = get_date('filter_submitted_to_date') + if filter_submitted_to_date: + filter_submitted_to_date = datetime.combine(filter_submitted_to_date , time.max) + + if filter_submitted_from_date and not filter_submitted_to_date: + queryset = queryset.filter(reported_date__gte=filter_submitted_from_date) - filter_submitted_to = request.GET.get('filter_submitted_to') - if filter_submitted_to and not filter_submitted_to.lower() == 'all': - queryset = queryset.filter(assigned_officer=filter_submitted_to) + if filter_submitted_from_date and filter_submitted_to_date: + queryset = queryset.filter(reported_date__range=[filter_submitted_from_date, filter_submitted_to_date]) getter = request.query_params.get fields = self.get_fields(getter) diff --git a/boranga/frontend/boranga/src/components/common/occurrence_report_fauna_dashboard.vue b/boranga/frontend/boranga/src/components/common/occurrence_report_fauna_dashboard.vue index 97e11051..c32e364e 100644 --- a/boranga/frontend/boranga/src/components/common/occurrence_report_fauna_dashboard.vue +++ b/boranga/frontend/boranga/src/components/common/occurrence_report_fauna_dashboard.vue @@ -32,23 +32,15 @@
-
- -
-
- -
@@ -136,15 +128,15 @@ export default { required: false, default: 'filterORFaunaStatus', }, - filterORFaunaSubmittedFrom_cache: { + filterORFaunaSubmittedFromDate_cache: { type: String, required: false, - default: 'filterORFaunaSubmittedFrom', + default: 'filterORFaunaSubmittedFromDate', }, - filterORFaunaSubmittedTo_cache: { + filterORFaunaSubmittedToDate_cache: { type: String, required: false, - default: 'filterORFaunaSubmittedTo', + default: 'filterORFaunaSubmittedToDate', }, }, @@ -167,11 +159,11 @@ export default { filterORFaunaStatus: sessionStorage.getItem(this.filterORFaunaStatus_cache) ? sessionStorage.getItem(this.filterORFaunaStatus_cache) : 'all', - filterORFaunaSubmittedFrom: sessionStorage.getItem(this.filterORFaunaSubmittedFrom_cache) ? - sessionStorage.getItem(this.filterORFaunaSubmittedFrom_cache) : 'all', + filterORFaunaSubmittedFromDate: sessionStorage.getItem(this.filterORFaunaSubmittedFromDate_cache) ? + sessionStorage.getItem(this.filterORFaunaSubmittedFromDate_cache) : '', - filterORFaunaSubmittedTo: sessionStorage.getItem(this.filterORFaunaSubmittedTo_cache) ? - sessionStorage.getItem(this.filterORFaunaSubmittedTo_cache) : 'all', + filterORFaunaSubmittedToDate: sessionStorage.getItem(this.filterORFaunaSubmittedToDate_cache) ? + sessionStorage.getItem(this.filterORFaunaSubmittedToDate_cache) : '', filterListsSpecies: {}, occurrence_list: [], @@ -236,15 +228,15 @@ export default { vm.$refs.fauna_or_datatable.vmDataTable.ajax.reload(helpers.enablePopovers,false); // This calls ajax() backend call. sessionStorage.setItem(vm.filterORFaunaStatus_cache, vm.filterORFaunaStatus); }, - filterORFaunaSubmittedFrom: function() { + filterORFaunaSubmittedFromDate: function() { let vm = this; vm.$refs.fauna_or_datatable.vmDataTable.ajax.reload(helpers.enablePopovers,false); // This calls ajax() backend call. - sessionStorage.setItem(vm.filterORFaunaSubmittedFrom_cache, vm.filterORFaunaSubmittedFrom); + sessionStorage.setItem(vm.filterORFaunaSubmittedFromDate_cache, vm.filterORFaunaSubmittedFromDate); }, - filterORFaunaSubmittedTo: function() { + filterORFaunaSubmittedToDate: function() { let vm = this; vm.$refs.fauna_or_datatable.vmDataTable.ajax.reload(helpers.enablePopovers,false); // This calls ajax() backend call. - sessionStorage.setItem(vm.filterORFaunaSubmittedTo_cache, vm.filterORFaunaSubmittedTo); + sessionStorage.setItem(vm.filterORFaunaSubmittedToDate_cache, vm.filterORFaunaSubmittedToDate); }, filterApplied: function(){ if (this.$refs.collapsible_filters){ @@ -258,8 +250,8 @@ export default { if(this.filterORFaunaOccurrence === 'all' && this.filterORFaunaScientificName === 'all' && this.filterORFaunaStatus === 'all' && - this.filterORFaunaSubmittedFrom === 'all' && - this.filterORFaunaSubmittedTo === 'all'){ + this.filterORFaunaSubmittedFromDate === '' && + this.filterORFaunaSubmittedToDate === ''){ return false } else { return true @@ -374,6 +366,7 @@ export default { name: "processing_status_display", } }, + // TODO update this to suit the design column_action: function(){ let vm = this return { @@ -489,8 +482,8 @@ export default { d.filter_occurrence = vm.filterORFaunaOccurrence; d.filter_species_scientific_name = vm.filterORFaunaScientificName; d.filter_submission_date_time = vm.filterORFaunaSubmissionDateTime; - d.filter_submitted_from = vm.filterORFaunaSubmittedFrom; - d.filter_submitted_to = vm.filterORFaunaSubmittedTo; + d.filter_submitted_from_date = vm.filterORFaunaSubmittedFromDate; + d.filter_submitted_to_date = vm.filterORFaunaSubmittedToDate; d.is_internal = vm.is_internal; } }, @@ -587,122 +580,6 @@ export default { searchField[0].focus(); }); }, - // initialiseStatusLookup: function(){ - // let vm = this; - // $(vm.$refs.or_status_lookup).select2({ - // minimumInputLength: 2, - // dropdownParent: $("#select_status"), - // "theme": "bootstrap-5", - // allowClear: true, - // placeholder:"Select Status", - // ajax: { - // url: api_endpoints.or_status_lookup, - // dataType: 'json', - // data: function(params) { - // var query = { - // term: params.term, - // type: 'public', - // group_type_id: vm.group_type_id, - // } - // return query; - // }, - // }, - // }). - // on("select2:select", function (e) { - // var selected = $(e.currentTarget); - // let data = e.params.data.id; - // vm.filterORFaunaStatus = data; - // sessionStorage.setItem("filterORFaunaStatusText", e.params.data.text); - // }). - // on("select2:unselect",function (e) { - // var selected = $(e.currentTarget); - // vm.filterORFaunaStatus = 'all'; - // sessionStorage.setItem("filterORFaunaStatusText",''); - // }). - // on("select2:open",function (e) { - // const searchField = $('[aria-controls="select2-or_status_lookup-results"]') - // // move focus to select2 field - // searchField[0].focus(); - // }); - // }, - initialiseSubmittedFromLookup: function(){ - let vm = this; - $(vm.$refs.or_submitted_from_lookup).select2({ - minimumInputLength: 2, - dropdownParent: $("#select_submitted_from"), - "theme": "bootstrap-5", - allowClear: true, - placeholder:"Select Submitted From", - ajax: { - url: api_endpoints.or_submitted_from_lookup, - dataType: 'json', - data: function(params) { - var query = { - term: params.term, - type: 'public', - group_type_id: vm.group_type_id, - } - return query; - }, - }, - }). - on("select2:select", function (e) { - var selected = $(e.currentTarget); - let data = e.params.data.id; - vm.filterORFaunaSubmittedFrom = data; - sessionStorage.setItem("filterORFaunaSubmittedFromText", e.params.data.text); - }). - on("select2:unselect",function (e) { - var selected = $(e.currentTarget); - vm.filterORFaunaSubmittedFrom = 'all'; - sessionStorage.setItem("filterORFaunaSubmittedFromText",''); - }). - on("select2:open",function (e) { - //const searchField = $(".select2-search__field") - const searchField = $('[aria-controls="select2-or_submitted_from_lookup-results"]') - // move focus to select2 field - searchField[0].focus(); - }); - }, - initialiseSubmittedToLookup: function(){ - let vm = this; - $(vm.$refs.or_submitted_to_lookup).select2({ - minimumInputLength: 2, - dropdownParent: $("#select_submitted_to"), - "theme": "bootstrap-5", - allowClear: true, - placeholder:"Select Submitted To", - ajax: { - url: api_endpoints.genera_lookup, - dataType: 'json', - data: function(params) { - var query = { - term: params.term, - type: 'public', - group_type_id: vm.group_type_id, - } - return query; - }, - }, - }). - on("select2:select", function (e) { - var selected = $(e.currentTarget); - let data = e.params.data.id; - vm.filterORFaunaSubmittedTo = data; - sessionStorage.setItem("filterORFaunaSubmittedToText", e.params.data.text); - }). - on("select2:unselect",function (e) { - var selected = $(e.currentTarget); - vm.filterORFaunaSubmittedTo = 'all'; - sessionStorage.setItem("filterORFaunaSubmittedToText",''); - }). - on("select2:open",function (e) { - //const searchField = $(".select2-search__field") - const searchField = $('[aria-controls="select2-or_submitted_to_lookup-results"]') - // move focus to select2 field - searchField[0].focus(); - }); - }, fetchFilterLists: function(){ let vm = this; //large FilterList of Species Values object @@ -912,8 +789,8 @@ export default { filter_occurrence: vm.filterORFaunaOccurrence, filter_scientific_name: vm.filterORFaunaScientificName, filter_status: vm.filterORFaunaStatus, - filter_submitted_from: vm.filterORFaunaSubmittedFrom, - filter_submitted_to: vm.filterORFaunaSubmittedTo, + filter_submitted_from_date: vm.filterORFaunaSubmittedFromDate, + filter_submitted_to_date: vm.filterORFaunaSubmittedToDate, is_internal: vm.is_internal, export_format: format }; @@ -1014,9 +891,6 @@ export default { this.$nextTick(() => { vm.initialiseOccurrenceLookup(); vm.initialiseScientificNameLookup(); - vm.initialiseStatusLookup(); - vm.initialiseSubmittedFromLookup(); - vm.initialiseSubmittedToLookup(); //vm.initialiseSearch(); vm.addEventListeners(); @@ -1034,24 +908,6 @@ export default { var newOption = new Option(sessionStorage.getItem("filterORFaunaScientificNameText"), vm.filterORFaunaScientificName, false, true); $('#or_scientific_name_lookup').append(newOption); } - // if(sessionStorage.getItem("filterORFaunaSubmissionDateTime")!='all' && sessionStorage.getItem("filterORFaunaSubmissionDateTime")!=null) - // { - // // contructor new Option(text, value, defaultSelected, selected) - // var newOption = new Option(sessionStorage.getItem("filterORFaunaSubmissionDateTimeText"), vm.filterORFaunaSubmissionDateTime, false, true); - // $('#or_status_lookup').append(newOption); - // } - if(sessionStorage.getItem("filterORFaunaSubmittedFrom")!='all' && sessionStorage.getItem("filterORFaunaSubmittedFrom")!=null) - { - // contructor new Option(text, value, defaultSelected, selected) - var newOption = new Option(sessionStorage.getItem("filterORFaunaSubmittedFromText"), vm.filterORFaunaSubmittedFrom, false, true); - $('#or_submitted_from_lookup').append(newOption); - } - if(sessionStorage.getItem("filterORFaunaSubmittedTo")!='all' && sessionStorage.getItem("filterORFaunaSubmittedTo")!=null) - { - // contructor new Option(text, value, defaultSelected, selected) - var newOption = new Option(sessionStorage.getItem("filterORFaunaSubmittedToText"), vm.filterORFaunaSubmittedTo, false, true); - $('#or_submitted_to_lookup').append(newOption); - } }); } } diff --git a/boranga/frontend/boranga/src/components/common/occurrence_report_flora_dashboard.vue b/boranga/frontend/boranga/src/components/common/occurrence_report_flora_dashboard.vue index ff058b26..7bc6cb70 100644 --- a/boranga/frontend/boranga/src/components/common/occurrence_report_flora_dashboard.vue +++ b/boranga/frontend/boranga/src/components/common/occurrence_report_flora_dashboard.vue @@ -32,23 +32,15 @@
-
- -
-
- -
@@ -136,15 +128,15 @@ export default { required: false, default: 'filterORFloraStatus', }, - filterORFloraSubmittedFrom_cache: { + filterORFloraSubmittedFromDate_cache: { type: String, required: false, - default: 'filterORFloraSubmittedFrom', + default: 'filterORFloraSubmittedFromDate', }, - filterORFloraSubmittedTo_cache: { + filterORFloraSubmittedToDate_cache: { type: String, required: false, - default: 'filterORFloraSubmittedTo', + default: 'filterORFloraSubmittedToDate', }, }, @@ -167,11 +159,11 @@ export default { filterORFloraStatus: sessionStorage.getItem(this.filterORFloraStatus_cache) ? sessionStorage.getItem(this.filterORFloraStatus_cache) : 'all', - filterORFloraSubmittedFrom: sessionStorage.getItem(this.filterORFloraSubmittedFrom_cache) ? - sessionStorage.getItem(this.filterORFloraSubmittedFrom_cache) : 'all', + filterORFloraSubmittedFromDate: sessionStorage.getItem(this.filterORFloraSubmittedFromDate_cache) ? + sessionStorage.getItem(this.filterORFloraSubmittedFromDate_cache) : '', - filterORFloraSubmittedTo: sessionStorage.getItem(this.filterORFloraSubmittedTo_cache) ? - sessionStorage.getItem(this.filterORFloraSubmittedTo_cache) : 'all', + filterORFloraSubmittedToDate: sessionStorage.getItem(this.filterORFloraSubmittedToDate_cache) ? + sessionStorage.getItem(this.filterORFloraSubmittedToDate_cache) : '', filterListsSpecies: {}, occurrence_list: [], @@ -236,15 +228,15 @@ export default { vm.$refs.flora_or_datatable.vmDataTable.ajax.reload(helpers.enablePopovers,false); // This calls ajax() backend call. sessionStorage.setItem(vm.filterORFloraStatus_cache, vm.filterORFloraStatus); }, - filterORFloraSubmittedFrom: function() { + filterORFloraSubmittedFromDate: function() { let vm = this; vm.$refs.flora_or_datatable.vmDataTable.ajax.reload(helpers.enablePopovers,false); // This calls ajax() backend call. - sessionStorage.setItem(vm.filterORFloraSubmittedFrom_cache, vm.filterORFloraSubmittedFrom); + sessionStorage.setItem(vm.filterORFloraSubmittedFromDate_cache, vm.filterORFloraSubmittedFromDate); }, - filterORFloraSubmittedTo: function() { + filterORFloraSubmittedToDate: function() { let vm = this; vm.$refs.flora_or_datatable.vmDataTable.ajax.reload(helpers.enablePopovers,false); // This calls ajax() backend call. - sessionStorage.setItem(vm.filterORFloraSubmittedTo_cache, vm.filterORFloraSubmittedTo); + sessionStorage.setItem(vm.filterORFloraSubmittedToDate_cache, vm.filterORFloraSubmittedToDate); }, filterApplied: function(){ if (this.$refs.collapsible_filters){ @@ -258,8 +250,8 @@ export default { if(this.filterORFloraOccurrence === 'all' && this.filterORFloraScientificName === 'all' && this.filterORFloraStatus === 'all' && - this.filterORFloraSubmittedFrom === 'all' && - this.filterORFloraSubmittedTo === 'all'){ + this.filterORFloraSubmittedFromDate === '' && + this.filterORFloraSubmittedToDate === ''){ return false } else { return true @@ -489,8 +481,8 @@ export default { d.filter_occurrence = vm.filterORFloraOccurrence; d.filter_species_scientific_name = vm.filterORFloraScientificName; d.filter_status = vm.filterORFloraStatus; - d.filter_submitted_from = vm.filterORFloraSubmittedFrom; - d.filter_submitted_to = vm.filterORFloraSubmittedTo; + d.filter_submitted_from_date = vm.filterORFloraSubmittedFromDate; + d.filter_submitted_to_date = vm.filterORFloraSubmittedToDate; d.is_internal = vm.is_internal; } }, @@ -587,122 +579,6 @@ export default { searchField[0].focus(); }); }, - // initialiseStatusLookup: function(){ - // let vm = this; - // $(vm.$refs.or_status_lookup).select2({ - // minimumInputLength: 2, - // dropdownParent: $("#select_status"), - // "theme": "bootstrap-5", - // allowClear: true, - // placeholder:"Select Status", - // ajax: { - // url: api_endpoints.or_status_lookup, - // dataType: 'json', - // data: function(params) { - // var query = { - // term: params.term, - // type: 'public', - // group_type_id: vm.group_type_id, - // } - // return query; - // }, - // }, - // }). - // on("select2:select", function (e) { - // var selected = $(e.currentTarget); - // let data = e.params.data.id; - // vm.filterORFloraStatus = data; - // sessionStorage.setItem("filterORFloraStatusText", e.params.data.text); - // }). - // on("select2:unselect",function (e) { - // var selected = $(e.currentTarget); - // vm.filterORFloraStatus = 'all'; - // sessionStorage.setItem("filterORFloraStatusText",''); - // }). - // on("select2:open",function (e) { - // const searchField = $('[aria-controls="select2-or_status_lookup-results"]') - // // move focus to select2 field - // searchField[0].focus(); - // }); - // }, - initialiseSubmittedFromLookup: function(){ - let vm = this; - $(vm.$refs.or_submitted_from_lookup).select2({ - minimumInputLength: 2, - dropdownParent: $("#select_submitted_from"), - "theme": "bootstrap-5", - allowClear: true, - placeholder:"Select Submitted From", - ajax: { - url: api_endpoints.or_submitted_from_lookup, - dataType: 'json', - data: function(params) { - var query = { - term: params.term, - type: 'public', - group_type_id: vm.group_type_id, - } - return query; - }, - }, - }). - on("select2:select", function (e) { - var selected = $(e.currentTarget); - let data = e.params.data.id; - vm.filterORFloraSubmittedFrom = data; - sessionStorage.setItem("filterORFloraSubmittedFromText", e.params.data.text); - }). - on("select2:unselect",function (e) { - var selected = $(e.currentTarget); - vm.filterORFloraSubmittedFrom = 'all'; - sessionStorage.setItem("filterORFloraSubmittedFromText",''); - }). - on("select2:open",function (e) { - //const searchField = $(".select2-search__field") - const searchField = $('[aria-controls="select2-or_submitted_from_lookup-results"]') - // move focus to select2 field - searchField[0].focus(); - }); - }, - initialiseSubmittedToLookup: function(){ - let vm = this; - $(vm.$refs.or_submitted_to_lookup).select2({ - minimumInputLength: 2, - dropdownParent: $("#select_submitted_to"), - "theme": "bootstrap-5", - allowClear: true, - placeholder:"Select Submitted To", - ajax: { - url: api_endpoints.genera_lookup, - dataType: 'json', - data: function(params) { - var query = { - term: params.term, - type: 'public', - group_type_id: vm.group_type_id, - } - return query; - }, - }, - }). - on("select2:select", function (e) { - var selected = $(e.currentTarget); - let data = e.params.data.id; - vm.filterORFloraSubmittedTo = data; - sessionStorage.setItem("filterORFloraSubmittedToText", e.params.data.text); - }). - on("select2:unselect",function (e) { - var selected = $(e.currentTarget); - vm.filterORFloraSubmittedTo = 'all'; - sessionStorage.setItem("filterORFloraSubmittedToText",''); - }). - on("select2:open",function (e) { - //const searchField = $(".select2-search__field") - const searchField = $('[aria-controls="select2-or_submitted_to_lookup-results"]') - // move focus to select2 field - searchField[0].focus(); - }); - }, fetchFilterLists: function(){ let vm = this; //large FilterList of Species Values object @@ -912,8 +788,8 @@ export default { filter_occurrence: vm.filterORFloraOccurrence, filter_scientific_name: vm.filterORFloraScientificName, filter_status: vm.filterORFloraStatus, - filter_submitted_from: vm.filterORFloraSubmittedFrom, - filter_submitted_to: vm.filterORFloraSubmittedTo, + filter_submitted_from_date: vm.filterORFloraSubmittedFromDate, + filter_submitted_to_date: vm.filterORFloraSubmittedToDate, is_internal: vm.is_internal, export_format: format }; @@ -1014,9 +890,6 @@ export default { this.$nextTick(() => { vm.initialiseOccurrenceLookup(); vm.initialiseScientificNameLookup(); - // vm.initialiseStatusLookup(); - vm.initialiseSubmittedFromLookup(); - vm.initialiseSubmittedToLookup(); //vm.initialiseSearch(); vm.addEventListeners(); @@ -1034,24 +907,6 @@ export default { var newOption = new Option(sessionStorage.getItem("filterORFloraScientificNameText"), vm.filterORFloraScientificName, false, true); $('#or_scientific_name_lookup').append(newOption); } - // if(sessionStorage.getItem("filterORFloraStatus")!='all' && sessionStorage.getItem("filterORFloraStatus")!=null) - // { - // // contructor new Option(text, value, defaultSelected, selected) - // var newOption = new Option(sessionStorage.getItem("filterORFloraStatus"), vm.filterORFloraStatus, false, true); - // $('#or_status_lookup').append(newOption); - // } - if(sessionStorage.getItem("filterORFloraSubmittedFrom")!='all' && sessionStorage.getItem("filterORFloraSubmittedFrom")!=null) - { - // contructor new Option(text, value, defaultSelected, selected) - var newOption = new Option(sessionStorage.getItem("filterORFloraSubmittedFromText"), vm.filterORFloraSubmittedFrom, false, true); - $('#or_submitted_from_lookup').append(newOption); - } - if(sessionStorage.getItem("filterORFloraSubmittedTo")!='all' && sessionStorage.getItem("filterORFloraSubmittedTo")!=null) - { - // contructor new Option(text, value, defaultSelected, selected) - var newOption = new Option(sessionStorage.getItem("filterORFloraSubmittedToText"), vm.filterORFloraSubmittedTo, false, true); - $('#or_submitted_to_lookup').append(newOption); - } }); } } From 7b2cf6732d4ebfa4f287c1d90dec129fa29ed17c Mon Sep 17 00:00:00 2001 From: Shruti Hindocha Date: Wed, 7 Feb 2024 16:44:58 +0800 Subject: [PATCH 3/3] seperated backend filters for external and internal --- boranga/components/occurrence/api.py | 94 ++++++++++++++++++---------- 1 file changed, 60 insertions(+), 34 deletions(-) diff --git a/boranga/components/occurrence/api.py b/boranga/components/occurrence/api.py index fb2bfc25..063b93f9 100644 --- a/boranga/components/occurrence/api.py +++ b/boranga/components/occurrence/api.py @@ -111,41 +111,67 @@ class OccurrenceReportFilterBackend(DatatablesFilterBackend): def filter_queryset(self, request, queryset, view): - total_count = queryset.count() - - filter_group_type = request.GET.get('filter_group_type') - if filter_group_type and not filter_group_type.lower() == 'all': - queryset = queryset.filter(group_type__name=filter_group_type) - - # To do - change group_type__name based on the relevant model - # filter_occurrence = request.GET.get('filter_occurrence') - # if filter_occurrence and not filter_occurrence.lower() == 'all': - # queryset = queryset.filter(group_type__name=filter_occurrence) - - 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) - - filter_status = request.GET.get('filter_status') - if filter_status and not filter_status.lower() == 'all': - queryset = queryset.filter(processing_status=filter_status) - - def get_date(filter_date): - date = request.GET.get(filter_date) - if date: - date = datetime.strptime(date,'%Y-%m-%d') - return date - - filter_submitted_from_date = get_date('filter_submitted_from_date') - filter_submitted_to_date = get_date('filter_submitted_to_date') - if filter_submitted_to_date: - filter_submitted_to_date = datetime.combine(filter_submitted_to_date , time.max) - - if filter_submitted_from_date and not filter_submitted_to_date: - queryset = queryset.filter(reported_date__gte=filter_submitted_from_date) + if 'internal' in view.name: + total_count = queryset.count() + + filter_group_type = request.GET.get('filter_group_type') + if filter_group_type and not filter_group_type.lower() == 'all': + queryset = queryset.filter(group_type__name=filter_group_type) + + # To do - change group_type__name based on the relevant model + # filter_occurrence = request.GET.get('filter_occurrence') + # if filter_occurrence and not filter_occurrence.lower() == 'all': + # queryset = queryset.filter(group_type__name=filter_occurrence) + + 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) + + filter_status = request.GET.get('filter_status') + if filter_status and not filter_status.lower() == 'all': + queryset = queryset.filter(processing_status=filter_status) + + def get_date(filter_date): + date = request.GET.get(filter_date) + if date: + date = datetime.strptime(date,'%Y-%m-%d') + return date + + filter_submitted_from_date = get_date('filter_submitted_from_date') + filter_submitted_to_date = get_date('filter_submitted_to_date') + if filter_submitted_to_date: + filter_submitted_to_date = datetime.combine(filter_submitted_to_date , time.max) + + if filter_submitted_from_date and not filter_submitted_to_date: + queryset = queryset.filter(reported_date__gte=filter_submitted_from_date) + + if filter_submitted_from_date and filter_submitted_to_date: + queryset = queryset.filter(reported_date__range=[filter_submitted_from_date, filter_submitted_to_date]) - if filter_submitted_from_date and filter_submitted_to_date: - queryset = queryset.filter(reported_date__range=[filter_submitted_from_date, filter_submitted_to_date]) + if 'external' in view.name: + total_count = queryset.count() + + flora = GroupType.GROUP_TYPE_FLORA + fauna = GroupType.GROUP_TYPE_FAUNA + community = GroupType.GROUP_TYPE_COMMUNITY + + filter_group_type = request.GET.get('filter_group_type') + if filter_group_type and not filter_group_type.lower() == 'all': + queryset = queryset.filter(group_type__name=filter_group_type) + + # filter_scientific_name is the species_id + filter_scientific_name = request.GET.get('filter_scientific_name') + if filter_scientific_name and not filter_scientific_name.lower() == 'all': + queryset = queryset.filter(species=filter_scientific_name) + + # filter_community_name is the community_id + filter_community_name = request.GET.get('filter_community_name') + if filter_community_name and not filter_community_name.lower() == 'all': + queryset = queryset.filter(community=filter_community_name) + + filter_application_status = request.GET.get('filter_application_status') + if filter_application_status and not filter_application_status.lower() == 'all': + queryset = queryset.filter(customer_status=filter_application_status) getter = request.query_params.get fields = self.get_fields(getter)