Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bulk task creation on paste #2273

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 205 additions & 0 deletions src/components/CreateMultipleTasksDialog.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<!--
Nextcloud - Tasks
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/>.
-->

<template>
<NcModal class="task-selector" size="small" @close="() => {!created ? cancel() : close()}">
<div v-if="!creating && !created" id="modal-inner">
<h3>{{ t('tasks', 'Create new tasks') }}</h3>

<p>{{ t('tasks', 'Create {numberOfTasks} tasks from pasted text', { numberOfTasks: tasksToCreate.numberOfTasks }) }}</p>

<div class="modal-buttons">
<NcButton @click="cancel">
{{ t('tasks', 'Cancel') }}
</NcButton>
<NcButton ref="createButton"
type="primary"
@click="addTasks">
{{ t('tasks', 'Create tasks') }}
</NcButton>
</div>
</div>
<div v-else id="modal-inner">
<NcEmptyContent v-if="creating" key="creating" :description="t('tasks', 'Creating new tasks…')">
<template #icon>
<NcLoadingIcon />
</template>
</NcEmptyContent>
<NcEmptyContent v-else-if="created" key="created" :description="createdMessage">
<template #icon>
<Check />
</template>
<template #action>
<NcButton @click="close">
{{ t('tasks', 'Close') }}
</NcButton>
</template>
</NcEmptyContent>
</div>
</NcModal>
</template>

<script>
import { translate as t } from '@nextcloud/l10n'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcEmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
import NcModal from '@nextcloud/vue/dist/Components/NcModal.js'
import Check from 'vue-material-design-icons/Check.vue'
import { mapActions } from 'vuex'
export default {
name: 'CreateMultipleTasksDialog',
components: {
Check,
NcButton,
NcEmptyContent,
NcLoadingIcon,
NcModal,
},
props: {
calendar: {
type: Object,
required: true,
},
tasksToCreate: {
type: Object,
required: true,
},
tasksAdditionalProperties: {
type: Object,
default() {
return {}

Check warning on line 90 in src/components/CreateMultipleTasksDialog.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CreateMultipleTasksDialog.vue#L89-L90

Added lines #L89 - L90 were not covered by tests
},
},
rootTask: {
type: Object,
default: undefined,
},
},
emits: ['cancel', 'close'],
data() {
return {

Check warning on line 100 in src/components/CreateMultipleTasksDialog.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CreateMultipleTasksDialog.vue#L99-L100

Added lines #L99 - L100 were not covered by tests
creating: false,
created: false,
}
},
computed: {
createdMessage() {
return t('tasks', '{numberOfTasks} tasks have been added to "{calendar}"', { numberOfTasks: this.tasksToCreate.numberOfTasks, calendar: this.calendar.displayName }, undefined, { sanitize: false, escape: false })

Check warning on line 108 in src/components/CreateMultipleTasksDialog.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CreateMultipleTasksDialog.vue#L107-L108

Added lines #L107 - L108 were not covered by tests
},
},
mounted() {
this.$nextTick(() => this.$refs.createButton?.$el?.focus())

Check warning on line 113 in src/components/CreateMultipleTasksDialog.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CreateMultipleTasksDialog.vue#L112-L113

Added lines #L112 - L113 were not covered by tests
},
methods: {
...mapActions([
'createTask',
]),
t,
cancel() {
this.$emit('cancel')
this.$root.$emit('close')

Check warning on line 125 in src/components/CreateMultipleTasksDialog.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CreateMultipleTasksDialog.vue#L123-L125

Added lines #L123 - L125 were not covered by tests
},
close() {
this.$emit('close')
this.$root.$emit('close')

Check warning on line 130 in src/components/CreateMultipleTasksDialog.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CreateMultipleTasksDialog.vue#L128-L130

Added lines #L128 - L130 were not covered by tests
},
async addTasks() {
this.creating = true
await Promise.all(this.tasksToCreate.tasks.map(task => this.addTaskWithParent(task, this.rootTask?.uid)))
this.creating = false
this.created = true

Check warning on line 137 in src/components/CreateMultipleTasksDialog.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CreateMultipleTasksDialog.vue#L133-L137

Added lines #L133 - L137 were not covered by tests
},
async addTaskWithParent(task, parentUid) {
const newParent = await this.createTask({

Check warning on line 141 in src/components/CreateMultipleTasksDialog.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CreateMultipleTasksDialog.vue#L140-L141

Added lines #L140 - L141 were not covered by tests
summary: task.summary,
calendar: this.calendar,
related: parentUid,
...this.tasksAdditionalProperties,
})
await Promise.all(task.children.map(child => this.addTaskWithParent(child, newParent?.uid)))

Check warning on line 147 in src/components/CreateMultipleTasksDialog.vue

View check run for this annotation

Codecov / codecov/patch

src/components/CreateMultipleTasksDialog.vue#L147

Added line #L147 was not covered by tests
},
},
}
</script>
<style lang="scss" scoped>
#modal-inner {
display: flex;
flex-direction: column;
padding: 20px;
.loading-overlay {
position: absolute;
top: calc(50% - 20px);
left: calc(50% - 20px);
z-index: 1000;
}
.empty-content {
margin: 10vh 0;
:deep(.empty-content__action) {
display: flex;
}
}
}
.property__item {
border-bottom: none;
margin-bottom: 3px;
:deep(.multiselect .multiselect__tags) {
border: 2px solid var(--color-border-dark);
}
}
.property {
position: relative;
.material-design-icon {
position: absolute;
top: 14px;
left: 14px;
}
}
.modal-buttons {
display: flex;
justify-content: flex-end;
}
:deep(.calendar-picker-option__label),
:deep(.property__item .multiselect__tags) input.multiselect__input {
font-weight: normal;
}
</style>
74 changes: 64 additions & 10 deletions src/components/HeaderBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
<div class="header">
<div v-if="$route.params.collectionId !== 'completed' && calendar && !calendar.readOnly"
class="header__input">
<NcTextField :value.sync="newTaskName"
<NcTextField ref="input"
:value.sync="newTaskName"
:label="placeholder"
autocomplete="off"
class="reactive"
Expand All @@ -32,11 +33,18 @@
:trailing-button-label="placeholder"
@trailing-button-click="addTask"
@keyup.esc="clearNewTask($event)"
@keyup.enter="addTask">
@keyup.enter="addTask"
@paste.stop="addMultipleTasks">
<Plus :size="20" />
</NcTextField>
</div>
<SortorderDropdown />
<CreateMultipleTasksDialog v-if="showCreateMultipleTasksModal"
:calendar="calendar"
:tasks-to-create="multipleTasks"
:tasks-additional-properties="additionalTaskProperties"
@cancel="createMultipleTasksCancelled"
@close="createMultipleTasksSuccessful" />
</div>
</template>

Expand All @@ -51,15 +59,22 @@

import { mapGetters, mapActions } from 'vuex'

import { textToTask } from '../utils/textToTask.js'
import CreateMultipleTasksDialog from './CreateMultipleTasksDialog.vue'

export default {
components: {
CreateMultipleTasksDialog,
NcTextField,
SortorderDropdown,
Plus,
},
data() {
return {
newTaskName: '',
showCreateMultipleTasksModal: false,
multipleTasks: { numberOfTasks: 0, tasks: {} },
additionalTaskProperties: {},
}
},
computed: {
Expand Down Expand Up @@ -91,31 +106,70 @@
this.newTaskName = ''
},

addTask() {
const task = { summary: this.newTaskName }

addTaskWithName(task) {

Check warning on line 109 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L109

Added line #L109 was not covered by tests
// If the task is created in the calendar view,
// we set the current calendar
if (this.$route.params.calendarId) {
task.calendar = this.calendar
}

return this.createTask({

Check warning on line 116 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L116

Added line #L116 was not covered by tests
...task,
...this.getAdditionalTaskProperties(),
})
},

getAdditionalTaskProperties() {
const taskProperties = {}

Check warning on line 123 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L122-L123

Added lines #L122 - L123 were not covered by tests
// If the task is created in a collection view,
// set the appropriate properties.
if (this.$route.params.collectionId === 'starred') {
task.priority = 1
taskProperties.priority = 1

Check warning on line 127 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L127

Added line #L127 was not covered by tests
}
if (this.$route.params.collectionId === 'today'
|| this.$route.params.collectionId === 'week') {
task.due = moment().startOf('day').format('YYYY-MM-DDTHH:mm:ss')
task.allDay = this.$store.state.settings.settings.allDay
taskProperties.due = moment().startOf('day').format('YYYY-MM-DDTHH:mm:ss')
taskProperties.allDay = this.$store.state.settings.settings.allDay

Check warning on line 132 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L131-L132

Added lines #L131 - L132 were not covered by tests
}
if (this.$route.params.collectionId === 'current') {
task.start = moment().format('YYYY-MM-DDTHH:mm:ss')
taskProperties.start = moment().format('YYYY-MM-DDTHH:mm:ss')

Check warning on line 135 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L135

Added line #L135 was not covered by tests
}
return taskProperties

Check warning on line 137 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L137

Added line #L137 was not covered by tests
},

addMultipleTasks($event) {
const pastedText = $event.clipboardData.getData('text')
const tasksFromText = textToTask(pastedText)

Check warning on line 142 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L140-L142

Added lines #L140 - L142 were not covered by tests

if (tasksFromText.numberOfTasks <= 1) {
return

Check warning on line 145 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L144-L145

Added lines #L144 - L145 were not covered by tests
}

this.createTask(task)
this.multipleTasks = tasksFromText
this.showCreateMultipleTasksModal = true
this.additionalTaskProperties = this.getAdditionalTaskProperties()

Check warning on line 150 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L148-L150

Added lines #L148 - L150 were not covered by tests
},

addTask() {
this.addTaskWithName({ summary: this.newTaskName })
this.newTaskName = ''

Check warning on line 155 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L153-L155

Added lines #L153 - L155 were not covered by tests
},

async createMultipleTasksCancelled() {
this.showCreateMultipleTasksModal = false
this.multipleTasks = { numberOfTasks: 0, tasks: {} }
this.additionalTaskProperties = {}
await this.$nextTick()
this.$refs.input.$refs.inputField.$refs.input.focus()

Check warning on line 163 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L158-L163

Added lines #L158 - L163 were not covered by tests
},

async createMultipleTasksSuccessful() {
this.showCreateMultipleTasksModal = false
this.multipleTasks = { numberOfTasks: 0, tasks: {} }
this.additionalTaskProperties = {}

Check warning on line 169 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L166-L169

Added lines #L166 - L169 were not covered by tests
this.newTaskName = ''
await this.$nextTick()
this.$refs.input.$refs.inputField.$refs.input.focus()

Check warning on line 172 in src/components/HeaderBar.vue

View check run for this annotation

Codecov / codecov/patch

src/components/HeaderBar.vue#L171-L172

Added lines #L171 - L172 were not covered by tests
},
},
}
Expand Down
Loading
Loading