2022-05-12 23:05:07 +08:00
|
|
|
<template>
|
|
|
|
<div class="attachment-container asset"
|
|
|
|
:data-asset-id="attachment.id"
|
2023-08-30 21:42:55 +08:00
|
|
|
@mouseover="isHovered = true"
|
|
|
|
@mouseleave="isHovered = false"
|
2022-05-12 23:05:07 +08:00
|
|
|
>
|
2023-09-22 16:36:07 +08:00
|
|
|
<a :class="{ hidden: isHovered }"
|
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"
|
|
|
|
>
|
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>
|
2023-09-22 16:36:07 +08:00
|
|
|
<div :class="{ hidden: !isHovered }" 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">
|
2023-12-13 23:33:53 +08:00
|
|
|
<MenuDropdown
|
|
|
|
v-if="isHovered && openOptions.length > 1"
|
|
|
|
:listItems="openOptions"
|
|
|
|
:btnClasses="'btn btn-light icon-btn thumbnail-action-btn'"
|
|
|
|
:position="'left'"
|
|
|
|
:btnIcon="'sn-icon sn-icon-open'"
|
|
|
|
:title="i18n.t('attachments.thumbnail.buttons.open')"
|
|
|
|
></MenuDropdown>
|
2023-09-26 22:23:16 +08:00
|
|
|
<a class="btn btn-light icon-btn thumbnail-action-btn"
|
2023-12-13 23:33:53 +08:00
|
|
|
v-else-if="canOpenLocally"
|
|
|
|
@click="openLocally"
|
|
|
|
:title="i18n.t('attachments.thumbnail.buttons.open')"
|
|
|
|
>
|
|
|
|
<i class="sn-icon sn-icon-open"></i>
|
|
|
|
</a>
|
|
|
|
<a class="btn btn-light icon-btn thumbnail-action-btn"
|
|
|
|
v-else-if="this.attachment.attributes.wopi && this.attachment.attributes.urls.edit_asset"
|
2023-09-26 22:23:16 +08:00
|
|
|
:href="attachment.attributes.urls.edit_asset"
|
2023-12-13 23:33:53 +08:00
|
|
|
:title="i18n.t('attachments.thumbnail.buttons.open')"
|
2023-09-26 22:23:16 +08:00
|
|
|
id="wopi_file_edit_button"
|
|
|
|
:class="attachment.attributes.wopi_context.edit_supported ? '' : 'disabled'"
|
2023-10-05 21:44:41 +08:00
|
|
|
target="_blank"
|
2023-09-26 22:23:16 +08:00
|
|
|
>
|
2023-12-13 23:33:53 +08:00
|
|
|
<i class="sn-icon sn-icon-open"></i>
|
2023-09-26 22:23:16 +08:00
|
|
|
</a>
|
|
|
|
<a class="btn btn-light icon-btn thumbnail-action-btn ove-edit-button"
|
|
|
|
v-else-if="attachment.attributes.asset_type == 'gene_sequence' && attachment.attributes.urls.open_vector_editor_edit"
|
|
|
|
@click="openOVEditor(attachment.attributes.urls.open_vector_editor_edit)"
|
|
|
|
>
|
2023-12-13 23:33:53 +08:00
|
|
|
<i class="sn-icon sn-icon-open"></i>
|
2023-09-26 22:23:16 +08:00
|
|
|
</a>
|
|
|
|
<a class="btn btn-light icon-btn thumbnail-action-btn marvinjs-edit-button"
|
|
|
|
v-else-if="attachment.attributes.asset_type == 'marvinjs' && attachment.attributes.urls.marvin_js_start_edit"
|
|
|
|
:data-sketch-id="attachment.id"
|
|
|
|
:data-update-url="attachment.attributes.urls.marvin_js"
|
|
|
|
:data-sketch-start-edit-url="attachment.attributes.urls.marvin_js_start_edit"
|
|
|
|
:data-sketch-name="attachment.attributes.metadata.name"
|
|
|
|
:data-sketch-description="attachment.attributes.metadata.description"
|
|
|
|
>
|
2023-12-13 23:33:53 +08:00
|
|
|
<i class="sn-icon sn-icon-open"></i>
|
2023-09-26 22:23:16 +08:00
|
|
|
</a>
|
2023-08-30 21:42:55 +08:00
|
|
|
<a class="btn btn-light icon-btn thumbnail-action-btn image-edit-button"
|
2023-09-26 22:23:16 +08:00
|
|
|
v-else-if="attachment.attributes.image_editable && attachment.attributes.urls.edit_asset"
|
2023-12-13 23:33:53 +08:00
|
|
|
:title="i18n.t('attachments.thumbnail.buttons.open')"
|
2023-08-30 21:42:55 +08:00
|
|
|
:data-image-id="attachment.id"
|
|
|
|
:data-image-name="attachment.attributes.file_name"
|
|
|
|
:data-image-url="attachment.attributes.urls.asset_file"
|
2023-09-05 20:43:16 +08:00
|
|
|
:data-image-quality="attachment.attributes.image_context && attachment.attributes.image_context.quality"
|
|
|
|
:data-image-mime-type="attachment.attributes.image_context && attachment.attributes.image_context.type"
|
2023-08-30 21:42:55 +08:00
|
|
|
:data-image-start-edit-url="attachment.attributes.urls.start_edit_image"
|
|
|
|
>
|
2023-12-13 23:33:53 +08:00
|
|
|
<i class="sn-icon sn-icon-open"></i>
|
2023-08-30 21:42:55 +08:00
|
|
|
</a>
|
2023-09-07 20:15:17 +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>
|
|
|
|
<template v-if="attachment.attributes.urls.delete">
|
|
|
|
<a class="btn btn-light icon-btn thumbnail-action-btn"
|
|
|
|
:title="i18n.t('attachments.thumbnail.buttons.delete')"
|
|
|
|
@click.prevent.stop="deleteModal = true">
|
|
|
|
<i class="sn-icon sn-icon-delete"></i>
|
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-05-17 16:39:17 +08:00
|
|
|
<ContextMenu
|
2023-09-18 21:32:53 +08:00
|
|
|
v-if="isHovered"
|
2022-05-17 16:39:17 +08:00
|
|
|
:attachment="attachment"
|
|
|
|
@attachment:viewMode="updateViewMode"
|
|
|
|
@attachment:delete="deleteAttachment"
|
2023-08-24 21:55:20 +08:00
|
|
|
@attachment:moved="attachmentMoved"
|
2023-10-05 21:44:41 +08:00
|
|
|
@attachment:uploaded="reloadAttachments"
|
2023-09-18 21:32:53 +08:00
|
|
|
:withBorder="true"
|
2022-05-17 16:39:17 +08:00
|
|
|
/>
|
2023-08-30 21:42:55 +08:00
|
|
|
<deleteAttachmentModal
|
|
|
|
v-if="deleteModal"
|
|
|
|
:fileName="attachment.attributes.file_name"
|
|
|
|
@confirm="deleteAttachment"
|
|
|
|
@cancel="deleteModal = false"
|
|
|
|
/>
|
2024-01-04 17:15:06 +08:00
|
|
|
<moveAssetModal
|
2023-12-14 23:15:30 +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"
|
|
|
|
@confirm="showNoPredefinedAppModal = false"
|
|
|
|
/>
|
2022-05-12 23:05:07 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-01-04 17:15:06 +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'
|
2024-01-04 20:27:28 +08:00
|
|
|
import MenuDropdown from '../../../shared/menu_dropdown.vue'
|
2024-01-04 17:15:06 +08:00
|
|
|
import MoveAssetModal from '../modal/move.vue'
|
|
|
|
import NoPredefinedAppModal from '../modal/no_predefined_app_modal.vue'
|
|
|
|
import MoveMixin from './mixins/move.js'
|
2024-01-04 20:27:28 +08:00
|
|
|
import OpenLocallyMixin from './mixins/open_locally.js'
|
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],
|
|
|
|
components: { ContextMenu, deleteAttachmentModal, MoveAssetModal, NoPredefinedAppModal, MenuDropdown },
|
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
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isHovered: false,
|
|
|
|
deleteModal: false,
|
|
|
|
showNoPredefinedAppModal: false
|
|
|
|
};
|
|
|
|
},
|
2024-01-04 20:27:28 +08:00
|
|
|
computed: {
|
|
|
|
openOptions() {
|
|
|
|
let options = [];
|
|
|
|
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 === 'gene_sequence' && this.attachment.attributes.urls.open_vector_editor_edit) {
|
|
|
|
options.push({
|
|
|
|
text: this.i18n.t('open_vector_editor.edit_sequence'),
|
|
|
|
emit: 'open_ove_editor',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (this.attachment.attributes.asset_type === 'marvinjs' && this.attachment.attributes.urls.marvin_js_start_edit) {
|
|
|
|
options.push({
|
|
|
|
text: this.i18n.t('assets.file_preview.edit_in_marvinjs'),
|
|
|
|
emit: 'open_marvinjs_editor',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
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'),
|
|
|
|
emit: 'open_scinote_editor',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (this.canOpenLocally) {
|
|
|
|
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({
|
|
|
|
text: text,
|
|
|
|
emit: 'open_locally'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return options;
|
2023-12-13 23:33:53 +08:00
|
|
|
},
|
2024-01-04 20:27:28 +08:00
|
|
|
},
|
2024-01-04 17:15:06 +08:00
|
|
|
mounted() {
|
|
|
|
$(this.$nextTick(function() {
|
|
|
|
$(`.attachment-preview img`)
|
|
|
|
.on('error', (event) => ActiveStoragePreviews.reCheckPreview(event))
|
|
|
|
.on('load', (event) => ActiveStoragePreviews.showPreview(event))
|
|
|
|
}))
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
isHovered: function(newValue) {
|
|
|
|
// reload thumbnail on mouse out
|
|
|
|
if (newValue) return;
|
|
|
|
|
2023-09-22 16:36:07 +08:00
|
|
|
$(this.$nextTick(function() {
|
|
|
|
$(`.attachment-preview img`)
|
|
|
|
.on('error', (event) => ActiveStoragePreviews.reCheckPreview(event))
|
|
|
|
.on('load', (event) => ActiveStoragePreviews.showPreview(event))
|
|
|
|
}))
|
2024-01-04 17:15:06 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
openOVEditor(url) {
|
|
|
|
window.showIFrameModal(url);
|
2022-05-13 19:07:50 +08:00
|
|
|
}
|
2022-05-12 23:05:07 +08:00
|
|
|
}
|
2024-01-04 17:15:06 +08:00
|
|
|
}
|
2022-05-12 23:05:07 +08:00
|
|
|
</script>
|