Commit f877b19b authored by hypsug0's avatar hypsug0
Browse files

feat: transmitter autoselect in sighting edit form

parent aa220c4e
......@@ -180,19 +180,7 @@ const sightingActionButtonGroup = (id, model, id_session=null) => {
'fa-info-circle',
`/${model}/${id}/detail`
),
actionButtons('Modifier', 'info', 'fa-edit', `session/${id_session}/sighting/edit`),
actionButtons(
'Ajouter une observation détaillée',
'success',
'fa-calendar-alt',
`/${model}/${id}/countdetail/add`
),
actionButtons(
'Supprimer',
'danger',
'fa-trash',
`/${model}/${id}/delete`
)
actionButtons('Modifier', 'info', 'fa-edit', `/session/${id_session}/sighting/edit`),
)
return btnGroup.outerHTML
}
......@@ -633,6 +621,14 @@ const placeDetailMap = () => {
// Sighting Search
const sightingSearchBlock = () => {
const aLink = (url, label) => {
const a = document.createElement('a')
a.href=url
a.target='_blank'
a.title=`Voir la page de détails de ${label}`
a.innerHTML = label
return a.outerHTML
}
const format = (d) => {
return (
'<strong>Commentaire</strong>&nbsp;:&nbsp;' +
......@@ -655,7 +651,7 @@ const sightingSearchBlock = () => {
},
{
data: (row) => {
return sightingActionButtonGroup(row.id, 'sighting', )
return sightingActionButtonGroup(row.id, 'sighting', row.properties.session_data.id_session )
},
width: '100',
},
......@@ -679,7 +675,7 @@ const sightingSearchBlock = () => {
return breed_colo
},
},
{ data: 'properties.session_data.place_data.name' },
{ data: (row)=>{ return aLink(`/place/${row.properties.session_data.place_data.id_place}/detail`, row.properties.session_data.place_data.name)}},
{
data: function (row) {
if (
......@@ -694,7 +690,7 @@ const sightingSearchBlock = () => {
return (
row.properties.session_data.place_data
.municipality_data.name +
'(' +
' (' +
row.properties.session_data.place_data
.municipality_data.code +
')'
......@@ -706,7 +702,7 @@ const sightingSearchBlock = () => {
},
},
{ data: 'properties.session_data.date_start' },
{ data: 'properties.session_data.name' },
{ data: (row)=>{ return aLink(`/session/${row.properties.session_data.id_session}/detail`, row.properties.session_data.name)}},
{ data: 'properties.session_data.contact_data.descr' },
{
data: (row) =>
......@@ -1026,6 +1022,18 @@ const countDetailOtherForm = [
'comment',
]
const countDetailTelemetryForm = [
'time',
'method',
'sex',
'age',
'unit',
'precision',
'transmitter',
'comment',
]
const CountDetailObject = () => {
return {
id_countdetail: null,
......@@ -1085,6 +1093,83 @@ new Vue({
},
})
Vue.component('transmitterSelect', {
data() {
return {
options: [],
}
},
props: {
value: {
type: Number,
},
session: {
type: Number,
},
},
template: `<v-select class="form-control v-select-style" label="reference" :reduce="e => e.id_transmitter" :filterable="false" :options="options" @search="onSearch" v-model="model">
<template slot="no-options">
Tapez pour rechercher un émetteur
</template>
<template v-slot:option="option">
{{ option.reference }}
</template>
<template v-slot:selected-option="option">
{{ option.reference }}
</template>
</v-select>`,
computed: {
model: {
get() {
return this.value
},
set(newValue) {
this.$emit('input', newValue)
},
},
},
methods: {
onSearch(search, loading) {
if (search.length >= 2) {
loading(true)
this.search(loading, search, this)
}
},
onInit() {
if (this.model) {
this.apiCall(this.model)
}
},
apiCall(id = null) {
$http
.get(`/api/v1/transmitter/search?id=${id}`)
.then((response) => {
this.options = response.data
loading(false)
})
.catch(function (error) {
console.error(error)
})
},
search: _debounce((loading, search, vm) => {
$http
.get(`/api/v1/transmitter/search?available&q=${escape(search)}`)
.then((response) => {
vm.options = response.data
loading(false)
})
.catch(function (error) {
console.error(error)
})
}, 350),
},
mounted() {
this.onInit()
},
})
Vue.component('observerSelect', {
data() {
return {
......@@ -1697,59 +1782,6 @@ const sigthingFormApp = (id_session, type_contact) => {
this.dictSpecies = JSON.parse(
localStorage.getItem('dictSpecies')
)
// $http
// .get('/api/v1/dicts')
// .then((response) => {
// this.dicts = response.data
// this.dictSpecies = this.dicts.Specie.sort((a, b) => {
// const ca = a.codesp,
// cb = b.codesp
// return ca < cb ? -1 : ca > cb ? 1 : 0
// }).sort((a, b) => Number(b.sp_true) - Number(a.sp_true))
// this.dictsLoaded = true
// })
// .catch((err) => {
// console.error(err)
// })
// console.debug('LocalStorageDIct status', localStorage.getItem('dicts') )
// if (localStorage.getItem('dicts') == null) {
// console.debug('No dicts in localStorage')
// $http
// .get('/api/v1/dicts')
// .then((response) => {
// console.debug(
// 'Saving downloaded dicts in localStorage',
// response.data
// )
// localStorage.setItem(
// 'dicts',
// JSON.stringify(response.data)
// )
// })
// .catch((err) => {
// console.error(err)
// })
// }
// // while (true) {
// // setTimeout(() => {console.debug('Wait for dict')}, 1000)
// // if (localStorage.getItem('dicts') != null) {
// // break;
// // }
// // }
// console.debug('LocalStorageDIct status', localStorage.getItem('dicts') )
// console.debug('loading dicts from localStorage')
// while (localStorage.getItem('dicts') == null) {
// setTimeout(() => {console.debug('Wait for dict')}, 100)
// }
// this.dicts = JSON.parse(localStorage.getItem('dicts'))
// this.dictSpecies = this.dicts.Specie.sort((a, b) => {
// const ca = a.codesp,
// cb = b.codesp
// return ca < cb ? -1 : ca > cb ? 1 : 0
// }).sort((a, b) => Number(b.sp_true) - Number(a.sp_true))
// this.dictsLoaded = true
},
getAutocompleteData(obj) {
this.data.user = obj
......
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Q
from rest_framework.generics import ListAPIView
from ..models import Transmitter
from .serializers import SearchTransmitterSerializer
class TransmitterSearchApi(
LoginRequiredMixin,
ListAPIView,
):
serializer_class = SearchTransmitterSerializer
pagination_class = None
def get_queryset(self, *args, **kwargs):
qs = Transmitter.objects
available = self.request.query_params.get("available", None)
q = self.request.query_params.get("q", None)
id = self.request.query_params.get("id", None)
qs = qs.filter(pk=id) if id else qs
qs = qs.filter(available=True) if available else qs
qs = qs.filter(Q(name__icontains=q) | Q(reference__icontains=q)) if q else qs
return qs.order_by("-timestamp_update")
from rest_framework.serializers import ModelSerializer
from ..models import Transmitter
class SearchTransmitterSerializer(ModelSerializer):
class Meta:
model = Transmitter
fields = (
"id_transmitter",
"reference",
"name",
"status",
)
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from django.views.generic import CreateView, DeleteView, UpdateView
from django_tables2.views import SingleTableView
from core import js
from ..forms import TransmitterForm
from ..mixins import ManagementAuthMixin
from ..models import Transmitter
from ..tables import TransmitterTable
class TransmitterCreate(LoginRequiredMixin, CreateView):
"""Create view for the Transmitter model."""
model = Transmitter
form_class = TransmitterForm
template_name = "normal_form.html"
def form_valid(self, form):
form.instance.created_by = self.request.user
return super(TransmitterCreate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(TransmitterCreate, self).get_context_data(**kwargs)
context["icon"] = "fa fa-podcast"
context["title"] = _("Ajout d'un émetteur")
context["js"] = js.DateInput
return context
class TransmitterUpdate(LoginRequiredMixin, UpdateView):
"""Update view for the Transmitter model."""
model = Transmitter
form_class = TransmitterForm
template_name = "normal_form.html"
def form_valid(self, form):
form.instance.updated_by = self.request.user
return super(TransmitterUpdate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(TransmitterUpdate, self).get_context_data(**kwargs)
context["icon"] = "fa fa-podcast"
context["title"] = _("Modification d'un émetteur")
context["js"] = js.DateInput
return context
class TransmitterDelete(ManagementAuthMixin, DeleteView):
"""Delete view for the Transmitter model."""
model = Transmitter
template_name = "confirm_delete.html"
success_url = reverse_lazy("management:transmitter_list")
def get_context_data(self, **kwargs):
context = super(TransmitterDelete, self).get_context_data(**kwargs)
context["icon"] = "fi-trash"
context["title"] = _("Suppression d'un émetteur")
context["message_alert"] = _("Êtes-vous certain de vouloir supprimer l'émetteur")
return context
class TransmitterList(LoginRequiredMixin, SingleTableView):
table_class = TransmitterTable
model = Transmitter
template_name = "table.html"
table_pagination = {"per_page": 25}
def get_context_data(self, **kwargs):
context = super(TransmitterList, self).get_context_data(**kwargs)
context["icon"] = "fa fa-podcast"
context["title"] = _("Liste des émetteurs")
context[
"js"
] = """
"""
return context
from django.urls import path
from .transmitter.api import TransmitterSearchApi
from .transmitter.views import (
TransmitterCreate,
TransmitterDelete,
TransmitterList,
TransmitterUpdate,
)
from .views import (
CatchAuthCreate,
CatchAuthDelete,
......@@ -9,10 +16,6 @@ from .views import (
StudyDelete,
StudyList,
StudyUpdate,
TransmitterCreate,
TransmitterDelete,
TransmitterList,
TransmitterUpdate,
)
app_name = "management"
......@@ -42,6 +45,11 @@ urlpatterns = [
TransmitterList.as_view(),
name="url_transmitter_list",
),
path(
"api/v1/transmitter/search",
TransmitterSearchApi.as_view(),
name="transmitter_search_api",
),
# CatchAuth relative URLS
path("catchauth/add", CatchAuthCreate.as_view(), name="catchauth_create"),
path("catchauth/<int:pk>/update", CatchAuthUpdate.as_view(), name="catchauth_update"),
......
......@@ -13,10 +13,10 @@ from django_tables2 import SingleTableView
from core import js
from .forms import CatchAuthForm, StudyForm, TransmitterForm
from .forms import CatchAuthForm, StudyForm
from .mixins import CatchAuthCreateAuthMixin, ManagementAuthMixin
from .models import CatchAuth, Study, Transmitter
from .tables import CatchAuthTable, StudyTable, TransmitterTable
from .models import CatchAuth, Study
from .tables import CatchAuthTable, StudyTable
class StudyCreate(LoginRequiredMixin, CreateView):
......@@ -91,76 +91,6 @@ class StudyList(LoginRequiredMixin, SingleTableView):
return context
class TransmitterCreate(LoginRequiredMixin, CreateView):
"""Create view for the Transmitter model."""
model = Transmitter
form_class = TransmitterForm
template_name = "normal_form.html"
def form_valid(self, form):
form.instance.created_by = self.request.user
return super(TransmitterCreate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(TransmitterCreate, self).get_context_data(**kwargs)
context["icon"] = "fa fa-podcast"
context["title"] = _("Ajout d'un émetteur")
context["js"] = js.DateInput
return context
class TransmitterUpdate(LoginRequiredMixin, UpdateView):
"""Update view for the Transmitter model."""
model = Transmitter
form_class = TransmitterForm
template_name = "normal_form.html"
def form_valid(self, form):
form.instance.updated_by = self.request.user
return super(TransmitterUpdate, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super(TransmitterUpdate, self).get_context_data(**kwargs)
context["icon"] = "fa fa-podcast"
context["title"] = _("Modification d'un émetteur")
context["js"] = js.DateInput
return context
class TransmitterDelete(ManagementAuthMixin, DeleteView):
"""Delete view for the Transmitter model."""
model = Transmitter
template_name = "confirm_delete.html"
success_url = reverse_lazy("management:transmitter_list")
def get_context_data(self, **kwargs):
context = super(TransmitterDelete, self).get_context_data(**kwargs)
context["icon"] = "fi-trash"
context["title"] = _("Suppression d'un émetteur")
context["message_alert"] = _("Êtes-vous certain de vouloir supprimer l'émetteur")
return context
class TransmitterList(LoginRequiredMixin, SingleTableView):
table_class = TransmitterTable
model = Transmitter
template_name = "table.html"
table_pagination = {"per_page": 25}
def get_context_data(self, **kwargs):
context = super(TransmitterList, self).get_context_data(**kwargs)
context["icon"] = "fa fa-podcast"
context["title"] = _("Liste des émetteurs")
context[
"js"
] = """
"""
return context
class CatchAuthCreate(CatchAuthCreateAuthMixin, CreateView):
"""Update view for the Transmitter model."""
......
......@@ -219,6 +219,14 @@ Observations de la session {{object.name}}
</div>
</validation-provider>
<div v-if="form_fields.includes('transmitter')" class="form-group" class="form-group" :class='classes'>
<label class="control-label" for="Precision">Transmetteur</label>
<transmitter-select id="transmitter" class="form-control" v-model="cd.transmitter"/>
</div>
<validation-provider
v-if="form_fields.includes('count') && !selectedCode(dicts.Method, cd.method, 'vvnc')" immediate
rules="required|positive" v-slot="{ errors, valid, invalid, classes}"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment