-
Notifications
You must be signed in to change notification settings - Fork 0
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 #16 from bcgov/feature/doc-download
Document download and delete
- Loading branch information
Showing
11 changed files
with
284 additions
and
106 deletions.
There are no files selected for viewing
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
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
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,109 @@ | ||
<script setup lang="ts"> | ||
import { filesize } from 'filesize'; | ||
import { Button, Card, useConfirm, useToast } from '@/lib/primevue'; | ||
import { documentService } from '@/services'; | ||
import { formatDateLong } from '@/utils/formatters'; | ||
import type { Document } from '@/types'; | ||
// Props | ||
type Props = { | ||
document: Document; | ||
deleteButton?: boolean; | ||
}; | ||
const props = withDefaults(defineProps<Props>(), { | ||
deleteButton: true | ||
}); | ||
// Emits | ||
const emit = defineEmits(['document:deleted']); | ||
// Actions | ||
const confirm = useConfirm(); | ||
const toast = useToast(); | ||
const confirmDelete = (documentId: string, filename: string) => { | ||
if (documentId) { | ||
confirm.require({ | ||
message: `Please confirm that you want to delete ${filename}.`, | ||
header: 'Delete document?', | ||
acceptLabel: 'Confirm', | ||
rejectLabel: 'Cancel', | ||
accept: () => { | ||
documentService | ||
.deleteDocument(documentId) | ||
.then(() => { | ||
emit('document:deleted', documentId); | ||
toast.success('File deleted'); | ||
}) | ||
.catch(() => {}); | ||
} | ||
}); | ||
} | ||
}; | ||
</script> | ||
|
||
<template> | ||
<Card class="pt-2 pb-1 text-center"> | ||
<template #header> | ||
<img | ||
alt="document header" | ||
src="@/assets/images/bcboxy.png" | ||
class="document-image" | ||
/> | ||
</template> | ||
<template #content> | ||
<div class="grid"> | ||
<h4 | ||
v-tooltip.bottom="props.document.filename" | ||
class="col-12 mb-0 text-left" | ||
style="text-overflow: ellipsis; overflow: hidden" | ||
> | ||
{{ props.document.filename }} | ||
</h4> | ||
<h6 class="col-8 text-left mt-0 mb-0"> | ||
{{ formatDateLong(props.document.createdAt as string) }} | ||
</h6> | ||
<h6 class="col-4 text-right mt-0 mb-0"> | ||
{{ filesize(props.document.filesize) }} | ||
</h6> | ||
</div> | ||
</template> | ||
<template #footer> | ||
<Button | ||
v-if="deleteButton" | ||
v-tooltip.bottom="'Delete document'" | ||
class="p-button-lg p-button-text p-button-danger p-0" | ||
aria-label="Delete object" | ||
@click=" | ||
(e) => { | ||
confirmDelete(props.document.documentId, props.document.filename); | ||
e.stopPropagation(); | ||
} | ||
" | ||
> | ||
<font-awesome-icon icon="fa-solid fa-trash" /> | ||
</Button> | ||
</template> | ||
</Card> | ||
</template> | ||
|
||
<style lang="scss"> | ||
.document-image { | ||
max-height: 140px; | ||
width: auto; | ||
height: auto; | ||
} | ||
.p-card-content { | ||
padding-top: 0; | ||
padding-bottom: 0; | ||
} | ||
.p-card-footer { | ||
padding: 0; | ||
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
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
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.