Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

remove default column and form field for enumerations of certain type

Klaus Zandersb91e2ebed556
diff --git a/app/components/enumerations/table_component.rb b/app/components/enumerations/table_component.rb
index 177f8510186..ffde9e733b7 100644
--- a/app/components/enumerations/table_component.rb
+++ b/app/components/enumerations/table_component.rb
@@ -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
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index da80df87146..c12c715822a 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -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
diff --git a/app/views/enumerations/_form.html.erb b/app/views/enumerations/_form.html.erb
index db1be44dbc1..8e0fe7566e9 100644
--- a/app/views/enumerations/_form.html.erb
+++ b/app/views/enumerations/_form.html.erb
@@ -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',
diff --git a/app/views/enumerations/index.html.erb b/app/views/enumerations/index.html.erb
index bc61f86715e..d9e9e910333 100644
--- a/app/views/enumerations/index.html.erb
+++ b/app/views/enumerations/index.html.erb
@@ -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 %>
diff --git a/modules/costs/app/models/time_entry_activity.rb b/modules/costs/app/models/time_entry_activity.rb
index 8f977362dcc..60ee893efb6 100644
--- a/modules/costs/app/models/time_entry_activity.rb
+++ b/modules/costs/app/models/time_entry_activity.rb
@@ -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)