Skip to content

Commit

Permalink
infite loading in saction outcome dashboard fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Shruti Hindocha committed Jan 22, 2024
1 parent 8967106 commit 18f8c9b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 54 deletions.
3 changes: 2 additions & 1 deletion wildlifecompliance/components/sanction_outcome/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ def filter_queryset(self, request, queryset, view):
q_objects &= Q(district__id=district_id)

# perform filters
queryset = queryset.filter(q_objects)
if queryset.exists:
queryset = queryset.filter(q_objects)

getter = request.query_params.get
fields = self.get_fields(getter)
Expand Down
1 change: 0 additions & 1 deletion wildlifecompliance/components/sanction_outcome/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class SanctionOutcome(models.Model):
# This is pending closure status
(STATUS_AWAITING_PRINT_AND_POST, 'Awaiting Print and Post'),
(STATUS_WITH_DOT, 'With Dep. of Transport'),
(STATUS_AWAITING_ISSUANCE, 'Awaiting Issuance'),
(STATUS_AWAITING_REVIEW, 'Awaiting Review'),
(STATUS_AWAITING_ISSUANCE, 'Awaiting Issuance'),
(STATUS_AWAITING_REMEDIATION_ACTIONS, 'Awaiting Remediation Actions'), # TODO: implement pending closuer of SanctionOutcome with type RemediationActions
Expand Down
5 changes: 5 additions & 0 deletions wildlifecompliance/components/sanction_outcome/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ class SanctionOutcomeDatatableSerializer(serializers.ModelSerializer):
# remediation_actions = serializers.SerializerMethodField()
# remediation_actions = RemediationActionSerializer(read_only=True, many=True) # This is related field
remediation_actions = serializers.SerializerMethodField()
region = serializers.SerializerMethodField()


class Meta:
model = SanctionOutcome
Expand Down Expand Up @@ -560,6 +562,9 @@ def get_user_action(self, obj):

urls = '<br />'.join(url_list)
return urls

def get_region(self,obj):
return obj.region_id


class RecordFerCaseNumberSerializer(serializers.ModelSerializer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,17 @@
<div class="row">
<div class="col-md-3">
<label class="">Region:</label>
<!-- <select class="form-control col-sm-9" v-on:change.prevent="sanction_outcome.region_id=$event.target.value; updateDistricts('updatefromUI')" v-bind:value="sanction_outcome.region_id">
<option v-for="option in regions" :value="option.id" v-bind:key="option.id">
{{ option.display_name }}
</option>
</select> -->
<select class="form-control" v-on:change.prevent="filterRegionId=$event.target.value; updateDistricts('updatefromUI')" v-bind:value="filterRegionId">
<option v-for="option in sanction_outcome_regions" :value="option.id" v-bind:key="option.id">
{{ option.display_name }}
</option>
</select>
<select class="form-control" v-on:change.prevent="filterRegionId=$event.target.value; updateDistricts()" v-bind:value="filterRegionId">
<option v-for="option in sanction_outcome_regions" :value="option.id" v-bind:key="option.id">
{{ option.name }}
</option>
</select>
</div>
<div class="col-md-3">
<label class="">District:</label>
<!-- <select class="form-control" v-model="sanction_outcome.district_id">
<option v-for="option in availableDistricts" :value="option.id" v-bind:key="option.id">
{{ option.display_name }}
</option>
</select> -->
<select class="form-control" v-model="filterDistrictId">
<option v-for="option in sanction_outcome_availableDistricts" :value="option.id" v-bind:key="option.id">
{{ option.display_name }}
<select class="form-control" v-model="filterDistrictId">
<option v-for="option in sanction_outcome_availableDistricts" :value="option.district_id" v-bind:key="option.district_id">
{{ option.district_name }}
</option>
</select>
</div>
Expand Down Expand Up @@ -281,15 +271,8 @@ export default {
vm.addEventListeners();
});
},
computed: {
current_region_id: function() {
return this.filterRegionId;
},
},
watch: {
current_region_id: function() {
this.updateDistricts();
},
filterType: function () {
this.$refs.sanction_outcome_table.vmDataTable.draw();
},
Expand Down Expand Up @@ -317,26 +300,20 @@ export default {
this.constructOptionsStatus();
this.constructOptionsPaymentStatus();
this.constructOptionsRegion();
this.constructOptionsDistrict();
// this.constructOptionsDistrict();
},
methods: {
updateDistricts: function(updateFromUI) {
updateDistricts: function() {
this.sanction_outcome_availableDistricts = []; // This is a list of options for district
for (let record of this.sanction_outcome_regionDistricts) {
if (this.filterRegionId == record.id) {
for (let district_id of record.districts) {
for (let district_record of this.sanction_outcome_regionDistricts) {
if (district_record.id == district_id) {
this.sanction_outcome_availableDistricts.push(district_record);
}
}
}
for (let region of this.sanction_outcome_regions) {
if (region.id == this.filterRegionId) {
this.sanction_outcome_availableDistricts = region.districts
}
}
this.sanction_outcome_availableDistricts.splice(0, 0, {
id: "all",
display_name: "All",
district_id: "all",
district_name: "All",
district: "",
districts: [],
region: null
Expand Down Expand Up @@ -413,25 +390,22 @@ export default {
constructOptionsRegion: async function() {
let returned_regions = await cache_helper.getSetCacheList(
"Regions",
"/api/region_district/get_regions/"
"/api/regions/"
);
Object.assign(this.sanction_outcome_regions, returned_regions);
this.sanction_outcome_regions.splice(0, 0, {
id: "all",
display_name: "All",
district: "",
districts: [],
region: null
name: "All",
});
},
constructOptionsDistrict: async function() {
let returned_region_districts = await cache_helper.getSetCacheList(
"RegionDistricts",
api_endpoints.region_district
);
Object.assign(this.sanction_outcome_regionDistricts, returned_region_districts);
this.updateDistricts();
},
// constructOptionsDistrict: async function() {
// let returned_region_districts = [];
// for (let region in this.sanction_outcome_regions){
// returned_region_districts.append(region.districts)
// }
// Object.assign(this.sanction_outcome_regionDistricts, returned_region_districts);
// this.updateDistricts();
// },
},
components: {
datatable,
Expand Down

0 comments on commit 18f8c9b

Please sign in to comment.