forked from nanego/my-dcim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nanego#307 from pantographe/360356-follow-up-conne…
…ction-index-update Merge Cables and Connections indexes
- Loading branch information
Showing
32 changed files
with
712 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
class CableDecorator < ApplicationDecorator | ||
include ActionView::Helpers::AssetTagHelper | ||
include Rails.application.routes.url_helpers | ||
include ActionView::Helpers::UrlHelper | ||
include ActionView::Helpers::TextHelper | ||
include ActionView::Context | ||
|
||
class << self | ||
def special_case_options_for_select | ||
[true, false].map do |s| | ||
[I18n.t("boolean.#{s}"), s] | ||
end | ||
end | ||
|
||
def colors_options_for_select | ||
Cable::COLORS.map do |k, v| | ||
[I18n.t(".activerecord.attributes.cable/color.#{v}"), k] | ||
end | ||
end | ||
end | ||
|
||
def server_connected_with_link(connection, from: false) | ||
tag.span class: class_names("text-body-emphasis col overflow-wrap", 'text-end': from) do | ||
if (server = connection&.server) | ||
link_to server.to_s, | ||
server_path(server), | ||
class: "text-body-emphasis", | ||
data: { turbo_frame: :_top } | ||
else | ||
tag.span "n/c", class: "fst-italic fw-lighter" | ||
end | ||
end | ||
end | ||
|
||
def draw_port(connection) | ||
if (twin_card_id = connection&.card&.twin_card_id) | ||
twin_card = Card.find(twin_card_id) | ||
twin_connections = twin_card.ports.map(&:connection) | ||
twin_card_used_ports = [] | ||
twin_connections.each { |c| twin_card_used_ports << c.port.position if c&.port } | ||
end | ||
|
||
if (port = connection&.port) && name.present? | ||
port_type_class = connection&.card&.card_type&.port_type&.decorated&.css_class_name | ||
|
||
tag.span name, | ||
class: class_names( | ||
"me-0 port #{color} text-body-emphasis #{port_type_class}", | ||
'fst-italic fw-lighter': name.blank?, | ||
no_client: port && port.cable_name && twin_card_used_ports&.exclude?(port.position) | ||
) | ||
else | ||
tag.span "n/c", class: "badge empty me-0 border text-body-emphasis fst-italic fw-lighter" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
class PortTypeDecorator < ApplicationDecorator | ||
def css_class_name | ||
case name | ||
when "RJ", "XRJ" | ||
"portRJ" | ||
when "FC", "SC" | ||
"portFC" | ||
when "ALIM" | ||
"portALIM" | ||
else | ||
"portSCSI" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
class CablesProcessor < ApplicationProcessor | ||
include Sortable | ||
SORTABLE_FIELDS = %w[special_case].freeze | ||
|
||
map :cable_name do |cable_name:| | ||
raw.where(name: cable_name) | ||
end | ||
|
||
map :special_case do |special_case:| | ||
raw.where(special_case:) | ||
end | ||
|
||
map :colors, filter_with: :non_empty_array do |colors:| | ||
raw.where(color: colors) | ||
end | ||
|
||
map :comments do |comments:| | ||
raw.where(Cable.arel_table[:comments].matches("%#{comments}%")) | ||
end | ||
|
||
map :vlans do |vlans:| | ||
raw.joins(:ports).where(Port.arel_table[:vlans].matches("%#{vlans}%")) | ||
end | ||
|
||
map :server_ids, filter_with: :non_empty_array do |server_ids:| | ||
raw.joins(:servers).where(servers: { id: server_ids }) | ||
end | ||
|
||
map :port_type_ids, filter_with: :non_empty_array do |port_type_ids:| | ||
raw.joins(:port_types).where(port_types: { id: port_type_ids }) | ||
end | ||
|
||
map :card_query do |card_query:| | ||
name_condition = Card.arel_table[:name].matches("%#{card_query}%") | ||
card_type_condition = CardType.arel_table[:name].matches("%#{card_query}%") | ||
slot_condition = Composant.arel_table[:name].matches("%#{card_query}%") | ||
combined_conditions = name_condition.or(card_type_condition).or(slot_condition) | ||
raw.joins(:cards, :card_types, cards: :composant).where(combined_conditions) | ||
end | ||
|
||
sortable fields: SORTABLE_FIELDS do | ||
having "comments" do |sort: "asc"| | ||
valid_sort_value!(sort) | ||
|
||
raw.reorder("comments #{sort.upcase} nulls last") | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.