21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-05 02:05:09 +02:00
chexpire/app/helpers/checks_helper.rb
2018-07-05 10:27:50 +02:00

66 lines
1.7 KiB
Ruby

module ChecksHelper
def check_row_class(check)
expiry_date = check.domain_expires_at
return unless expiry_date.present?
return "table-danger" if expiry_date <= 3.days.from_now
return "table-warning" if expiry_date < 1.month.from_now
end
def checks_sort_links(field)
%i[asc desc].map { |direction|
checks_sort_link(field, direction)
}.join
end
def checks_sort_link(field, direction)
classes = "btn btn-light btn-sm mx-1 mx-1 px-1 py-0"
current_sort_str = current_sort.to_a.join("_")
sort = "#{field}_#{direction}"
icon = direction == :asc ? "chevron-up" : "chevron-down"
html = Octicons::Octicon.new(icon).to_svg.html_safe
filter_params = current_criterias.merge(sort: sort)
link_to_unless sort == current_sort_str, html, checks_path(filter_params), class: classes do
content_tag(:span, html, class: classes + " active")
end
end
def current_criterias
current_scopes.merge(sort: params[:sort])
end
def scoped_with?(scope)
name, value = scope.first
scope_value = current_scopes[name]
scope_value = scope_value.to_sym if scope_value.respond_to?(:to_sym)
scope_value == value
end
def check_button_criterias(scope)
if scoped_with?(scope)
current_criterias.except(scope.keys.first)
else
current_criterias.merge(scope)
end
end
def check_button_scope_class(scope = nil)
"btn btn-sm " << if scope && scoped_with?(scope)
"btn-info active"
else
"btn-outline-info"
end
end
def check_last_success_title(check)
return t(".never_succeeded") if check.last_success_at.nil?
t(".days_from_last_success", count: check.days_from_last_success)
end
end