-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3118 from nextcloud/feature/trashbin
Add a UI for the Nextcloud CalDAV trashbin
- Loading branch information
Showing
9 changed files
with
424 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<template> | ||
<span class="live-relative-timestamp" :data-timestamp="timestamp * 1000" :title="title">{{ formatted }}</span> | ||
</template> | ||
|
||
<script> | ||
import moment from '@nextcloud/moment' | ||
export default { | ||
name: 'Moment', | ||
props: { | ||
timestamp: { | ||
type: Number, | ||
required: true, | ||
}, | ||
format: { | ||
type: String, | ||
default: 'LLL', | ||
}, | ||
}, | ||
computed: { | ||
title() { | ||
return moment.unix(this.timestamp).format(this.format) | ||
}, | ||
formatted() { | ||
return moment.unix(this.timestamp).fromNow() | ||
}, | ||
}, | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
<!-- | ||
- @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at> | ||
- | ||
- @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at> | ||
- | ||
- @license GNU AGPL version 3 or any later version | ||
- | ||
- This program is free software: you can redistribute it and/or modify | ||
- it under the terms of the GNU Affero General Public License as | ||
- published by the Free Software Foundation, either version 3 of the | ||
- License, or (at your option) any later version. | ||
- | ||
- This program 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 program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
|
||
<template> | ||
<AppNavigationItem :title="t('calendar', 'Trashbin')" | ||
:pinned="true" | ||
icon="icon-delete" | ||
@click.prevent="onShow"> | ||
<template #extra> | ||
<Modal v-if="showModal" | ||
@close="showModal = false"> | ||
<div class="modal__content"> | ||
<h2>{{ t('calendar', 'Trashbin') }}</h2> | ||
<span v-if="!items.length">{{ t('calendar', 'You do not have any deleted calendars or events') }}</span> | ||
<table v-else> | ||
<tr> | ||
<th>{{ t('calendar', 'Name') }}</th> | ||
<th class="deletedAt"> | ||
{{ t('calendar', 'Deleted at') }} | ||
</th> | ||
<th> </th> | ||
</tr> | ||
<tr v-for="item in items" :key="item.url"> | ||
<td>{{ item.name }}</td> | ||
<td class="deletedAt"> | ||
<Moment class="timestamp" :timestamp="item.deletedAt" /> | ||
</td> | ||
<td> | ||
<button @click="restore(item)"> | ||
restore | ||
</button> | ||
</td> | ||
</tr> | ||
</table> | ||
</div> | ||
</Modal> | ||
</template> | ||
</AppNavigationItem> | ||
</template> | ||
|
||
<script> | ||
import AppNavigationItem from '@nextcloud/vue/dist/Components/AppNavigationItem' | ||
import Modal from '@nextcloud/vue/dist/Components/Modal' | ||
import logger from '../../../utils/logger' | ||
import { showError } from '@nextcloud/dialogs' | ||
import { mapGetters } from 'vuex' | ||
import Moment from './Moment' | ||
|
||
export default { | ||
name: 'Trashbin', | ||
components: { | ||
AppNavigationItem, | ||
Modal, | ||
Moment, | ||
}, | ||
data() { | ||
return { | ||
showModal: false, | ||
} | ||
}, | ||
computed: { | ||
...mapGetters([ | ||
'trashBin', | ||
]), | ||
calendars() { | ||
return this.$store.getters.sortedDeletedCalendars | ||
}, | ||
objects() { | ||
return this.$store.getters.deletedCalendarObjects | ||
}, | ||
items() { | ||
const formattedCalendars = this.calendars.map(calendar => ({ | ||
calendar, | ||
type: 'calendar', | ||
key: calendar.url, | ||
name: calendar.displayname, | ||
url: calendar._url, | ||
deletedAt: calendar._props['{http://nextcloud.com/ns}deleted-at'], | ||
})) | ||
const formattedCalendarObjects = this.objects.map(vobject => { | ||
let eventSummary = t('calendar', 'Untitled event') | ||
try { | ||
// TODO: there _has to be_ a less error prone way … | ||
eventSummary = vobject.calendarComponent?._components?.get('VEVENT')[0]?._properties?.get('SUMMARY')[0]?.value | ||
} catch (e) { | ||
// ignore | ||
} | ||
return { | ||
vobject, | ||
type: 'object', | ||
key: vobject.id, | ||
name: `${eventSummary} (${vobject.calendar.displayName})`, | ||
url: vobject.uri, | ||
deletedAt: vobject.dav._props['{http://nextcloud.com/ns}deleted-at'], | ||
} | ||
}) | ||
|
||
return formattedCalendars.concat(formattedCalendarObjects) | ||
}, | ||
}, | ||
methods: { | ||
async onShow() { | ||
this.showModal = true | ||
|
||
try { | ||
await Promise.all([ | ||
this.$store.dispatch('loadDeletedCalendars'), | ||
this.$store.dispatch('loadDeletedCalendarObjects'), | ||
]) | ||
|
||
logger.debug('deleted calendars loaded', { | ||
calendars: this.calendars, | ||
objects: this.objects, | ||
}) | ||
} catch (error) { | ||
logger.error('could not load deleted calendars and objects', { | ||
error, | ||
}) | ||
|
||
showError(t('calendar', 'Could not load deleted calendars and objects')) | ||
} | ||
}, | ||
async restore(item) { | ||
logger.debug('restoring ' + item.url, item) | ||
try { | ||
switch (item.type) { | ||
case 'calendar': | ||
await this.$store.dispatch('restoreCalendar', { calendar: item.calendar }) | ||
this.$store.dispatch('loadCollections') | ||
break | ||
case 'object': | ||
await this.$store.dispatch('restoreCalendarObject', { vobject: item.vobject }) | ||
break | ||
} | ||
} catch (error) { | ||
logger.error('could not restore ' + item.url, { error }) | ||
|
||
showError(t('calendar', 'Could not restore calendar or event')) | ||
} | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.modal__content { | ||
width: 40vw; | ||
margin: 2vw; | ||
} | ||
table { | ||
width: 100%; | ||
} | ||
th, td { | ||
padding: 4px; | ||
} | ||
th { | ||
font-weight: bold; | ||
} | ||
.deletedAt { | ||
text-align: right; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.