21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-15 15:08:38 +02:00
chexpire/app/helpers/checks_helper.rb

84 lines
2.1 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
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)
2018-07-05 09:54:29 +02:00
%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"
2018-07-05 10:24:26 +02:00
sort = [field, direction]
2018-07-03 20:11:52 +02:00
2018-07-05 09:54:29 +02:00
icon = direction == :asc ? "chevron-up" : "chevron-down"
html = Octicons::Octicon.new(icon).to_svg.html_safe
2018-07-03 20:11:52 +02:00
2018-07-05 10:24:26 +02:00
sort_path = checks_path(current_criterias.merge(sort: sort.join("_")))
link_to_unless sort == current_sort, html, sort_path, class: classes do
2018-07-05 09:54:29 +02:00
content_tag(:span, html, class: classes + " active")
end
2018-07-03 20:11:52 +02:00
end
def check_in_error?(check)
check.consecutive_failures >=
Rails.configuration.chexpire.interface.consecutive_failures_as_error
end
def check_error(check)
2018-07-05 10:24:26 +02:00
content_tag(
:span,
Octicons::Octicon.new("alert", class: "ml-1").to_svg.html_safe,
class: "in-error text-danger",
data: {
toggle: "tooltip",
placement: "bottom",
2018-07-05 12:26:57 +02:00
title: check_last_success_title(check),
},
)
2018-07-05 10:24:26 +02:00
end
2018-07-03 20:11:52 +02:00
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)
2018-07-05 10:24:26 +02:00
"btn-info active"
else
"btn-outline-info"
end
2018-07-04 12:33:50 +02:00
end
2018-07-04 19:05:52 +02:00
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
2018-05-29 10:28:03 +02:00
end