Commit 22a6de21 authored by hypsug0's avatar hypsug0
Browse files

Some cleanyp

parent 6cc91d29
......@@ -143,7 +143,7 @@ const actionButtons = (label, style, icon, url) => {
return a
}
const placeActionButtonGroup = (id, model, id_session=null) => {
const placeActionButtonGroup = (id, model, id_session = null) => {
const btnGroup = document.createElement('div')
// btnGroup.classList.add('btn-group', 'btn-group-xs');
btnGroup.append(
......@@ -170,7 +170,7 @@ const placeActionButtonGroup = (id, model, id_session=null) => {
return btnGroup.outerHTML
}
const sightingActionButtonGroup = (id, model, id_session=null) => {
const sightingActionButtonGroup = (id, model, id_session = null) => {
const btnGroup = document.createElement('div')
// btnGroup.classList.add('btn-group', 'btn-group-xs');
btnGroup.append(
......@@ -180,7 +180,12 @@ const sightingActionButtonGroup = (id, model, id_session=null) => {
'fa-info-circle',
`/${model}/${id}/detail`
),
actionButtons('Modifier', 'info', 'fa-edit', `/session/${id_session}/sighting/edit`),
actionButtons(
'Modifier',
'info',
'fa-edit',
`/session/${id_session}/sighting/edit`
)
)
return btnGroup.outerHTML
}
......@@ -623,12 +628,12 @@ const placeDetailMap = () => {
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.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;' +
......@@ -651,7 +656,11 @@ const sightingSearchBlock = () => {
},
{
data: (row) => {
return sightingActionButtonGroup(row.id, 'sighting', row.properties.session_data.id_session )
return sightingActionButtonGroup(
row.id,
'sighting',
row.properties.session_data.id_session
)
},
width: '100',
},
......@@ -675,7 +684,14 @@ const sightingSearchBlock = () => {
return breed_colo
},
},
{ data: (row)=>{ return aLink(`/place/${row.properties.session_data.place_data.id_place}/detail`, row.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 (
......@@ -702,7 +718,14 @@ const sightingSearchBlock = () => {
},
},
{ data: 'properties.session_data.date_start' },
{ data: (row)=>{ return aLink(`/session/${row.properties.session_data.id_session}/detail`, row.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) =>
......@@ -1033,7 +1056,6 @@ const countDetailTelemetryForm = [
'comment',
]
const CountDetailObject = () => {
return {
id_countdetail: null,
......@@ -1087,11 +1109,6 @@ const SightingObject = (session_id) => {
created_by: null,
}
}
new Vue({
components: {
autocomplete: Vue2Autocomplete,
},
})
Vue.component('transmitterSelect', {
......@@ -1169,94 +1186,6 @@ Vue.component('transmitterSelect', {
},
})
Vue.component('observerSelect', {
data() {
return {
selected: this.value,
dict: [],
options: [],
edit: false,
}
},
props: {
value: {
type: Number,
},
},
template: `
<span>
<v-select :disabled="!edit" class="form-control v-select-style" :options="options" :reduce="e => e.id" label="codesp" v-model="model">
<template v-slot:option="option">
<span class="label label-default" :class="option.sp_true?'label-success':'label-default' ">{{option.codesp}}</span> {{option.sci_name}}
</template>
<template #selected-option="{ sp_true, codesp, sci_name }">
<span class="label" :class="sp_true?'label-success':'label-default' ">{{codesp}}</span>&nbsp;{{sci_name}}
</template>
</v-select>
<i class="fas fa-edit" :class="edit ? 'text-muted':'text-warning'" @click="editState"></i>
</span>
`,
computed: {
model: {
get() {
console.debug('actual', this.selected)
return this.value
},
set(newValue) {
console.debug('test', newValue)
this.$emit('input', newValue)
},
},
selectedDetail: function () {
return this.options.find((e) => e.id == this.model)
},
},
methods: {
editState() {
this.edit = !this.edit
},
getSpecieDict() {
this.edit = this.value == null
if (localStorage.getItem('species') == null) {
console.debug('No dict in localStorage')
$http
.get('/api/v1/dict/specie')
.then((response) => {
console.debug(
'Saving downloaded dicts in localStorage',
response.data
)
this.options = response.data
localStorage.setItem(
'species',
JSON.stringify(this.options)
)
})
.catch((err) => {
console.error(err)
})
} else {
console.debug('loading species dict from localStorage')
this.options = JSON.parse(localStorage.getItem('species'))
}
this.options = this.options
.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))
},
},
mounted() {
this.getSpecieDict()
// this.edit = this.value == null
// console.debug('mounted edit', this.value, this.edit, this.value == null)
},
})
Vue.component('specieSelect', {
data() {
return {
......@@ -1277,12 +1206,12 @@ Vue.component('specieSelect', {
:disabled="disabled" class="form-control v-select-style"
:options="options" :reduce="e => e.id" label="codesp" v-model="model"
data-toggle="tooltip" data-placement="bottom"
title="Cliquez sur l'icone d'édition pour modifier le taxon">
title="Cliquez sur l'icône d'édition pour modifier le taxon">
<template v-slot:option="option">
<span class="label label-default" :class="option.sp_true?'label-success':option.codesp.startsWith('0') ? 'label-primary':'label-default' ">{{option.codesp}}</span> {{option.sci_name}}
<span class="label label-default" :class="formatCodesp(option.sp_true, option.codesp)">{{option.codesp}}</span> {{option.sci_name}}
</template>
<template #selected-option="{ sp_true, codesp, sci_name }">
<span class="label" :class="sp_true?'label-success':codesp.startsWith('0') ? 'label-primary':'label-default' ">{{codesp}}</span>&nbsp;{{sci_name}}
<span class="label" :class="formatCodesp(sp_true, codesp)">{{codesp}}</span>&nbsp;{{sci_name}}
</template>
</v-select>
<i class="fas fa-edit" :class="disabled ? 'text-muted':'text-warning'" @click="editState()"></i>
......@@ -1308,6 +1237,15 @@ Vue.component('specieSelect', {
},
},
methods: {
formatCodesp(spTrue, codeSp) {
if (codeSp != null && typeof codeSp === 'string') {
return spTrue
? 'label-success'
: codeSp.startsWith('0')
? 'label-primary'
: 'label-default'
}
},
editState() {
console.debug('disable bef>', this.disabled)
this.disabled = !this.disabled
......@@ -1504,11 +1442,11 @@ const sigthingFormApp = (id_session, type_contact) => {
})
VeeValidate.configure({
classes: {
classes: true,
classNames: {
valid: 'has-success',
invalid: 'has-error',
dirty: 'has-warning', // multiple classes per flag!
// ...
},
})
......@@ -1546,6 +1484,7 @@ const sigthingFormApp = (id_session, type_contact) => {
messages: [],
countDetailSelectedItem: -1,
postInProgress: 0,
sightingToDelete: -1
}
},
methods: {
......@@ -1553,14 +1492,16 @@ const sigthingFormApp = (id_session, type_contact) => {
return dict.find((e) => e.code === code)
},
displayCountDetailForm(icd) {
if (this.countDetailSelectedItem > -1) {
this.countDetailSelectedItem = -1
} else {
this.countDetailSelectedItem = icd
}
this.countDetailSelectedItem = icd
// if (this.countDetailSelectedItem > -1) {
// this.countDetailSelectedItem = -1
// } else {
// this.countDetailSelectedItem = icd
// }
},
selectItem(i) {
this.selectedItem = i
this.countDetailSelectedItem = -1
},
showCountDetail(item) {
item.isVisible = !item.isVisible
......@@ -1574,7 +1515,9 @@ const sigthingFormApp = (id_session, type_contact) => {
},
addNewSighting() {
if (!this.data.find((e) => e.codesp == null)) {
const newSightingObject = JSON.parse(JSON.stringify(this.newSighting))
const newSightingObject = JSON.parse(
JSON.stringify(this.newSighting)
)
const newCountDetailObject = { ...this.newCountDetail }
const allCountDetails = []
this.data.forEach((es) =>
......@@ -1646,13 +1589,13 @@ const sigthingFormApp = (id_session, type_contact) => {
specieList = this.dicts.Specie
return isp
? specieList.find((r) => r.id === isp)[field]
: 'Not defined'
: null
},
getSpClass(isp) {
specieList = this.dicts.Specie
return isp
? specieList.find((r) => r.id === isp).sci_name
: 'Not defined'
: null
},
postItem(d) {
console.log('PostInProgress', this.postInProgress)
......@@ -1696,6 +1639,9 @@ const sigthingFormApp = (id_session, type_contact) => {
})
})
},
deleteSightingShowModal(i) {
this.sightingToDelete = i
},
delSighting(i) {
id = this.data[i].id_sighting
if (id) {
......@@ -1704,10 +1650,12 @@ const sigthingFormApp = (id_session, type_contact) => {
.then((r) => {
console.log('DELETE', r)
this.data.splice(i, 1)
})
} else {
this.data.splice(i, 1)
}
this.sightingToDelete = -1
},
postOneData(i) {
this.postSighting(this.data[i])
......@@ -1759,10 +1707,10 @@ const sigthingFormApp = (id_session, type_contact) => {
return contact ? dict.filter((e) => e.contact == contact) : dict
},
selectedValueHtml(dict, value) {
console.debug(
'selectedValue',
dict.find((e) => e.id == value)
)
// console.debug(
// 'selectedValue',
// dict.find((e) => e.id == value)
// )
const r = dict.find((e) => e.id == value)
return value
? `<span class="label label-default">${r?.code}</span> ${
......@@ -1825,7 +1773,7 @@ const sigthingFormApp = (id_session, type_contact) => {
.slice(0, i)
.concat(duplicates.slice(i + 1, duplicates.length))
})
console.debug('<dupSpecies>', duplicates) //[ 1, 5 ]
// console.debug('<dupSpecies>', duplicates) //[ 1, 5 ]
if (duplicates.length > 0) {
this.messages.push({
type: 'danger',
......@@ -1846,7 +1794,13 @@ const sigthingFormApp = (id_session, type_contact) => {
handler() {
if (type_contact != 'du') {
this.data.forEach((e, i) => {
e.total_count = this.sumCountDetails(i)
if (
e.total_count != null &&
e.countdetails.length == 0
) {
} else {
e.total_count = this.sumCountDetails(i)
}
})
}
this.dupSpecies()
......
......@@ -4,14 +4,13 @@ import logging
from django.contrib.auth.mixins import LoginRequiredMixin
from django.db.models import Prefetch
from rest_framework.generics import ListAPIView
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.permissions import IsAuthenticated
# from rest_framework.views import APIView
from rest_framework.viewsets import GenericViewSet, ModelViewSet, mixins
from sights.countdetail.serializers import CountDetailSerializer
from sights.mixins import LargeGeoJsonPageNumberPagination, SightingFilteredListWithPermissions
from sights.models import CountDetail, Sighting
from sights.models import Sighting
from sights.observation.serializers import (
EditSightingSerializer,
EditSightingSerializerTest,
......@@ -21,10 +20,6 @@ from sights.observation.serializers import (
from ..mixins import SightingListPermissionsMixin
from .permissions import SightingEditPermission
# from rest_framework.permissions import IsAuthenticated
# Get an instance of a logger
logger = logging.getLogger(__name__)
......@@ -78,75 +73,7 @@ class EditSighting(SightingListPermissionsMixin, ModelViewSet):
class DeleteSighting(mixins.DestroyModelMixin, GenericViewSet):
serializer_class = EditSightingSerializer
queryset = Sighting.objects.all()
# permission_class = [IsAuthenticated]
# class SessionCountDetailsListView(ModelViewSet):
# permission_classes = (AllowAny,)
# serializer_class = CountDetailSerializer
# def get_queryset(self):
# logger.debug(f"CALL QUERY {self}")
# print(f"CALL QUERY {self}")
# if self.action == "list":
# session = self.kwargs["session"]
# return CountDetail.objects.filter(sighting__session=session)
# else:
# return CountDetail.objects.all()
# def perform_create(self, serializer):
# logger.debug(f"USERRRR {self.request.user} {type(self.request.user)}")
# serializer.save(created_by=self.request.user)
# def perform_update(self, serializer):
# logger.debug(f"USERRRR {self.request.user} {type(self.request.user)}")
# serializer.save(updated_by=self.request.user)
# def get_serializer_class(self):
# return CountDetailSerializer
# def list(self, request, session):
# # session = self.kwargs["session"]
# logger.debug(f"<SessionCountDetailsListView.list>")
# q = CountDetail.objects.filter(sighting__session=session)
# serializer = CountDeta(q, many=True)
# logger.debug(f"A {CountDetailBaseSerializer.Meta.fields}")
# logger.debug(f"B {serializer.data}")
# logger.debug(f"C {q.all()}")
# return Response(serializer.data)
# def create(self, request, session):
# logger.debug(f"<SessionCountDetailsListView.create>")
# logger.debug(f"request {request.data}")
# for cd in request.data:
# taxa = cd.pop("taxa")
# cd.pop("sighting")
# cd.pop("session")
# obj, created = Sighting.objects.get_or_create(codesp=taxa, session=session)
# logger.debug(f"sighting {type(obj)}")
# cd["sighting"] = obj.id_sighting
# s = CountDetailSerializer(data=cd)
# s.is_valid()
# logger.debug(s.data)
# logger.debug(s.errors)
# CountDetail.save(**s.data)
# serializer = CountDetailSerializer(self.get_queryset(), many=True)
# return Response(serializer.data)
# # def retrieve(self, request, pk=None):
# # logger.debug(f"<SessionCountDetailsListView.retrieve>")
# # pass
# def update(self, request, pk=None):
# logger.debug(f"<SessionCountDetailsListView.update>")
# pass
# def partial_update(self, request, pk=None):
# logger.debug(f"<SessionCountDetailsListView.partial_update>")
# pass
# def destroy(self, request, pk=None):
# logger.debug(f"<SessionCountDetailsListView.destroy>")
# pass
permission_classes = [
IsAuthenticated,
SightingEditPermission,
]
......@@ -46,10 +46,5 @@ urlpatterns = [
EditSighting.as_view({"delete": "destroy"}),
name="delete_observation_api",
),
# path(
# "api/v1/countdetails/<int:pk>",
# SessionCountDetailsListView.as_view({"get": "retrieve"}),
# name="count_detail_retrieve_api",
# ),
path("sighting/search", SightingSearch.as_view(), name="sighting_search"),
]
{% extends 'base.html' %} {% load i18n %} {% block title %}Profile de {{ object.username }}{%endblock %}
{% extends 'base.html' %} {% load i18n %} {% block title %}{% trans "Utilisateur" %} {{object.username}}{%endblock %}
{% block content %}
<h1>
<i class="fi-torsos-female-male"></i>
{% trans "Mes données" %}
{% trans "Utilisateur" %} {{object.username}}
</h1>
<p> <span class="text-muted">Compte créé le</span> {{object.timestamp_create}}
{% if object.timestamp_update %}
......@@ -19,7 +19,7 @@
<h3>Informations principales</h1>
<dl class="dl-horizontal">
<dt>Nom d'utilisateur</dt>
<dd>{{ object.username }}</dd>
<dd><span class="label label-primary" style="font-size:1.5rem;">{{ object.username }}</strong></dd>
</dl>
<dl class="dl-horizontal">
<dt>Nom complet</dt>
......@@ -65,7 +65,7 @@
<a
class="btn btn-block btn-primary btn-lg"
href="{% url 'accounts:user_update' pk=object.pk %}"
><i class="fa fa-fw fa-edit-alt"></i>
><i class="fa fa-fw fa-edit"></i>
{% trans 'Modifier' %}</a>
</div>
<div class="col-xs-12 col-md-4">
......
......@@ -28,11 +28,9 @@
<link rel="stylesheet" href="https://unpkg.com/vue-select@latest/dist/vue-select.css">
<script src="{% static 'js/jquery/jquery.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}" defer></script>
<script src="{% static 'js/vue.js' %}" defer></script>
<script src="https://unpkg.com/vue-select@latest" defer></script>
<script src="https://cdn.jsdelivr.net/npm/vee-validate@latest/dist/vee-validate.js" defer></script>
<script src="{% static 'js/vue2-autocomplete.js' %}" defer></script>
<link href="{% static 'css/vue2-autocomplete.css' %}" rel="stylesheet">
<script src="{% static 'js/vue.js' %}" defer ></script>
<script src="{% static 'js/vee-validate.js' %}" defer></script>
<script src="{% static 'js/vue-select.js' %}" defer></script>
<script src="{% static 'js/axios.min.js' %}" defer></script>
<script src="{% static 'js/preload_app.js' %}" defer></script>
<script src="{% static 'js/datatables.min.js' %} " defer></script>
......
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