mirror of https://github.com/Evolix/chexpire.git
Reduce checks helper method complexity
This commit is contained in:
parent
900bdb8b1e
commit
837f48ff81
|
@ -9,7 +9,7 @@ class ChecksController < ApplicationController
|
|||
has_scope :recurrent_failures, type: :boolean
|
||||
|
||||
def index
|
||||
@checks = apply_scopes(policy_scope(Check)).order(current_sort).page(params[:page])
|
||||
@checks = apply_scopes(policy_scope(Check)).order(Hash[*current_sort]).page(params[:page])
|
||||
end
|
||||
|
||||
def new
|
||||
|
@ -99,6 +99,6 @@ class ChecksController < ApplicationController
|
|||
return unless valid_fields.include?(field)
|
||||
return unless valid_directions.include?(direction)
|
||||
|
||||
{ field => direction }
|
||||
[field, direction]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,19 +18,29 @@ module ChecksHelper
|
|||
|
||||
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}"
|
||||
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
|
||||
sort_path = checks_path(current_criterias.merge(sort: sort.join("_")))
|
||||
link_to_unless sort == current_sort, html, sort_path, class: classes do
|
||||
content_tag(:span, html, class: classes + " active")
|
||||
end
|
||||
end
|
||||
|
||||
def check_in_error(check)
|
||||
content_tag(
|
||||
:span,
|
||||
Octicons::Octicon.new("alert", class: "ml-1").to_svg.html_safe,
|
||||
class: "in-error text-danger",
|
||||
data: {
|
||||
toggle: "tooltip",
|
||||
placement: "bottom",
|
||||
title: check_last_success_title(check)
|
||||
})
|
||||
end
|
||||
|
||||
def current_criterias
|
||||
current_scopes.merge(sort: params[:sort])
|
||||
end
|
||||
|
@ -53,10 +63,10 @@ module ChecksHelper
|
|||
|
||||
def check_button_scope_class(scope = nil)
|
||||
"btn btn-sm " + if scope && scoped_with?(scope)
|
||||
"btn-info active"
|
||||
else
|
||||
"btn-outline-info"
|
||||
end
|
||||
"btn-info active"
|
||||
else
|
||||
"btn-outline-info"
|
||||
end
|
||||
end
|
||||
|
||||
def check_last_success_title(check)
|
||||
|
|
|
@ -69,7 +69,7 @@ class Check < ApplicationRecord
|
|||
}
|
||||
|
||||
def self.default_sort
|
||||
{ domain_expires_at: :asc }
|
||||
[:domain_expires_at, :asc]
|
||||
end
|
||||
|
||||
def in_error?
|
||||
|
|
|
@ -26,17 +26,7 @@
|
|||
<span class="badge badge-info"><%= t(".kind_labels.#{check.kind}") %></span>
|
||||
</td>
|
||||
<td>
|
||||
<%- if check.in_error? %>
|
||||
<%== content_tag(
|
||||
:span,
|
||||
Octicons::Octicon.new("alert", class: "ml-1").to_svg.html_safe,
|
||||
class: "in-error text-danger",
|
||||
data: {
|
||||
toggle: "tooltip",
|
||||
placement: "bottom",
|
||||
title: check_last_success_title(check)
|
||||
}) %>
|
||||
<% end %>
|
||||
<%= check_in_error(check) if check.in_error? %>
|
||||
<strong><%= check.domain %></strong>
|
||||
</td>
|
||||
<td>
|
||||
|
|
Loading…
Reference in New Issue