Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TaskCreateDialog.vue « components « src - github.com/nextcloud/tasks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4d635309f08a38bc9d3249df3dd1ae9827e4bd44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!--
Nextcloud - Tasks

@author Julius Härtl
@copyright 2021 Julius Härtl <jus@bitgrid.net>

@author Jakob Röhrl
@copyright 2021 Jakob Röhrl <jakob.roehrl@web.de>

@author Raimund Schlüßler
@copyright 2021 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/>.

-->

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

			<CalendarPickerItem :disabled="loading"
				:calendar="pendingCalendar"
				:calendars="writableCalendars"
				@change-calendar="changeCalendar" />

			<div class="property property__summary">
				<ViewHeadline :size="20" />
				<input v-model="pendingTitle"
					type="text"
					:placeholder="t('tasks', 'Task summary')"
					:disabled="loading">
			</div>

			<div class="property property__notes">
				<TextBoxOutline :size="20" />
				<textarea v-model="pendingDescription"
					:disabled="loading" />
			</div>
			<div class="modal-buttons">
				<NcButton @click="close">
					{{ t('tasks', 'Cancel') }}
				</NcButton>
				<NcButton :disabled="loading"
					type="primary"
					@click="addTask">
					{{ t('tasks', 'Create task') }}
				</NcButton>
			</div>
		</div>
		<div v-else id="modal-inner">
			<NcEmptyContent v-if="creating" key="creating">
				{{ t('tasks', 'Creating the new task…') }}
				<template #icon>
					<NcLoadingIcon />
				</template>
			</NcEmptyContent>
			<NcEmptyContent v-else-if="created" key="created">
				{{ t('tasks', '"{task}" was added to "{calendar}"', { task: pendingTitle, calendar: pendingCalendar.displayName }, undefined, { sanitize: false, escape: false }) }}
				<template #icon>
					<Check />
				</template>
				<template #desc>
&nbsp;
					<NcButton @click="close">
						{{ t('tasks', 'Close') }}
					</NcButton>
					<NcButton type="primary" @click="openNewTask">
						{{ t('tasks', 'Open task') }}
					</NcButton>
				</template>
			</NcEmptyContent>
		</div>
	</NcModal>
</template>

<script>

import CalendarPickerItem from './AppSidebar/CalendarPickerItem.vue'
import client from '../services/cdav.js'

import { translate as t } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
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 TextBoxOutline from 'vue-material-design-icons/TextBoxOutline.vue'
import ViewHeadline from 'vue-material-design-icons/ViewHeadline.vue'

import { mapGetters, mapActions } from 'vuex'

export default {
	name: 'TaskCreateDialog',
	components: {
		CalendarPickerItem,
		Check,
		NcButton,
		NcEmptyContent,
		NcLoadingIcon,
		NcModal,
		TextBoxOutline,
		ViewHeadline,
	},
	props: {
		title: {
			type: String,
			default: '',
		},
		description: {
			type: String,
			default: '',
		},
	},
	data() {
		return {
			pendingTitle: '',
			pendingDescription: '',
			pendingCalendar: null,
			loading: true,
			creating: false,
			created: false,
			newTask: null,
		}
	},

	computed: {
		...mapGetters({
			writableCalendars: 'getSortedWritableCalendars',
			defaultCalendar: 'getDefaultCalendar',
		}),
	},

	beforeMount() {
		this.fetchCalendars()
	},

	mounted() {
		this.pendingTitle = this.title
		this.pendingDescription = this.description
	},

	methods: {
		...mapActions([
			'createTask',
		]),

		t,

		changeCalendar(calendar) {
			this.pendingCalendar = calendar
		},

		close() {
			this.$emit('close')
			this.$root.$emit('close')
		},

		async fetchCalendars() {
			this.loading = true
			await client.connect({ enableCalDAV: true })
			await this.$store.dispatch('fetchCurrentUserPrincipal')
			await this.$store.dispatch('getCalendarsAndTrashBin')
			// TODO: Would be good to select the default calendar instead of the first one
			this.pendingCalendar = this.writableCalendars[0]
			this.loading = false
		},

		async addTask() {
			this.creating = true
			const task = {
				summary: this.pendingTitle,
				note: this.pendingDescription,
				calendar: this.pendingCalendar,
			}
			this.newTask = await this.createTask(task)
			this.creating = false
			this.created = true
		},
		openNewTask() {
			window.location = generateUrl('apps/tasks') + `/#/calendars/${this.pendingCalendar.id}/tasks/${this.newTask.uri}`
		},
	},

}
</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;

			::v-deep p {
				display: flex;
				justify-content: flex-end;
			}
		}
	}

	.property__item {
		border-bottom: none;
		margin-bottom: 3px;

		&::v-deep .multiselect {
			border: 1px solid var(--color-border-dark);
			border-radius: var(--border-radius);
		}
	}

	.property {
		position: relative;

		.material-design-icon {
			position: absolute;
			top: 12px;
			left: 12px;
		}

		input,
		textarea {
			width: 100%;
			font-size: var(--default-font-size);
			padding-left: 44px;
		}

		input {
			height: 44px !important;
			margin: 0;
		}

		textarea {
			min-width: 100%;
			max-width: 100%;
			min-height: 100px;
		}
	}

	.modal-buttons {
		display: flex;
		justify-content: flex-end;
	}

	::v-deep {
		.calendar-picker-option__label,
		.property__item .multiselect__tags input.multiselect__input {
			font-weight: normal;
		}
	}
</style>