Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/models/power_distribution_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class PowerDistributionUnit < ApplicationRecord
validates :serial_number, presence: true, uniqueness: true, format: { without: /\s/ }
validates :ipmi_url, format: URI::DEFAULT_PARSER.make_regexp(%w[http https]), allow_blank: true

validate :type_cannot_change_if_connections_present

accepts_nested_attributes_for :circuits, allow_destroy: true

delegate :to_s, to: :name
Expand All @@ -43,8 +45,19 @@ def deep_dup
end
end

# TODO: remove me when connections are implemented
def connections
[]
end

private

def type_cannot_change_if_connections_present
return unless connections.present? && will_save_change_to_type?

errors.add(:type, :cannot_change_if_connections_present)
end

def slug_candidates
[
:name,
Expand Down
3 changes: 2 additions & 1 deletion app/views/power_distribution_units/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
PowerDistributionUnitDecorator.power_distribution_unit_types_options_for_select,
{ prompt: true },
class: "form-select",
data: { controller: "select" } %>
data: { controller: "select" },
disabled: f.object.connections.present? %>
</fieldset>
<% end %>

Expand Down
5 changes: 5 additions & 0 deletions config/locales/activerecord.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ en:
domain_ids:
blank: can't be blank, or "All domains" must be checked

power_distribution_unit:
attributes:
type:
cannot_change_if_connections_present: cannot bed changed if there is connections

# Common attributes
attributes:
bay_id: Bay
Expand Down
5 changes: 5 additions & 0 deletions config/locales/activerecord.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ fr:
domain_ids:
blank: doit être rempli, ou "Tous les domaines" doit être coché

power_distribution_unit:
attributes:
type:
cannot_change_if_connections_present: ne peut pas être changé s'il y a des connections

# Common attributes
attributes:
bay_id: Baie
Expand Down
Loading