rosa-build/app/helpers/application_helper.rb

69 lines
2.2 KiB
Ruby
Raw Normal View History

2011-03-09 13:13:36 +00:00
module ApplicationHelper
def layout_class
case
when controller_name == 'issues' && action_name == 'new'
'right nopadding'
when controller_name == 'build_lists' && ['new', 'create'].include?(action_name)
nil
when controller_name == 'platforms' && ['build_all', 'mass_builds'].include?(action_name)
2012-05-28 11:28:19 +01:00
'right slim'
when controller_name == 'platforms' && action_name == 'show'
'right bigpadding'
when controller_name == 'platforms' && action_name == 'clone'
'right middlepadding'
when controller_name == 'contacts' && action_name == 'sended'
'all feedback_sended'
else
content_for?(:sidebar) ? 'right' : 'all'
end
end
2012-03-29 19:34:45 +01:00
def top_menu_class(base)
(controller_name.include?('build_lists') ? controller_name : params[:controller]).include?(base.to_s) ? 'active' : nil
end
2012-03-30 13:30:39 +01:00
def title_object object
return object.advisory_id if object.class == Advisory
2012-03-30 13:30:39 +01:00
name = object.class == Group ? object.uname : object.name
object_name = t "activerecord.models.#{object.class.name.downcase}"
case object.class.name
when 'Project', 'Platform'
"#{object_name} #{object.owner.uname}/#{object.name}"
when 'Repository', 'Product'
"#{object_name} #{object.name} - #{title_object object.platform}"
when 'Group'
"#{object_name} #{object.uname}"
else object.class.name
end
end
2012-08-29 15:58:58 +01:00
2012-09-24 18:34:14 +01:00
def local_alert(text, type = 'error')
html = "<div class='flash'><div class='alert #{type}'> #{text}"
2014-01-21 04:51:49 +00:00
html << link_to('×', '#', class: 'close close-alert', 'data-dismiss' => 'alert')
2012-09-24 18:34:14 +01:00
html << '</div></div>'
end
2013-08-22 14:55:44 +01:00
# Why 42? Because it is the Answer!
def short_message(message, length = 42)
2014-01-21 04:51:49 +00:00
truncate(message, length: length, omission: '…')
2013-08-22 14:55:44 +01:00
end
2013-09-01 13:06:42 +01:00
def datetime_moment(date, options = {})
tag = options[:tag] || :div
2014-07-08 15:52:10 +01:00
title = options[:title] || date.strftime('%Y-%m-%d %H:%M:%S UTC')
2013-09-01 13:06:42 +01:00
klass = "datetime_moment #{options[:class]}"
2014-07-08 15:52:10 +01:00
content_tag(tag, nil, class: klass, title: title, origin_datetime: date.to_i)
2013-09-01 13:06:42 +01:00
end
2014-07-09 12:56:21 +01:00
def alert_class(type)
case type.to_s
2014-07-09 17:21:03 +01:00
when 'error'
'alert-danger'
when 'notice'
'alert-success'
else
"alert-#{type}"
end
2014-07-09 12:56:21 +01:00
end
2011-03-09 13:13:36 +00:00
end