From 2769add4d9cda882b6475560a9e5e53a5cbd7211 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 31 Dec 2018 18:10:12 +0100 Subject: [PATCH] Disable edit button for unsupported WOPI formats [SCI-2904] --- .../javascripts/sitewide/file_preview.js.erb | 3 +++ app/controllers/assets_controller.rb | 21 +++++++++++++++- app/helpers/file_icons_helper.rb | 24 +++++++++---------- .../shared/_file_wopi_controlls.html.erb | 12 +++++++++- config/initializers/constants.rb | 11 +++++++++ config/locales/en.yml | 3 +++ 6 files changed, 60 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/sitewide/file_preview.js.erb b/app/assets/javascripts/sitewide/file_preview.js.erb index 58597fe05..a12963c76 100644 --- a/app/assets/javascripts/sitewide/file_preview.js.erb +++ b/app/assets/javascripts/sitewide/file_preview.js.erb @@ -56,6 +56,9 @@ modal.modal('hide'); }); modal.modal(); + modal.find('a[disabled=disabled]').click(function(ev){ + ev.preventDefault(); + }); $('.modal-backdrop').last().css('z-index', modal.css('z-index') - 1); }, error: function(ev) { diff --git a/app/controllers/assets_controller.rb b/app/controllers/assets_controller.rb index f4bf73b9c..eadff61ec 100644 --- a/app/controllers/assets_controller.rb +++ b/app/controllers/assets_controller.rb @@ -78,9 +78,28 @@ class AssetsController < ApplicationController elsif @assoc.class == RepositoryCell can_manage_repository_rows?(@repository.team) end + file_ext = @asset.file_file_name.split('.').last + if Constants::WOPI_EDITABLE_FORMATS.include?(file_ext) + edit_supported = true + title = '' + else + edit_supported = false + title = if Constants::FILE_TEXT_FORMATS.include?(file_ext) + I18n.t('assets.wopi_supported_text_formats_title') + elsif Constants::FILE_TABLE_FORMATS.include?(file_ext) + I18n.t('assets.wopi_supported_table_formats_title') + else + I18n.t('assets.wopi_supported_presentation_formats_title') + end + end response_json['wopi-controls'] = render_to_string( partial: 'shared/file_wopi_controlls.html.erb', - locals: { asset: @asset, can_edit: can_edit } + locals: { + asset: @asset, + can_edit: can_edit, + edit_supported: edit_supported, + title: title + } ) end respond_to do |format| diff --git a/app/helpers/file_icons_helper.rb b/app/helpers/file_icons_helper.rb index 1bed35a35..f531363f9 100644 --- a/app/helpers/file_icons_helper.rb +++ b/app/helpers/file_icons_helper.rb @@ -7,11 +7,11 @@ module FileIconsHelper # For showing next to file def file_fa_icon_class(asset) file_ext = asset.file_file_name.split('.').last - if %w(doc docm docx dot dotm dotx odt rtf).include?(file_ext) + if Constants::FILE_TEXT_FORMATS.include?(file_ext) fa_class = 'fa-file-word' - elsif %w(ods xls xlsb xlsm xlsx).include?(file_ext) + elsif Constants::FILE_TABLE_FORMATS.include?(file_ext) fa_class = 'fa-file-excel' - elsif %w(odp pot potm potx pps ppsm ppsx ppt pptm pptx).include?(file_ext) + elsif Constants::FILE_PRESENTATION_FORMATS.include?(file_ext) fa_class = 'fa-file-powerpoint' elsif %w(pdf).include?(file_ext) fa_class = 'fa-file-pdf' @@ -31,11 +31,11 @@ module FileIconsHelper # For showing next to file def file_extension_icon(asset) file_ext = asset.file_file_name.split('.').last - if %w(doc docm docx dot dotm dotx odt rtf).include?(file_ext) + if Constants::FILE_TEXT_FORMATS.include?(file_ext) image_link = 'office/Word-docx_20x20x32.png' - elsif %w(csv ods xls xlsb xlsm xlsx).include?(file_ext) + elsif Constants::FILE_TABLE_FORMATS.include?(file_ext) image_link = 'office/Excel-xlsx_20x20x32.png' - elsif %w(odp pot potm potx pps ppsm ppsx ppt pptm pptx).include?(file_ext) + elsif Constants::FILE_PRESENTATION_FORMATS.include?(file_ext) image_link = 'office/PowerPoint-pptx_20x20x32.png' end @@ -54,11 +54,11 @@ module FileIconsHelper # For showing in view/edit buttons (WOPI) def file_application_icon(asset) file_ext = asset.file_file_name.split('.').last - if %w(doc docm docx dot dotm dotx odt rtf).include?(file_ext) + if Constants::FILE_TEXT_FORMATS.include?(file_ext) image_link = 'office/Word-color_16x16x32.png' - elsif %w(csv ods xls xlsb xlsm xlsx).include?(file_ext) + elsif Constants::FILE_TABLE_FORMATS.include?(file_ext) image_link = 'office/Excel-color_16x16x32.png' - elsif %w(odp pot potm potx pps ppsm ppsx ppt pptm pptx).include?(file_ext) + elsif Constants::FILE_PRESENTATION_FORMATS.include?(file_ext) image_link = 'office/PowerPoint-Color_16x16x32.png' end @@ -72,11 +72,11 @@ module FileIconsHelper # 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 docm docx dot dotm dotx odt rtf).include?(file_ext) + if Constants::FILE_TEXT_FORMATS.include?(file_ext) app = 'Word Online' - elsif %w(csv ods xls xlsb xlsm xlsx).include?(file_ext) + elsif Constants::FILE_TABLE_FORMATS.include?(file_ext) app = 'Excel Online' - elsif %w(odp pot potm potx pps ppsm ppsx ppt pptm pptx).include?(file_ext) + elsif Constants::FILE_PRESENTATION_FORMATS.include?(file_ext) app = 'PowerPoint Online' end diff --git a/app/views/shared/_file_wopi_controlls.html.erb b/app/views/shared/_file_wopi_controlls.html.erb index cfd80c8dc..07762f7d7 100644 --- a/app/views/shared/_file_wopi_controlls.html.erb +++ b/app/views/shared/_file_wopi_controlls.html.erb @@ -5,7 +5,7 @@ <%= file_application_icon(asset) %> <%= wopi_button_text(asset, 'view') %> <% end %> -<% if can_edit %> +<% if can_edit && edit_supported %> <%= link_to edit_asset_url(id: asset), class: 'btn btn-default btn-sm', target: '_blank', @@ -13,4 +13,14 @@ <%= file_application_icon(asset) %> <%= wopi_button_text(asset, 'edit') %> <% end %> +<% elsif can_edit %> + <%= link_to edit_asset_url(id: asset), + class: 'btn btn-default btn-sm', + target: '_blank', + title: title, + disabled: true, + style: 'display: inline-block' do %> + <%= file_application_icon(asset) %> + <%= wopi_button_text(asset, 'edit') %> + <% end %> <% end %> diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 5b8f0f5e0..2de7387cb 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -187,6 +187,17 @@ class Constants # Other #============================================================================= + FILE_TEXT_FORMATS = %w(doc docm docx dot dotm dotx odt rtf).freeze + + FILE_TABLE_FORMATS = %w(csv ods xls xlsb xlsm xlsx).freeze + + FILE_PRESENTATION_FORMATS = + %w(odp pot potm potx pps ppsm ppsx ppt pptm pptx).freeze + + WOPI_EDITABLE_FORMATS = %w( + docx docm odt xlsx xlsm xlsb ods pptx ppsx odp + ).freeze + TEXT_EXTRACT_FILE_TYPES = [ 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', diff --git a/config/locales/en.yml b/config/locales/en.yml index 08b2f5a62..191d786ea 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1918,6 +1918,9 @@ en: add_image: 'Add' file_name: 'File name' file_name_placeholder: 'Image' + wopi_supported_text_formats_title: 'Only .docx, .docm, .odt file formats are supported for editing in Word Online.' + wopi_supported_table_formats_title: 'Only .xlsx, .xlsm, .xlsb, .ods file formats are supported for editing in Excel Online.' + wopi_supported_presentation_formats_title: 'Only .pptx, ppsx, .odp file formats are supported for editing in Powerpoint Online.' atwho: no_results: "No results found" users: