2022-05-12 23:05:07 +08:00
|
|
|
<template>
|
|
|
|
<div class="attachment-container asset"
|
|
|
|
:data-asset-id="attachment.id"
|
2024-01-18 21:49:46 +08:00
|
|
|
@mouseenter="handleMouseEnter"
|
2024-01-10 22:33:13 +08:00
|
|
|
@mouseleave="handleMouseLeave"
|
2024-01-18 21:49:46 +08:00
|
|
|
v-click-outside="handleClickOutsideThumbnail"
|
2024-06-07 18:05:31 +08:00
|
|
|
:data-e2e="`e2e-CO-${dataE2e}-attachment${attachment.id}-thumbnail`"
|
2022-05-12 23:05:07 +08:00
|
|
|
>
|
2024-01-10 22:33:13 +08:00
|
|
|
<a :class="{ hidden: showOptions }"
|
2023-08-30 21:42:55 +08:00
|
|
|
:href="attachment.attributes.urls.blob"
|
2022-05-12 23:05:07 +08:00
|
|
|
class="file-preview-link file-name"
|
|
|
|
:id="`modal_link${attachment.id}`"
|
|
|
|
data-no-turbolink="true"
|
|
|
|
:data-id="attachment.id"
|
2023-07-24 19:28:44 +08:00
|
|
|
:data-gallery-view-id="parentId"
|
2022-05-12 23:05:07 +08:00
|
|
|
:data-preview-url="attachment.attributes.urls.preview"
|
2024-01-16 00:17:55 +08:00
|
|
|
:data-e2e="`e2e-BT-attachment-${attachment.id}`"
|
2022-05-12 23:05:07 +08:00
|
|
|
>
|
2022-05-13 19:07:50 +08:00
|
|
|
<div class="attachment-preview" :class= "attachment.attributes.asset_type">
|
|
|
|
<img v-if="attachment.attributes.medium_preview !== null"
|
2023-09-18 21:32:53 +08:00
|
|
|
class="rounded-sm"
|
2022-05-13 19:07:50 +08:00
|
|
|
:src="attachment.attributes.medium_preview"
|
2022-05-12 23:05:07 +08:00
|
|
|
style='opacity: 0' />
|
2023-09-18 21:32:53 +08:00
|
|
|
<div v-else class="w-[186px] h-[186px] bg-sn-super-light-grey rounded-sm"></div>
|
2022-05-12 23:05:07 +08:00
|
|
|
</div>
|
2022-09-02 21:09:56 +08:00
|
|
|
<div class="attachment-label"
|
|
|
|
data-toggle="tooltip"
|
|
|
|
data-placement="bottom"
|
2022-08-16 18:20:37 +08:00
|
|
|
:title="`${ attachment.attributes.file_name }`">
|
2022-05-12 23:05:07 +08:00
|
|
|
{{ attachment.attributes.file_name }}
|
|
|
|
</div>
|
2023-08-30 21:42:55 +08:00
|
|
|
</a>
|
2024-01-10 22:33:13 +08:00
|
|
|
<div :class="{ hidden: !showOptions }" class="hovered-thumbnail h-full">
|
2023-08-30 21:42:55 +08:00
|
|
|
<a
|
|
|
|
:href="attachment.attributes.urls.blob"
|
|
|
|
class="file-preview-link file-name"
|
|
|
|
:id="`modal_link${attachment.id}`"
|
|
|
|
data-no-turbolink="true"
|
|
|
|
:data-id="attachment.id"
|
|
|
|
:data-gallery-view-id="parentId"
|
|
|
|
:data-preview-url="attachment.attributes.urls.preview"
|
|
|
|
>
|
|
|
|
{{ attachment.attributes.file_name }}
|
|
|
|
</a>
|
2023-09-25 20:15:08 +08:00
|
|
|
<div class="absolute bottom-16 text-sn-grey">
|
2022-05-13 19:07:50 +08:00
|
|
|
{{ attachment.attributes.file_size_formatted }}
|
2022-05-12 23:05:07 +08:00
|
|
|
</div>
|
2023-09-26 22:23:16 +08:00
|
|
|
<div class="absolute bottom-4 w-[184px] grid grid-cols-[repeat(4,_2.5rem)] justify-between">
|
2024-06-20 17:48:35 +08:00
|
|
|
<openMenu
|
|
|
|
:attachment="attachment"
|
|
|
|
:multipleOpenOptions="multipleOpenOptions"
|
|
|
|
@open="toggleMenu"
|
|
|
|
@close="toggleMenu"
|
|
|
|
@option:click="$emit($event)"
|
|
|
|
/>
|
2024-06-07 18:05:31 +08:00
|
|
|
<a v-if="attachment.attributes.urls.move"
|
|
|
|
@click.prevent.stop="showMoveModal"
|
|
|
|
class="btn btn-light icon-btn thumbnail-action-btn"
|
|
|
|
:title="i18n.t('attachments.thumbnail.buttons.move')">
|
2023-08-30 21:42:55 +08:00
|
|
|
<i class="sn-icon sn-icon-move"></i>
|
|
|
|
</a>
|
|
|
|
<a class="btn btn-light icon-btn thumbnail-action-btn"
|
|
|
|
:title="i18n.t('attachments.thumbnail.buttons.download')"
|
|
|
|
:href="attachment.attributes.urls.download" data-turbolinks="false">
|
|
|
|
<i class="sn-icon sn-icon-export"></i>
|
|
|
|
</a>
|
2024-04-30 16:32:24 +08:00
|
|
|
<ContextMenu
|
|
|
|
class="!relative !top-0 !left-0"
|
|
|
|
v-show="showOptions"
|
|
|
|
:attachment="attachment"
|
|
|
|
:hideEdit="true"
|
|
|
|
@attachment:viewMode="updateViewMode"
|
|
|
|
@attachment:delete="deleteAttachment"
|
|
|
|
@attachment:moved="attachmentMoved"
|
|
|
|
@attachment:uploaded="reloadAttachments"
|
|
|
|
@attachment:changed="$emit('attachment:changed', $event)"
|
|
|
|
@attachment:update="$emit('attachment:update', $event)"
|
|
|
|
@menu-toggle="toggleMenu"
|
|
|
|
:withBorder="true"
|
|
|
|
/>
|
2023-08-30 21:42:55 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-02-07 18:26:40 +08:00
|
|
|
<Teleport to="body">
|
|
|
|
<deleteAttachmentModal
|
|
|
|
v-if="deleteModal"
|
|
|
|
:fileName="attachment.attributes.file_name"
|
|
|
|
@confirm="deleteAttachment"
|
|
|
|
@cancel="deleteModal = false"
|
|
|
|
/>
|
2024-03-20 23:06:46 +08:00
|
|
|
<MoveAssetModal
|
2024-02-07 18:26:40 +08:00
|
|
|
v-if="movingAttachment"
|
|
|
|
:parent_type="attachment.attributes.parent_type"
|
|
|
|
:targets_url="attachment.attributes.urls.move_targets"
|
|
|
|
@confirm="moveAttachment($event)" @cancel="closeMoveModal"
|
|
|
|
/>
|
|
|
|
<NoPredefinedAppModal
|
|
|
|
v-if="showNoPredefinedAppModal"
|
|
|
|
:fileName="attachment.attributes.file_name"
|
2024-02-15 21:10:24 +08:00
|
|
|
@close="showNoPredefinedAppModal = false"
|
2024-02-07 18:26:40 +08:00
|
|
|
/>
|
|
|
|
<UpdateVersionModal
|
|
|
|
v-if="showUpdateVersionModal"
|
2024-02-15 21:10:24 +08:00
|
|
|
@close="showUpdateVersionModal = false"
|
|
|
|
/>
|
|
|
|
<editLaunchingApplicationModal
|
|
|
|
v-if="editAppModal"
|
|
|
|
:fileName="attachment.attributes.file_name"
|
|
|
|
:application="this.localAppName"
|
|
|
|
@close="editAppModal = false"
|
2024-02-07 18:26:40 +08:00
|
|
|
/>
|
|
|
|
</Teleport>
|
2024-01-11 21:41:32 +08:00
|
|
|
<a class="image-edit-button hidden"
|
|
|
|
v-if="attachment.attributes.asset_type != 'marvinjs'
|
|
|
|
&& attachment.attributes.image_editable
|
|
|
|
&& attachment.attributes.urls.start_edit_image"
|
|
|
|
ref="imageEditButton"
|
|
|
|
:data-image-id="attachment.id"
|
|
|
|
:data-image-name="attachment.attributes.file_name"
|
|
|
|
:data-image-url="attachment.attributes.urls.asset_file"
|
|
|
|
:data-image-quality="attachment.attributes.image_context.quality"
|
|
|
|
:data-image-mime-type="attachment.attributes.image_context.type"
|
|
|
|
:data-image-start-edit-url="attachment.attributes.urls.start_edit_image"
|
|
|
|
></a>
|
2022-05-12 23:05:07 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-01-04 20:59:54 +08:00
|
|
|
import AttachmentMovedMixin from './mixins/attachment_moved.js';
|
|
|
|
import ContextMenuMixin from './mixins/context_menu.js';
|
|
|
|
import ContextMenu from './context_menu.vue';
|
|
|
|
import deleteAttachmentModal from './delete_modal.vue';
|
|
|
|
import MenuDropdown from '../../../shared/menu_dropdown.vue';
|
|
|
|
import MoveAssetModal from '../modal/move.vue';
|
|
|
|
import MoveMixin from './mixins/move.js';
|
|
|
|
import OpenLocallyMixin from './mixins/open_locally.js';
|
2024-06-20 17:48:35 +08:00
|
|
|
import OpenMenu from './open_menu.vue';
|
2024-01-18 21:49:46 +08:00
|
|
|
import { vOnClickOutside } from '@vueuse/components';
|
2023-08-30 21:42:55 +08:00
|
|
|
|
2024-01-04 17:15:06 +08:00
|
|
|
export default {
|
|
|
|
name: 'thumbnailAttachment',
|
2024-01-04 20:27:28 +08:00
|
|
|
mixins: [ContextMenuMixin, AttachmentMovedMixin, MoveMixin, OpenLocallyMixin],
|
2024-01-04 20:59:54 +08:00
|
|
|
components: {
|
|
|
|
ContextMenu,
|
|
|
|
deleteAttachmentModal,
|
|
|
|
MoveAssetModal,
|
2024-06-20 17:48:35 +08:00
|
|
|
MenuDropdown,
|
|
|
|
OpenMenu
|
2024-01-04 20:59:54 +08:00
|
|
|
},
|
2024-01-04 17:15:06 +08:00
|
|
|
props: {
|
|
|
|
attachment: {
|
|
|
|
type: Object,
|
|
|
|
required: true
|
2023-08-30 21:42:55 +08:00
|
|
|
},
|
2024-01-04 17:15:06 +08:00
|
|
|
parentId: {
|
|
|
|
type: Number,
|
|
|
|
required: true
|
2024-06-07 18:05:31 +08:00
|
|
|
},
|
|
|
|
dataE2e: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
2024-01-04 17:15:06 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2024-01-15 20:44:50 +08:00
|
|
|
showOptions: false,
|
2024-01-04 17:15:06 +08:00
|
|
|
deleteModal: false,
|
2024-02-01 17:42:40 +08:00
|
|
|
isMenuOpen: false
|
2024-01-04 17:15:06 +08:00
|
|
|
};
|
|
|
|
},
|
2024-01-18 21:49:46 +08:00
|
|
|
directives: {
|
|
|
|
'click-outside': vOnClickOutside
|
|
|
|
},
|
2024-01-04 20:27:28 +08:00
|
|
|
computed: {
|
2024-01-11 21:41:32 +08:00
|
|
|
multipleOpenOptions() {
|
2024-01-04 20:59:54 +08:00
|
|
|
const options = [];
|
2024-01-04 20:27:28 +08:00
|
|
|
if (this.attachment.attributes.wopi && this.attachment.attributes.urls.edit_asset) {
|
|
|
|
options.push({
|
|
|
|
text: this.attachment.attributes.wopi_context.button_text,
|
|
|
|
url: this.attachment.attributes.urls.edit_asset,
|
|
|
|
url_target: '_blank'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.attachment.attributes.asset_type !== 'marvinjs'
|
|
|
|
&& this.attachment.attributes.image_editable
|
|
|
|
&& this.attachment.attributes.urls.start_edit_image) {
|
|
|
|
options.push({
|
|
|
|
text: this.i18n.t('assets.file_preview.edit_in_scinote'),
|
2024-01-04 20:59:54 +08:00
|
|
|
emit: 'open_scinote_editor'
|
|
|
|
});
|
2024-01-04 20:27:28 +08:00
|
|
|
}
|
|
|
|
if (this.canOpenLocally) {
|
2024-01-04 20:59:54 +08:00
|
|
|
const text = this.localAppName
|
|
|
|
? this.i18n.t('attachments.open_locally_in', { application: this.localAppName })
|
|
|
|
: this.i18n.t('attachments.open_locally');
|
2023-12-13 23:33:53 +08:00
|
|
|
|
2024-01-04 20:27:28 +08:00
|
|
|
options.push({
|
2024-01-04 20:59:54 +08:00
|
|
|
text,
|
2024-03-06 09:17:45 +08:00
|
|
|
emit: 'open_locally',
|
|
|
|
data_e2e: 'e2e-BT-attachmentOptions-openLocally'
|
2024-01-04 20:27:28 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return options;
|
2024-06-07 18:05:31 +08:00
|
|
|
}
|
2024-01-04 20:27:28 +08:00
|
|
|
},
|
2024-01-04 17:15:06 +08:00
|
|
|
mounted() {
|
2024-01-04 20:59:54 +08:00
|
|
|
$(this.$nextTick(() => {
|
|
|
|
$('.attachment-preview img')
|
2024-01-04 17:15:06 +08:00
|
|
|
.on('error', (event) => ActiveStoragePreviews.reCheckPreview(event))
|
2024-01-04 20:59:54 +08:00
|
|
|
.on('load', (event) => ActiveStoragePreviews.showPreview(event));
|
|
|
|
}));
|
2024-01-04 17:15:06 +08:00
|
|
|
},
|
|
|
|
watch: {
|
2024-01-15 20:44:50 +08:00
|
|
|
showOptions(newValue) {
|
2024-01-04 17:15:06 +08:00
|
|
|
// reload thumbnail on mouse out
|
|
|
|
if (newValue) return;
|
|
|
|
|
2024-01-04 20:59:54 +08:00
|
|
|
$(this.$nextTick(() => {
|
|
|
|
$('.attachment-preview img')
|
2023-09-22 16:36:07 +08:00
|
|
|
.on('error', (event) => ActiveStoragePreviews.reCheckPreview(event))
|
2024-01-04 20:59:54 +08:00
|
|
|
.on('load', (event) => ActiveStoragePreviews.showPreview(event));
|
|
|
|
}));
|
2024-01-04 17:15:06 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
openOVEditor(url) {
|
|
|
|
window.showIFrameModal(url);
|
2024-01-10 22:33:13 +08:00
|
|
|
},
|
2024-01-11 21:41:32 +08:00
|
|
|
openScinoteEditor() {
|
|
|
|
this.$refs.imageEditButton.click();
|
2024-01-15 23:16:20 +08:00
|
|
|
},
|
2024-01-10 22:33:13 +08:00
|
|
|
handleMouseLeave() {
|
|
|
|
if (!this.isMenuOpen) {
|
|
|
|
this.showOptions = false;
|
|
|
|
}
|
|
|
|
},
|
2024-01-18 21:49:46 +08:00
|
|
|
async handleMouseEnter() {
|
|
|
|
await this.fetchLocalAppInfo();
|
|
|
|
this.showOptions = true;
|
|
|
|
},
|
2024-03-20 23:06:46 +08:00
|
|
|
toggleMenu(isMenuOpen) {
|
2024-03-04 16:24:04 +08:00
|
|
|
this.isMenuOpen = isMenuOpen;
|
|
|
|
if (isMenuOpen) {
|
|
|
|
this.showOptions = true;
|
2024-01-18 21:49:46 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
handleClickOutsideThumbnail(event) {
|
|
|
|
const isClickInsideModal = event.target.closest('.modal');
|
|
|
|
if (!isClickInsideModal) {
|
|
|
|
this.showOptions = false;
|
|
|
|
this.isMenuOpen = false;
|
|
|
|
}
|
|
|
|
},
|
2022-05-12 23:05:07 +08:00
|
|
|
}
|
2024-01-04 20:59:54 +08:00
|
|
|
};
|
2022-05-12 23:05:07 +08:00
|
|
|
</script>
|