Remember last all-day setting for initial date

Signed-off-by: Raimund Schlüßler <raimund.schluessler@mailbox.org>
This commit is contained in:
Raimund Schlüßler 2019-11-20 22:12:49 +01:00
parent 621c87b1b9
commit 38c1c5db4e
No known key found for this signature in database
GPG key ID: 036FA7EB1A599178
3 changed files with 41 additions and 20 deletions

View file

@ -88,7 +88,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
:type="'date'" :placeholder="$t('tasks', 'Set start date')"
class="date" @change="setStartDate"
/>
<DatetimePicker v-if="!task.allDay" :value="tmpTask.start" :lang="lang"
<DatetimePicker v-if="!allDay" :value="tmpTask.start" :lang="lang"
:format="timeFormat" :clearable="false" :time-picker-options="timePickerOptions"
:type="'time'" :placeholder="$t('tasks', 'Set start time')"
class="time" @change="setStartTime"
@ -122,7 +122,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
:type="'date'" :placeholder="$t('tasks', 'Set due date')"
class="date" @change="setDueDate"
/>
<DatetimePicker v-if="!task.allDay" :value="tmpTask.due" :lang="lang"
<DatetimePicker v-if="!allDay" :value="tmpTask.due" :lang="lang"
:format="timeFormat" :clearable="false" :time-picker-options="timePickerOptions"
:type="'time'" :placeholder="$t('tasks', 'Set due time')"
class="time" @change="setDueTime"
@ -147,8 +147,8 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
class="checkbox"
name="isAllDayPossible"
:class="{'disabled': task.calendar.readOnly}"
:aria-checked="task.allDay"
:checked="task.allDay"
:aria-checked="allDay"
:checked="allDay"
:disabled="task.calendar.readOnly"
@click="toggleAllDay(task)"
>
@ -433,10 +433,23 @@ export default {
}
},
computed: {
/**
* Whether the dates of a task are all-day
* When no dates are set, we consider the last used value.
*
* @returns {Boolean} Are the dates all-day
*/
allDay: function() {
if (this.task.startMoment.isValid() || this.task.dueMoment.isValid()) {
return this.task.allDay
} else {
return this.$store.state.settings.settings.allDay
}
},
startDateString: function() {
const $t = this.$t
if (this.task.startMoment.isValid()) {
if (this.task.allDay) {
if (this.allDay) {
return this.task.startMoment.calendar(null, {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string and keep the brackets.
sameDay: this.$t('tasks', '[Starts today]'),
@ -495,7 +508,7 @@ export default {
dueDateString: function() {
const $t = this.$t
if (this.task.dueMoment.isValid()) {
if (this.task.allDay) {
if (this.allDay) {
return this.task.dueMoment.calendar(null, {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string and keep the brackets.
sameDay: this.$t('tasks', '[Due today]'),
@ -787,10 +800,10 @@ export default {
this.setPercentComplete({ task: this.task, complete: value })
break
case 'start':
this.setStart({ task: this.task, start: value })
this.setStart({ task: this.task, start: value, allDay: this.allDay })
break
case 'due':
this.setDue({ task: this.task, due: value })
this.setDue({ task: this.task, due: value, allDay: this.allDay })
break
}
this.edit = ''
@ -809,7 +822,7 @@ export default {
if (due.isBefore(reference)) {
reference = due.subtract(1, 'm')
}
reference.startOf(this.task.allDay ? 'day' : 'hour')
reference.startOf(this.allDay ? 'day' : 'hour')
return reference
}
return start
@ -825,7 +838,7 @@ export default {
if (!due.isValid()) {
var start = this.task.startMoment
var reference = start.isAfter() ? start : moment()
if (this.task.allDay) {
if (this.allDay) {
reference.startOf('day').add(1, 'd')
} else {
reference.startOf('hour').add(1, 'h')

View file

@ -405,6 +405,9 @@ export default class Task {
this.updateLastModified()
this._start = this.vtodo.getFirstPropertyValue('dtstart')
this._startMoment = moment(this._start, 'YYYYMMDDTHHmmss')
// Check all day setting
var d = this._due || this._start
this._allDay = d !== null && d.isDate
}
get startMoment() {
@ -424,6 +427,9 @@ export default class Task {
this.updateLastModified()
this._due = this.vtodo.getFirstPropertyValue('due')
this._dueMoment = moment(this._due, 'YYYYMMDDTHHmmss')
// Check all day setting
var d = this._due || this._start
this._allDay = d !== null && d.isDate
}
get dueMoment() {

View file

@ -446,8 +446,9 @@ const mutations = {
* @param {Object} state The store data
* @param {Task} task The task
* @param {Moment} due The due date moment
* @param {Boolean} allDay Whether the date is all-day
*/
setDue(state, { task, due }) {
setDue(state, { task, due, allDay }) {
if (due === null) {
// If the date is null, just set (remove) it.
Vue.set(task, 'due', due)
@ -462,10 +463,10 @@ const mutations = {
} else {
start = due.clone()
}
Vue.set(task, 'start', momentToICALTime(start, task.allDay))
Vue.set(task, 'start', momentToICALTime(start, allDay))
}
// Set the due date, convert it to ICALTime first.
Vue.set(task, 'due', momentToICALTime(due, task.allDay))
Vue.set(task, 'due', momentToICALTime(due, allDay))
}
},
@ -475,8 +476,9 @@ const mutations = {
* @param {Object} state The store data
* @param {Task} task The task
* @param {Moment} start The start date moment
* @param {Boolean} allDay Whether the date is all-day
*/
setStart(state, { task, start }) {
setStart(state, { task, start, allDay }) {
if (start === null) {
// If the date is null, just set (remove) it.
Vue.set(task, 'start', start)
@ -491,10 +493,10 @@ const mutations = {
} else {
due = start.clone()
}
Vue.set(task, 'due', momentToICALTime(due, task.allDay))
Vue.set(task, 'due', momentToICALTime(due, allDay))
}
// Set the due date, convert it to ICALTime first.
Vue.set(task, 'start', momentToICALTime(start, task.allDay))
Vue.set(task, 'start', momentToICALTime(start, allDay))
}
},
@ -1008,8 +1010,8 @@ const actions = {
* @param {Object} context The store context
* @param {Task} task The task to update
*/
async setDue(context, { task, due }) {
context.commit('setDue', { task: task, due: due })
async setDue(context, { task, due, allDay }) {
context.commit('setDue', { task: task, due: due, allDay: allDay })
context.dispatch('scheduleTaskUpdate', task)
},
@ -1019,8 +1021,8 @@ const actions = {
* @param {Object} context The store context
* @param {Task} task The task to update
*/
async setStart(context, { task, start }) {
context.commit('setStart', { task: task, start: start })
async setStart(context, { task, start, allDay }) {
context.commit('setStart', { task: task, start: start, allDay: allDay })
context.dispatch('scheduleTaskUpdate', task)
},