From 6f76e86171e2d6c06f85aa75c3704558f3c2b551 Mon Sep 17 00:00:00 2001 From: ajugo Date: Mon, 7 Aug 2023 10:45:52 +0200 Subject: [PATCH] Implement results tab for shareable task link [SCI-8753] (#5910) * Implement results tab for shareable task link [SCI-8753] --- .../my_module_protocol_show.js | 15 +++-- .../shareable_links/my_module_results_show.js | 56 ++++++++++++++++++ .../my_module_shareable_links_controller.rb | 58 +++++++++++++++---- app/helpers/secondary_navigation_helper.rb | 2 +- .../my_module_results_show.html.erb | 50 ++++++++++++++++ .../my_modules/_attachments.html.erb | 4 +- .../my_modules/_header_actions.html.erb | 2 +- .../my_modules/_protocol.html.erb | 4 +- .../my_modules/results/_comments.html.erb | 14 +++++ .../results/_comments_list.html.erb | 18 ++++++ .../my_modules/results/_result.html.erb | 50 ++++++++++++++++ .../step_attachments/_file_preview.html.erb | 20 +++++-- .../step_attachments/_inline.html.erb | 4 +- .../step_attachments/_list.html.erb | 4 +- .../step_attachments/_thumbnail.html.erb | 4 +- config/initializers/assets.rb | 1 + config/locales/en.yml | 1 + config/routes.rb | 8 ++- 18 files changed, 282 insertions(+), 33 deletions(-) create mode 100644 app/assets/javascripts/shareable_links/my_module_results_show.js create mode 100644 app/views/shareable_links/my_module_results_show.html.erb create mode 100644 app/views/shareable_links/my_modules/results/_comments.html.erb create mode 100644 app/views/shareable_links/my_modules/results/_comments_list.html.erb create mode 100644 app/views/shareable_links/my_modules/results/_result.html.erb diff --git a/app/assets/javascripts/shareable_links/my_module_protocol_show.js b/app/assets/javascripts/shareable_links/my_module_protocol_show.js index 3b9a309ba..d7d939279 100644 --- a/app/assets/javascripts/shareable_links/my_module_protocol_show.js +++ b/app/assets/javascripts/shareable_links/my_module_protocol_show.js @@ -1,4 +1,4 @@ -/* global tableColRowName*/ +/* global tableColRowName notTurbolinksPreview */ (function() { 'use strict'; @@ -8,9 +8,12 @@ } function initStepsExpandCollapse() { - $(document).on('click', '.protocol-step-actions', function(event) { - let action = $(event.target).hasClass('steps-expand') ? 'show' : 'hide'; - $('.step-container .collapse').collapse(action); + $(document).on('click', '#steps-collapse-btn', function() { + $('.step-container .collapse').collapse('hide'); + }); + + $(document).on('click', '#steps-expand-btn', function() { + $('.step-container .collapse').collapse('show'); }); } @@ -68,5 +71,7 @@ }); } - initMyModuleProtocolShow(); + if (notTurbolinksPreview()) { + initMyModuleProtocolShow(); + } }()); diff --git a/app/assets/javascripts/shareable_links/my_module_results_show.js b/app/assets/javascripts/shareable_links/my_module_results_show.js new file mode 100644 index 000000000..a17af4da5 --- /dev/null +++ b/app/assets/javascripts/shareable_links/my_module_results_show.js @@ -0,0 +1,56 @@ +/* global notTurbolinksPreview */ + +(function() { + 'use strict'; + + function initializeHandsonTable(el) { + var input = el.siblings('input.hot-table-contents'); + var inputObj = JSON.parse(input.attr('value')); + var metadataJson = el.siblings('input.hot-table-metadata'); + var data = inputObj.data; + var metadata; + + metadata = JSON.parse(metadataJson.val() || '{}'); + el.handsontable({ + disableVisualSelection: true, + rowHeaders: true, + colHeaders: true, + editor: false, + copyPaste: false, + formulas: true, + data: data, + cell: metadata.cells || [] + }); + } + + function initAttachments() { + $(document).on('click', '.shareable-file-preview-link, .shareable-gallery-switcher', function(e) { + e.preventDefault(); + $('.modal-file-preview.in').modal('hide'); + $($(`.modal-file-preview[data-object-id=${$(this).data('id')}]`)).modal('show'); + }); + } + + function initResultsExpandCollapse() { + $(document).on('click', '#results-collapse-btn', function() { + $('.result .panel-collapse').collapse('hide'); + }); + + $(document).on('click', '#results-expand-btn', function() { + $('.result .panel-collapse').collapse('show'); + }); + } + + function initMyModuleResultsShow() { + initAttachments(); + initResultsExpandCollapse(); + + $('.hot-table-container').each(function() { + initializeHandsonTable($(this)); + }); + } + + if (notTurbolinksPreview()) { + initMyModuleResultsShow(); + } +}()); diff --git a/app/controllers/my_module_shareable_links_controller.rb b/app/controllers/my_module_shareable_links_controller.rb index 57aad4f8e..391dbff53 100644 --- a/app/controllers/my_module_shareable_links_controller.rb +++ b/app/controllers/my_module_shareable_links_controller.rb @@ -4,23 +4,30 @@ class MyModuleShareableLinksController < ApplicationController before_action :load_my_module, except: %i(protocol_show repository_index_dt repository_snapshot_index_dt - download_asset) + download_step_asset + download_result_asset + results_show) before_action :check_view_permissions, only: :show before_action :check_manage_permissions, except: %i(protocol_show repository_index_dt repository_snapshot_index_dt - download_asset) + download_step_asset + download_result_asset + results_show) before_action :shareable_link_load_my_module, only: %i(protocol_show repository_index_dt repository_snapshot_index_dt - download_asset) + download_step_asset + download_result_asset + results_show) before_action :load_repository, only: :repository_index_dt before_action :load_repository_snapshot, only: :repository_snapshot_index_dt - before_action :load_asset, only: :download_asset skip_before_action :authenticate_user!, only: %i(protocol_show repository_index_dt repository_snapshot_index_dt - download_asset) + download_step_asset + download_result_asset + results_show) skip_before_action :verify_authenticity_token, only: %i(protocol_show repository_index_dt repository_snapshot_index_dt) @@ -34,6 +41,26 @@ class MyModuleShareableLinksController < ApplicationController render 'shareable_links/my_module_protocol_show', layout: 'shareable_links' end + def results_show + @results_order = params[:order] || 'new' + + @results = @my_module.results.active + @results = @results.page(params[:page]).per(Constants::RESULTS_PER_PAGE_LIMIT) + + @results = case @results_order + when 'old' then @results.order(created_at: :asc) + when 'old_updated' then @results.order(updated_at: :asc) + when 'new_updated' then @results.order(updated_at: :desc) + when 'atoz' then @results.order(name: :asc) + when 'ztoa' then @results.order(name: :desc) + else @results.order(created_at: :desc) + end + + @gallery = @results.left_joins(:asset).pluck('assets.id').compact + + render 'shareable_links/my_module_results_show', layout: 'shareable_links' + end + def repository_index_dt @draw = params[:draw].to_i per_page = params[:length].to_i < 1 ? Constants::REPOSITORY_DEFAULT_PAGE_SIZE : params[:length].to_i @@ -71,7 +98,20 @@ class MyModuleShareableLinksController < ApplicationController render 'repository_rows/simple_view_index' end - def download_asset + def download_step_asset + @asset = @my_module.assets_in_steps.find_by(id: params[:id]) + + return render_404 if @asset.blank? + + redirect_to @asset.file.url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes, disposition: 'attachment'), + allow_other_host: true + end + + def download_result_asset + @asset = @my_module.assets_in_results.find_by(id: params[:id]) + + return render_404 if @asset.blank? + redirect_to @asset.file.url(expires_in: Constants::URL_SHORT_EXPIRE_TIME.minutes, disposition: 'attachment'), allow_other_host: true end @@ -123,12 +163,6 @@ class MyModuleShareableLinksController < ApplicationController @my_module = @shareable_link.shareable end - def load_asset - @asset = @my_module.assets_in_steps.find_by(id: params[:id]) - - return render_404 if @asset.blank? - end - def load_repository @repository = @my_module.assigned_repositories.find_by(id: params[:id]) render_404 unless @repository diff --git a/app/helpers/secondary_navigation_helper.rb b/app/helpers/secondary_navigation_helper.rb index db7e5df09..c0dea6fbf 100644 --- a/app/helpers/secondary_navigation_helper.rb +++ b/app/helpers/secondary_navigation_helper.rb @@ -37,7 +37,7 @@ module SecondaryNavigationHelper end def is_module_protocols? - %w(protocols my_module_protocol_show).include?(action_name) + %w(protocols protocol_show).include?(action_name) end def is_module_results? diff --git a/app/views/shareable_links/my_module_results_show.html.erb b/app/views/shareable_links/my_module_results_show.html.erb new file mode 100644 index 000000000..544f743d1 --- /dev/null +++ b/app/views/shareable_links/my_module_results_show.html.erb @@ -0,0 +1,50 @@ +
<%= @my_module.name %>
+ +
+
+ <%= render partial: 'shareable_links/my_modules/header_actions' %> +
+
+ + +
+ +
+ +
+ <% @results.each do |result| %> + <%= render partial: "shareable_links/my_modules/results/result", locals: { result: result, gallery: @gallery } %> + <% end %> +
+
+ <%= paginate @results, outer_window: 1, window: 1 %> +
+ +
+
+ +<%= javascript_include_tag "handsontable.full" %> +<%= render 'shared/formulas_libraries' %> +<%= javascript_include_tag 'shareable_links/my_module_results_show' %> + +<%= javascript_include_tag 'shared/file_preview' %> +<%= javascript_include_tag 'pdf_js' %> +<%= stylesheet_link_tag 'pdf_js_styles' %> diff --git a/app/views/shareable_links/my_modules/_attachments.html.erb b/app/views/shareable_links/my_modules/_attachments.html.erb index 16f0d896b..1c92812d0 100644 --- a/app/views/shareable_links/my_modules/_attachments.html.erb +++ b/app/views/shareable_links/my_modules/_attachments.html.erb @@ -7,8 +7,8 @@
<% attachments.each do |attachment| %> <% if attachment.file.attached? %> - <%= render partial: "shareable_links/my_modules/step_attachments/#{ attachment.view_mode }", locals: { asset: attachment, step: step } %> - <%= render partial: "shareable_links/my_modules/step_attachments/file_preview", locals: { asset: attachment, gallery: attachments.pluck(:id) } %> + <%= render partial: "shareable_links/my_modules/step_attachments/#{ attachment.view_mode }", locals: { asset: attachment, show_context: true } %> + <%= render partial: "shareable_links/my_modules/step_attachments/file_preview", locals: { asset: attachment, gallery: attachments.pluck(:id) } %> <% else %> <%= attachment.view_mode %> <%= render partial: "shareable_links/my_modules/step_attachments/empty", locals: { asset: attachment } %> diff --git a/app/views/shareable_links/my_modules/_header_actions.html.erb b/app/views/shareable_links/my_modules/_header_actions.html.erb index c74f367a0..5d867008e 100644 --- a/app/views/shareable_links/my_modules/_header_actions.html.erb +++ b/app/views/shareable_links/my_modules/_header_actions.html.erb @@ -6,7 +6,7 @@ <%= t("nav2.modules.steps") %> " - href="#" + href="<%= shared_protocol_results_path(@shareable_link.uuid) %>" title="<%= t("nav2.modules.results") %>" > <%= t("nav2.modules.results") %> diff --git a/app/views/shareable_links/my_modules/_protocol.html.erb b/app/views/shareable_links/my_modules/_protocol.html.erb index 24cd00e8a..8274a6fac 100644 --- a/app/views/shareable_links/my_modules/_protocol.html.erb +++ b/app/views/shareable_links/my_modules/_protocol.html.erb @@ -47,11 +47,11 @@
<% if protocol.steps.length > 0 %>
- - diff --git a/app/views/shareable_links/my_modules/results/_comments.html.erb b/app/views/shareable_links/my_modules/results/_comments.html.erb new file mode 100644 index 000000000..674e6be61 --- /dev/null +++ b/app/views/shareable_links/my_modules/results/_comments.html.erb @@ -0,0 +1,14 @@ +
+
+

+ <%=t('my_modules.results.comments_tab') %> + (<%= comments.count %>) +

+
+
+
+
+ <%= render partial: "shareable_links/my_modules/results/comments_list", locals: { comments: comments } %> +
+
+
diff --git a/app/views/shareable_links/my_modules/results/_comments_list.html.erb b/app/views/shareable_links/my_modules/results/_comments_list.html.erb new file mode 100644 index 000000000..2143a1f94 --- /dev/null +++ b/app/views/shareable_links/my_modules/results/_comments_list.html.erb @@ -0,0 +1,18 @@ +<% comments.order(created_at: :asc).each do |comment| %> +
+
+ + <%= image_tag avatar_path(comment.user, :icon_small), class: 'avatar' %> + +
+
+
<%= comment.user.full_name %>
+
+
<%= comment.created_at.iso8601 %>
+
+
+
<%= smart_annotation_text(comment.message) %>
+
+
+
+<% end %> diff --git a/app/views/shareable_links/my_modules/results/_result.html.erb b/app/views/shareable_links/my_modules/results/_result.html.erb new file mode 100644 index 000000000..57ece5c3d --- /dev/null +++ b/app/views/shareable_links/my_modules/results/_result.html.erb @@ -0,0 +1,50 @@ +
+
+ <% if result.is_text %> + + <% elsif result.is_table %> + + <% elsif result.is_asset %> + + <% end %> +
+
+ +
+
+
+
+ <% if result.is_text %> +
+ <%= smart_annotation_text(result.result_text.shareable_tinymce_render(:text)) %> +
+ <% elsif result.is_table %> +
+ + +
+
+ <% elsif result.is_asset %> + <%= render partial: "shareable_links/my_modules/step_attachments/#{ result.asset.view_mode }", locals: { asset: result.asset } %> + <%= render partial: "shareable_links/my_modules/step_attachments/file_preview", locals: { asset: result.asset, gallery: gallery } %> + <% end %> +
+
+
+
+ <%= render partial: "shareable_links/my_modules/results/comments", locals: { comments: result.comments } %> +
+
+
+
+
+
diff --git a/app/views/shareable_links/my_modules/step_attachments/_file_preview.html.erb b/app/views/shareable_links/my_modules/step_attachments/_file_preview.html.erb index 347cfd96a..8c5924bb0 100644 --- a/app/views/shareable_links/my_modules/step_attachments/_file_preview.html.erb +++ b/app/views/shareable_links/my_modules/step_attachments/_file_preview.html.erb @@ -10,13 +10,21 @@ diff --git a/app/views/shareable_links/my_modules/step_attachments/_inline.html.erb b/app/views/shareable_links/my_modules/step_attachments/_inline.html.erb index 4f0cea393..49dc36ae8 100644 --- a/app/views/shareable_links/my_modules/step_attachments/_inline.html.erb +++ b/app/views/shareable_links/my_modules/step_attachments/_inline.html.erb @@ -19,7 +19,9 @@ <%= t('assets.placeholder.size_label', size: number_to_human_size(asset.file_size)) %>
- <%= render partial: "shareable_links/my_modules/step_attachments/context_menu", locals: { asset: asset } %> + <% if defined?(show_context) && show_context %> + <%= render partial: "shareable_links/my_modules/step_attachments/context_menu", locals: { asset: asset } %> + <% end %>
<% if wopi_enabled? && wopi_file?(asset) %> diff --git a/app/views/shareable_links/my_modules/step_attachments/_list.html.erb b/app/views/shareable_links/my_modules/step_attachments/_list.html.erb index 83ea532e4..cc43c7f93 100644 --- a/app/views/shareable_links/my_modules/step_attachments/_list.html.erb +++ b/app/views/shareable_links/my_modules/step_attachments/_list.html.erb @@ -17,5 +17,7 @@ <%= t('assets.placeholder.modified_label') %> <%= asset.updated_at.iso8601 if asset.updated_at %> <%= t('assets.placeholder.size_label', size: number_to_human_size(asset.file_size)) %> - <%= render partial: "shareable_links/my_modules/step_attachments/context_menu", locals: { asset: asset } %> + <% if defined?(show_context) && show_context %> + <%= render partial: "shareable_links/my_modules/step_attachments/context_menu", locals: { asset: asset } %> + <% end %> diff --git a/app/views/shareable_links/my_modules/step_attachments/_thumbnail.html.erb b/app/views/shareable_links/my_modules/step_attachments/_thumbnail.html.erb index c4ba547d8..dc617b176 100644 --- a/app/views/shareable_links/my_modules/step_attachments/_thumbnail.html.erb +++ b/app/views/shareable_links/my_modules/step_attachments/_thumbnail.html.erb @@ -26,5 +26,7 @@ <%= number_to_human_size(asset.file_size) %> <% end %> - <%= render partial: "shareable_links/my_modules/step_attachments/context_menu", locals: { asset: asset } %> + <% if defined?(show_context) && show_context %> + <%= render partial: "shareable_links/my_modules/step_attachments/context_menu", locals: { asset: asset } %> + <% end %> diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 6f2c38c0d..8110f8993 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -125,6 +125,7 @@ Rails.application.config.assets.precompile += %w(my_modules/shared/layout_overri Rails.application.config.assets.precompile += %w(shareable_links/my_module_protocol_show.js) Rails.application.config.assets.precompile += %w(shareable_links/repositories.js) Rails.application.config.assets.precompile += %w(shareable_links/date_formatting.js) +Rails.application.config.assets.precompile += %w(shareable_links/my_module_results_show.js) # Libraries needed for Handsontable formulas Rails.application.config.assets.precompile += %w(jquery.js) diff --git a/config/locales/en.yml b/config/locales/en.yml index b629365b0..216cb0e2d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1209,6 +1209,7 @@ en: new_table_result: "Table" new_asset_result: "File" published_on_html: "Added on %{timestamp} by %{user}" + published_on_iso_html: "Added on %{timestamp} by %{user}" published_table: "entered a table on %{timestamp}." published_text: "entered a text on %{timestamp}." published_asset: "uploaded a file on %{timestamp}." diff --git a/config/routes.rb b/config/routes.rb index e727dde11..bdc68cf1a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -966,8 +966,14 @@ Rails.application.routes.draw do to: 'my_module_shareable_links#protocol_show', as: :shared_protocol get '/shared/:uuid/protocol/asset/:id/download', - to: 'my_module_shareable_links#download_asset', + to: 'my_module_shareable_links#download_step_asset', as: :shared_protocol_asset_download + get '/shared/:uuid/protocol/asset/:id/download_result', + to: 'my_module_shareable_links#download_result_asset', + as: :shared_protocol_result_asset_download + get '/shared/:uuid/protocol/results', + to: 'my_module_shareable_links#results_show', + as: :shared_protocol_results post '/shared/:uuid/repositories/:id/items', to: 'my_module_shareable_links#repository_index_dt', as: :shared_protocol_items,