From 2769add4d9cda882b6475560a9e5e53a5cbd7211 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 31 Dec 2018 18:10:12 +0100 Subject: [PATCH 01/12] 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: From 534866467bf5a09f3832d4ffe6e2bf3bb801c6f4 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 3 Jan 2019 14:11:00 +0100 Subject: [PATCH 02/12] Add counters to task inventories dropdown [SCI-2776] --- .../javascripts/secondary_navigation.js | 24 +++++++++++++++++++ app/controllers/my_modules_controller.rb | 16 +++++++++++-- app/models/my_module.rb | 6 +++++ app/models/my_module_repository_row.rb | 1 + app/models/repository_row.rb | 2 +- .../_repositories_dropdown.html.erb | 16 +++++++++++++ .../shared/_secondary_navigation.html.erb | 24 ++++++------------- config/initializers/assets.rb | 1 + config/routes.rb | 6 +++++ 9 files changed, 76 insertions(+), 20 deletions(-) create mode 100644 app/assets/javascripts/secondary_navigation.js create mode 100644 app/views/my_modules/_repositories_dropdown.html.erb diff --git a/app/assets/javascripts/secondary_navigation.js b/app/assets/javascripts/secondary_navigation.js new file mode 100644 index 000000000..5c870fa77 --- /dev/null +++ b/app/assets/javascripts/secondary_navigation.js @@ -0,0 +1,24 @@ +(function() { + 'use strict'; + + function initRepositoriesDropDown() { + var dropDown = $('.repositories-dropdown'); + var dropDownMenu = $('.repositories-dropdown-menu'); + dropDown.on('show.bs.dropdown', function() { + dropDownMenu.html( + '
' + ); + $.ajax({ + url: dropDown.data('url'), + type: 'GET', + dataType: 'json', + success: function(data) { + dropDownMenu.html(data.html); + } + }); + }); + } + + // init + initRepositoriesDropDown(); +}()); diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index f525f1165..b2edcafbf 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -14,7 +14,8 @@ class MyModulesController < ApplicationController complete_my_module repository repository_index assign_repository_records unassign_repository_records unassign_repository_records_modal - assign_repository_records_modal) + assign_repository_records_modal + repositories_dropdown) before_action :load_vars_nested, only: %i(new create) before_action :load_repository, only: %i(assign_repository_records unassign_repository_records @@ -27,7 +28,7 @@ class MyModulesController < ApplicationController before_action :check_manage_permissions, only: %i(description due_date) before_action :check_view_permissions, only: %i(show activities activities_tab protocols results samples samples_index - archive) + archive repositories_dropdown) before_action :check_complete_module_permission, only: :complete_my_module before_action :check_assign_repository_records_permissions, only: %i(unassign_repository_records_modal @@ -403,6 +404,17 @@ class MyModulesController < ApplicationController render 'repository_rows/index.json' end + def repositories_dropdown + load_repository if params[:repository_id].present? + respond_to do |format| + format.json do + render json: { + html: render_to_string(partial: 'repositories_dropdown.html.erb') + } + end + end + end + # Submit actions def assign_repository_records if params[:selected_rows].present? && params[:repository_id].present? diff --git a/app/models/my_module.rb b/app/models/my_module.rb index c96de8944..28936dc8f 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -174,6 +174,12 @@ class MyModule < ApplicationRecord restored end + def repository_rows_count(repository) + my_module_repository_rows.joins(repository_row: :repository) + .where('repositories.id': repository.id) + .count + end + def unassigned_users User.find_by_sql( "SELECT DISTINCT users.id, users.full_name FROM users " + diff --git a/app/models/my_module_repository_row.rb b/app/models/my_module_repository_row.rb index f17cc8743..e2eef2382 100644 --- a/app/models/my_module_repository_row.rb +++ b/app/models/my_module_repository_row.rb @@ -5,6 +5,7 @@ class MyModuleRepositoryRow < ApplicationRecord optional: true belongs_to :repository_row, optional: true, + touch: true, inverse_of: :my_module_repository_rows belongs_to :my_module, optional: true, inverse_of: :my_module_repository_rows diff --git a/app/models/repository_row.rb b/app/models/repository_row.rb index 4daa0aae3..17e9e2b06 100644 --- a/app/models/repository_row.rb +++ b/app/models/repository_row.rb @@ -1,7 +1,7 @@ class RepositoryRow < ApplicationRecord include SearchableModel - belongs_to :repository, optional: true + belongs_to :repository, touch: true, optional: true belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User', diff --git a/app/views/my_modules/_repositories_dropdown.html.erb b/app/views/my_modules/_repositories_dropdown.html.erb new file mode 100644 index 000000000..f31da3fdc --- /dev/null +++ b/app/views/my_modules/_repositories_dropdown.html.erb @@ -0,0 +1,16 @@ +<% @my_module.experiment.project.team.repositories.order(created_at: :asc).each do |repository| %> +
  • + help_tooltips" + data-tooltiplink="<%= I18n.t('tooltips.link.protocol.inventories') %>" + data-tooltipcontent="<%= I18n.t('tooltips.text.protocol.inventories') %>" + href="<%= repository_my_module_url(id: @my_module, repository_id: repository) %>" + title="<%= repository.name %>"> + <% cache [current_user, repository] do %> + <%= truncate(repository.name) + " (#{@my_module.repository_rows_count(repository)})" %> + <% end %> + +
  • + <% unless @my_module.experiment.project.team.repositories.last == repository %> +
  • + <% end %> +<% end %> diff --git a/app/views/shared/_secondary_navigation.html.erb b/app/views/shared/_secondary_navigation.html.erb index fc9cdd311..1b098503a 100644 --- a/app/views/shared/_secondary_navigation.html.erb +++ b/app/views/shared/_secondary_navigation.html.erb @@ -123,28 +123,15 @@
  • <% if can_read_team?(@my_module.experiment.project.team) && @my_module.experiment.project.team.repositories.exists? %> -
  • "> +
  • dropdown repositories-dropdown" + data-url="<%= module_repository_page? ? repositories_dropdown_repository_tab_my_module_path(repository: @repository) : repositories_dropdown_my_module_path %>"> " data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> - +
  • <% end %> <% if can_read_experiment?(@my_module.experiment) then %> @@ -168,4 +155,7 @@ + +<%= javascript_include_tag('secondary_navigation') %> + <% end %> diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index f5fc0767e..d610a3859 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -66,6 +66,7 @@ Rails.application.config.assets.precompile += Rails.application.config.assets.precompile += %w(datatables.js) Rails.application.config.assets.precompile += %w(search/index.js) Rails.application.config.assets.precompile += %w(navigation.js) +Rails.application.config.assets.precompile += %w(secondary_navigation.js) Rails.application.config.assets.precompile += %w(datatables.css) Rails.application.config.assets.precompile += %w(my_modules.js) Rails.application.config.assets.precompile += %w(canvas-to-blob.min.js) diff --git a/config/routes.rb b/config/routes.rb index 77462cbe8..9c57f2eb7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -374,6 +374,12 @@ Rails.application.routes.draw do get 'archive' # Archive view for single module get 'complete_my_module' post 'toggle_task_state' + get 'repositories_dropdown', + to: 'my_modules#repositories_dropdown', + as: :repositories_dropdown + get 'repositories_dropdown/:repository_id', + to: 'my_modules#repositories_dropdown', + as: :repositories_dropdown_repository_tab # Renders sample datatable for single module (ajax action) # post 'samples_index' # post :assign_samples, From 6a64b23f90462152a98764bf722cedb7a5485722 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Fri, 4 Jan 2019 10:44:38 +0100 Subject: [PATCH 03/12] Rename CORE_API_V1_PREVIEW env. variable to CORE_API_V1_ENABLED [SCI-2888] --- app/services/api.rb | 4 ++-- config/initializers/api.rb | 4 ++-- config/routes.rb | 2 +- spec/rails_helper.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/services/api.rb b/app/services/api.rb index 3dd4a5f52..322d01e26 100644 --- a/app/services/api.rb +++ b/app/services/api.rb @@ -16,7 +16,7 @@ module Api attr_accessor :core_api_token_ttl attr_accessor :core_api_token_iss attr_accessor :azure_ad_apps - attr_accessor :core_api_v1_preview + attr_accessor :core_api_v1_enabled attr_accessor :core_api_rate_limit def initialize @@ -24,7 +24,7 @@ module Api @core_api_token_ttl = 30.minutes @core_api_token_iss = 'SciNote' @azure_ad_apps = {} - @core_api_v1_preview = false + @core_api_v1_enabled = false @core_api_rate_limit = 1000 end end diff --git a/config/initializers/api.rb b/config/initializers/api.rb index 71db82830..196dd88f0 100644 --- a/config/initializers/api.rb +++ b/config/initializers/api.rb @@ -11,9 +11,9 @@ Api.configure do |config| config.core_api_rate_limit = ENV['CORE_API_RATE_LIMIT'].to_i || 1000 - config.core_api_v1_preview = true if ENV['CORE_API_V1_PREVIEW'] + config.core_api_v1_enabled = true if ENV['CORE_API_V1_ENABLED'] - Paperclip::DataUriAdapter.register if ENV['CORE_API_V1_PREVIEW'] + Paperclip::DataUriAdapter.register if ENV['CORE_API_V1_ENABLED'] vars = ENV.select { |name, _| name =~ /^[[:alnum:]]*_AZURE_AD_APP_ID/ } vars.each do |name, value| diff --git a/config/routes.rb b/config/routes.rb index 77462cbe8..33259a0cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -561,7 +561,7 @@ Rails.application.routes.draw do namespace :api, defaults: { format: 'json' } do get 'health', to: 'api#health' get 'status', to: 'api#status' - if Api.configuration.core_api_v1_preview + if Api.configuration.core_api_v1_enabled namespace :v1 do resources :teams, only: %i(index show) do resources :inventories, diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 1f74b4ae3..fa9acd82e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -6,7 +6,7 @@ require 'devise' require_relative 'support/controller_macros' ENV['RAILS_ENV'] = 'test' -ENV['CORE_API_V1_PREVIEW'] = 'true' +ENV['CORE_API_V1_ENABLED'] = 'true' require File.expand_path('../../config/environment', __FILE__) # Prevent database truncation if the environment is production From ec28db6f4fb7b7e0472c534ad97a8dedec5df0f7 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 10 Jan 2019 14:16:09 +0100 Subject: [PATCH 04/12] Fix image URLs in export all document [SCI-2931] --- app/assets/stylesheets/reports.scss | 5 +++++ app/assets/stylesheets/themes/scinote.scss | 4 ---- app/helpers/tiny_mce_helper.rb | 10 +++++++++- .../elements/_my_module_result_asset_element.html.erb | 6 +++++- .../elements/_my_module_result_text_element.html.erb | 3 ++- .../reports/elements/_my_module_step_element.html.erb | 3 ++- .../reports/elements/_step_asset_element.html.erb | 6 +++++- 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/app/assets/stylesheets/reports.scss b/app/assets/stylesheets/reports.scss index a1efb5700..9752b1f84 100644 --- a/app/assets/stylesheets/reports.scss +++ b/app/assets/stylesheets/reports.scss @@ -206,6 +206,11 @@ label { padding-top: 10px; padding-left: 15px; padding-right: 15px; + + .report-export-img { + max-height: 300px; + max-width: 300px; + } } .report-element-children { diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index d9e5a715c..4eca577ba 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1945,10 +1945,6 @@ a.disabled-with-click-events { padding-bottom: 60px; } -.tiny-mce-pdf-ready { - max-width: 100%; -} - .doorkeeper-authorization { margin-bottom: 45px; diff --git a/app/helpers/tiny_mce_helper.rb b/app/helpers/tiny_mce_helper.rb index 091c586c1..809a5655d 100644 --- a/app/helpers/tiny_mce_helper.rb +++ b/app/helpers/tiny_mce_helper.rb @@ -26,7 +26,15 @@ module TinyMceHelper img = TinyMceAsset.find_by_id(match[1]) next unless img && check_image_permissions(obj, img) if pdf_export_ready - report_image_asset_url(img, :tiny_mce_asset, 'tiny-mce-pdf-ready') + tmp_f = Tempfile.open(img.image_file_name, Rails.root.join('tmp')) + begin + img.image.copy_to_local_file(:large, tmp_f.path) + encoded_image = Base64.strict_encode64(tmp_f.read) + "" + ensure + tmp_f.close + tmp_f.unlink + end else image_tag(img.url, class: 'img-responsive', diff --git a/app/views/reports/elements/_my_module_result_asset_element.html.erb b/app/views/reports/elements/_my_module_result_asset_element.html.erb index 84f341a44..62cc048c3 100644 --- a/app/views/reports/elements/_my_module_result_asset_element.html.erb +++ b/app/views/reports/elements/_my_module_result_asset_element.html.erb @@ -38,7 +38,11 @@
    - <%= report_image_asset_url(asset) %> + <% if defined?(export_all) && export_all %> + + <% else %> + <%= report_image_asset_url(asset) %> + <% end %>
    diff --git a/app/views/reports/elements/_my_module_result_text_element.html.erb b/app/views/reports/elements/_my_module_result_text_element.html.erb index 69c452a37..9159f7c78 100644 --- a/app/views/reports/elements/_my_module_result_text_element.html.erb +++ b/app/views/reports/elements/_my_module_result_text_element.html.erb @@ -3,6 +3,7 @@ <% comments = result.result_comments %> <% timestamp = result.created_at %> <% name = result.name %> +<% pdf_export_ready = defined?(export_all) && export_all %>
    " data-name="<%= name %>" data-icon-class="fas fa-asterisk">
    @@ -23,7 +24,7 @@
    - <%= custom_auto_link(generate_image_tag_from_token(result_text.text, result_text, true), + <%= custom_auto_link(generate_image_tag_from_token(result_text.text, result_text, pdf_export_ready), team: current_team, simple_format: false, tags: %w(img)) %> diff --git a/app/views/reports/elements/_my_module_step_element.html.erb b/app/views/reports/elements/_my_module_step_element.html.erb index 6490d4c23..b6c602d0c 100644 --- a/app/views/reports/elements/_my_module_step_element.html.erb +++ b/app/views/reports/elements/_my_module_step_element.html.erb @@ -6,6 +6,7 @@ <% assets = step.assets %> <% checklists = step.checklists %> <% comments = step.step_comments %> +<% pdf_export_ready = defined?(export_all) && export_all %>
    " data-name="<%=t "projects.reports.elements.step.sidebar_name", pos: (step.position + 1), name: step.name %>" data-icon-class="fas fa-arrow-circle-right">
    @@ -30,7 +31,7 @@
    <% if strip_tags(step.description).present? %> - <%= custom_auto_link(generate_image_tag_from_token(step.description, step, true), + <%= custom_auto_link(generate_image_tag_from_token(step.description, step, pdf_export_ready), team: current_team, simple_format: false, tags: %w(img)) %> diff --git a/app/views/reports/elements/_step_asset_element.html.erb b/app/views/reports/elements/_step_asset_element.html.erb index fb09808ca..f9bbcde53 100644 --- a/app/views/reports/elements/_step_asset_element.html.erb +++ b/app/views/reports/elements/_step_asset_element.html.erb @@ -32,7 +32,11 @@ <% if is_image %>
    - <%= report_image_asset_url(asset) %> + <% if defined?(export_all) && export_all %> + + <% else %> + <%= report_image_asset_url(asset) %> + <% end %>
    <% end %> From 132f46b1367caf3c37fb62ccbd89ab04e5a706b3 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 10 Jan 2019 21:11:20 +0100 Subject: [PATCH 05/12] Improve error handling in task inventories dropdown [SCI-2776] --- app/assets/javascripts/secondary_navigation.js | 9 ++++++--- app/controllers/my_modules_controller.rb | 5 ++++- app/views/my_modules/_repositories_dropdown.html.erb | 10 ++++++++-- app/views/shared/_secondary_navigation.html.erb | 4 +++- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/secondary_navigation.js b/app/assets/javascripts/secondary_navigation.js index 5c870fa77..9da8f176b 100644 --- a/app/assets/javascripts/secondary_navigation.js +++ b/app/assets/javascripts/secondary_navigation.js @@ -5,15 +5,18 @@ var dropDown = $('.repositories-dropdown'); var dropDownMenu = $('.repositories-dropdown-menu'); dropDown.on('show.bs.dropdown', function() { - dropDownMenu.html( - '
    ' - ); + dropDownMenu + .find('.assigned-items-counter') + .html(''); $.ajax({ url: dropDown.data('url'), type: 'GET', dataType: 'json', success: function(data) { dropDownMenu.html(data.html); + }, + error: function() { + dropDownMenu.find('.assigned-items-counter').html(''); } }); }); diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index b2edcafbf..3a2123332 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -409,7 +409,10 @@ class MyModulesController < ApplicationController respond_to do |format| format.json do render json: { - html: render_to_string(partial: 'repositories_dropdown.html.erb') + html: render_to_string( + partial: 'repositories_dropdown.html.erb', + locals: { enable_counters: true } + ) } end end diff --git a/app/views/my_modules/_repositories_dropdown.html.erb b/app/views/my_modules/_repositories_dropdown.html.erb index f31da3fdc..00146bb1f 100644 --- a/app/views/my_modules/_repositories_dropdown.html.erb +++ b/app/views/my_modules/_repositories_dropdown.html.erb @@ -5,8 +5,14 @@ data-tooltipcontent="<%= I18n.t('tooltips.text.protocol.inventories') %>" href="<%= repository_my_module_url(id: @my_module, repository_id: repository) %>" title="<%= repository.name %>"> - <% cache [current_user, repository] do %> - <%= truncate(repository.name) + " (#{@my_module.repository_rows_count(repository)})" %> + <% if enable_counters %> + <% cache [current_user, repository] do %> + <%= truncate(repository.name) %> + <%= "(#{@my_module.repository_rows_count(repository)})" %> + <% end %> + <% else %> + <%= truncate(repository.name) %> + <% end %> diff --git a/app/views/shared/_secondary_navigation.html.erb b/app/views/shared/_secondary_navigation.html.erb index 1b098503a..3ff0a346d 100644 --- a/app/views/shared/_secondary_navigation.html.erb +++ b/app/views/shared/_secondary_navigation.html.erb @@ -131,7 +131,9 @@ - + <% end %> <% if can_read_experiment?(@my_module.experiment) then %> From 89240659a7f26e58afaf9028e50b1e04f166faf5 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Fri, 11 Jan 2019 17:20:04 +0100 Subject: [PATCH 06/12] Fix task tags update on canvas cards [SCI-2875] --- app/assets/javascripts/projects/canvas.js.erb | 13 ++++++---- app/controllers/my_module_tags_controller.rb | 26 +++++++++++++++---- .../canvas/full_zoom/_my_module.html.erb | 3 +-- .../canvas/medium_zoom/_my_module.html.erb | 3 +-- app/views/experiments/canvas.html.erb | 2 +- config/routes.rb | 1 + 6 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/projects/canvas.js.erb b/app/assets/javascripts/projects/canvas.js.erb index 6c007e782..8df86898d 100644 --- a/app/assets/javascripts/projects/canvas.js.erb +++ b/app/assets/javascripts/projects/canvas.js.erb @@ -873,18 +873,21 @@ function bindEditTagsAjax(elements) { manageTagsModalBody = manageTagsModal.find(".modal-body"); // Reload tags HTML element when modal is closed - manageTagsModal.on("hide.bs.modal", function(){ + manageTagsModal.off().on("hide.bs.modal", function(){ var task = $("div.panel[data-module-id='" + manageTagsModal.data('module-id') + "']"); // Load HTML $.ajax({ - url: task.attr("data-module-tags-url"), + url: $('#canvas-container').attr('data-module-tags-url'), type: "GET", dataType: "json", - success: function(data){ - task.find(".edit-tags-link") - .html(data.html_canvas); + success: function(data) { + $.each(data.my_modules, function(index, my_module){ + $('div.panel[data-module-id=' + my_module.id + ']') + .find(".edit-tags-link") + .html(my_module.tags); + }); // initialize tooltips again $.initTooltips(); }, diff --git a/app/controllers/my_module_tags_controller.rb b/app/controllers/my_module_tags_controller.rb index 79ff20cb5..9a5eb5d31 100644 --- a/app/controllers/my_module_tags_controller.rb +++ b/app/controllers/my_module_tags_controller.rb @@ -1,5 +1,5 @@ class MyModuleTagsController < ApplicationController - before_action :load_vars + before_action :load_vars, except: :canvas_index before_action :check_view_permissions, only: :index before_action :check_manage_permissions, only: %i(create index_edit destroy) @@ -25,10 +25,6 @@ class MyModuleTagsController < ApplicationController respond_to do |format| format.json do render json: { - html_canvas: render_to_string( - partial: 'canvas/tags.html.erb', - locals: { my_module: @my_module } - ), html_module_header: render_to_string( partial: 'my_modules/tags.html.erb', locals: { my_module: @my_module } @@ -38,6 +34,26 @@ class MyModuleTagsController < ApplicationController end end + def canvas_index + experiment = Experiment.find(params[:id]) + render_403 unless can_read_experiment?(experiment) + res = [] + experiment.active_my_modules.each do |my_module| + res << { + id: my_module.id, + tags: render_to_string( + partial: 'canvas/tags.html.erb', + locals: { my_module: my_module } + ) + } + end + respond_to do |format| + format.json do + render json: { my_modules: res } + end + end + end + def create @mt = MyModuleTag.new(mt_params.merge(my_module: @my_module)) @mt.created_by = current_user diff --git a/app/views/canvas/full_zoom/_my_module.html.erb b/app/views/canvas/full_zoom/_my_module.html.erb index a01666266..1b3663781 100644 --- a/app/views/canvas/full_zoom/_my_module.html.erb +++ b/app/views/canvas/full_zoom/_my_module.html.erb @@ -9,8 +9,7 @@ data-module-x="<%= my_module.x %>" data-module-y="<%= my_module.y %>" data-module-conns="<%= construct_module_connections(my_module) %>" - data-module-tags-url="<%= my_module_my_module_tags_url(my_module, format: :json) %>" - data-module-users-tab-url="<%= my_module_user_my_modules_url(my_module_id: my_module.id, format: :json) %>"> + data-module-tags-url="<%= my_module_tags_experiment_path(my_module.experiment, format: :json) %>"> <% if can_manage_module?(my_module) %> diff --git a/app/views/canvas/medium_zoom/_my_module.html.erb b/app/views/canvas/medium_zoom/_my_module.html.erb index 3ffe35842..2ef03b8ff 100644 --- a/app/views/canvas/medium_zoom/_my_module.html.erb +++ b/app/views/canvas/medium_zoom/_my_module.html.erb @@ -8,8 +8,7 @@ <% end %> data-module-x="<%= my_module.x %>" data-module-y="<%= my_module.y %>" - data-module-conns="<%= construct_module_connections(my_module) %>" - data-module-tags-url="<%= my_module_my_module_tags_url(my_module, format: :json) %>"> + data-module-conns="<%= construct_module_connections(my_module) %>"> <% if can_manage_module?(my_module) %> diff --git a/app/views/experiments/canvas.html.erb b/app/views/experiments/canvas.html.erb index a9c7d008f..54cf13687 100644 --- a/app/views/experiments/canvas.html.erb +++ b/app/views/experiments/canvas.html.erb @@ -45,7 +45,7 @@
    -
    +
    <%= render partial: 'canvas/full_zoom', locals: { experiment: @experiment, my_modules: @active_modules } %>
    diff --git a/config/routes.rb b/config/routes.rb index 33259a0cc..761d57ce9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -311,6 +311,7 @@ Rails.application.routes.draw do get 'canvas/small_zoom', to: 'canvas#small_zoom' # AJAX-loaded canvas zoom post 'canvas', to: 'canvas#update' # Save updated canvas action get 'module_archive' # Module archive for single experiment + get 'my_module_tags', to: 'my_module_tags#canvas_index' get 'archive' # archive experiment get 'clone_modal' # return modal with clone options post 'clone' # clone experiment From 3a4b992f4e5bbde6b66f247d24f6e100bbd6c29b Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Mon, 14 Jan 2019 16:31:23 +0100 Subject: [PATCH 07/12] Code style fixies []SCI-2875] --- app/assets/javascripts/projects/canvas.js.erb | 2 +- app/controllers/my_module_tags_controller.rb | 2 +- app/views/experiments/canvas.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/projects/canvas.js.erb b/app/assets/javascripts/projects/canvas.js.erb index 8df86898d..d4f524071 100644 --- a/app/assets/javascripts/projects/canvas.js.erb +++ b/app/assets/javascripts/projects/canvas.js.erb @@ -886,7 +886,7 @@ function bindEditTagsAjax(elements) { $.each(data.my_modules, function(index, my_module){ $('div.panel[data-module-id=' + my_module.id + ']') .find(".edit-tags-link") - .html(my_module.tags); + .html(my_module.tags_html); }); // initialize tooltips again $.initTooltips(); diff --git a/app/controllers/my_module_tags_controller.rb b/app/controllers/my_module_tags_controller.rb index 9a5eb5d31..b40673108 100644 --- a/app/controllers/my_module_tags_controller.rb +++ b/app/controllers/my_module_tags_controller.rb @@ -41,7 +41,7 @@ class MyModuleTagsController < ApplicationController experiment.active_my_modules.each do |my_module| res << { id: my_module.id, - tags: render_to_string( + tags_html: render_to_string( partial: 'canvas/tags.html.erb', locals: { my_module: my_module } ) diff --git a/app/views/experiments/canvas.html.erb b/app/views/experiments/canvas.html.erb index 54cf13687..2769de66f 100644 --- a/app/views/experiments/canvas.html.erb +++ b/app/views/experiments/canvas.html.erb @@ -45,7 +45,7 @@
    -
    +
    <%= render partial: 'canvas/full_zoom', locals: { experiment: @experiment, my_modules: @active_modules } %>
    From 1d4fc7172da0403f1efdf96fdad455e721470a1b Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Tue, 15 Jan 2019 17:10:10 +0100 Subject: [PATCH 08/12] Update Ruby to 2.4.5 and add jemalloc package --- Dockerfile | 3 ++- Dockerfile.production | 3 ++- Gemfile | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2fa0a78d8..c991986ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,11 @@ -FROM ruby:2.4.4 +FROM ruby:2.4.5 MAINTAINER BioSistemika # additional dependecies RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \ apt-get update -qq && \ apt-get install -y \ + libjemalloc1 \ nodejs \ postgresql-client \ default-jre-headless \ diff --git a/Dockerfile.production b/Dockerfile.production index 9bdbb4fea..61efe3707 100644 --- a/Dockerfile.production +++ b/Dockerfile.production @@ -1,10 +1,11 @@ -FROM ruby:2.4.4 +FROM ruby:2.4.5 MAINTAINER BioSistemika # additional dependecies RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \ apt-get update -qq && \ apt-get install -y \ + libjemalloc1 \ nodejs \ groff-base \ awscli \ diff --git a/Gemfile b/Gemfile index 00ff3ff12..72e09a076 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'http://rubygems.org' -ruby '2.4.4' +ruby '2.4.5' gem 'rails', '5.1.6' gem 'webpacker', '~> 2.0' From 4f9eb7e16568f13bf0b93ec737ad6b7a7a66c9c5 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Wed, 16 Jan 2019 17:07:05 +0100 Subject: [PATCH 09/12] Fix binary files in Export All archive [SCI2950] --- app/models/team_zip_export.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/models/team_zip_export.rb b/app/models/team_zip_export.rb index a87dc11d5..a3c03464c 100644 --- a/app/models/team_zip_export.rb +++ b/app/models/team_zip_export.rb @@ -193,12 +193,7 @@ class TeamZipExport < ZipExport name = "#{directory}/#{append_file_suffix(asset.file_file_name, "_#{i}")}" end - file = FileUtils.touch(name).first - if asset.file.exists? - File.open(file, 'wb') do |f| - f.write(Paperclip.io_adapters.for(asset.file).read) - end - end + asset.file.copy_to_local_file(:original, name) if asset.file.exists? asset_indexes[asset.id] = name end @@ -266,8 +261,7 @@ class TeamZipExport < ZipExport # Save all attachments (it doesn't work directly in callback function assets.each do |asset, asset_path| - file = FileUtils.touch(asset_path).first - File.open(file, 'wb') { |f| f.write asset.open.read } + asset.file.copy_to_local_file(:original, asset_path) end csv_file_path @@ -301,7 +295,7 @@ class TeamZipExport < ZipExport write_entries(input_dir, subdir, zip_file_path, io) else io.get_output_stream(zip_file_path) do |f| - f.puts File.open(disk_file_path, 'rb').read + f.write(File.open(disk_file_path, 'rb').read) end end end From e62e1873b07d45cb0ce021889ad45e04c97d9b12 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 17 Jan 2019 15:04:20 +0100 Subject: [PATCH 10/12] Fix issue with caching in inventories dropdown [SCI-2776] --- app/models/my_module_repository_row.rb | 4 +++- app/models/repository_row.rb | 2 +- app/views/my_modules/_repositories_dropdown.html.erb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/my_module_repository_row.rb b/app/models/my_module_repository_row.rb index e2eef2382..c28ce10a0 100644 --- a/app/models/my_module_repository_row.rb +++ b/app/models/my_module_repository_row.rb @@ -4,10 +4,12 @@ class MyModuleRepositoryRow < ApplicationRecord class_name: 'User', optional: true belongs_to :repository_row, + optional: true, + inverse_of: :my_module_repository_rows + belongs_to :my_module, optional: true, touch: true, inverse_of: :my_module_repository_rows - belongs_to :my_module, optional: true, inverse_of: :my_module_repository_rows validates :repository_row, :my_module, presence: true validates :repository_row, uniqueness: { scope: :my_module } diff --git a/app/models/repository_row.rb b/app/models/repository_row.rb index 17e9e2b06..4daa0aae3 100644 --- a/app/models/repository_row.rb +++ b/app/models/repository_row.rb @@ -1,7 +1,7 @@ class RepositoryRow < ApplicationRecord include SearchableModel - belongs_to :repository, touch: true, optional: true + belongs_to :repository, optional: true belongs_to :created_by, foreign_key: :created_by_id, class_name: 'User', diff --git a/app/views/my_modules/_repositories_dropdown.html.erb b/app/views/my_modules/_repositories_dropdown.html.erb index 00146bb1f..46e4cbf3b 100644 --- a/app/views/my_modules/_repositories_dropdown.html.erb +++ b/app/views/my_modules/_repositories_dropdown.html.erb @@ -6,7 +6,7 @@ href="<%= repository_my_module_url(id: @my_module, repository_id: repository) %>" title="<%= repository.name %>"> <% if enable_counters %> - <% cache [current_user, repository] do %> + <% cache [repository, @my_module] do %> <%= truncate(repository.name) %> <%= "(#{@my_module.repository_rows_count(repository)})" %> <% end %> From 1861f86b2c3bc48aa13d2d505e36a65241c5d615 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 17 Jan 2019 17:27:32 +0100 Subject: [PATCH 11/12] Improve export all modal messages in case of unlimited exports [SCI-2965] --- app/views/projects/export/_modal.html.erb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/views/projects/export/_modal.html.erb b/app/views/projects/export/_modal.html.erb index 02a119c04..3dfc75ac4 100644 --- a/app/views/projects/export/_modal.html.erb +++ b/app/views/projects/export/_modal.html.erb @@ -1,5 +1,7 @@

    <%=t 'projects.export_projects.modal_text_p1_html', num_projects: num_projects, team: @team.name %>

    <%=t 'projects.export_projects.modal_text_p2_html' %>

    -

    - <%=t 'projects.export_projects.modal_text_p3_html', limit: limit, num: num_of_requests_left %> -

    +<% unless limit.zero? %> +

    + <%=t 'projects.export_projects.modal_text_p3_html', limit: limit, num: num_of_requests_left %> +

    +<% end %> From b6d291d658fc3ead913ca4ded1cac839b9d5037e Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Fri, 18 Jan 2019 10:53:57 +0100 Subject: [PATCH 12/12] Update VERSION to 1.15.3 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 42cf0675c..f2380cc7a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.15.2 +1.15.3