remove default column and form field for enumerations of certain type

This commit is contained in:
Klaus Zanders
2025-01-28 17:41:27 +01:00
parent 49333b3c62
commit b91e2ebed5
5 changed files with 26 additions and 14 deletions
+12 -12
View File
@@ -30,12 +30,15 @@
module Enumerations
class TableComponent < ::TableComponent
attr_reader :enumeration
def initialize(enumeration:, rows: [], **)
super(rows: rows, **)
@enumeration = enumeration
end
def columns
%i[name is_default active sort].tap do |default|
if with_colors
default.insert 3, :color
end
end
headers.map(&:first)
end
def sortable?
@@ -43,16 +46,13 @@ module Enumerations
end
def headers
[
@headers ||= [
["name", { caption: Enumeration.human_attribute_name(:name) }],
["is_default", { caption: Enumeration.human_attribute_name(:is_default) }],
enumeration.can_have_default_value? ? ["is_default", { caption: Enumeration.human_attribute_name(:is_default) }] : nil,
["active", { caption: Enumeration.human_attribute_name(:active) }],
with_colors ? ["color", { caption: Enumeration.human_attribute_name(:color) }] : nil,
["sort", { caption: I18n.t(:label_sort) }]
].tap do |default|
if with_colors
default.insert 3, ["color", { caption: Enumeration.human_attribute_name(:color) }]
end
end
].compact
end
def with_colors
+5
View File
@@ -75,6 +75,11 @@ class Enumeration < ApplicationRecord
end
end
# boolean to define if the enumeration can set a default
def self.can_have_default_value?
true
end
# Destroys enumerations in a single transaction
# It ensures, that the transactions can be safely transferred to each
# entry's parent
+4 -1
View File
@@ -37,7 +37,10 @@ See COPYRIGHT and LICENSE files for more details.
<%= f.hidden_field 'type' %>
<div class="form--field -required"><%= f.text_field 'name', required: true, container_class: '-middle' %></div>
<div class="form--field"><%= f.check_box 'active' %></div>
<div class="form--field"><%= f.check_box 'is_default' %></div>
<% if @enumeration.class.can_have_default_value? %>
<div class="form--field"><%= f.check_box 'is_default' %></div>
<% end %>
<% if @enumeration.class.colored? %>
<%= render partial: '/colors/color_autocomplete_field',
+1 -1
View File
@@ -38,5 +38,5 @@ See COPYRIGHT and LICENSE files for more details.
<% Enumeration.subclasses.each do |klass| %>
<h3 class="-no-border"><%= t(klass::OptionName) %></h3>
<%= render(::Enumerations::TableComponent.new(rows: klass.shared)) %>
<%= render(::Enumerations::TableComponent.new(rows: klass.shared, enumeration: klass)) %>
<% end %>
@@ -64,6 +64,10 @@ class TimeEntryActivity < Enumeration
Project.activated_time_activity(self)
end
def self.can_have_default_value?
false
end
private
def detect_project_time_entry_activity_active_state(project)