-
Notifications
You must be signed in to change notification settings - Fork 3
Extract PDUs from Servers views #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nicolas-brousse
merged 13 commits into
nanego:master
from
pantographe:330721-extract-pdu-from-server-and-add-them-attributes
Feb 5, 2025
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5d984b7
Create PowerDistributionUnitsController and its views
B-Rass 804ecef
Fixing tests
B-Rass 995f06a
Fix after rebase
B-Rass bb34245
Remove field stack on form
B-Rass 8b26528
Remove Critique & Domaine from PDUs
B-Rass 8104713
Rebase rework
B-Rass a1df0c3
Fix regression: cable color css class on Cables#index
B-Rass 34c9ca6
Update PDU views with last blocks added
B-Rass c5076ef
Review rework
B-Rass 5a6000f
Fixing tests
B-Rass 6277b1f
Rebase changes
B-Rass fd07ad1
Review rework
B-Rass 572c796
Update app/controllers/power_distribution_units_controller.rb
B-Rass File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,106 @@ | ||
# frozen_string_literal: true | ||
|
||
class PowerDistributionUnitsController < ApplicationController | ||
before_action :set_pdu, only: %i[show edit update destroy destroy_connections] | ||
|
||
def index | ||
@pdus = Server.only_pdus.includes(:frame, :room, :islet, bay: :frames, modele: :category) | ||
.references(:room, :islet, :bay, modele: :category) | ||
.order(:name) | ||
@filter = ProcessorFilter.new(@pdus, params) | ||
|
||
@pdus = @filter.results | ||
@search_params = search_params | ||
|
||
respond_to do |format| | ||
format.json | ||
format.html { @pagy, @pdus = pagy(@pdus) } | ||
end | ||
end | ||
|
||
def show; end | ||
|
||
def new | ||
@pdu = Server.new | ||
end | ||
|
||
def edit; end | ||
|
||
def create | ||
@pdu = Server.new(pdu_params) | ||
|
||
respond_to do |format| | ||
if @pdu.save | ||
format.html { redirect_to power_distribution_unit_path(@pdu), notice: t(".flashes.created") } | ||
format.json { render :show, status: :created, location: @pdu } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @pdu.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @pdu.update(pdu_params) | ||
format.html { redirect_to power_distribution_unit_path(@pdu), notice: t(".flashes.updated") } | ||
format.json { render :show, status: :ok, location: @pdu } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @pdu.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
respond_to do |format| | ||
if @pdu.destroy | ||
format.html { redirect_to power_distribution_units_path(search_params), notice: t(".flashes.destroyed") } | ||
format.json { head :no_content } | ||
else | ||
format.html { redirect_to power_distribution_units_path(search_params), alert: t(".flashes.not_destroyed") } | ||
format.json { head :bad_request } | ||
end | ||
end | ||
end | ||
|
||
def duplicate | ||
@original_pdu = Server.friendly.find(params[:id].to_s.downcase) | ||
@pdu = @original_pdu.deep_dup | ||
end | ||
|
||
def destroy_connections | ||
if @pdu.destroy_connections! | ||
flash[:notice] = t(".flashes.connections_destroyed") | ||
else | ||
flash[:alert] = t(".flashes.connections_not_destroyed") | ||
end | ||
|
||
redirect_to power_distribution_unit_path(@pdu) | ||
end | ||
|
||
private | ||
|
||
def set_pdu | ||
@pdu = Server.friendly_find_by_numero_or_name(params[:id].to_s.downcase) | ||
end | ||
|
||
def pdu_params | ||
params.expect( | ||
power_distribution_unit: [ | ||
:photo, :comment, :position, :frame_id, :gestion_id, :fc_futur, :rj45_cm, :name, :modele_id, :numero, :critique, | ||
:domaine_id, :fc_total, :fc_utilise, :rj45_total, :rj45_utilise, :rj45_futur, :ipmi_utilise, :ipmi_futur, | ||
:ipmi_dedie, | ||
:frame, # TODO: Check if it should be removed or if it's used somewhere | ||
{ cards_attributes: [%i[composant_id card_type_id twin_card_id orientation name first_position _destroy id]] }, | ||
{ documents_attributes: [%i[document id _destroy]] }, | ||
] | ||
) | ||
end | ||
|
||
def search_params | ||
params.permit(:sort, :sort_by, :page, :per_page, :q, | ||
network_types: [], bay_ids: [], islet_ids: [], room_ids: [], frame_ids: [], cluster_ids: [], | ||
gestion_ids: [], domaine_ids: [], modele_ids: [], server_state_ids: [], stack_ids: []) | ||
end | ||
end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.