Merge pull request #405 from ZmagoD/zd_SCI_832

Visualization of User smart annotation after saving the field
This commit is contained in:
Zmago Devetak 2017-01-18 09:36:42 +01:00 committed by GitHub
commit 1b9f7db385
15 changed files with 149 additions and 38 deletions

View file

@ -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');

View file

@ -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;
}
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
"<span>#{image_tag avatar_path(user, :icon_small)} " \
"#{user.full_name}</span>"
organization ||= current_organization
if user && organization
user_org = user
.user_organizations
.where('user_organizations.organization_id = ?',
organization).first
user_description = %(<div class='pull-left'>
<img src='#{avatar_path(user, :thumb)}' alt='thumb'>
</div><div class='pull-right'>
<div class='row'><div class='col-xs-9 text-left'><h5>
#{user.full_name}</h5></div><div class='col-xs-3 text-right'>
<span class='glyphicon glyphicon-remove' aria-hidden='true'></span>
</div></div><div class='row'><div class='col-xs-12'>
<p class='user-email'>#{user.email}</p><p>
#{I18n.t('atwho.popover',
role: user_org.role.capitalize,
organization: user_org.organization.name,
time: user_org.created_at.strftime('%B %Y'))}
</p></div></div></div>)
raw(image_tag(avatar_path(user, :icon_small),
class: 'atwho-user-img-popover')) +
raw('<a onClick="$(this).popover(\'show\')" ' \
'class="atwho-user-popover" data-container="body" ' \
'data-html="true" tabindex="0" data-trigger="focus" ' \
'data-placement="top" data-toggle="popover" data-content="') +
raw(user_description) + raw('" >') + user.full_name + raw('</a>')
end
end
new_text

View file

@ -39,11 +39,12 @@
</div>
<strong><%= comment.user.full_name %>:</strong>
<div data-role="comment-message-container">
<p data-role="comment-message"><%= auto_link(
simple_format(
smart_annotation_parser(comment.message)
<span data-role="comment-message"><%= auto_link(
smart_annotation_parser(simple_format(
comment.message),
),
link: :urls,
sanitize: false,
html: { target: '_blank' }
) %></p>
).html_safe %></span>
</div>

View file

@ -39,11 +39,12 @@
</div>
<strong><%= comment.user.full_name %>:</strong>
<div data-role="comment-message-container">
<p data-role="comment-message"><%= auto_link(
simple_format(
smart_annotation_parser(comment.message)
<span data-role="comment-message"><%= auto_link(
smart_annotation_parser(simple_format(
comment.message),
),
link: :urls,
sanitize: false,
html: { target: '_blank' }
) %></p>
).html_safe %></span>
</div>

View file

@ -68,12 +68,13 @@
<div class="row">
<div class="col-xs-12">
<%= 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 %>
</div>
</div>
</div>

View file

@ -50,12 +50,13 @@
<% if experiment.description? %>
<div class='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 %>
</div>
<% else %>
<span class='experiment-no-description'>

View file

@ -40,7 +40,12 @@
<% end %>
</div>
<div data-role="comment-message-container">
<p data-role="comment-message"><%= auto_link(simple_format(smart_annotation_parser(comment.message)),
link: :urls,
html: { target: '_blank' }) %></p>
<span data-role="comment-message"><%= auto_link(
smart_annotation_parser(simple_format(
comment.message),
),
link: :urls,
sanitize: false,
html: { target: '_blank' }
).html_safe %></span>
</div>

View file

@ -40,11 +40,12 @@
<% end %>
</div>
<div data-role="comment-message-container">
<p data-role="comment-message"><%= auto_link(
simple_format(
smart_annotation_parser(comment.message)
<span data-role="comment-message"><%= auto_link(
smart_annotation_parser(simple_format(
comment.message),
),
link: :urls,
sanitize: false,
html: { target: '_blank' }
) %></p>
).html_safe %></span>
</div>

View file

@ -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.