From a4aa933151c43b05ec8142003b817f740ca0e0b3 Mon Sep 17 00:00:00 2001 From: zmagod Date: Wed, 11 Jan 2017 10:34:14 +0100 Subject: [PATCH] refactor smart annotation parser helper --- .../javascripts/sitewide/atwho_res.js.erb | 21 +++++--- app/assets/stylesheets/themes/scinote.scss | 18 +++++++ app/helpers/application_helper.rb | 52 ++++++++++++++++--- .../my_module_comments/_comment.html.erb | 10 ++-- .../experiment_archive/_experiment.html.erb | 9 +++- config/locales/en.yml | 4 +- 6 files changed, 92 insertions(+), 22 deletions(-) diff --git a/app/assets/javascripts/sitewide/atwho_res.js.erb b/app/assets/javascripts/sitewide/atwho_res.js.erb index 18aa86d96..5dbcf5faa 100644 --- a/app/assets/javascripts/sitewide/atwho_res.js.erb +++ b/app/assets/javascripts/sitewide/atwho_res.js.erb @@ -141,15 +141,21 @@ var SmartAnnotation = (function() { }); } + // initialise dropdown dismiss button + function initDismissButton() { + $('.atwho-header-res .dismiss').off('click'); + $('.atwho-header-res .dismiss').on('click', function() { + $(field).atwho('destroy'); + init(); + }); + } + // Initialize filter buttons function initButtons(query, search_filter) { $('.atwho-header-res query_obj button').off(); $('.atwho-header-res .dismiss').off('click'); - $('.atwho-header-res .dismiss').on('click', function() { - $(field).atwho('destroy'); - init(); - }); + initDismissButton(); resourcesChecker(query, search_filter); $('.atwho-header-res .title button').on('click', function(e) { @@ -290,7 +296,7 @@ var SmartAnnotation = (function() { res += map.name; res += ''; if(map.archived) { - res += '(archived)'; + res += '<%= I18n.t("atwho.res.archived") %>'; } else { res += ''; } @@ -308,8 +314,6 @@ var SmartAnnotation = (function() { case 'sam': res += '' + map.description + ''; break; - default: - break; } res += ''; @@ -327,6 +331,7 @@ var SmartAnnotation = (function() { {query: query}, function(data) { callback(data.users); + initDismissButton(); } ); }, @@ -385,7 +390,7 @@ var SmartAnnotation = (function() { }, headerTpl: '
' + - '
<%= I18n.t("atwho.users.title") %>
' + + '
<%= I18n.t("atwho.users.title") %>
' + '
' + '
' + '<%= I18n.t("atwho.users.navigate_1") %> ' + diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 23b3f2c3f..5d79cbf21 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1794,6 +1794,10 @@ th.custom-field .modal-tooltiptext { } } + .title-user { + padding-top: 4px; + } + .help { float: right; padding-top: 4px; @@ -1857,3 +1861,17 @@ th.custom-field .modal-tooltiptext { font-size: 10px; } } + +.sa-type { + border: 1px solid $color-black; + border-radius: 4px; + color: $color-black; + font-weight: 600; + padding: 0 2px; + text-decoration: none; + text-transform: capitalize; + + &:hover { + text-decoration: none; + } +} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d0817ba4a..5021b9fb1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -59,19 +59,55 @@ module ApplicationHelper match = el.match(sa_reg) case match[2] when 'prj' - link_to match[1], project_path(match[3].to_i) + project = Project.find_by_id(match[3].to_i) + next unless project + if project.archived? + "#{sanitize(match[2])} " \ + "#{link_to project.name, + projects_archive_path} #{t'atwho.res.archived'}" + else + "#{sanitize(match[2])} " \ + "#{link_to project.name, + project_path(project)}" + end when 'exp' - link_to match[1], canvas_experiment_path(match[3].to_i) + experiment = Experiment.find_by_id(match[3].to_i) + next unless experiment + if experiment.archived? + "#{sanitize(match[2])} " \ + "#{link_to experiment.name, + experiment_archive_project_path(experiment.project)} " \ + "#{t'atwho.res.archived'}" + else + "#{sanitize(match[2])} " \ + "#{link_to experiment.name, + canvas_experiment_path(experiment)}" + end when 'tsk' - link_to match[1], protocols_my_module_path(match[3].to_i) + my_module = MyModule.find_by_id(match[3].to_i) + next unless my_module + if my_module.archived? + "#{sanitize(match[2])} " \ + "#{link_to my_module.name, + module_archive_experiment_path(my_module.experiment)}" \ + "#{t'atwho.res.archived'}" + else + "#{sanitize(match[2])} " \ + "#{link_to my_module.name, + protocols_my_module_path(my_module)}" + end when 'sam' sample = Sample.find_by_id(match[3]) if sample - link_to match[1], - samples_project_path(sample - .organization - .projects - .first) + " " \ + "#{link_to sample.name, + samples_project_path(sample + .organization + .projects + .first)}" + else + " " \ + "#{match[1]} #{t'atwho.res.deleted'}" end end end diff --git a/app/views/my_module_comments/_comment.html.erb b/app/views/my_module_comments/_comment.html.erb index 67c087dd5..e441746b1 100644 --- a/app/views/my_module_comments/_comment.html.erb +++ b/app/views/my_module_comments/_comment.html.erb @@ -39,7 +39,11 @@
<%= comment.user.full_name %>:
-

<%= auto_link(simple_format(comment.message), - link: :urls, - html: { target: '_blank' }) %>

+

<%= auto_link( + simple_format( + smart_annotation_parser(comment.message) + ), + link: :urls, + html: { target: '_blank' } + ) %>

diff --git a/app/views/projects/experiment_archive/_experiment.html.erb b/app/views/projects/experiment_archive/_experiment.html.erb index 508bd1983..d0b25bedc 100644 --- a/app/views/projects/experiment_archive/_experiment.html.erb +++ b/app/views/projects/experiment_archive/_experiment.html.erb @@ -67,8 +67,13 @@
- <%= experiment.description %> - + <%= auto_link( + simple_format( + smart_annotation_parser(experiment.description) + ), + link: :urls, + html: { target: '_blank' } + ) %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index f26b0c85d..7e0ae6f73 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1460,7 +1460,9 @@ en: confirm_2: "to confirm" dismiss_1: "esc" dismiss_2: "to dismiss" - + res: + archived: "(archived)" + deleted: "(deleted)" # This section contains general words that can be used in any parts of # application.