Commit 242212f6 authored by hypsug0's avatar hypsug0
Browse files

wip: Sighting edit form

parent 9414cc7a
......@@ -913,9 +913,9 @@ BS Full screen Modal
#specieDetail {
padding: 5px;
border-bottom: 1px solid #777 ;
border-top: 1px solid #777 ;
background-color: white;
/*border-bottom: 1px solid #777 ;
border-top: 1px solid #777 ;*/
background-color: whitesmoke;
}
.bg-default {
......@@ -926,6 +926,14 @@ BS Full screen Modal
padding: 10px;
}
#moreCountDetailForm{
padding: 10px;
}
#countDetailEditLine{
padding: 0px;
}
/************************************/
/* Some custom css */
/************************************/
......@@ -957,7 +965,6 @@ BS Full screen Modal
line-height: 30px;
padding: 0px;
min-width: 200px;
display: block;
width: 100%;
/* height: 36px; */
......@@ -975,4 +982,3 @@ BS Full screen Modal
-o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
}
}
......@@ -1015,15 +1015,15 @@ const countDetailBiomForm = [
const countDetailAcousticForm = ['time', 'method', 'count', 'unit', 'comment']
const countDetailOtherForm = [
"time",
"method",
"sex",
"age",
"count",
"unit",
"precision",
"transmitter",
"comment",
'time',
'method',
'sex',
'age',
'count',
'unit',
'precision',
'transmitter',
'comment',
]
const CountDetailObject = (lastdata) => {
......@@ -1281,10 +1281,10 @@ Vue.component('dictSelect', {
},
template: `<v-select class="form-control v-select-style" :options="options" :reduce="e => e.id" label="code" v-model="model">
<template v-slot:option="option">
<span class="label label-default">{{option.code}}</span> {{option.descr}}
<span class="label label-default">{{option.code}}</span>&nbsp;{{option.short_descr ? option.short_descr : option.descr}}
</template>
<template #selected-option="{ code, descr }">
<span class="label label-default">{{code}}</span>&nbsp;{{descr}}
<template #selected-option="{ code, short_descr, descr }">
<span class="label label-default">{{code}}</span>&nbsp;{{short_descr ? short_descr : descr}}
</template>
</v-select>`,
computed: {
......@@ -1304,7 +1304,12 @@ const sigthingFormApp = (id_session, type_contact) => {
return value >= 0
})
const form_fields = type_contact == 'vm' ? countDetailBiomForm : type_contact=='du' ? countDetailAcousticForm : countDetailOtherForm
const form_fields =
type_contact == 'vm'
? countDetailBiomForm
: type_contact == 'du'
? countDetailAcousticForm
: countDetailOtherForm
VeeValidate.extend('required', {
validate(value) {
......@@ -1336,7 +1341,12 @@ const sigthingFormApp = (id_session, type_contact) => {
return {
data: [],
dicts: {},
form_fields: type_contact == 'vm' ? countDetailBiomForm : type_contact=='du' ? countDetailAcousticForm : countDetailOtherForm,
form_fields:
type_contact == 'vm'
? countDetailBiomForm
: type_contact == 'du'
? countDetailAcousticForm
: countDetailOtherForm,
url: sightingDataListUrl,
loadingMessage: true,
initialDataLoaded: false,
......@@ -1350,14 +1360,24 @@ const sigthingFormApp = (id_session, type_contact) => {
selectedItem: 0,
typeContact: type_contact,
moreSightingForm: false,
moreCountDetailForm: false,
dictSpecies: [],
errors: [],
messages: [],
countDetailSelectedItem: -1,
postInProgress: 0,
}
},
methods: {
findCondition(dict, code) {
return dict.find((e) => e.code === code)
},
displayCountDetailForm(icd) {
if (this.countDetailSelectedItem > -1) {
this.countDetailSelectedItem = -1
} else {
this.countDetailSelectedItem = icd
}
},
selectItem(i) {
this.selectedItem = i
},
......@@ -1419,23 +1439,46 @@ const sigthingFormApp = (id_session, type_contact) => {
? specieList.find((r) => r.id === isp).sci_name
: 'Not defined'
},
async postSighting(d) {
postItem(d) {
console.log('PostInProgress', this.postInProgress)
console.debug('POST datas', d)
const sightingUpdateUrl = d.id_sighting
? `/api/v1/observation/${d.id_sighting}/update`
: `/api/v1/session/${id_session}/observation/add`
const $httpMethod = d.id_sighting ? $http.put : $http.post
return $httpMethod(sightingUpdateUrl, d)
.then((resp) => {
++this.postInProgress
return resp
})
.catch((err) => {
console.error(err)
this.messages.push({
type: 'danger',
message: err.response.data,
})
})
},
postSighting(d) {
console.log('PostInProgress', this.postInProgress)
console.debug('POST datas', d)
const sightingUpdateUrl = d.id_sighting
? `/api/v1/observation/${d.id_sighting}/update`
: `/api/v1/session/${id_session}/observation/add`
const $httpMethod = d.id_sighting ? $http.put : $http.post
await $httpMethod(sightingUpdateUrl, d)
return $httpMethod(sightingUpdateUrl, d)
.then((response) => {
console.debug('response', response)
})
.then(() => {
this.postLoad = false
++this.postInProgress
})
.catch((err) => {
console.error(err)
this.errors.push(err.response.data)
this.messages.push({
type: 'danger',
message: err.response.data,
})
})
},
deleteSighting(i) {
......@@ -1456,33 +1499,62 @@ const sigthingFormApp = (id_session, type_contact) => {
const callback = () => {
this.getData()
}
this.messages.length = 0
this.messages.push({
type: 'info',
message: `Saving data in progress`,
})
this.postInProgress = 0
axios
.all(this.data.map((item) => this.postItem(item)))
.then(
axios.spread((...responses) => {
console.log(responses)
responses.forEach((item, index) =>
console.debug('TEST', item, index)
)
if (
responses.every(
(item) =>
item?.status == 200 ||
item?.status == 201
)
) {
this.messages.length = 0
this.messages.push({
type: 'success',
message: 'Données enregistrées avec succès',
})
var itemsProcessed = 0
this.data.forEach((item, index, array) => {
this.postSighting(item, () => {
itemsProcessed++
console.warn('after')
if (itemsProcessed === array.length) {
callback()
}
this.getData()
}
this.postInProgress = 0
})
)
.catch((err) => {
this.messages.length = 0
console.debug('ERROR', err)
this.messages.push({ type: 'danger', message: err })
})
})
// console.log(typeof this.data)
// // asyncForEach(this.data, async (e) => this.postSighting(e)).then(
// // this.getData()
// // )
// this.data.forEach(e => this.postSighting(e))
},
filteredDict(dict, contact) {
contact = contact || null
return contact ? dict.filter((e) => e.contact == contact) : dict
},
selectedValueHtml(dict, 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> ${
r?.short_decr ? r.short_descr : r?.descr
}`
: '-'
},
selectedCode(dict, value, code) {
// console.debug('selectedCode', dict, value, code)
// console.debug('find', dict.find(e=>e.id==value))
const select = dict.find((e) => e.id == value)
return dict.find((e) => e.id == value)?.code == code
},
taxaSelectOptions(dict, contact) {
......@@ -1523,8 +1595,8 @@ const sigthingFormApp = (id_session, type_contact) => {
console.warn(obj)
},
sumCountDetails(is) {
Countsum = (a, c) => a + parseInt(c.count)
return this.data[is].countdetails.reduce(Countsum, 0)
const CountSum = (a, c) => a + parseInt(c.count)
return this.data[is].countdetails.reduce(CountSum, 0)
},
getData() {
$http
......@@ -1541,6 +1613,7 @@ const sigthingFormApp = (id_session, type_contact) => {
})
.catch((err) => {
console.error(err)
this.message.push({ type: 'error', message: err })
})
},
},
......@@ -1571,6 +1644,7 @@ const sigthingFormApp = (id_session, type_contact) => {
mounted() {
this.getDicts()
this.getData()
this.messages.push()
},
// options
}
......
This diff is collapsed.
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