Remove extension from file renaming [SCI-10766]

This commit is contained in:
Anton 2024-06-04 12:13:10 +02:00
parent 85c1362903
commit 59f9589ea1
4 changed files with 21 additions and 18 deletions

View file

@ -323,7 +323,7 @@ class AssetsController < ApplicationController
end
ActiveRecord::Base.transaction do
old_name = @asset.name
old_name = @asset.file_name
@asset.last_modified_by = current_user
@asset.rename_file(new_name)
@asset.save!

View file

@ -44,8 +44,7 @@
<Teleport to="body">
<RenameAttachmentModal
v-if="renameModal"
:url_path="attachment.attributes.urls.rename"
:fileName="attachment.attributes.file_name"
:attachment="attachment"
@attachment:update="$emit('attachment:update', $event)"
@close="renameModal = false"
/>

View file

@ -1,6 +1,6 @@
<template>
<div ref="modal" @keydown.esc="close" class="modal" id="renameAttachmentModal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-md" role="document">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><i class="sn-icon sn-icon-close"></i></button>
@ -9,9 +9,14 @@
</h4>
</div>
<div class="modal-body">
<p>{{ i18n.t('assets.from_clipboard.file_name')}}</p>
<div class="sci-input-container" :class="{ 'error': error }" :data-error-text="error">
<input ref="input" v-model="name" type="text" class="sci-input-field" @keyup.enter="renameAttachment(name)" required="true" />
<label class="sci-label">
{{ i18n.t('assets.from_clipboard.file_name')}}
</label>
<div class="flex gap-1 items-center">
<div class="sci-input-container" :class="{ 'error': error }" :data-error-text="error">
<input ref="input" v-model="name" type="text" class="sci-input-field" @keyup.enter="renameAttachment(name)" required="true" />
</div>
<div class="shrink-0">.{{ this.attachment.attributes.file_extension }}</div>
</div>
</div>
<div class="modal-footer">
@ -31,14 +36,10 @@ export default {
name: 'RenameAttachmentModal',
mixins: [modalMixin],
props: {
url_path: {
type: String,
attachment: {
type: Object,
required: true
},
fileName: {
type: String,
required: true
}
},
data() {
return {
@ -47,7 +48,7 @@ export default {
};
},
created() {
this.name = this.fileName;
this.name = this.attachment.attributes.file_name_without_extension;
},
watch: {
name() {
@ -71,10 +72,9 @@ export default {
return;
}
const payload = { asset: { name: newName } };
const payload = { asset: { name: `${newName}.${this.attachment.attributes.file_extension}` } };
try {
const response = await axios.patch(this.url_path, payload);
const response = await axios.patch(this.attachment.attributes.urls.rename, payload);
this.$emit('attachment:update', response.data.data);
this.close();
} catch (error) {

View file

@ -9,7 +9,7 @@ class AssetSerializer < ActiveModel::Serializer
include ApplicationHelper
attributes :file_name, :file_extension, :view_mode, :icon, :urls, :updated_at_formatted,
:file_size, :medium_preview, :large_preview, :asset_type, :wopi,
:file_size, :medium_preview, :large_preview, :asset_type, :wopi, :file_name_without_extension,
:wopi_context, :pdf_previewable, :file_size_formatted, :asset_order,
:updated_at, :metadata, :image_editable, :image_context, :pdf, :attached, :parent_type,
:edit_version_range
@ -23,6 +23,10 @@ class AssetSerializer < ActiveModel::Serializer
object.render_file_name
end
def file_name_without_extension
File.basename(object.file_name, '.*')
end
def file_extension
File.extname(object.file_name)[1..]
end