Merge pull request #7915 from artoscinote/ma_SCI_11043

Add file editing & versioning to inventories [SCI-11043]
This commit is contained in:
Martin Artnik 2024-10-02 15:12:30 +02:00 committed by GitHub
commit 98d70d6c8a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 30 additions and 10 deletions

View file

@ -1,8 +1,8 @@
<template> <template>
<div class="sn-open-locally-menu" @mouseenter="fetchLocalAppInfo"> <div class="sn-open-locally-menu flex" @mouseenter="fetchLocalAppInfo">
<div v-if="(!canOpenLocally || disableLocalOpen) && (attachment.attributes.wopi && attachment.attributes.urls.edit_asset)"> <div v-if="(!canOpenLocally) && (attachment.attributes.wopi && attachment.attributes.urls.edit_asset)">
<a :href="editWopiSupported ? attachment.attributes.urls.edit_asset : null" target="_blank" <a :href="editWopiSupported ? attachment.attributes.urls.edit_asset : null" target="_blank"
class="block whitespace-nowrap rounded px-3 py-2.5 hover:!text-sn-blue hover:no-underline cursor-pointer hover:bg-sn-super-light-grey" class="btn btn-light"
:class="{ 'disabled': !editWopiSupported }" :class="{ 'disabled': !editWopiSupported }"
:title="editWopiSupported ? null : attachment.attributes.wopi_context.title" :title="editWopiSupported ? null : attachment.attributes.wopi_context.title"
style="pointer-events: all" style="pointer-events: all"
@ -26,6 +26,7 @@
{{ menu[0].text }} {{ menu[0].text }}
</a> </a>
</div> </div>
<a @click="fileVersionsModal = true" class="btn btn-light"><i class="sn-icon sn-icon-history-search"></i>{{ i18n.t('assets.context_menu.versions') }}</a>
<Teleport to="body"> <Teleport to="body">
<NoPredefinedAppModal <NoPredefinedAppModal
@ -47,6 +48,13 @@
v-if="showUpdateVersionModal" v-if="showUpdateVersionModal"
@close="showUpdateVersionModal = false" @close="showUpdateVersionModal = false"
/> />
<FileVersionsModal
v-if="fileVersionsModal"
:versionsUrl="attachment.attributes.urls.versions"
:restoreVersionUrl="attachment.attributes.urls.restore_version"
@close="fileVersionsModal = false"
@fileVersionRestored="refreshPreview"
/>
</Teleport> </Teleport>
</div> </div>
</template> </template>
@ -55,14 +63,19 @@
import OpenLocallyMixin from './mixins/open_locally.js'; import OpenLocallyMixin from './mixins/open_locally.js';
import MenuDropdown from '../../menu_dropdown.vue'; import MenuDropdown from '../../menu_dropdown.vue';
import UpdateVersionModal from '../modal/update_version_modal.vue'; import UpdateVersionModal from '../modal/update_version_modal.vue';
import FileVersionsModal from '../../file_versions_modal.vue';
export default { export default {
name: 'OpenLocallyMenu', name: 'OpenLocallyMenu',
mixins: [OpenLocallyMixin], mixins: [OpenLocallyMixin],
components: { MenuDropdown, UpdateVersionModal }, components: { MenuDropdown, UpdateVersionModal, FileVersionsModal },
props: { props: {
attachment: { type: Object, required: true }, attachment: { type: Object, required: true }
disableLocalOpen: { type: Boolean, default: false } },
data() {
return {
fileVersionsModal: false
};
}, },
created() { created() {
this.fetchLocalAppInfo(); this.fetchLocalAppInfo();
@ -92,7 +105,7 @@ export default {
}); });
} }
if (this.canOpenLocally && !this.disableLocalOpen) { if (this.canOpenLocally) {
const text = this.localAppName const text = this.localAppName
? this.i18n.t('attachments.open_locally_in', { application: this.localAppName }) ? this.i18n.t('attachments.open_locally_in', { application: this.localAppName })
: this.i18n.t('attachments.open_locally'); : this.i18n.t('attachments.open_locally');
@ -116,6 +129,13 @@ export default {
methods: { methods: {
openImageEditor() { openImageEditor() {
document.getElementById('editImageButton').click(); document.getElementById('editImageButton').click();
},
refreshPreview() {
const imageElement = document.querySelector('.file-preview-container .asset-image');
if (!imageElement) return;
window.ActiveStoragePreviews.reCheckPreview({ target: imageElement });
} }
} }
}; };

View file

@ -4,7 +4,7 @@
<% if can_edit && !preview %> <% if can_edit && !preview %>
<% if wopi_enabled? && wopi_file?(asset) %> <% if wopi_enabled? && wopi_file?(asset) %>
<div id="openLocallyMenu" data-behaviour="vue"> <div id="openLocallyMenu" data-behaviour="vue">
<open-locally-menu :disable-local-open="<%= asset.repository_asset_value.present? %>" :attachment="<%= { attributes: AssetSerializer.new(asset, scope: { user: current_user }).as_json }.to_json %>" /> <open-locally-menu :attachment="<%= { attributes: AssetSerializer.new(asset, scope: { user: current_user }).as_json }.to_json %>" />
</div> </div>
<% elsif asset.file.metadata[:asset_type] == 'marvinjs' %> <% elsif asset.file.metadata[:asset_type] == 'marvinjs' %>
<button class="btn btn-light marvinjs-edit-button" <button class="btn btn-light marvinjs-edit-button"
@ -40,7 +40,7 @@
</button> </button>
<% end %> <% end %>
<div id="openLocallyMenu" data-behaviour="vue"> <div id="openLocallyMenu" data-behaviour="vue">
<open-locally-menu :disable-local-open="<%= asset.repository_asset_value.present? %>" :attachment="<%= { attributes: AssetSerializer.new(asset, scope: { user: current_user }).as_json }.to_json %>" /> <open-locally-menu :attachment="<%= { attributes: AssetSerializer.new(asset, scope: { user: current_user }).as_json }.to_json %>" />
</div> </div>
<% end %> <% end %>
<a class="btn btn-light file-download-link" href="<%= rails_blob_path(asset.file, disposition: 'attachment') %>" data-turbolinks="false"> <a class="btn btn-light file-download-link" href="<%= rails_blob_path(asset.file, disposition: 'attachment') %>" data-turbolinks="false">

View file

@ -4013,7 +4013,7 @@ en:
inline_html: "Large" inline_html: "Large"
thumbnail_html: "Thumbnail" thumbnail_html: "Thumbnail"
list_html: "List" list_html: "List"
versions: "Versions" versions: "Version history"
file_versions_modal: file_versions_modal:
title: "Version history" title: "Version history"
download: "Download" download: "Download"