2019-05-22 21:40:03 +02:00
|
|
|
<template>
|
2019-10-25 14:00:07 +02:00
|
|
|
<AppNavigationItem
|
|
|
|
:title="title"
|
|
|
|
:icon="icon"
|
|
|
|
:menu-open.sync="actionsOpen"
|
|
|
|
:to="{ name: 'note', params: { noteId: note.id.toString() } }"
|
|
|
|
:class="{ actionsOpen }"
|
2019-10-26 22:11:28 +02:00
|
|
|
:undo="isPrepareDeleting"
|
|
|
|
@undo="onUndoDeleteNote"
|
2019-10-25 14:00:07 +02:00
|
|
|
>
|
2019-10-26 22:11:28 +02:00
|
|
|
<template v-if="!note.deleting" slot="actions">
|
2019-10-25 14:00:07 +02:00
|
|
|
<ActionButton :icon="actionFavoriteIcon" @click="onToggleFavorite">
|
|
|
|
{{ actionFavoriteText }}
|
|
|
|
</ActionButton>
|
|
|
|
<ActionButton icon="icon-files-dark" @click="onCategorySelected">
|
|
|
|
{{ actionCategoryText }}
|
|
|
|
</ActionButton>
|
|
|
|
<ActionButton :icon="actionDeleteIcon" @click="onDeleteNote">
|
|
|
|
{{ t('notes', 'Delete note') }}
|
|
|
|
</ActionButton>
|
|
|
|
</template>
|
|
|
|
</AppNavigationItem>
|
2019-05-22 21:40:03 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import {
|
2019-10-25 14:00:07 +02:00
|
|
|
ActionButton,
|
2019-05-22 21:40:03 +02:00
|
|
|
AppNavigationItem,
|
2019-10-25 14:00:07 +02:00
|
|
|
} from '@nextcloud/vue'
|
2020-02-19 21:35:19 +01:00
|
|
|
|
|
|
|
import { categoryLabel, setFavorite, prepareDeleteNote, undoDeleteNote, deleteNote } from '../NotesService'
|
2019-05-22 21:40:03 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'NavigationNoteItem',
|
|
|
|
|
|
|
|
components: {
|
2019-10-25 14:00:07 +02:00
|
|
|
ActionButton,
|
2019-05-22 21:40:03 +02:00
|
|
|
AppNavigationItem,
|
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
note: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
data: function() {
|
|
|
|
return {
|
|
|
|
loading: {
|
|
|
|
favorite: false,
|
|
|
|
delete: false,
|
|
|
|
},
|
2019-10-25 14:00:07 +02:00
|
|
|
actionsOpen: false,
|
2019-10-26 22:11:28 +02:00
|
|
|
undoTimer: null,
|
2019-05-22 21:40:03 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2019-10-25 14:00:07 +02:00
|
|
|
icon() {
|
2019-05-22 21:40:03 +02:00
|
|
|
let icon = ''
|
|
|
|
if (this.note.error) {
|
|
|
|
icon = 'nav-icon icon-error-color'
|
|
|
|
} else if (this.note.favorite) {
|
|
|
|
icon = 'nav-icon icon-starred'
|
|
|
|
}
|
2019-10-25 14:00:07 +02:00
|
|
|
return icon
|
|
|
|
},
|
|
|
|
|
2019-10-26 22:11:28 +02:00
|
|
|
isPrepareDeleting() {
|
|
|
|
return this.note.deleting === 'prepare'
|
|
|
|
},
|
|
|
|
|
2019-10-25 14:00:07 +02:00
|
|
|
title() {
|
2019-10-26 22:11:28 +02:00
|
|
|
if (this.isPrepareDeleting) {
|
|
|
|
return this.t('notes', 'Deleted {title}', { title: this.note.title })
|
|
|
|
} else {
|
|
|
|
return this.note.title + (this.note.unsaved ? ' *' : '')
|
|
|
|
}
|
2019-10-25 14:00:07 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
actionFavoriteText() {
|
|
|
|
return this.note.favorite ? this.t('notes', 'Remove from favorites') : this.t('notes', 'Add to favorites')
|
|
|
|
},
|
|
|
|
|
|
|
|
actionFavoriteIcon() {
|
|
|
|
let icon = this.note.favorite ? 'icon-star-dark' : 'icon-starred'
|
2019-05-22 21:40:03 +02:00
|
|
|
if (this.loading.favorite) {
|
2019-10-25 14:00:07 +02:00
|
|
|
icon += ' loading'
|
2019-05-22 21:40:03 +02:00
|
|
|
}
|
2019-10-25 14:00:07 +02:00
|
|
|
return icon
|
|
|
|
},
|
|
|
|
|
|
|
|
actionCategoryText() {
|
2020-02-19 21:35:19 +01:00
|
|
|
return categoryLabel(this.note.category)
|
2019-10-25 14:00:07 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
actionDeleteIcon() {
|
|
|
|
return 'icon-delete' + (this.loading.delete ? ' loading' : '')
|
2019-05-22 21:40:03 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
onToggleFavorite() {
|
|
|
|
this.loading.favorite = true
|
2020-02-19 21:35:19 +01:00
|
|
|
setFavorite(this.note.id, !this.note.favorite)
|
2019-05-22 21:40:03 +02:00
|
|
|
.catch(() => {
|
|
|
|
})
|
2020-02-19 21:35:19 +01:00
|
|
|
.then(() => {
|
2019-05-22 21:40:03 +02:00
|
|
|
this.loading.favorite = false
|
2019-10-25 14:00:07 +02:00
|
|
|
this.actionsOpen = false
|
2019-05-22 21:40:03 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
onCategorySelected() {
|
2019-10-25 14:00:07 +02:00
|
|
|
this.actionsOpen = false
|
2019-05-22 21:40:03 +02:00
|
|
|
this.$emit('category-selected', this.note.category)
|
|
|
|
},
|
|
|
|
|
|
|
|
onDeleteNote() {
|
2019-10-26 22:11:28 +02:00
|
|
|
this.actionsOpen = false
|
2020-02-19 21:35:19 +01:00
|
|
|
prepareDeleteNote(this.note.id)
|
2019-10-26 22:11:28 +02:00
|
|
|
this.undoTimer = setTimeout(this.onDeleteNoteFinally, 7000)
|
|
|
|
this.$emit('note-deleted')
|
|
|
|
},
|
|
|
|
|
|
|
|
onUndoDeleteNote() {
|
|
|
|
clearTimeout(this.undoTimer)
|
2020-02-19 21:35:19 +01:00
|
|
|
undoDeleteNote(this.note.id)
|
2019-10-26 22:11:28 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
onDeleteNoteFinally() {
|
2019-05-22 21:40:03 +02:00
|
|
|
this.loading.delete = true
|
2020-02-19 21:35:19 +01:00
|
|
|
deleteNote(this.note.id)
|
2019-05-22 21:40:03 +02:00
|
|
|
.then(() => {
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
})
|
2020-02-19 21:35:19 +01:00
|
|
|
.then(() => {
|
2019-05-22 21:40:03 +02:00
|
|
|
this.loading.delete = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|