feat: show start date as label in task body

Signed-off-by: Raimund Schlüßler <raimund.schluessler@mailbox.org>
This commit is contained in:
Raimund Schlüßler 2024-01-04 21:42:21 +01:00
parent 381262d0ef
commit 21eba45a49
No known key found for this signature in database
GPG Key ID: 036FA7EB1A599178
3 changed files with 149 additions and 105 deletions

View File

@ -78,7 +78,7 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
<span class="calendar__name">{{ task.calendar.displayName }}</span>
</div>
<SortVariant v-if="hasHiddenSubtasks" :size="20" :title="t('tasks', 'Task has hidden subtasks')" />
<CalendarClock v-if="!overdue(task.startMoment) && task.start" :size="20" :title="t('tasks', 'Task has not yet started')" />
<CalendarClock v-if="!overdue(task.startMoment) && task.start" :size="20" :title="startDateString(task)" />
<Pin v-if="task.pinned" :size="20" :title="t('tasks', 'Task is pinned')" />
<TextBoxOutline v-if="task.note!=''"
:size="20"
@ -188,6 +188,7 @@ import TaskStatusDisplay from './TaskStatusDisplay.vue'
import TaskDragContainer from './TaskDragContainer.vue'
import Task from '../models/task.js'
import openNewTask from '../mixins/openNewTask.js'
import { startDateString } from '../utils/dateStrings.js'
import { emit } from '@nextcloud/event-bus'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
@ -473,6 +474,7 @@ export default {
methods: {
t,
n,
startDateString,
...mapActions([
'toggleCompleted',

143
src/utils/dateStrings.js Normal file
View File

@ -0,0 +1,143 @@
/**
* Nextcloud - Tasks
*
* @author Raimund Schlüßler
*
* @copyright 2024 Raimund Schlüßler <raimund.schluessler@mailbox.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Returns a formatted string for the due date
*
* @param {Task} task The task
* @return {string} The formatted due date string
*/
export function dueDateString(task) {
if (task.allDay) {
return 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: t('tasks', '[Due today]'),
// 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.
nextDay: t('tasks', '[Due tomorrow]'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string and keep the brackets and the "LL".
nextWeek: t('tasks', '[Due on] LL'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string, but keep the brackets.
lastDay: t('tasks', '[Was due yesterday]'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, but keep the brackets and the "LL".
lastWeek: t('tasks', '[Was due on] LL'),
sameElse(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string, but keep the brackets and the "LL".
return t('tasks', '[Was due on] LL')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string, but keep the brackets and the "LL".
return t('tasks', '[Due on] LL')
}
},
})
} else {
return task.dueMoment.calendar(null, {
sameDay(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
return t('tasks', '[Was due today at] LT')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
return t('tasks', '[Due today at] LT')
}
},
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
nextDay: t('tasks', '[Due tomorrow at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
nextWeek: t('tasks', '[Due on] LL [at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
lastDay: t('tasks', '[Was due yesterday at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
lastWeek: t('tasks', '[Was due on] LL [at] LT'),
sameElse(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
return t('tasks', '[Was due on] LL [at] LT')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
return t('tasks', '[Due on] LL [at] LT')
}
},
})
}
}
/**
* Returns a formatted string for the start date
*
* @param {Task} task The task
* @return {string} The formatted start date string
*/
export function startDateString(task) {
if (task.allDay) {
return 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: t('tasks', '[Starts today]'),
// 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.
nextDay: t('tasks', '[Starts tomorrow]'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
nextWeek: t('tasks', '[Starts on] LL'),
// 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.
lastDay: t('tasks', '[Started yesterday]'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
lastWeek: t('tasks', '[Started on] LL'),
sameElse(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
return t('tasks', '[Started on] LL')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
return t('tasks', '[Starts on] LL')
}
},
})
} else {
return task.startMoment.calendar(null, {
sameDay(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
return t('tasks', '[Started today at] LT')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
return t('tasks', '[Starts today at] LT')
}
},
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
nextDay: t('tasks', '[Starts tomorrow at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
nextWeek: t('tasks', '[Starts on] LL [at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
lastDay: t('tasks', '[Started yesterday at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
lastWeek: t('tasks', '[Started on] LL [at] LT'),
sameElse(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
return t('tasks', '[Started on] LL [at] LT')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
return t('tasks', '[Starts on] LL [at] LT')
}
},
})
}
}

View File

@ -252,6 +252,7 @@ import NotesItem from '../components/AppSidebar/NotesItem.vue'
import TaskCheckbox from '../components/TaskCheckbox.vue'
// import TaskStatusDisplay from '../components/TaskStatusDisplay'
import Task from '../models/task.js'
import { startDateString, dueDateString } from '../utils/dateStrings.js'
import { subscribe, unsubscribe } from '@nextcloud/event-bus'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'
@ -568,116 +569,14 @@ export default {
},
startDateString() {
if (this.task.startMoment.isValid()) {
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: t('tasks', '[Starts today]'),
// 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.
nextDay: t('tasks', '[Starts tomorrow]'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
nextWeek: t('tasks', '[Starts on] LL'),
// 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.
lastDay: t('tasks', '[Started yesterday]'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
lastWeek: t('tasks', '[Started on] LL'),
sameElse(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
return t('tasks', '[Started on] LL')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, and keep the brackets and the "LL".
return t('tasks', '[Starts on] LL')
}
},
})
} else {
return this.task.startMoment.calendar(null, {
sameDay(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
return t('tasks', '[Started today at] LT')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
return t('tasks', '[Starts today at] LT')
}
},
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
nextDay: t('tasks', '[Starts tomorrow at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
nextWeek: t('tasks', '[Starts on] LL [at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
lastDay: t('tasks', '[Started yesterday at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
lastWeek: t('tasks', '[Started on] LL [at] LT'),
sameElse(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
return t('tasks', '[Started on] LL [at] LT')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
return t('tasks', '[Starts on] LL [at] LT')
}
},
})
}
return startDateString(this.task)
} else {
return t('tasks', 'Set start date')
}
},
dueDateString() {
if (this.task.dueMoment.isValid()) {
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: t('tasks', '[Due today]'),
// 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.
nextDay: t('tasks', '[Due tomorrow]'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string and keep the brackets and the "LL".
nextWeek: t('tasks', '[Due on] LL'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string, but keep the brackets.
lastDay: t('tasks', '[Was due yesterday]'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986'. Please translate the string, but keep the brackets and the "LL".
lastWeek: t('tasks', '[Was due on] LL'),
sameElse(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string, but keep the brackets and the "LL".
return t('tasks', '[Was due on] LL')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. Please translate the string, but keep the brackets and the "LL".
return t('tasks', '[Due on] LL')
}
},
})
} else {
return this.task.dueMoment.calendar(null, {
sameDay(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
return t('tasks', '[Was due today at] LT')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
return t('tasks', '[Due today at] LT')
}
},
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
nextDay: t('tasks', '[Due tomorrow at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
nextWeek: t('tasks', '[Due on] LL [at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets and the "LT".
lastDay: t('tasks', '[Was due yesterday at] LT'),
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
lastWeek: t('tasks', '[Was due on] LL [at] LT'),
sameElse(now) {
if (this.isBefore(now)) {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
return t('tasks', '[Was due on] LL [at] LT')
} else {
// TRANSLATORS This is a string for moment.js. The square brackets escape the string from moment.js. "LL" will be replaced with a date, e.g. 'September 4 1986' and "LT" will be replaced with a time, e.g. '08:30 PM'. Please translate the string and keep the brackets the "LL" and the "LT".
return t('tasks', '[Due on] LL [at] LT')
}
},
})
}
return dueDateString(this.task)
} else {
return t('tasks', 'Set due date')
}