Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vespadb #206

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
622 changes: 0 additions & 622 deletions output.log

This file was deleted.

26 changes: 25 additions & 1 deletion src/components/FilterComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ export default {
const minDateCET = minDate.value ? DateTime.fromJSDate(minDate.value).setZone('Europe/Paris').toFormat('yyyy-MM-dd\'T\'HH:mm:ss') : null;
const maxDateCET = maxDate.value ? DateTime.fromJSDate(maxDate.value).setZone('Europe/Paris').toFormat('yyyy-MM-dd\'T\'HH:mm:ss') : null;



vespaStore.applyFilters({
municipalities: selectedMunicipalities.value.length > 0 ? selectedMunicipalities.value : [],
provinces: selectedProvinces.value.length > 0 ? selectedProvinces.value : [],
Expand All @@ -119,6 +121,7 @@ export default {
max_observation_date: maxDateCET,
visible: visibleActief.value
});

}, 300);

const toggleMenu1 = () => {
Expand Down Expand Up @@ -153,9 +156,30 @@ export default {

watch([selectedMunicipalities, selectedProvinces, selectedNestType, selectedNestStatus, anbAreasActief, selectedObservationStart, selectedObservationEnd, visibleActief], () => {
emitFilterUpdate();
}, { deep: true });
}, { deep: true});

watch(() => vespaStore.filters, (newFilters, oldFilters) => {
const hasChanged = JSON.stringify(newFilters) !== JSON.stringify(oldFilters);

if (hasChanged) {
selectedMunicipalities.value = newFilters.municipalities || [];
selectedProvinces.value = newFilters.provinces || [];
anbAreasActief.value = newFilters.anbAreasActief || null;
selectedNestType.value = newFilters.nestType || [];
selectedNestStatus.value = newFilters.nestStatus || [];
minDate.value = newFilters.min_observation_date ? new Date(newFilters.min_observation_date) : null;
maxDate.value = newFilters.max_observation_date ? new Date(newFilters.max_observation_date) : null;
}
}, { immediate: true, deep: true });

onMounted(async () => {
selectedMunicipalities.value = vespaStore.filters.municipalities || [];
selectedProvinces.value = vespaStore.filters.provinces || [];
anbAreasActief.value = vespaStore.filters.anbAreasActief;
selectedNestType.value = vespaStore.filters.nestType || [];
selectedNestStatus.value = vespaStore.filters.nestStatus || [];
minDate.value = vespaStore.filters.min_observation_date ? new Date(vespaStore.filters.min_observation_date) : new Date(new Date().getFullYear(), 3, 1);
maxDate.value = vespaStore.filters.max_observation_date ? new Date(vespaStore.filters.max_observation_date) : null;
if (!vespaStore.municipalitiesFetched) await vespaStore.fetchMunicipalities();
if (!vespaStore.provincesFetched) await vespaStore.fetchProvinces();
});
Expand Down
15 changes: 9 additions & 6 deletions src/components/MapPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default {
map.value.setView([result.lat, result.lon], 16);
} else {
// Handle case when address is not found
console.log('Adres niet gevonden');

}
} catch (error) {
console.error('Error searching address:', error);
Expand Down Expand Up @@ -143,6 +143,7 @@ export default {

const updateMarkers = debounce(async () => {
if (isFetchingGeoJson.value) return; // Prevent multiple calls

isFetchingGeoJson.value = true;

try {
Expand Down Expand Up @@ -182,6 +183,7 @@ export default {
} finally {
isFetchingGeoJson.value = false;
isMapLoading.value = false;
vespaStore.getObservations(1, 25).catch(error => console.error('Error fetching observations:', error));
}
}, 300);

Expand Down Expand Up @@ -219,6 +221,7 @@ export default {
() => vespaStore.filters,
(newFilters) => {
filtersUpdated.value = true;

clearAndUpdateMarkers();
},
{ deep: true }
Expand All @@ -236,7 +239,6 @@ export default {
onMounted(async () => {
if (!vespaStore.municipalitiesFetched) await vespaStore.fetchMunicipalities();
if (!vespaStore.provincesFetched) await vespaStore.fetchProvinces();

vespaStore.markerClusterGroup = L.markerClusterGroup({
spiderfyOnMaxZoom: false,
showCoverageOnHover: true,
Expand Down Expand Up @@ -300,11 +302,12 @@ export default {
}

vespaStore.map = map.value;
if (vespaStore.lastAppliedFilters === null || vespaStore.lastAppliedFilters === 'null') {
vespaStore.setLastAppliedFilters();
}
// if (vespaStore.lastAppliedFilters === null || vespaStore.lastAppliedFilters === 'null') {
// vespaStore.setLastAppliedFilters();
// }
updateMarkers();
vespaStore.getObservations(1, 25).catch(error => console.error('Error fetching observations:', error));


});

return {
Expand Down
16 changes: 10 additions & 6 deletions src/components/NavbarComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@
<div class="d-flex align-items-center">
<!-- View Mode Toggle -->
<div class="btn-group me-2" role="group">
<router-link to="/map" class="btn btn-outline-dark" active-class="active" aria-current="page">Map</router-link>
<router-link to="/map" class="btn btn-outline-dark" active-class="active"
aria-current="page">Map</router-link>
<router-link to="/table" class="btn btn-outline-dark" active-class="active">Tabel</router-link>
</div>

<!-- Export Toggle (Hidden on Medium Devices and below) -->
<div class="btn-group me-2 d-md-inline-flex">
<button type="button" class="btn btn-outline-dark dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<button type="button" class="btn btn-outline-dark dropdown-toggle" data-bs-toggle="dropdown"
aria-expanded="false">
Export
</button>
<ul class="dropdown-menu">
<li><button class="dropdown-item" @click="exportData('csv')">CSV</button></li>
<li><button class="dropdown-item" @click="exportData('json')">JSON</button></li>
</ul>
</div>

<!-- User Login/Logout -->
<span v-if="isLoggedIn && !loadingAuth" class="navbar-text">
<div class="btn-group">
<button type="button" class="btn btn-outline-dark dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
<button type="button" class="btn btn-outline-dark dropdown-toggle" data-bs-toggle="dropdown"
aria-expanded="false">
{{ username }}
</button>
<ul class="dropdown-menu dropdown-menu-end">
Expand All @@ -35,12 +37,14 @@
</ul>
</div>
</span>
<router-link v-if="!isLoggedIn && !loadingAuth" to="/login" class="btn btn-outline-dark" active-class="active">Inloggen</router-link>
<router-link v-if="!isLoggedIn && !loadingAuth" to="/login" class="btn btn-outline-dark"
active-class="active">Inloggen</router-link>
<span v-if="loadingAuth" class="navbar-text">Loading...</span> <!-- Placeholder while loading -->
</div>
</div>
</nav>
<ModalMessage :title="modalTitle" :message="modalMessage" :isVisible="isModalVisible" @close="isModalVisible = false" />
<ModalMessage :title="modalTitle" :message="modalMessage" :isVisible="isModalVisible"
@close="isModalVisible = false" />
</template>

<script>
Expand Down
43 changes: 22 additions & 21 deletions src/components/ObservationDetailsComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@
<div id="eradication" class="accordion-collapse collapse" aria-labelledby="eradication-header"
data-bs-parent="#sections">
<div class="accordion-body">
<div class="row mb-2">
<label class="col-4 col-form-label">Resultaat</label>
<div class="col-8">
<select v-if="selectedObservation.eradication_result !== undefined"
v-model="editableObservation.eradication_result" class="form-select"
:class="{ 'is-invalid': eradicationResultError }" :disabled="!canEdit">
<option :value="null">Geen</option>
<option v-for="(label, value) in eradicationResultEnum" :key="value"
:value="value">{{ label
}}</option>
</select>
<div v-if="eradicationResultError" class="invalid-feedback">
{{ eradicationResultError }}
</div>
</div>
</div>
<div class="row mb-2">
<label class="col-4 col-form-label">Datum</label>
<div class="col-8">
Expand Down Expand Up @@ -86,22 +102,6 @@
:class="{ 'form-control-plaintext': !canEdit }" />
</div>
</div>
<div class="row mb-2">
<label class="col-4 col-form-label">Resultaat</label>
<div class="col-8">
<select v-if="selectedObservation.eradication_result !== undefined"
v-model="editableObservation.eradication_result" class="form-select"
:class="{ 'is-invalid': eradicationResultError }" :disabled="!canEdit">
<option :value="null">Geen</option>
<option v-for="(label, value) in eradicationResultEnum" :key="value"
:value="value">{{ label
}}</option>
</select>
<div v-if="eradicationResultError" class="invalid-feedback">
{{ eradicationResultError }}
</div>
</div>
</div>
<div v-if="isLoggedIn" class="row mb-2">
<label class="col-4 col-form-label">Methode</label>
<div class="col-8">
Expand Down Expand Up @@ -141,7 +141,7 @@
</select>
</div>
</div>
<div class="row mb-2">
<div v-if="isLoggedIn" class="row mb-2">
<label class="col-4 col-form-label">Problemen</label>
<div class="col-8">
<select v-if="selectedObservation.eradication_problems !== undefined"
Expand All @@ -154,7 +154,7 @@
</select>
</div>
</div>
<div class="row mb-2">
<div v-if="isLoggedIn" class="row mb-2">
<label class="col-4 col-form-label">Opmerkingen</label>
<div class="col-8">
<textarea v-if="selectedObservation.eradication_notes !== undefined"
Expand Down Expand Up @@ -278,14 +278,14 @@
</p>
</div>
</div>
<div class="row mb-2">
<div v-if="isLoggedIn" class="row mb-2">
<label class="col-4 col-form-label">Opmerking validator</label>
<div class="col-8">
<p class="form-control-plaintext">{{ selectedObservation.wn_notes }}</p>
</div>
</div>
</div>
<div class="row mb-2">
<div v-if="isLoggedIn" class="row mb-2">
<div class="col-8 offset-4">
<div class="form-check form-switch">
<input v-if="selectedObservation.public_domain !== undefined"
Expand Down Expand Up @@ -468,7 +468,8 @@ export default {
const eradicationResultEnum = {
"successful": "Succesvol behandeld",
"unsuccessful": "Niet succesvol behandeld",
"untreated": "Niet behandeld",
"untreated": "Niet behandeld want andere soort",
"untreatable": "Onbehandelbaar (bv. te hoog, inactief)",
"unknown": "Onbekend"
};

Expand Down
19 changes: 16 additions & 3 deletions src/components/TableViewPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export default {
sortBy.value = field;
sortOrder.value = 'asc';
}

vespaStore.getObservations(page.value, pageSize.value, sortBy.value, sortOrder.value);
};

Expand All @@ -129,6 +130,7 @@ export default {
} else if (direction === 'prev' && previousPage.value) {
page.value--;
}

vespaStore.getObservations(page.value, pageSize.value, sortBy.value, sortOrder.value);
};

Expand Down Expand Up @@ -164,6 +166,10 @@ export default {
const lastAppliedFilters = vespaStore.lastAppliedFilters;

if (currentFilters !== lastAppliedFilters) {



//vespaStore.setLastAppliedFilters();
vespaStore.getObservations(page.value, pageSize.value, sortBy.value, sortOrder.value).then(() => {
vespaStore.getObservationsGeoJson();
});
Expand All @@ -174,13 +180,20 @@ export default {
if (!vespaStore.municipalitiesFetched) await vespaStore.fetchMunicipalities();
if (!vespaStore.provincesFetched) await vespaStore.fetchProvinces();

if (vespaStore.lastAppliedFilters === null || vespaStore.lastAppliedFilters === 'null') {
vespaStore.setLastAppliedFilters();
}

// if (vespaStore.lastAppliedFilters === null || vespaStore.lastAppliedFilters === 'null') {
// console.log("set hier?")
// vespaStore.setLastAppliedFilters();
// }

// Avoid calling getObservations if data is already loaded with the same filters
if (vespaStore.table_observations.length === 0 || JSON.stringify(vespaStore.filters) !== JSON.stringify(vespaStore.lastAppliedFilters)) {



//vespaStore.setLastAppliedFilters();
vespaStore.getObservations(page.value, pageSize.value, sortBy.value, sortOrder.value);
vespaStore.getObservationsGeoJson();
}
});

Expand Down
10 changes: 6 additions & 4 deletions src/stores/vespaStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ export const useVespaStore = defineStore('vespaStore', {
},
async applyFilters(filters) {
this.filters = { ...this.filters, ...filters };
// await this.getObservations();
// await this.getObservationsGeoJson();
//await this.getObservations();
},
async fetchProvinces() {
Expand Down Expand Up @@ -296,11 +298,11 @@ export const useVespaStore = defineStore('vespaStore', {
}
if (observation.eradication_date) {
observation.eradication_date = this.formatDateWithoutTime(observation.eradication_date);
console.log("transformed date:")
console.log(observation.eradication_date);


}
console.log("the observation erad date is");
console.log(observation.eradication_date);


try {
const response = await ApiService.patch(`/observations/${observation.id}/`, observation);
if (response.status === 200) {
Expand Down
5 changes: 4 additions & 1 deletion vespadb/observations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class ObservationAdmin(gis_admin.GISModelAdmin):
"eradicator_name",
"reserved_by",
"modified_by",
"modified_datetime",
"public_domain",
"reserved_datetime",
)
Expand All @@ -132,6 +133,8 @@ class ObservationAdmin(gis_admin.GISModelAdmin):
"municipality",
"anb",
"reserved_by",
"modified_datetime",
"modified_by",
"created_by",
"modified_by",
ObserverReceivedEmailFilter,
Expand Down Expand Up @@ -164,7 +167,7 @@ class ObservationAdmin(gis_admin.GISModelAdmin):
"municipality",
)

def get_readonly_fields(self, obj: Observation | None = None) -> list[str]:
def get_readonly_fields(self, request: HttpRequest, obj: Observation | None = None) -> list[str]:
"""."""
if obj: # editing an existing object
return [*self.readonly_fields, "location"]
Expand Down
Loading
Loading