From 5cc6cd094ef143b1e6ea31a062349a1e10a946a8 Mon Sep 17 00:00:00 2001 From: zmagod Date: Fri, 17 Mar 2017 16:47:58 +0100 Subject: [PATCH] refactor --- app/controllers/assets_controller.rb | 2 +- app/helpers/wopi_helper.rb | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index fe1d0748c..d6b0ce7bc 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb @@ -60,7 +60,7 @@ class AssetsController < ApplicationController Constants::FILENAME_TRUNCATION_LENGTH), 'download-url' => download_asset_path(@asset), 'type' => asset_data_type(@asset), - 'wopi-file-name' => wopi_asset_file_name(@asset), + 'wopi-file-name' => wopi_asset_file_name(@asset, true), 'wopi-edit' => (wopi_asset_edit_button(@asset) if wopi_file?(@asset)), 'wopi-view' => (wopi_asset_view_button(@asset) if wopi_file?(@asset)) }, status: 200 diff --git a/app/helpers/wopi_helper.rb b/app/helpers/wopi_helper.rb index 5c70e13c3..097a5cbc1 100644 --- a/app/helpers/wopi_helper.rb +++ b/app/helpers/wopi_helper.rb @@ -51,18 +51,23 @@ module WopiHelper end end - def wopi_asset_file_name(asset) + def wopi_asset_file_name(asset, link = false) html = '

' html += "#{file_extension_icon(asset)} " - html += link_to download_asset_path(asset), - data: { no_turbolink: true, - id: true, - status: 'asset-present' } do - truncate( - asset.file_file_name, - length: Constants::FILENAME_TRUNCATION_LENGTH - ) - end + if link + html += link_to download_asset_path(asset), + data: { no_turbolink: true, + id: true, + status: 'asset-present' } do + truncate( + asset.file_file_name, + length: Constants::FILENAME_TRUNCATION_LENGTH + ) + end + else + html += truncate(asset.file_file_name, + length: Constants::FILENAME_TRUNCATION_LENGTH) + end html += ' 

' sanitize_input(html, %w(img a)) end