diff --git a/app/helpers/file_icons_helper.rb b/app/helpers/file_icons_helper.rb new file mode 100644 index 000000000..01721e38b --- /dev/null +++ b/app/helpers/file_icons_helper.rb @@ -0,0 +1,60 @@ +module FileIconsHelper + def wopi_file?(asset) + file_ext = asset.file_file_name.split('.').last + %w(doc docx xls xlsx ppt pptx).include?(file_ext) + end + + # For showing next to file + def file_extension_icon(asset) + file_ext = asset.file_file_name.split('.').last + if %w(doc docx).include?(file_ext) + image_link = 'office/Word-docx_20x20x32.png' + elsif %w(xls xlsx).include?(file_ext) + image_link = 'office/Excel-xlsx_20x20x32.png' + elsif %w(ppt pptx).include?(file_ext) + image_link = 'office/PowerPoint-pptx_20x20x32.png' + end + + if image_link + image_tag image_link + else + '' + end + end + + # For showing in view/edit buttons (WOPI) + def file_application_icon(asset) + file_ext = asset.file_file_name.split('.').last + if %w(doc docx).include?(file_ext) + image_link = 'office/Word-color_16x16x32.png' + elsif %w(xls xlsx).include?(file_ext) + image_link = 'office/Excel-color_16x16x32.png' + elsif %w(ppt pptx).include?(file_ext) + image_link = 'office/PowerPoint-Color_16x16x32.png' + end + + if image_link + image_tag image_link + else + '' + end + end + + # Shows correct WOPI application text (Word Online/Excel ..) + def wopi_button_text(asset, action) + file_ext = asset.file_file_name.split('.').last + if %w(doc docx).include?(file_ext) + app = 'Word Online' + elsif %w(xls xlsx).include?(file_ext) + app = 'Excel Online' + elsif %w(ppt pptx).include?(file_ext) + app = 'PowerPoint Online' + end + + if action == 'view' + t('result_assets.wopi_open_file', app: app) + elsif action == 'edit' + t('result_assets.wopi_edit_file', app: app) + end + end +end diff --git a/app/views/result_assets/_edit.html.erb b/app/views/result_assets/_edit.html.erb index b1bf833fd..68158d989 100644 --- a/app/views/result_assets/_edit.html.erb +++ b/app/views/result_assets/_edit.html.erb @@ -3,7 +3,10 @@ <%= f.text_field :name, style: "margin-top: 10px;" %>
<%= f.fields_for :asset do |ff| %> <%=t "result_assets.edit.uploaded_asset" %> -

<%= ff.object.file_file_name %>

+

+ <%= file_extension_icon(ff.object) %> + <%= ff.object.file_file_name %> +

<%= ff.file_field :file %> <% end %>
diff --git a/app/views/results/_result_asset.html.erb b/app/views/results/_result_asset.html.erb index 3391b61ab..81506ebf5 100644 --- a/app/views/results/_result_asset.html.erb +++ b/app/views/results/_result_asset.html.erb @@ -1,16 +1,36 @@ <% if can_view_or_download_result_assets(result.my_module) %> <%= link_to download_asset_path(result.asset), data: {no_turbolink: true} do %> <%= image_tag(preview_asset_path result.asset) if result.asset.is_image? %> -

<%= truncate(result.asset.file_file_name, length: 50) %>

+ <% if wopi_file?(result.asset) %> +

+ <%= file_extension_icon(result.asset) %> + <%= truncate(result.asset.file_file_name, length: 50) %> +

+ <% else %> +

<%= truncate(result.asset.file_file_name, length: 50) %>

+ <% end %> <% end %> <% if result.asset.can_perform_action("view") %> - <%= link_to "View", view_asset_url(id: result.asset) %> + <%= link_to view_asset_url(id: result.asset), + class: 'btn btn-default btn-sm', + style: 'display: inline-block' do %> + <%= file_application_icon(result.asset) %> + <%= wopi_button_text(result.asset, 'view') %> + <% end %> <% end %> <% if can_edit_result_asset_in_module(result.my_module) && result.asset.can_perform_action("edit") %> - <%= link_to "Edit", edit_asset_url(id: result.asset) %> + <%= link_to edit_asset_url(id: result.asset), + class: 'btn btn-default btn-sm', + style: 'display: inline-block' do %> + <%= file_application_icon(result.asset) %> + <%= wopi_button_text(result.asset, 'edit') %> + <% end %> <% end %> <% else %> <%= image_tag(preview_asset_path result.asset) if result.asset.is_image? %> -

<%= result.asset.file_file_name %>

+

+ <%= file_extension_icon(result.asset) %> + <%= truncate(result.asset.file_file_name, length: 50) %> +

<% end %> diff --git a/app/views/steps/_form_assets.html.erb b/app/views/steps/_form_assets.html.erb index 9792e1da5..8dc1cd0d8 100644 --- a/app/views/steps/_form_assets.html.erb +++ b/app/views/steps/_form_assets.html.erb @@ -15,11 +15,17 @@ <% if can_view_or_download_step_assets(@protocol) %> <%= link_to download_asset_path(ff.object), data: {no_turbolink: true} do %> <%= image_tag(preview_asset_path ff.object) if ff.object.is_image? %> -

<%= ff.object.file_file_name %>

+

+ <%= file_extension_icon(ff.object) %> + <%= ff.object.file_file_name %> +

<% end %> <% else %> <%= image_tag(preview_asset_path ff.object) if ff.object.is_image? %> -

<%= ff.object.file_file_name %>

+

+ <%= file_extension_icon(ff.object) %> + <%= ff.object.file_file_name %> +

<% end %> <% else %> <%= ff.file_field :file %> diff --git a/app/views/steps/_step.html.erb b/app/views/steps/_step.html.erb index 07d5ce2e1..483ab23da 100644 --- a/app/views/steps/_step.html.erb +++ b/app/views/steps/_step.html.erb @@ -71,21 +71,41 @@ <% if asset.file_present %> <%= link_to download_asset_path(asset), data: {no_turbolink: true, id: true, status: "asset-present"} do %> <%= image_tag preview_asset_path(asset) if asset.is_image? %> -

<%= truncate(asset.file_file_name, length: 50) %>

+ <% if wopi_file?(asset) %> +

+ <%= file_extension_icon(asset) %> + <%= truncate(asset.file_file_name, length: 50) %> +

+ <% else %> +

<%= truncate(asset.file_file_name, length: 50) %>

+ <% end %> <% end %> <% if asset.can_perform_action("view") %> - <%= link_to "View", view_asset_url(id: asset) %> + <%= link_to view_asset_url(id: asset), + class: 'btn btn-default btn-sm', + style: 'display: inline-block' do %> + <%= file_application_icon(asset) %> + <%= wopi_button_text(asset, 'view') %> + <% end %> <% end %> <% if can_edit_step_in_protocol(@protocol) && asset.can_perform_action("edit") %> - <%= link_to "Edit", edit_asset_url(id: asset) %> + <%= link_to edit_asset_url(id: asset), + class: 'btn btn-default btn-sm', + style: 'display: inline-block' do %> + <%= file_application_icon(asset) %> + <%= wopi_button_text(asset, 'edit') %> + <% end %> <% end %> <% else %> <%= asset_loading_span(asset) %> <% end %> <% else %> <%= image_tag preview_asset_path(asset) if asset.is_image? %> -

<%= truncate(asset.file_file_name, length: 50) %>

+

+ <%= file_extension_icon(asset) %> + <%= truncate(asset.file_file_name, length: 50) %> +

<% end %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index e67728e30..f1484e517 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -847,6 +847,8 @@ en: error_flash: "Couldn't archive file result. Someone is editing that file." destroy: success_flash: "File result successfully deleted." + wopi_open_file: "Open in %{app}" + wopi_edit_file: "Edit in %{app}" result_tables: new: diff --git a/public/images/office/Excel-color_16x16x32.png b/public/images/office/Excel-color_16x16x32.png new file mode 100644 index 000000000..5d4f705c4 Binary files /dev/null and b/public/images/office/Excel-color_16x16x32.png differ diff --git a/public/images/office/Excel-xlsx_20x20x32.png b/public/images/office/Excel-xlsx_20x20x32.png new file mode 100644 index 000000000..b6f683372 Binary files /dev/null and b/public/images/office/Excel-xlsx_20x20x32.png differ diff --git a/public/images/office/PowerPoint-Color_16x16x32.png b/public/images/office/PowerPoint-Color_16x16x32.png new file mode 100644 index 000000000..cfa3a6bf9 Binary files /dev/null and b/public/images/office/PowerPoint-Color_16x16x32.png differ diff --git a/public/images/office/PowerPoint-pptx_20x20x32.png b/public/images/office/PowerPoint-pptx_20x20x32.png new file mode 100644 index 000000000..2fdb3cb5f Binary files /dev/null and b/public/images/office/PowerPoint-pptx_20x20x32.png differ diff --git a/public/images/office/Word-color_16x16x32.png b/public/images/office/Word-color_16x16x32.png new file mode 100644 index 000000000..a6b7889c8 Binary files /dev/null and b/public/images/office/Word-color_16x16x32.png differ diff --git a/public/images/office/Word-docx_20x20x32.png b/public/images/office/Word-docx_20x20x32.png new file mode 100644 index 000000000..69e8ab3d1 Binary files /dev/null and b/public/images/office/Word-docx_20x20x32.png differ