21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-16 07:28:39 +02:00
chexpire/app/helpers/checks_helper.rb

53 lines
1.4 KiB
Ruby
Raw Normal View History

2018-05-29 10:28:03 +02:00
module ChecksHelper
2018-06-05 17:27:12 +02:00
def check_row_class(check)
expiry_date = check.domain_expires_at
return unless expiry_date.present?
2018-07-04 12:33:50 +02:00
return "table-danger" if expiry_date <= 3.days.from_now
return "table-warning" if expiry_date < 1.month.from_now
2018-06-05 17:27:12 +02:00
end
2018-07-03 20:11:52 +02:00
def checks_sort_links(field)
current_sort_str = current_sort.to_a.join("_")
%i[asc desc].map { |direction|
sort = "#{field}_#{direction}"
icon = direction == :asc ? "chevron-up" : "chevron-down"
2018-07-04 12:33:50 +02:00
html = Octicons::Octicon.new(icon, class: "mx-1").to_svg.html_safe
2018-07-03 20:11:52 +02:00
filter_params = current_criterias.merge(sort: sort)
link_to_unless sort == current_sort_str, html, checks_path(filter_params)
}.join
end
def current_criterias
current_scopes.merge(sort: params[:sort])
end
2018-07-04 12:33:50 +02:00
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
2018-05-29 10:28:03 +02:00
end