Commit 80e9c451 authored by hypsug0's avatar hypsug0
Browse files

fix: dicts always init from API

parent 2ca8c789
......@@ -1366,7 +1366,7 @@ const sigthingFormApp = (id_session, type_contact) => {
typeContact: type_contact,
moreSightingForm: false,
moreCountDetailForm: false,
dictSpecies: [],
// dictSpecies: [],
messages: [],
countDetailSelectedItem: -1,
postInProgress: 0,
......@@ -1398,8 +1398,8 @@ const sigthingFormApp = (id_session, type_contact) => {
},
addNewSighting() {
const newS = { ...this.newSighting }
const cds = []
this.data.forEach(es => cds.push([...es.countdetails]))
const cds = []
this.data.forEach((es) => cds.push([...es.countdetails]))
last = cds.slice(-1)
console.debug('last', last)
console.debug('cd0', newS.countdetails[0])
......@@ -1576,33 +1576,58 @@ const sigthingFormApp = (id_session, type_contact) => {
},
getDictSpecie() {},
getDicts() {
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
)
this.dicts = response.data
localStorage.setItem(
'dicts',
JSON.stringify(this.dicts)
)
})
.catch((err) => {
console.error(err)
})
}
console.debug('loading dicts from localStorage')
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
$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
......@@ -1613,6 +1638,9 @@ const sigthingFormApp = (id_session, type_contact) => {
return this.data[is].countdetails.reduce(CountSum, 0)
},
getData() {
if (this.dicts != null) {
this.getDicts()
}
$http
.get(this.url)
.then((response) => {
......@@ -1644,7 +1672,9 @@ const sigthingFormApp = (id_session, type_contact) => {
if (duplicates.length > 0) {
this.messages.push({
type: 'danger',
message: `Espèce(s) ${duplicates.map(e => `${this.getSpecieValue(e, 'sci_name')}`)} en double`,
message: `Espèce(s) ${duplicates.map(
(e) => `${this.getSpecieValue(e, 'sci_name')}`
)} en double`,
})
}
},
......
......@@ -14,13 +14,12 @@ Observations de la session {{object.name}}
<div id="sessionSightingEdit">
<div id="sessionSightingEditTitle" class="col-12">
<h1><i class="{{ icon | safe }}"></i> {{ title | safe }} <span v-if="initialDataLoaded"
class="pull-right label label-success label-sm">[[data.length]] obs</span>
class="pull-right label label-success label-sm">[[data.length]] taxons</span>
</h1>
<ol class="breadcrumb">
<li><a href="{% url 'sights:place_detail' pk=object.place.pk %}">Localité</a> (<span class="text-muted">{{object.place.name}}</span>)
<li><a href="{% url 'sights:place_detail' pk=object.place.pk %}">Localité</a> <span class="text-muted hidden-xs">({{object.place.name}})</span>
</li>
<li><a href="{% url 'sights:session_detail' pk=object.pk %}">Session</a> (<span class="text-muted">{{object.name}} <span
class="label label-default">{{object.contact.descr}}</span></span>)
<li><a href="{% url 'sights:session_detail' pk=object.pk %}">Session</a> <span class="text-muted hidden-xs">({{object.name}}<span class="label label-default">{{object.contact.descr}}</span>)</span>
</li>
</ol>
<div v-if="messages.length > 0" >
......@@ -100,11 +99,11 @@ Observations de la session {{object.name}}
<span class="text-info pull-right" @click="postOneData(selectedItem)"><i
class="fa fa-fw fa-save"></i></span>
</span>
<span v-if="data[selectedItem].id_sighting" class="text-muted">
{% comment %} <span v-if="data[selectedItem].id_sighting" class="text-muted">
#[[data[selectedItem].id_sighting]]
</span>
</span> {% endcomment %}
<span v-else class="label label-success">new</span>
Edition de [[ data[selectedItem].codesp ?
[[ data[selectedItem].codesp ?
getSpecieValue(data[selectedItem].codesp, 'sci_name'):
'Choisissez une espèce']]
</h3>
......@@ -126,6 +125,7 @@ Observations de la session {{object.name}}
<input id="codeSp" type="number" class="form-control input-sm" placeholder="Nombre total"
class="form-control" min="0" v-model:title="data[selectedItem].total_count"
v-model="data[selectedItem].total_count" disabled>
<p class="help-block"><i class="fa fa-exclamation-triangle fa-fw"></i>Le nombre total est estimé à partir des données détaillées</p>
</div>
<div class="checkbox">
......@@ -154,8 +154,7 @@ Observations de la session {{object.name}}
</div>
</div>
</div>
<table class="table table-sm table-scroll">
<thead>
<table class="table table-sm table-scroll table-condensed">
<tr>
<th><span class="text-muted"><small>#</small></th>
<!-- <th><span class="text-muted"><small>Actions</small></th>-->
......@@ -168,8 +167,6 @@ Observations de la session {{object.name}}
<th v-if="form_fields.includes('poids')">Poids</th>
<th v-if="form_fields.includes('count')">Dénombrement</th>
</tr>
</thead>
<tbody>
<template v-for="(cd, icd) in data[selectedItem].countdetails">
<tr @click="displayCountDetailForm(icd)" :class="{'info' : countDetailSelectedItem == icd}" >
<td><span class="text-muted"><small>[[icd]]</small></td>
......@@ -386,7 +383,6 @@ Observations de la session {{object.name}}
</td>
</tr>
</template>
</tbody>
</table>
......
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