Added creator_link and updator_link helpers

This commit is contained in:
Priit Tark 2015-03-23 11:17:27 +02:00
parent 15272bad76
commit d8d951974e
3 changed files with 24 additions and 7 deletions

View file

@ -17,4 +17,20 @@ module ApplicationHelper
"#{contact.ident} [#{contact.ident_country_code} #{contact.ident_type}]" "#{contact.ident} [#{contact.ident_country_code} #{contact.ident_type}]"
end end
end end
def creator_link(model)
return 'not present' if model.blank?
return model if model.kind_of? String
# can be api user or some other user
link_to(model.creator, ['admin', model.creator])
end
def updator_link(model)
return 'not present' if model.blank?
return model if model.kind_of? String
# can be api user or some other user
link_to(model.creator, ['admin', model.updator])
end
end end

View file

@ -27,21 +27,25 @@ module Versions
def creator def creator
return nil if creator_str.blank? return nil if creator_str.blank?
if creator_str =~ /^\d-api-/ creator = if creator_str =~ /^\d-api-/
ApiUser.find_by(id: creator_str) ApiUser.find_by(id: creator_str)
else else
AdminUser.find_by(id: creator_str) AdminUser.find_by(id: creator_str)
end end
creator.present? ? creator : creator_str
end end
def updator def updator
return nil if updator_str.blank? return nil if updator_str.blank?
if updator_str =~ /^\d-api-/ updator = if updator_str =~ /^\d-api-/
ApiUser.find_by(id: updator_str) ApiUser.find_by(id: updator_str)
else else
AdminUser.find_by(id: updator_str) AdminUser.find_by(id: updator_str)
end end
updator.present? ? updator : updator_str
end end
# callbacks # callbacks

View file

@ -32,18 +32,15 @@
%dd %dd
= l(@contact.created_at, format: :short) = l(@contact.created_at, format: :short)
by by
= link_to(@contact.creator, [:admin, @contact.creator]) = creator_link(@contact)
%dt= t(:updated) %dt= t(:updated)
%dd %dd
= l(@contact.updated_at, format: :short) = l(@contact.updated_at, format: :short)
by by
= link_to(@contact.updator, [:admin, @contact.updator]) = updator_link(@contact)
%dt= t(:registrar) %dt= t(:registrar)
%dd %dd
- if @contact.registrar.present? - if @contact.registrar.present?
= link_to(@contact.registrar, admin_registrar_path(@contact.registrar)) = link_to(@contact.registrar, admin_registrar_path(@contact.registrar))