mirror of
https://github.com/Evolix/chexpire.git
synced 2024-05-03 09:20:49 +02:00
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
|
has_scope :recurrent_failures, type: :boolean
|
||||||
|
|
||||||
def index
|
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
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
@ -99,6 +99,6 @@ class ChecksController < ApplicationController
|
||||||
return unless valid_fields.include?(field)
|
return unless valid_fields.include?(field)
|
||||||
return unless valid_directions.include?(direction)
|
return unless valid_directions.include?(direction)
|
||||||
|
|
||||||
{ field => direction }
|
[field, direction]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,19 +18,29 @@ module ChecksHelper
|
||||||
|
|
||||||
def checks_sort_link(field, direction)
|
def checks_sort_link(field, direction)
|
||||||
classes = "btn btn-light btn-sm mx-1 mx-1 px-1 py-0"
|
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"
|
icon = direction == :asc ? "chevron-up" : "chevron-down"
|
||||||
html = Octicons::Octicon.new(icon).to_svg.html_safe
|
html = Octicons::Octicon.new(icon).to_svg.html_safe
|
||||||
|
|
||||||
filter_params = current_criterias.merge(sort: sort)
|
sort_path = checks_path(current_criterias.merge(sort: sort.join("_")))
|
||||||
link_to_unless sort == current_sort_str, html, checks_path(filter_params), class: classes do
|
link_to_unless sort == current_sort, html, sort_path, class: classes do
|
||||||
content_tag(:span, html, class: classes + " active")
|
content_tag(:span, html, class: classes + " active")
|
||||||
end
|
end
|
||||||
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
|
def current_criterias
|
||||||
current_scopes.merge(sort: params[:sort])
|
current_scopes.merge(sort: params[:sort])
|
||||||
end
|
end
|
||||||
|
@ -53,10 +63,10 @@ module ChecksHelper
|
||||||
|
|
||||||
def check_button_scope_class(scope = nil)
|
def check_button_scope_class(scope = nil)
|
||||||
"btn btn-sm " + if scope && scoped_with?(scope)
|
"btn btn-sm " + if scope && scoped_with?(scope)
|
||||||
"btn-info active"
|
"btn-info active"
|
||||||
else
|
else
|
||||||
"btn-outline-info"
|
"btn-outline-info"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_last_success_title(check)
|
def check_last_success_title(check)
|
||||||
|
|
|
@ -69,7 +69,7 @@ class Check < ApplicationRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
def self.default_sort
|
def self.default_sort
|
||||||
{ domain_expires_at: :asc }
|
[:domain_expires_at, :asc]
|
||||||
end
|
end
|
||||||
|
|
||||||
def in_error?
|
def in_error?
|
||||||
|
|
|
@ -26,17 +26,7 @@
|
||||||
<span class="badge badge-info"><%= t(".kind_labels.#{check.kind}") %></span>
|
<span class="badge badge-info"><%= t(".kind_labels.#{check.kind}") %></span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%- if check.in_error? %>
|
<%= check_in_error(check) 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 %>
|
|
||||||
<strong><%= check.domain %></strong>
|
<strong><%= check.domain %></strong>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
Loading…
Reference in a new issue