fix add/edit event

This commit is contained in:
les
2020-10-27 11:56:47 +01:00
parent 1001a4d25b
commit 0731b4dd8c
4 changed files with 44 additions and 30 deletions

View File

@@ -1,5 +1,6 @@
<template lang="pug"> <template lang="pug">
v-row v-row
p {{value}}
v-menu( v-menu(
v-model="datePickerMenu" v-model="datePickerMenu"
:close-on-content-click="false" :close-on-content-click="false"
@@ -10,7 +11,7 @@ v-row
) )
template(v-slot:activator="{ on, attrs }") template(v-slot:activator="{ on, attrs }")
v-text-field.col-md-8( v-text-field.col-md-8(
v-model='date' :value='value.date'
:label="$t('common.when')" :label="$t('common.when')"
:rules="[$validators.required('common.when')]" :rules="[$validators.required('common.when')]"
prepend-icon='mdi-calendar' prepend-icon='mdi-calendar'
@@ -19,7 +20,7 @@ v-row
v-on="on") v-on="on")
v-date-picker( v-date-picker(
:min='today' :min='today'
v-model="date" v-model="value.date"
:range="type === 'multidate'" :range="type === 'multidate'"
:locale='settings.locale' :locale='settings.locale'
@input="pick") @input="pick")

View File

@@ -5,7 +5,7 @@
:close-on-content-click="false" :close-on-content-click="false"
transition="slide-x-transition" transition="slide-x-transition"
ref='startTimeMenu' ref='startTimeMenu'
:return-value.sync="time.start" :return-value.sync="value.start"
offset-y offset-y
absolute absolute
top top
@@ -15,7 +15,7 @@
v-text-field( v-text-field(
:label="$t('event.from')" :label="$t('event.from')"
:rules="[$validators.required('event.from')]" :rules="[$validators.required('event.from')]"
:value='time.start' :value='value.start'
v-on='on' v-on='on'
clearable) clearable)
v-time-picker( v-time-picker(
@@ -24,7 +24,7 @@
format="24hr" format="24hr"
ref='time_start' ref='time_start'
:allowed-minutes="[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]" :allowed-minutes="[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]"
v-model='time.start' v-model='value.start'
@click:minute="selectTime('start')") @click:minute="selectTime('start')")
v-col.col-6 v-col.col-6
@@ -41,7 +41,7 @@
template(v-slot:activator='{ on }') template(v-slot:activator='{ on }')
v-text-field( v-text-field(
:label="$t('event.due')" :label="$t('event.due')"
:value='time.end' :value='value.end'
v-on='on' v-on='on'
clearable clearable
readonly) readonly)
@@ -50,7 +50,7 @@
:label="$t('event.due')" :label="$t('event.due')"
format="24hr" format="24hr"
:allowed-minutes="[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]" :allowed-minutes="[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]"
v-model='time.end' v-model='value.end'
@click:minute="selectTime('end')") @click:minute="selectTime('end')")
</template> </template>
@@ -61,7 +61,9 @@ export default {
value: { type: Object, default: () => { } } value: { type: Object, default: () => { } }
}, },
data () { data () {
// console.error('sono dentro data ', this.value)
return { return {
// time: { start: this.value.start, end: this.value.end },
time: {}, time: {},
startTimeMenu: false, startTimeMenu: false,
endTimeMenu: false endTimeMenu: false
@@ -69,8 +71,8 @@ export default {
}, },
methods: { methods: {
selectTime (type) { selectTime (type) {
this.$refs[`${type}TimeMenu`].save(this.time.end) this.$refs[`${type}TimeMenu`].save(this.value[type])
this.$emit('input', this.time) this.$emit('input', this.value)
} }
} }
} }

View File

@@ -7,6 +7,7 @@
:hide-no-data="!place._name" :hide-no-data="!place._name"
:search-input.sync="place._name" :search-input.sync="place._name"
persistent-hint persistent-hint
:value="value.place"
:items="places" :items="places"
item-text='name' item-text='name'
@change='selectPlace') @change='selectPlace')
@@ -19,7 +20,7 @@
:rules="[$validators.required('common.address')]" :rules="[$validators.required('common.address')]"
:label="$t('common.address')" :label="$t('common.address')"
@change="changeAddress" @change="changeAddress"
:value="place.address") :value="value.address")
</template> </template>
<script> <script>
@@ -27,6 +28,9 @@ import { mapState } from 'vuex'
export default { export default {
name: 'WhereInput', name: 'WhereInput',
props: {
value: { type: Object, default: () => {} }
},
data () { data () {
return { return {
place: { _name: '' }, place: { _name: '' },

View File

@@ -93,22 +93,27 @@ export default {
error({ statusCode: 404, message: 'Event not found!' }) error({ statusCode: 404, message: 'Event not found!' })
return {} return {}
} }
data.event.recurrent = {}
data.event.place.name = event.place.name data.event.place.name = event.place.name
data.event.place.address = event.place.address || '' data.event.place.address = event.place.address || ''
data.date = {}
if (event.multidate) { if (event.multidate) {
data.date = { start: dayjs.unix(event.start_datetime).toDate(), end: dayjs.unix(event.end_datetime).toDate() } data.date = {
data.event.type = 'multidate' type: 'multidate',
start: dayjs.unix(event.start_datetime).toDate(),
end: dayjs.unix(event.end_datetime).toDate()
}
} else if (event.recurrent) { } else if (event.recurrent) {
data.event.type = 'recurrent' data.date.type = 'recurrent'
data.event.recurrent = event.recurrent data.date.recurrent = event.recurrent
} else { } else {
data.event.type = 'normal' data.date.type = 'normal'
data.date = dayjs.unix(event.start_datetime).toDate() data.date.date = dayjs.unix(event.start_datetime).format('YYYY-MM-DD')
} }
data.time.start = dayjs.unix(event.start_datetime).format('HH:mm') data.time.start = dayjs.unix(event.start_datetime).format('HH:mm')
data.time.end = dayjs.unix(event.end_datetime).format('HH:mm') data.time.end = dayjs.unix(event.end_datetime).format('HH:mm')
data.event.title = event.title data.event.title = event.title
data.event.description = event.description data.event.description = event.description
data.event.id = event.id data.event.id = event.id
@@ -165,6 +170,7 @@ export default {
this.loading = true this.loading = true
let start_datetime, end_datetime let start_datetime, end_datetime
const [start_hour, start_minute] = this.time.start.split(':') const [start_hour, start_minute] = this.time.start.split(':')
console.error('TIME: hour', start_hour, this.time)
if (!this.time.end) { if (!this.time.end) {
this.time.end = (Number(start_hour) + 2) + ':' + start_minute this.time.end = (Number(start_hour) + 2) + ':' + start_minute
} }
@@ -172,29 +178,30 @@ export default {
const formData = new FormData() const formData = new FormData()
if (this.event.type === 'multidate') { if (this.date.type === 'multidate') {
start_datetime = dayjs(this.date.start) start_datetime = dayjs(this.date.date[0])
.set('hour', start_hour).set('minute', start_minute) .set('hour', start_hour).set('minute', start_minute)
end_datetime = dayjs(this.date.end) end_datetime = dayjs(this.date.date[1])
.set('hour', end_hour).set('minute', end_minute) .set('hour', end_hour).set('minute', end_minute)
} else if (this.event.type === 'normal') { } else if (this.date.type === 'normal') {
start_datetime = dayjs(this.date).set('hour', start_hour).set('minute', start_minute) console.error('dentro type normal', this.date.type)
end_datetime = dayjs(this.date).set('hour', end_hour).set('minute', end_minute) start_datetime = dayjs(this.date.date).set('hour', start_hour).set('minute', start_minute)
end_datetime = dayjs(this.date.date).set('hour', end_hour).set('minute', end_minute)
if (end_hour < start_hour) { if (end_hour < start_hour) {
end_datetime = end_datetime.add(1, 'day') end_datetime = end_datetime.add(1, 'day')
} }
} else if (this.event.type === 'recurrent') { } else if (this.date.type === 'recurrent') {
start_datetime = dayjs().set('hour', start_hour).set('minute', start_minute) start_datetime = dayjs().set('hour', start_hour).set('minute', start_minute)
end_datetime = dayjs().set('hour', end_hour).set('minute', end_minute) end_datetime = dayjs().set('hour', end_hour).set('minute', end_minute)
const recurrent = { // const recurrent = {
frequency: this.event.recurrent.frequency, // frequency: this.event.recurrent.frequency,
days: this.event.recurrent.type === 'ordinal' ? _.map(this.date, d => dayjs(d).date()) : _.map(this.date, d => dayjs(d).day() + 1), // days: this.event.recurrent.type === 'ordinal' ? _.map(this.date, d => dayjs(d).date()) : _.map(this.date, d => dayjs(d).day() + 1),
type: this.event.recurrent.type // type: this.event.recurrent.type
} // }
if (end_hour < start_hour) { if (end_hour < start_hour) {
end_datetime = end_datetime.add(1, 'day') end_datetime = end_datetime.add(1, 'day')
} }
formData.append('recurrent', JSON.stringify(recurrent)) formData.append('recurrent', JSON.stringify(this.date.recurrent))
} }
if (this.event.image) { if (this.event.image) {