diff --git a/app/assets/javascripts/comments.js.erb b/app/assets/javascripts/comments.js.erb index 18aef4c0d..26244d078 100644 --- a/app/assets/javascripts/comments.js.erb +++ b/app/assets/javascripts/comments.js.erb @@ -310,9 +310,8 @@ var Comments = (function() { .on('ajax:send', function() { input.attr('readonly', true); }) - .on('ajax:success', function() { - var newMessage = input.val(); - oldMessage.html(newMessage); + .on('ajax:success', function(xhr, data) { + oldMessage.html(data.comment); form.off('ajax:send ajax:success ajax:error ajax:complete'); submitBtn.off('click'); diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 5d79cbf21..27611b6b2 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1875,3 +1875,32 @@ th.custom-field .modal-tooltiptext { text-decoration: none; } } + +.atwho-user-popover { + cursor: pointer; + padding-left: 5px; +} + +.atwho-user-img-popover { + cursor: not-allowed; +} + +.popover { + border-radius: 3px; + min-width: 450px; + padding: 15px 10px; + z-index: 9999; + + h5 { + font-weight: bold; + } + + .user-email { + color: $color-silver-chalice; + } + + p { + max-width: 260px; + word-wrap: break-word; + } +} diff --git a/app/controllers/my_module_comments_controller.rb b/app/controllers/my_module_comments_controller.rb index 7bd9668e8..956f39ecc 100644 --- a/app/controllers/my_module_comments_controller.rb +++ b/app/controllers/my_module_comments_controller.rb @@ -1,4 +1,7 @@ class MyModuleCommentsController < ApplicationController + include ActionView::Helpers::TextHelper + include ApplicationHelper + before_action :load_vars before_action :check_view_permissions, only: :index before_action :check_add_permissions, only: [:create] @@ -112,7 +115,15 @@ class MyModuleCommentsController < ApplicationController module: @my_module.name ) ) - render json: {}, status: :ok + message = auto_link( + smart_annotation_parser( + simple_format(@comment.message) + ), + link: :urls, + sanitize: false, + html: { target: '_blank' } + ).html_safe + render json: { comment: message }, status: :ok else render json: { errors: @comment.errors.to_hash(true) }, status: :unprocessable_entity diff --git a/app/controllers/project_comments_controller.rb b/app/controllers/project_comments_controller.rb index ca9c9b1e0..453e7f1f3 100644 --- a/app/controllers/project_comments_controller.rb +++ b/app/controllers/project_comments_controller.rb @@ -1,4 +1,7 @@ class ProjectCommentsController < ApplicationController + include ActionView::Helpers::TextHelper + include ApplicationHelper + before_action :load_vars before_action :check_view_permissions, only: :index before_action :check_add_permissions, only: [:create] @@ -109,7 +112,15 @@ class ProjectCommentsController < ApplicationController project: @project.name ) ) - render json: {}, status: :ok + message = auto_link( + smart_annotation_parser( + simple_format(@comment.message) + ), + link: :urls, + sanitize: false, + html: { target: '_blank' } + ).html_safe + render json: { comment: message }, status: :ok else render json: { errors: @comment.errors.to_hash(true) }, status: :unprocessable_entity diff --git a/app/controllers/result_comments_controller.rb b/app/controllers/result_comments_controller.rb index 09f3c6533..c6c667deb 100644 --- a/app/controllers/result_comments_controller.rb +++ b/app/controllers/result_comments_controller.rb @@ -1,4 +1,7 @@ class ResultCommentsController < ApplicationController + include ActionView::Helpers::TextHelper + include ApplicationHelper + before_action :load_vars before_action :check_view_permissions, only: [:index] @@ -110,7 +113,15 @@ class ResultCommentsController < ApplicationController result: @result.name ) ) - render json: {}, status: :ok + message = auto_link( + smart_annotation_parser( + simple_format(@comment.message) + ), + link: :urls, + sanitize: false, + html: { target: '_blank' } + ).html_safe + render json: { comment: message }, status: :ok else render json: { errors: @comment.errors.to_hash(true) }, status: :unprocessable_entity diff --git a/app/controllers/step_comments_controller.rb b/app/controllers/step_comments_controller.rb index 2876c630b..64fcbab12 100644 --- a/app/controllers/step_comments_controller.rb +++ b/app/controllers/step_comments_controller.rb @@ -1,4 +1,7 @@ class StepCommentsController < ApplicationController + include ActionView::Helpers::TextHelper + include ApplicationHelper + before_action :load_vars before_action :check_view_permissions, only: [:index] @@ -115,7 +118,15 @@ class StepCommentsController < ApplicationController ) ) end - render json: {}, status: :ok + message = auto_link( + smart_annotation_parser( + simple_format(@comment.message) + ), + link: :urls, + sanitize: false, + html: { target: '_blank' } + ).html_safe + render json: { comment: message }, status: :ok else render json: { errors: @comment.errors.to_hash(true) }, status: :unprocessable_entity diff --git a/app/datatables/sample_datatable.rb b/app/datatables/sample_datatable.rb index cbf933a14..87411654f 100644 --- a/app/datatables/sample_datatable.rb +++ b/app/datatables/sample_datatable.rb @@ -122,10 +122,11 @@ class SampleDatatable < AjaxDatatablesRails::Base # Add custom attributes record.sample_custom_fields.each do |scf| sample[@cf_mappings[scf.custom_field_id]] = auto_link( - smart_annotation_parser(scf.value), + smart_annotation_parser(scf.value, @organization), link: :urls, + sanitize: false, html: { target: '_blank' } - ) + ).html_safe end sample end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aa3f59a17..d6d869ab7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,7 @@ module ApplicationHelper + include ActionView::Helpers::AssetTagHelper + include ActionView::Helpers::UrlHelper + def module_page? controller_name == 'my_modules' end @@ -53,7 +56,7 @@ module ApplicationHelper !@experiment.nil? end - def smart_annotation_parser(text) + def smart_annotation_parser(text, organization = nil) sa_reg = /\[\#(.*?)~(prj|exp|tsk|sam)~([0-9a-zA-Z]+)\]/ new_text = text.gsub(sa_reg) do |el| match = el.match(sa_reg) @@ -114,9 +117,33 @@ module ApplicationHelper new_text = new_text.gsub(sa_user) do |el| match = el.match(sa_user) user = User.find_by_id(match[2].base62_decode) - if user - "#{image_tag avatar_path(user, :icon_small)} " \ - "#{user.full_name}" + organization ||= current_organization + if user && organization + user_org = user + .user_organizations + .where('user_organizations.organization_id = ?', + organization).first + user_description = %(
+ thumb +
+
+ #{user.full_name}
+ +
+

#{user.email}

+ #{I18n.t('atwho.popover', + role: user_org.role.capitalize, + organization: user_org.organization.name, + time: user_org.created_at.strftime('%B %Y'))} +

) + + raw(image_tag(avatar_path(user, :icon_small), + class: 'atwho-user-img-popover')) + + raw('') + user.full_name + raw('') end end new_text diff --git a/app/views/my_module_comments/_comment.html.erb b/app/views/my_module_comments/_comment.html.erb index e441746b1..660c6170e 100644 --- a/app/views/my_module_comments/_comment.html.erb +++ b/app/views/my_module_comments/_comment.html.erb @@ -39,11 +39,12 @@ <%= comment.user.full_name %>:
-

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

+ ).html_safe %>
diff --git a/app/views/project_comments/_comment.html.erb b/app/views/project_comments/_comment.html.erb index c6047cba9..e71f319ef 100644 --- a/app/views/project_comments/_comment.html.erb +++ b/app/views/project_comments/_comment.html.erb @@ -39,11 +39,12 @@ <%= comment.user.full_name %>:
-

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

+ ).html_safe %>
diff --git a/app/views/projects/experiment_archive/_experiment.html.erb b/app/views/projects/experiment_archive/_experiment.html.erb index d0b25bedc..62a0274bf 100644 --- a/app/views/projects/experiment_archive/_experiment.html.erb +++ b/app/views/projects/experiment_archive/_experiment.html.erb @@ -68,12 +68,13 @@
<%= auto_link( - simple_format( - smart_annotation_parser(experiment.description) - ), - link: :urls, - html: { target: '_blank' } - ) %> + smart_annotation_parser( + simple_format(experiment.description) + ), + link: :urls, + sanitize: false, + html: { target: '_blank' } + ).html_safe %>
diff --git a/app/views/projects/show/_experiment.html.erb b/app/views/projects/show/_experiment.html.erb index 51d28781c..315c14f3c 100644 --- a/app/views/projects/show/_experiment.html.erb +++ b/app/views/projects/show/_experiment.html.erb @@ -50,12 +50,13 @@ <% if experiment.description? %>
<%= auto_link( - simple_format( - smart_annotation_parser(experiment.description) - ), + smart_annotation_parser( + simple_format(experiment.description) + ), link: :urls, + sanitize: false, html: { target: '_blank' } - ) %> + ).html_safe %>
<% else %> diff --git a/app/views/result_comments/_comment.html.erb b/app/views/result_comments/_comment.html.erb index 2bb9e2066..89dbeb1d6 100644 --- a/app/views/result_comments/_comment.html.erb +++ b/app/views/result_comments/_comment.html.erb @@ -40,7 +40,12 @@ <% end %>
-

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

+ <%= auto_link( + smart_annotation_parser(simple_format( + comment.message), + ), + link: :urls, + sanitize: false, + html: { target: '_blank' } + ).html_safe %>
diff --git a/app/views/step_comments/_comment.html.erb b/app/views/step_comments/_comment.html.erb index dda7fa8c6..1c119e2b1 100644 --- a/app/views/step_comments/_comment.html.erb +++ b/app/views/step_comments/_comment.html.erb @@ -40,11 +40,12 @@ <% end %>
-

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

+ ).html_safe %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 7e0ae6f73..8d7a829aa 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1463,6 +1463,7 @@ en: res: archived: "(archived)" deleted: "(deleted)" + popover: "%{role} of %{organization} and member since %{time}." # This section contains general words that can be used in any parts of # application.