Skip to content

Commit

Permalink
submitted to and from date filters occurrence report dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
Shruti Hindocha committed Feb 2, 2024
1 parent bda7490 commit 47f6013
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 345 deletions.
23 changes: 16 additions & 7 deletions boranga/components/occurrence/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,15 @@
</div>
</div>
<div class="col-md-4">
<div class="form-group" id="select_submitted_from">
<label for="or_submitted_from_lookup">Submitted From:</label>
<select
id="or_submitted_from_lookup"
name="or_submitted_from_lookup"
ref="or_submitted_from_lookup"
class="form-control" />
<div class="form-group">
<label for="">Submitted From Date:</label>
<input type="date" class="form-control" placeholder="DD/MM/YYYY" id="submitted_from_date" v-model="filterORFaunaSubmittedFromDate">
</div>
</div>
<div class="col-md-4">
<div class="form-group" id="select_submitted_to">
<label for="or_submitted_to_lookup">Submitted To:</label>
<select
id="or_submitted_to_lookup"
name="or_submitted_to_lookup"
ref="or_submitted_to_lookup"
class="form-control" />
<div class="form-group">
<label for="">Submitted To Date:</label>
<input type="date" class="form-control" placeholder="DD/MM/YYYY" id="submitted_from_date" v-model="filterORFaunaSubmittedToDate">
</div>
</div>
</div>
Expand Down Expand Up @@ -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',
},
},
Expand All @@ -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: [],
Expand Down Expand Up @@ -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){
Expand All @@ -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
Expand Down Expand Up @@ -374,6 +366,7 @@ export default {
name: "processing_status_display",
}
},
// TODO update this to suit the design
column_action: function(){
let vm = this
return {
Expand Down Expand Up @@ -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;
}
},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -1014,9 +891,6 @@ export default {
this.$nextTick(() => {
vm.initialiseOccurrenceLookup();
vm.initialiseScientificNameLookup();
vm.initialiseStatusLookup();
vm.initialiseSubmittedFromLookup();
vm.initialiseSubmittedToLookup();
//vm.initialiseSearch();
vm.addEventListeners();
Expand All @@ -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);
}
});
}
}
Expand Down
Loading

0 comments on commit 47f6013

Please sign in to comment.