Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse committed Aug 7, 2024
1 parent e84d6e4 commit c9520c5
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 200 deletions.
30 changes: 15 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ GEM
bootstrap (5.3.2)
autoprefixer-rails (>= 9.1.0)
popper_js (>= 2.11.8, < 3)
builder (3.2.4)
builder (3.3.0)
byebug (11.1.3)
capybara (3.40.0)
addressable
Expand All @@ -114,7 +114,7 @@ GEM
xpath (~> 3.2)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
concurrent-ruby (1.3.1)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
content_disposition (1.0.0)
crass (1.0.6)
Expand Down Expand Up @@ -159,7 +159,7 @@ GEM
drb (2.2.1)
email_validator (2.2.4)
activemodel
erubi (1.12.0)
erubi (1.13.0)
exception_notification (4.5.0)
actionmailer (>= 5.2, < 8)
activesupport (>= 5.2, < 8)
Expand Down Expand Up @@ -197,7 +197,7 @@ GEM
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.7.2)
irb (1.13.1)
irb (1.14.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jbuilder (2.11.5)
Expand Down Expand Up @@ -267,7 +267,7 @@ GEM
mini_mime (1.1.5)
mini_racer (0.12.0)
libv8-node (~> 21.7.2.0)
minitest (5.23.1)
minitest (5.24.1)
msgpack (1.7.2)
mutex_m (0.2.0)
net-http (0.4.1)
Expand All @@ -282,11 +282,11 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.1)
nokogiri (1.16.5-arm64-darwin)
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-darwin)
nokogiri (1.16.7-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.5-x86_64-linux)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
omniauth (2.1.2)
hashie (>= 3.4.6)
Expand Down Expand Up @@ -331,8 +331,8 @@ GEM
public_suffix (5.0.5)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.8.0)
rack (3.0.11)
racc (1.8.1)
rack (3.1.7)
rack-mini-profiler (3.3.1)
rack (>= 1.2.0)
rack-oauth2 (2.2.1)
Expand Down Expand Up @@ -393,13 +393,13 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rdoc (6.6.3.1)
rdoc (6.7.0)
psych (>= 4.0.0)
record_tag_helper (1.0.1)
actionview (>= 5)
redcarpet (3.6.0)
regexp_parser (2.9.1)
reline (0.5.6)
reline (0.5.9)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
Expand Down Expand Up @@ -511,7 +511,7 @@ GEM
railties (>= 6.0.0)
store_attribute (1.2.0)
activerecord (>= 6.0)
stringio (3.1.0)
stringio (3.1.1)
strscan (3.1.0)
swd (2.0.3)
activesupport (>= 3)
Expand All @@ -526,7 +526,7 @@ GEM
thread_safe (0.3.6)
tilt (2.3.0)
timeout (0.4.1)
turbo-rails (2.0.5)
turbo-rails (2.0.6)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
Expand Down Expand Up @@ -566,7 +566,7 @@ GEM
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.36)
zeitwerk (2.6.13)
zeitwerk (2.6.17)

PLATFORMS
arm64-darwin-22
Expand Down
56 changes: 0 additions & 56 deletions app/controllers/islets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,62 +94,6 @@ def destroy
end
end

# TODO
def infrastructure
@room = Room.friendly.find(params[:room_id])
@islet = @room.islets.find(params[:id])

@servers = Server.includes(:frame, :stack, :ports, :cards => [:ports])
.where.not(network_types: [])
# .includes(:cards, :ports => [:connection => [:port, :cable =>[:connections => [:port => :card]]]]).
@concentrateurs_ids = [383, 384, 1043, 1044]
@concentrateurs = Server.where(id: @concentrateurs_ids).includes(:ports => :connection, :cards => [:ports => :connection])
@switchs_lan_ids = @concentrateurs_ids | @servers.pluck(:id) # Switch LAN
# TODO: Remove hard-coded values
@hubs = {}

unless Rails.env.test?
@hubs = { "gbe" => { 4 => Server.find(383), 3 => Server.find(384) }, "10gbe" => { 4 => Server.find(1043), 3 => Server.find(1044) } } # Concentrateurs per room
end

@connections = {}
@stacks = @servers.map(&:stack).uniq.compact
@servers.each do |server|
@connections[server.id] = server.directly_connected_servers_ids_with_color.reject { |conn| @switchs_lan_ids.exclude?(conn[:server_id]) }
end
@concentrateurs.each do |hub|
@connections[hub.id] = hub.connected_servers_ids_through_twin_cards_with_color.reject { |conn| @switchs_lan_ids.exclude?(conn[:server_id]) }
end

# TODO: remove when hard-coded system will be removed
@network_types = Modele::Network::TYPES.excluding("fiber")
@network = params[:network_type] # TODO: take from params and raise error if not good

if @room.id == 4 || @room.id == 3
@hub = @hubs[@network][@room.id]
@second_room = Room.find(@room.id == 4 ? 3 : 4)
@second_hub = @hubs[@network][@second_room.id]
end

# TODO: only respond to turbo frame or stream
respond_to do |format|
format.html
end
end

def network_capacity
@room = Room.friendly.find(params[:room_id])
@islet = @room.islets.find(params[:id])
@network = params[:network_type] # TODO: take from params and raise error if not good

@bays = @islet.bays.sorted

# TODO: only respond to turbo frame or stream
respond_to do |format|
format.html
end
end

private

# Use callbacks to share common setup or constraints between actions.
Expand Down
46 changes: 43 additions & 3 deletions app/controllers/visualization/infrastructures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,51 @@ def show
@filter = Filter.new(params, %i[network_type islet_id])

unless @filter.filled?
@filter.islet_id = Islet.sorted.not_empty.has_name.distinct.first.id
@filter.network_type = :gbe
islet_id = Islet.sorted.not_empty.has_name.distinct.first.id

redirect_to islet_id:, network_type: :gbe
end

@islet = Islet.find(@filter.islet_id) if @filter.filled?
load_data! if turbo_frame_request?
end

private

def load_data!
@islet = Islet.find(@filter.islet_id)
@room = @islet.room

@servers = Server.includes(:frame, :stack, :ports, :cards => [:ports])
.where.not(network_types: [])
# .includes(:cards, :ports => [:connection => [:port, :cable =>[:connections => [:port => :card]]]]).
@concentrateurs_ids = [383, 384, 1043, 1044]
@concentrateurs = Server.where(id: @concentrateurs_ids).includes(:ports => :connection, :cards => [:ports => :connection])
@switchs_lan_ids = @concentrateurs_ids | @servers.pluck(:id) # Switch LAN
# TODO: Remove hard-coded values
@hubs = {}

unless Rails.env.test?
@hubs = { "gbe" => { 4 => Server.find(383), 3 => Server.find(384) }, "10gbe" => { 4 => Server.find(1043), 3 => Server.find(1044) } } # Concentrateurs per room
end

@connections = {}
@stacks = @servers.map(&:stack).uniq.compact
@servers.each do |server|
@connections[server.id] = server.directly_connected_servers_ids_with_color.reject { |conn| @switchs_lan_ids.exclude?(conn[:server_id]) }
end
@concentrateurs.each do |hub|
@connections[hub.id] = hub.connected_servers_ids_through_twin_cards_with_color.reject { |conn| @switchs_lan_ids.exclude?(conn[:server_id]) }
end

# TODO: remove when hard-coded system will be removed
@network_types = Modele::Network::TYPES.excluding("fiber")
@network = @filter.network_type # TODO: take from params and raise error if not good

return unless @room.id == 4 || @room.id == 3

@hub = @hubs[@network][@room.id]
@second_room = Room.find(@room.id == 4 ? 3 : 4)
@second_hub = @hubs[@network][@second_room.id]
end
end
end
17 changes: 14 additions & 3 deletions app/controllers/visualization/network_capacities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@ module Visualization
class NetworkCapacitiesController < ApplicationController
def show
@filter = Filter.new(params, %i[network_type islet_id])
@filter_filled = @filter.filled?

unless @filter.filled?
@filter.islet_id = Islet.sorted.not_empty.has_name.distinct.first.id
@filter.network_type = :gbe
islet_id = Islet.sorted.not_empty.has_name.distinct.first.id

redirect_to islet_id:, network_type: :gbe
end

@islet = Islet.find(@filter.islet_id) if @filter.filled?
load_data! if turbo_frame_request?
end

private

def load_data!
@islet = Islet.find(@filter.islet_id)
@room = @islet.room
@network = @filter.network_type # TODO: take from params and raise error if not good
@bays = @islet.bays.sorted
end
end
end
2 changes: 1 addition & 1 deletion app/models/bay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Bay < ApplicationRecord
scope :sorted_by_room, -> { joins(:room, :islet).order(:site_id, 'rooms.position', 'rooms.name', 'islets.name', :lane, 'bays.position') }

def to_s
frames.map { _1.name }.sort.join('/')
frames.map(&:name).sort.join('/')
end

def detailed_name
Expand Down
8 changes: 4 additions & 4 deletions app/models/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def filled_attributes

def attributes
@attributes ||= if @params.respond_to?(:permit)
@params.permit(*attribute_names).to_h
else
@params.with_indifferent_access
end
@params.permit(*attribute_names).to_h
else
@params.with_indifferent_access
end
end
alias to_h attributes

Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
<% hide_inventories_sidebar! %>
<%= turbo_frame_tag "infrastructure_room_islet" do %>
<div class="container-fluid room_overview show_room rooms-network-capacity" id="network-capacity">
<div class="card mb-3">
<div class="card-body d-flex">
<div class="tab-content infrastructure bg-body-tertiary overflow-x-scroll">
<% # TODO: move html here? %>
<div class="islet">
<% if @room.id == 4 || @room.id == 3 %>
<% if room.id == 4 || room.id == 3 %>
<div class="hubs">
<% bgColorHub1 = define_background_color(server: @hub, mode: params["bg"]) %>
<div class="hub_material hub-top server_<%= @hub.id %>"
id="hub1-<%= @room.id %>-<%= @islet %>"
<% bgColorHub1 = define_background_color(server: hub, mode: params["bg"]) %>
<div class="hub_material hub-top server_<%= hub.id %>"
id="hub1-<%= room.id %>-<%= islet %>"
style="background-color: <%= bgColorHub1 %>"
data-url="<%= server_path(@hub) %>">
<%= link_to server_path(@hub), class: "link-dark", target: :_blank, rel: :noopener do %>
data-url="<%= server_path(hub) %>">
<%= link_to server_path(hub), class: "link-dark", target: :_blank, rel: :noopener do %>
Concentrateur
<br>
<%= @hub %>
<%= hub %>
<% end %>
</div>
<div class="other_room_hub">
<% bgColorHub2 = define_background_color(server: @second_hub, mode: params["bg"]) %>
<span style="color: grey;"><%= @second_room %></span>
<div class="hub_material hub-bottom ms-1 server_<%= @second_hub.id %>"
data-url="<%= server_path(@second_hub) %>"
<% bgColorHub2 = define_background_color(server: second_hub, mode: params["bg"]) %>
<span style="color: grey;"><%= second_room %></span>
<div class="hub_material hub-bottom ms-1 server_<%= second_hub.id %>"
data-url="<%= server_path(second_hub) %>"
style="background-color: <%= bgColorHub2 %>"
id="hub2-<%= @room.id %>-<%= @islet %>">
<%= link_to server_path(@second_hub), class: "link-dark",
id="hub2-<%= room.id %>-<%= islet %>">
<%= link_to server_path(second_hub), class: "link-dark",
target: :_blank, rel: :noopener do %>
Concentrateur
<br>
<%= @second_hub %>
<%= second_hub %>
<% end %>
</div>
</div>
</div>
<% end %>
<div>
<div class="rooms-overview">
<% @islet.bays.sorted.each do |bay| %>
<% islet.bays.sorted.each do |bay| %>
<div class="couple" style="grid-column: <%= "#{bay.position}/#{bay.position+1}" %>;
grid-row: <%= "#{bay.lane.to_i}/#{bay.lane.to_i+1}" %>;">
<% bay.frames.sorted.each_with_index do |frame, index| %>
<% servers = frame.servers.includes(:bay, :modele, :stack)
.where("servers.network_types @> ?", "{#{@network}}") # Switch LAN %>
.where("servers.network_types @> ?", "{#{network}}") # Switch LAN %>
<div class="<%= class_names("overviewed_frame bg-secondary-subtle border-secondary-subtle border",
"no-margin": index > 0) %>"
data-bay-id="<%= bay.id %>" data-frame-id="<%= frame.id %>">
Expand All @@ -53,9 +50,9 @@
odd: bay.lane.to_i.odd?) %>"
style="z-index: -3000;">.</div>
<div class="title">
<%= link_to frame.name, room_path(@room,
<%= link_to frame.name, room_path(room,
view: params[:view],
islet: @islet.name,
islet: islet.name,
"bay-id": bay.id,
"frame-id": frame,
bg: params[:bg]),
Expand Down Expand Up @@ -108,6 +105,10 @@ var lines = []
var current_connections = []

$(document).ready(function () {
$("svg.leader-line").each(function () {
$(this).remove()
})

drawCurrentLines()
resetLinesPositionOnScroll()
})
Expand Down Expand Up @@ -152,9 +153,9 @@ function deleteOldLines() {
function drawCurrentLines() {
var disabled_stacks = disabled_colors()

<% @connections.each do |server_id, connections| %>
<% connections.each do |server_id, connections| %>
<% connections.each do |connection| %>
<% unless @concentrateurs_ids.include?(connection[:server_id]) && @concentrateurs_ids.exclude?(server_id) %>
<% unless concentrateurs_ids.include?(connection[:server_id]) && concentrateurs_ids.exclude?(server_id) %>
if(disabled_stacks.indexOf(colors_hash['<%= connection[:cable_color] %>']) < 0) {
drawInterSwitchsConnections('<%= server_id %>', '<%= connection[:server_id] %>', '<%= connection[:cable_color] %>')
}
Expand Down Expand Up @@ -262,5 +263,3 @@ function setParamsAndDraw(start_element, end_element, color) {
drawLine(start_element, end_element, params)
}
</script>

<% end %>
Loading

0 comments on commit c9520c5

Please sign in to comment.