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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
|
<!--
Nextcloud - Tasks
@author Raimund Schlüßler
@copyright 2018 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>
<AppNavigation>
<template #list>
<AppNavigationItem
v-for="collection in collections"
v-show="!hideCollection(collection)"
:id="'collection_' + collection.id"
:key="collection.id"
:collection-id="collection.id"
:to="{ name: 'collections', params: { collectionId: collection.id } }"
:title="collection.displayName"
class="collection reactive"
draggable="false"
@dragstart.native="dragStart"
@drop.native="dropTaskOnCollection(...arguments, collection)"
@dragover.native="dragOver"
@dragenter.native="dragEnter(...arguments, collection)"
@dragleave.native="dragLeave"
@click="setInitialRoute(`/collections/${collection.id}`)">
<template #icon>
<component
:is="collection.icon"
:size="20"
decorative />
</template>
<template #counter>
<AppNavigationCounter v-show="collectionCount(collection.id)">
{{ collectionCount(collection.id) | counterFormatter }}
</AppNavigationCounter>
</template>
</AppNavigationItem>
<draggable
class="draggable-container"
:set-data="setData"
v-bind="{swapThreshold: 0.30, delay: 500, delayOnTouchOnly: true, touchStartThreshold: 3}"
@update="update">
<ListItemCalendar
v-for="calendar in calendars"
:key="calendar.id"
:calendar="calendar"
@click.native="setInitialRoute(`/calendars/${calendar.id}`)" />
</draggable>
<AppNavigationItem v-click-outside="cancelCreate"
:title="t('tasks', 'Add List…')"
:class="{'collection--edit': creating}"
class="collection reactive"
@click="startCreate($event)">
<template #icon>
<Plus :size="20" decorative />
</template>
<div :class="{error: nameError}" class="app-navigation-entry-edit">
<form>
<input id="newListInput"
v-model="newCalendarName"
v-tooltip="{
content: tooltipMessage,
show: showTooltip('list_'),
trigger: 'manual'
}"
:placeholder="t('tasks', 'New List')"
class="edit"
type="text"
@keyup="checkName($event, null, create)">
<input :title="t('tasks', 'Cancel')"
type="cancel"
value=""
class="action icon-close"
@click="cancelCreate">
<input :title="t('tasks', 'Save')"
type="button"
value=""
class="action icon-checkmark"
@click="create($event)">
</form>
<Colorpicker :selected-color="selectedColor" @color-selected="setColor(...arguments)" />
</div>
</AppNavigationItem>
<Trashbin v-if="hasTrashBin" />
</template>
<template #footer>
<AppNavigationSettings />
</template>
</AppNavigation>
</template>
<script>
import ListItemCalendar from '../components/AppNavigation/ListItemCalendar'
import Colorpicker from '../components/AppNavigation/Colorpicker'
import AppNavigationSettings from '../components/AppNavigation/AppNavigationSettings'
import Trashbin from '../components/AppNavigation/Trashbin'
import { translate as t } from '@nextcloud/l10n'
import AppNavigation from '@nextcloud/vue/dist/Components/AppNavigation'
import AppNavigationCounter from '@nextcloud/vue/dist/Components/AppNavigationCounter'
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem'
import CalendarToday from 'vue-material-design-icons/CalendarToday'
import CalendarWeek from 'vue-material-design-icons/CalendarWeek'
import Check from 'vue-material-design-icons/Check'
import CircleOutline from 'vue-material-design-icons/CircleOutline'
import Plus from 'vue-material-design-icons/Plus'
import Star from 'vue-material-design-icons/Star'
import TrendingUp from 'vue-material-design-icons/TrendingUp'
import draggable from 'vuedraggable'
import ClickOutside from 'v-click-outside'
import { mapState, mapGetters, mapActions } from 'vuex'
export default {
components: {
ListItemCalendar,
Colorpicker,
Trashbin,
AppNavigation,
AppNavigationItem,
AppNavigationCounter,
AppNavigationSettings,
draggable,
CalendarToday,
CalendarWeek,
Check,
CircleOutline,
Plus,
TrendingUp,
Star,
},
directives: {
clickOutside: ClickOutside.directive,
},
filters: {
counterFormatter(count) {
switch (false) {
case count !== 0:
return ''
case count < 999:
return '999+'
default:
return count
}
},
},
data() {
return {
editing: '',
shareOpen: '',
copySuccess: false,
copied: false,
creating: false,
nameError: false,
newCalendarName: '',
selectedColor: '',
tooltipMessage: '',
tooltipTarget: '',
}
},
computed: {
...mapState({
collections: state => state.collections.collections,
}),
...mapGetters({
calendars: 'getSortedCalendars',
collectionCount: 'getCollectionCount',
calendarCount: 'getCalendarCount',
isCalendarNameUsed: 'isCalendarNameUsed',
getTask: 'getTaskByUri',
initialRoute: 'initialRoute',
hasTrashBin: 'hasTrashBin',
}),
},
methods: {
t,
...mapActions([
'appendCalendar',
'setPriority',
'setPercentComplete',
'setDate',
'setSetting',
'setCalendarOrder',
]),
/**
* Indicate that we drag a calendar item
*
* @param {object} dataTransfer The dataTransfer object
*/
setData(dataTransfer) {
dataTransfer.setData('text/plain', 'calendar')
},
/**
* Called when the calendar list order is changed.
*
* @param {object} $event The event which caused the sorting
*/
update($event) {
const newIndex = $event.newIndex
const oldIndex = $event.oldIndex
// If the calendars array has no entry, we don't need to sort.
if (this.calendars.length === 0) {
return
}
// If the calendar is inserted at its current position, don't sort.
if (newIndex === oldIndex) {
return
}
// Get a copy of the sorted calendars array
const calendars = [...this.calendars]
// In case the task to move is already in the array, move it to the new position
if (oldIndex > -1) {
calendars.splice(newIndex, 0, calendars.splice(oldIndex, 1)[0])
} else {
return
}
// Get the new sort order for the moved calendar and apply it.
// We just do that to minimize the number of other calendars to be changed.
let newSortOrder
if (newIndex + 1 < calendars.length
&& (newIndex < 1 || calendars[newIndex + 1].order - 1 > calendars[newIndex - 1].order)) {
newSortOrder = calendars[newIndex + 1].order - 1
} else {
newSortOrder = calendars[newIndex - 1].order + 1
}
if (newSortOrder < 0) {
newSortOrder = 0
}
// Apply the new sort order for the moved calendar
this.setCalendarOrder({ calendar: calendars[newIndex], order: newSortOrder })
// Check the sort orders to be strictly monotonous
let currentIndex = 1
while (currentIndex < calendars.length) {
if (calendars[currentIndex].order <= calendars[currentIndex - 1].order) {
const order = { calendar: calendars[currentIndex], order: calendars[currentIndex - 1].order + 1 }
this.setCalendarOrder(order)
}
currentIndex++
}
},
/**
* Handle the drag start
*
* @param {object} e The event object
* @return {boolean}
*/
dragStart(e) {
e.stopPropagation()
e.preventDefault()
return false
},
/**
* Handle the drag over
*
* @param {object} e The event object
* @return {boolean}
*/
dragOver(e) {
if (e.preventDefault) {
e.preventDefault()
}
return false
},
/**
* Set the appropriate class on hovering
*
* @param {object} e The event object
* @param {object} collection The collection on which the task was dropped
*/
dragEnter(e, collection) {
// Check if dropping here is allowed
if (!['starred', 'completed', 'today', 'week'].includes(collection.id)) {
return
}
// Dragging calendars has no effect
if (e.dataTransfer.getData('text/plain') === 'calendar') {
return
}
// Get the correct element, in case we hover a child.
if (e.target.closest) {
const target = e.target.closest('li.collection')
if (target) {
const collections = document.querySelectorAll('li.collection')
collections.forEach((f) => { f.classList.remove('dnd-hover') })
target.classList.add('dnd-hover')
}
}
},
/**
* Remove the hovering class after leaving
*
* @param {object} e The event object
*/
dragLeave(e) {
// Don't do anything if we leave towards a child element.
if (e.target.contains(e.relatedTarget)) {
return
}
// Get the correct element, in case we leave directly from a child.
if (e.target.closest) {
const target = e.target.closest('li.collection')
if (!target || target.contains(e.relatedTarget)) {
return
}
target.classList.remove('dnd-hover')
}
},
/**
* Drop a task on a collection
*
* @param {object} e The event object
* @param {object} collection The collection
*/
dropTaskOnCollection(e, collection) {
// Remove all hover classes
const collections = document.querySelectorAll('li.collection')
collections.forEach((f) => { f.classList.remove('dnd-hover') })
// Check if dropping here is allowed
if (!['starred', 'completed', 'today', 'week'].includes(collection.id)) {
return
}
const taskUri = e.dataTransfer.getData('text/plain')
if (taskUri) {
const task = this.getTask(taskUri)
switch (collection.id) {
case 'starred':
this.setPriority({ task, priority: 1 })
break
case 'completed':
this.setPercentComplete({ task, complete: 100 })
break
case 'today':
this.setDate({ task, day: 0 })
break
case 'week':
this.setDate({ task, day: 6 })
break
}
}
},
hideCollection(collection) {
switch (collection.show) {
case 0:
return true
case 1:
return false
case 2:
return this.collectionCount(collection.id) < 1
}
},
showTooltip(target) {
return this.tooltipTarget === target
},
startCreate(e) {
if (this.$OCA.Theming) {
this.selectedColor = this.$OCA.Theming.color
} else {
this.selectedColor = '#0082C9'
}
this.newCalendarName = ''
this.creating = true
this.$nextTick(
() => document.getElementById('newListInput').focus()
)
e.stopPropagation()
},
cancelCreate() {
this.creating = false
},
create() {
if (!this.isNameAllowed(this.newCalendarName, 'new').allowed) {
return
}
this.appendCalendar({ displayName: this.newCalendarName, color: this.selectedColor })
this.creating = false
},
checkName(event, calendar, callback) {
const calendarId = calendar ? calendar.id : ''
const check = this.isNameAllowed(this.newCalendarName, calendarId)
this.tooltipMessage = check.msg
if (!check.allowed) {
this.tooltipTarget = 'list_' + calendarId
this.nameError = true
} else {
this.tooltipTarget = ''
this.nameError = false
}
if (event.keyCode === 13) {
callback(calendar)
}
if (event.keyCode === 27) {
event.preventDefault()
this.tooltipTarget = ''
this.creating = false
this.editing = false
this.nameError = false
}
},
isNameAllowed(name, id) {
const check = {
allowed: false,
msg: '',
}
if (this.isCalendarNameUsed(name, id)) {
check.msg = t('tasks', 'The name "{calendar}" is already used.', { calendar: name }, undefined, { sanitize: false, escape: false })
} else if (!name) {
check.msg = t('tasks', 'An empty name is not allowed.')
} else {
check.allowed = true
}
return check
},
setColor(color) {
this.selectedColor = color
},
/**
* Saves the current route as new initial route
*
* @param {string} route The new initial route
*/
setInitialRoute(route) {
if (route === this.initialRoute) {
return
}
this.setSetting({ type: 'initialRoute', value: route })
},
},
}
</script>
<style lang="scss" scoped>
$color-error: #e9322d;
.collection::v-deep {
&.collection--edit {
.app-navigation-entry-link {
display: none;
}
.app-navigation-entry-edit {
display: inline-block;
}
}
.app-navigation-entry-edit {
padding-left: 5px !important;
display: none;
position: relative;
&.error input.edit {
color: var(--color-error);
border-color: var(--color-error) !important;
box-shadow: 0 0 6px transparentize( $color-error, .7 );
}
form {
display: flex;
input {
margin-right: 0;
&[type='text'] {
flex-grow: 1;
}
&.action {
background-color: var(--color-background-dark);
width: 36px;
border-left: 0 none;
background-position: center;
cursor: pointer;
&:hover {
border-left: 1px solid;
margin-left: -1px;
width: 37px;
}
}
}
}
}
}
</style>
|