2016-07-21 19:11:15 +08:00
|
|
|
module ProtocolStatusHelper
|
|
|
|
|
|
|
|
def protocol_status_href(protocol)
|
|
|
|
parent = protocol.parent
|
2017-01-11 22:50:11 +08:00
|
|
|
res = ''
|
2019-05-13 16:17:47 +08:00
|
|
|
res << '<a href="#" data-toggle="popover" data-html="true" class="preview-protocol"'
|
2017-01-11 22:50:11 +08:00
|
|
|
res << 'data-trigger="focus" data-placement="bottom" title="'
|
2017-01-05 23:05:48 +08:00
|
|
|
res << protocol_status_popover_title(parent) +
|
2017-01-04 00:27:22 +08:00
|
|
|
'" data-content="' + protocol_status_popover_content(parent) +
|
2019-06-20 21:28:15 +08:00
|
|
|
'">' + protocol_name(parent).truncate(Constants::NAME_TRUNCATION_LENGTH) + '</a>'
|
2017-01-11 22:50:11 +08:00
|
|
|
res.html_safe
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def protocol_private_for_current_user?(protocol)
|
|
|
|
protocol.in_repository_private? && protocol.added_by != current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def protocol_name(protocol)
|
2017-01-05 23:05:48 +08:00
|
|
|
if protocol_private_for_current_user?(protocol)
|
|
|
|
I18n.t('my_modules.protocols.protocol_status_bar.private_parent')
|
|
|
|
else
|
2017-01-11 22:50:11 +08:00
|
|
|
escape_input(protocol.name)
|
2017-01-05 23:05:48 +08:00
|
|
|
end
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def protocol_status_popover_title(protocol)
|
|
|
|
res = ""
|
|
|
|
if protocol.in_repository_public?
|
2018-05-22 22:55:58 +08:00
|
|
|
res << "<span class='fas fa-eye' title='" + I18n.t("my_modules.protocols.protocol_status_bar.public_desc") + "'></span>"
|
2016-07-21 19:11:15 +08:00
|
|
|
elsif protocol.in_repository_private?
|
2018-05-22 22:55:58 +08:00
|
|
|
res << "<span class='fas fa-eye-slash' title='" + I18n.t("my_modules.protocols.protocol_status_bar.private_desc") + "'></span>"
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
res << " "
|
2017-12-06 02:51:44 +08:00
|
|
|
if can_read_protocol_in_repository?(protocol)
|
2016-07-21 19:11:15 +08:00
|
|
|
res << "<a href='" + edit_protocol_path(protocol) + "' target='_blank'>" + protocol_name(protocol) + "</a>"
|
|
|
|
else
|
|
|
|
res << "<span style='font-weight: bold;'>" + protocol_name(protocol) + "</span>"
|
|
|
|
end
|
|
|
|
res << " - "
|
|
|
|
res << "<span style='font-style: italic;'>" + I18n.t("my_modules.protocols.protocol_status_bar.added_by") + " "
|
2017-01-05 23:05:48 +08:00
|
|
|
res << "<a href='#' data-toggle='tooltip' data-placement='right' title='" +
|
|
|
|
I18n.t('my_modules.protocols.protocol_status_bar.added_by_tooltip',
|
|
|
|
ts: I18n.l(protocol.created_at, format: :full)) + "'>" +
|
2017-01-11 22:50:11 +08:00
|
|
|
escape_input(protocol.added_by.full_name) + '</a></span>'
|
|
|
|
res
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def protocol_status_popover_content(protocol)
|
|
|
|
if protocol_private_for_current_user?(protocol)
|
2019-05-20 21:04:54 +08:00
|
|
|
res = '<p><em>' + I18n.t('my_modules.protocols.protocol_status_bar.private_protocol_desc') + '</em></p>'
|
2016-07-21 19:11:15 +08:00
|
|
|
else
|
2019-05-20 21:04:54 +08:00
|
|
|
res = '<p><b>' + I18n.t('my_modules.protocols.protocol_status_bar.keywords') + ':</b> '
|
|
|
|
if protocol.protocol_keywords.size.positive?
|
2016-07-21 19:11:15 +08:00
|
|
|
protocol.protocol_keywords.each do |kw|
|
2019-05-20 21:04:54 +08:00
|
|
|
res << kw.name + ', '
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
res = res[0..-3]
|
|
|
|
else
|
2019-05-20 21:04:54 +08:00
|
|
|
res << '<em>' + I18n.t('my_modules.protocols.protocol_status_bar.no_keywords') + '</em>'
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
2019-05-20 21:04:54 +08:00
|
|
|
res << '</p>'
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
2019-05-13 16:17:47 +08:00
|
|
|
escape_input(res)
|
2016-07-21 19:11:15 +08:00
|
|
|
end
|
|
|
|
end
|