Merge pull request #1746 from biosistemika/lm-sci-3426

Changes to create new office file button [SCI-3426]
This commit is contained in:
Miha Mencin 2019-05-13 10:55:58 +02:00 committed by GitHub
commit 5ff344c208
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 49 additions and 14 deletions

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 53.59 64.356" width="53.589577" height="64.356148">
<g transform="translate(-216.07358,-549.28882)">
<g transform="matrix(1.8232952,0,0,1.8232952,-597.71681,-124.12247)">
<g transform="translate(0,-91.137241)">
<g fill="#eb3c00" transform="matrix(0.74069815,0,0,0.74069815,98.5698,-8.2505871)">
<path d="m469.87,671.03,0-28.52,25.229-9.3238,13.711,4.3877,0,38.392-13.711,4.133-25.229-9.0691,25.229,3.0361,0-33.201-16.454,3.8392,0,22.487z"/>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 627 B

View file

@ -20,9 +20,8 @@ function initCreateWopiFileModal() {
$('#new-office-file-modal form')
.on('ajax:success', function(ev, data) {
window.open(data.edit_url, '_blank');
$('#new-office-file-modal').modal('hide');
// location.reload();
window.focus();
location.reload(); // Reload current page, to display the new element
})
.on('ajax:error', function(ev, response) {
var element;

View file

@ -61,7 +61,7 @@
img {
margin-right: 5px;
width: 23px;
height: 20px;
}
}

View file

@ -5,6 +5,7 @@ class AssetsController < ApplicationController
include ActionView::Helpers::TextHelper
include ActionView::Helpers::UrlHelper
include ActionView::Context
include ApplicationHelper
include InputSanitizeHelper
include FileIconsHelper
@ -81,10 +82,10 @@ class AssetsController < ApplicationController
)
end
if wopi_file?(@asset)
if wopi_enabled? && wopi_file?(@asset)
edit_supported, title = wopi_file_edit_button_status
response_json['wopi-controls'] = render_to_string(
partial: 'shared/file_wopi_controlls.html.erb',
partial: 'assets/wopi/file_wopi_controls.html.erb',
locals: {
asset: @asset,
can_edit: can_edit,
@ -204,11 +205,25 @@ class AssetsController < ApplicationController
render_403 && return unless %w(docx xlsx pptx).include?(params[:file_type])
# Asset validation
original_filename = "#{params[:file_name]}.#{params[:file_type]}"
file = Paperclip.io_adapters.for(StringIO.new)
file.original_filename = "#{params[:file_name]}.#{params[:file_type]}"
file.original_filename = original_filename
file.content_type = wopi_content_type(params[:file_type])
asset = Asset.new(file: file, created_by: current_user, file_present: true)
# Filename length validation (this cannot be checked by Paperclip,
# as it depends on OS)
if original_filename.length > Constants::FILENAME_MAX_LENGTH
render json: {
message: {
file: I18n.t(
'assets.create_wopi_file.errors.file_name_too_long',
limit: Constants::FILENAME_MAX_LENGTH
)
}
}, status: 400 and return
end
unless asset.valid?(:wopi_file_creation)
render json: {
message: asset.errors
@ -307,6 +322,7 @@ class AssetsController < ApplicationController
def asset_data_type(asset)
return 'wopi' if wopi_file?(asset)
return 'image' if asset.is_image?
'file'
end
end

View file

@ -221,4 +221,8 @@ module ApplicationHelper
user.avatar(style) == '/images/icon_small/missing.png' ||
user.avatar(style) == '/images/thumb/missing.png'
end
def wopi_enabled?
ENV['WOPI_ENABLED'] == 'true'
end
end

View file

@ -1,11 +1,12 @@
<%= link_to create_wopi_file_path,
class: 'btn btn-default create-wopi-file-btn',
target: '_blank',
<% if wopi_enabled? %>
<%= link_to create_wopi_file_path,
class: 'btn btn-default create-wopi-file-btn',
target: '_blank',
title: 'Create_new_file',
data: { 'id': element_id, 'type': element_type, } do %>
<span class="btn btn-default new-asset-upload-button">
<span class="fas fa-file-medical new-asset-upload-icon"></span>
<span class="btn btn-default new-asset-upload-button">
<%= image_tag 'office/office.svg' %>
<%=t 'assets.create_wopi_file.button_text' %>
</span>
</span>
<% end %>
<% end %>

View file

@ -23,6 +23,9 @@ class Constants
COLOR_MAX_LENGTH = 7
# Max characters for text in dropdown list element
DROPDOWN_TEXT_MAX_LENGTH = 15
# Max characters limit for (on most operating systems, it's ~255 characters,
# but this is with a bit more safety margin)
FILENAME_MAX_LENGTH = 100
# Max characters for filenames, after which they get truncated
FILENAME_TRUNCATION_LENGTH = 50
# Max characters for names of exported files and folders, after which they get

View file

@ -1916,6 +1916,7 @@ en:
errors:
forbidden: 'You do not have permission to add files.'
not_found: 'Element not found.'
file_name_too_long: 'is too long (maximum is %{limit} characters, with extension)'
atwho:
no_results: "No results found"
users: