From 356edba1b3c3d445681262366a48b1727c2ae847 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Thu, 5 Jan 2017 18:08:59 +0100 Subject: [PATCH 1/3] add protocol preview to search results --- app/assets/javascripts/protocols/index.js | 6 ++- app/views/search/results/_protocols.html.erb | 19 +++++++ .../results/partials/_protocol_text.html.erb | 54 ++++++++----------- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index eed54dc7c..c6c65fb29 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -191,7 +191,11 @@ function initKeywordFiltering() { function initProtocolPreviewModal() { // Only do this if the repository is public/private if (repositoryType !== "archive") { - protocolsTableEl.on("click", "a[data-action='protocol-preview']", function(e) { + var protocolsEl = protocolsTableEl; + if (document.getElementById("search-content")) { + protocolsEl = $("#search-content"); + } + protocolsEl.on("click", "a[data-action='protocol-preview']", function(e) { var link = $(this); $.ajax({ url: link.attr("data-url"), diff --git a/app/views/search/results/_protocols.html.erb b/app/views/search/results/_protocols.html.erb index 2a9de39b0..e3aea0810 100644 --- a/app/views/search/results/_protocols.html.erb +++ b/app/views/search/results/_protocols.html.erb @@ -1,3 +1,5 @@ +<%= render partial: "protocols/index/protocol_preview_modal.html.erb" %> + <% results.each do |protocol| %> <% has_description = protocol.description.present? && !protocol.description.empty? %> <% has_authors = protocol.authors.present? && !protocol.authors.empty? %> @@ -119,3 +121,20 @@
<% end %> + +<%= stylesheet_link_tag 'datatables' %> +<%= javascript_include_tag "protocols/index" %> +<%= javascript_include_tag "protocols/steps" %> + + +<%= javascript_include_tag "lodash" %> +<%= javascript_include_tag "numeral" %> +<%= javascript_include_tag "numeric" %> +<%= javascript_include_tag "md5" %> +<%= javascript_include_tag "jstat" %> +<%= javascript_include_tag "formula" %> +<%= javascript_include_tag "parser" %> +<%= javascript_include_tag "ruleJS" %> +<%= javascript_include_tag "handsontable.formula" %> +<%= javascript_include_tag "big.min" %> +<%= stylesheet_link_tag "handsontable.formula" %> diff --git a/app/views/search/results/partials/_protocol_text.html.erb b/app/views/search/results/partials/_protocol_text.html.erb index 137f7a62d..79d90f29b 100644 --- a/app/views/search/results/partials/_protocol_text.html.erb +++ b/app/views/search/results/partials/_protocol_text.html.erb @@ -1,40 +1,28 @@ <% query ||= nil %> <% text = query.present? ? highlight(protocol.name, query.strip.split(/\s+/)) : (protocol.name.empty? ? t("search.index.no_name") : protocol.name) %> -<% if protocol.in_module? %> + +<% if protocol.in_repository_public? %> - + <%=t "search.index.public" %> + +   +<% elsif protocol.in_repository_private? %> + + <%=t "search.index.private" %> + +   +<% elsif protocol.in_repository_archived? %> + + <%=t "search.index.archived" %>   - <% if can_view_steps_in_protocol(protocol) %> - <%= route_to_other_org protocols_my_module_path(protocol.my_module), - protocol.organization, - text %> - <% else %> - <%= text %> - <% end %> -<% else %> - <% if protocol.in_repository_public? %> - - <%=t "search.index.public" %> - -   - <% elsif protocol.in_repository_private? %> - - <%=t "search.index.private" %> - -   - <% elsif protocol.in_repository_archived? %> - - <%=t "search.index.archived" %> - -   - <% end %> - <% if can_edit_protocol(protocol) %> - <%= route_to_other_org edit_protocol_path(protocol), - protocol.organization, - text %> - <% else %> - <%= text %> - <% end %> +<% end %> +<% if can_edit_protocol(protocol) %> + <%= route_to_other_org edit_protocol_path(protocol), + protocol.organization, + text %> + <%= link_to text, '#', 'data-action' => 'protocol-preview', 'data-url' => preview_protocol_path(protocol) %> +<% else %> + <%= text %> <% end %> From 4e7e261225757b423fc836163a65602071780b68 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Fri, 6 Jan 2017 10:10:33 +0100 Subject: [PATCH 2/3] fix protocol preview --- app/assets/javascripts/protocols/index.js | 2 ++ app/helpers/search_helper.rb | 12 ++++++++++++ .../index/_protocol_preview_modal_footer.html.erb | 4 +++- .../search/results/partials/_protocol_text.html.erb | 6 +----- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index c6c65fb29..c892e59f0 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -191,7 +191,9 @@ function initKeywordFiltering() { function initProtocolPreviewModal() { // Only do this if the repository is public/private if (repositoryType !== "archive") { + // If you are in protocol repository var protocolsEl = protocolsTableEl; + // If you are in search results if (document.getElementById("search-content")) { protocolsEl = $("#search-content"); } diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index ee40a4c92..d2abd0c73 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -17,4 +17,16 @@ module SearchHelper link_to text, path end end + + def route_to_other_org_btn(path, search_org, text) + if search_org != current_organization + link_to text, + path, + :class => 'btn btn-primary', + data: { confirm: t('users.settings.changed_org_in_search', + team: search_org.name) } + else + link_to text, path, :class => 'btn btn-primary' + end + end end diff --git a/app/views/protocols/index/_protocol_preview_modal_footer.html.erb b/app/views/protocols/index/_protocol_preview_modal_footer.html.erb index 430b7e028..6b60460a4 100644 --- a/app/views/protocols/index/_protocol_preview_modal_footer.html.erb +++ b/app/views/protocols/index/_protocol_preview_modal_footer.html.erb @@ -1,4 +1,6 @@ <% if can_edit_protocol(@protocol) %> - <%= link_to t("general.edit"), edit_protocol_path(@protocol), :class => "btn btn-primary" %> + <%= route_to_other_org_btn edit_protocol_path(protocol), + protocol.organization, + t("general.edit") %> <% end %> diff --git a/app/views/search/results/partials/_protocol_text.html.erb b/app/views/search/results/partials/_protocol_text.html.erb index 79d90f29b..47918fb9e 100644 --- a/app/views/search/results/partials/_protocol_text.html.erb +++ b/app/views/search/results/partials/_protocol_text.html.erb @@ -1,7 +1,6 @@ <% query ||= nil %> <% text = query.present? ? highlight(protocol.name, query.strip.split(/\s+/)) : (protocol.name.empty? ? t("search.index.no_name") : protocol.name) %> - <% if protocol.in_repository_public? %> <%=t "search.index.public" %> @@ -18,10 +17,7 @@   <% end %> -<% if can_edit_protocol(protocol) %> - <%= route_to_other_org edit_protocol_path(protocol), - protocol.organization, - text %> +<% if can_view_protocol(protocol) %> <%= link_to text, '#', 'data-action' => 'protocol-preview', 'data-url' => preview_protocol_path(protocol) %> <% else %> <%= text %> From aad2eadeae9773af52eca3dc21c617ac4ea0b6f3 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Fri, 6 Jan 2017 10:46:36 +0100 Subject: [PATCH 3/3] syntax fix --- app/helpers/search_helper.rb | 4 ++-- app/views/search/results/partials/_protocol_text.html.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index d2abd0c73..1f3d46130 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -22,11 +22,11 @@ module SearchHelper if search_org != current_organization link_to text, path, - :class => 'btn btn-primary', + class: 'btn btn-primary', data: { confirm: t('users.settings.changed_org_in_search', team: search_org.name) } else - link_to text, path, :class => 'btn btn-primary' + link_to text, path, class: 'btn btn-primary' end end end diff --git a/app/views/search/results/partials/_protocol_text.html.erb b/app/views/search/results/partials/_protocol_text.html.erb index 47918fb9e..cfb09b68d 100644 --- a/app/views/search/results/partials/_protocol_text.html.erb +++ b/app/views/search/results/partials/_protocol_text.html.erb @@ -18,7 +18,7 @@   <% end %> <% if can_view_protocol(protocol) %> - <%= link_to text, '#', 'data-action' => 'protocol-preview', 'data-url' => preview_protocol_path(protocol) %> + <%= link_to text, '#', 'data-action': 'protocol-preview', 'data-url': preview_protocol_path(protocol) %> <% else %> <%= text %> <% end %>