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

[#58865] add enterprise banner to new custom field form

Eric Schubertd27a077d4b7c
diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb
index 229e80f835a..2f2e907304e 100644
--- a/app/helpers/custom_fields_helper.rb
+++ b/app/helpers/custom_fields_helper.rb
@@ -68,7 +68,7 @@ module CustomFieldsHelper
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
field_id = "#{name}_custom_field_values_#{custom_field.id}"
- field_format = OpenProject::CustomFieldFormat.find_by_name(custom_field.field_format)
+ field_format = OpenProject::CustomFieldFormat.find_by(name: custom_field.field_format)
tag = case field_format.try(:edit_as)
when "date"
@@ -146,7 +146,7 @@ module CustomFieldsHelper
def custom_field_tag_for_bulk_edit(name, custom_field, project = nil) # rubocop:disable Metrics/AbcSize
field_name = "#{name}[custom_field_values][#{custom_field.id}]"
field_id = "#{name}_custom_field_values_#{custom_field.id}"
- field_format = OpenProject::CustomFieldFormat.find_by_name(custom_field.field_format)
+ field_format = OpenProject::CustomFieldFormat.find_by(name: custom_field.field_format)
case field_format.try(:edit_as)
when "date"
@@ -198,21 +198,25 @@ module CustomFieldsHelper
format.name == "hierarchy" && !OpenProject::FeatureDecisions.custom_field_of_type_hierarchy_active?
end
- OpenProject::CustomFieldFormat
- .all_for_field(custom_field)
- .sort_by(&:order)
- .reject { |format| format.label.nil? }
- .reject(&hierarchy_if_deactivated)
- .map do |custom_field_format|
- [label_for_custom_field_format(custom_field_format.name), custom_field_format.name]
- end
+ OpenProject::CustomFieldFormat.all_for_field(custom_field)
+ .sort_by(&:order)
+ .reject { |format| format.label.nil? }
+ .reject(&hierarchy_if_deactivated)
+ .map do |custom_field_format|
+ [label_for_custom_field_format(custom_field_format.name), custom_field_format.name]
+ end
end
def label_for_custom_field_format(format_string)
- format = OpenProject::CustomFieldFormat.find_by_name(format_string)
+ show_enterprise_text = format_string == "hierarchy" && !EnterpriseToken.allows_to?(:custom_field_hierarchies)
- if format
- format.label.is_a?(Proc) ? format.label.call : I18n.t(format.label)
- end
+ format = OpenProject::CustomFieldFormat.find_by(name: format_string)
+ label = if format
+ format.label.is_a?(Proc) ? format.label.call : I18n.t(format.label)
+ end
+
+ label += " (#{I18n.t(:label_enterprise_addon)})" if show_enterprise_text
+
+ label
end
end
diff --git a/app/models/custom_value.rb b/app/models/custom_value.rb
index 5208e36cc60..8a2da3ce928 100644
--- a/app/models/custom_value.rb
+++ b/app/models/custom_value.rb
@@ -59,7 +59,7 @@ class CustomValue < ApplicationRecord
def strategy
@strategy ||= begin
format = custom_field&.field_format || "empty"
- OpenProject::CustomFieldFormat.find_by_name(format).formatter.new(self) # rubocop:disable Rails/DynamicFindBy
+ OpenProject::CustomFieldFormat.find_by(name: format).formatter.new(self) # rubocop:disable Rails/DynamicFindBy
end
end
diff --git a/app/services/authorization/enterprise_service.rb b/app/services/authorization/enterprise_service.rb
index 7ddd9730e29..4e419b03d20 100644
--- a/app/services/authorization/enterprise_service.rb
+++ b/app/services/authorization/enterprise_service.rb
@@ -34,6 +34,7 @@ class Authorization::EnterpriseService
board_view
conditional_highlighting
custom_actions
+ custom_field_hierarchies
date_alerts
define_custom_style
edit_attribute_groups
diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erb
index b85a490efcd..4aded3ec875 100644
--- a/app/views/custom_fields/_form.html.erb
+++ b/app/views/custom_fields/_form.html.erb
@@ -32,9 +32,6 @@ See COPYRIGHT and LICENSE files for more details.
<section
class="form--section"
id="custom_field_form"
- data-controller="admin--custom-fields"
- data-application-target="dynamic"
- data-admin--custom-fields-format-config-value="<%= OpenProject::CustomFieldFormatDependent.stimulus_config %>"
>
<div class="form--field -required" id="custom_field_name_attributes">
<%= f.text_field :name,
@@ -62,6 +59,17 @@ See COPYRIGHT and LICENSE files for more details.
}
%>
</div>
+ <div class="form--field-extra-actions" <%= format_dependent.attributes(:enterpriseBanner) %>>
+ <%= angular_component_tag "opce-enterprise-banner",
+ inputs: {
+ collapsible: true,
+ opReferrer: "custom-field-hierarchy",
+ textMessage: "PLACEHOLDER - upgrade to Starkiller Base",
+ moreInfoLink: OpenProject::Static::Links.links[:enterprise_docs][:boards][:href]
+ }
+ %>
+ </div>
+
<div class="form--grouping" id="custom_field_length" <%= format_dependent.attributes(:length) %>>
<div class="form--grouping-label">
<%= t(:label_min_max_length) %> <br>
diff --git a/app/views/custom_fields/edit.html.erb b/app/views/custom_fields/edit.html.erb
index b6741374f91..dba36d962c7 100644
--- a/app/views/custom_fields/edit.html.erb
+++ b/app/views/custom_fields/edit.html.erb
@@ -33,6 +33,8 @@ See COPYRIGHT and LICENSE files for more details.
<%= error_messages_for 'custom_field' %>
+<% content_controller "admin--custom-fields", dynamic: true %>
+
<% if @custom_field.field_format_hierarchy? %>
<%= render CustomFields::DetailsComponent.new(@custom_field) %>
<% else %>
diff --git a/app/views/custom_fields/new.html.erb b/app/views/custom_fields/new.html.erb
index eeae3a50da0..e5a49ea86e6 100644
--- a/app/views/custom_fields/new.html.erb
+++ b/app/views/custom_fields/new.html.erb
@@ -42,10 +42,20 @@ See COPYRIGHT and LICENSE files for more details.
<%= error_messages_for 'custom_field' %>
+<% content_controller "admin--custom-fields",
+ dynamic: true,
+ 'admin--custom-fields-format-config-value': OpenProject::CustomFieldFormatDependent.stimulus_config,
+ 'admin--custom-fields-enterprise-edition-value': EnterpriseToken.active?
+%>
+
<%= labelled_tabular_form_for @custom_field, as: :custom_field,
url: custom_fields_path,
html: {id: 'custom_field_form', class: "-wide-labels"} do |f| %>
<%= render partial: 'form', locals: { f: f } %>
<%= hidden_field_tag 'type', @custom_field.type %>
- <%= styled_button_tag t(:button_save), class: '-primary -with-icon icon-checkmark' %>
+ <%= styled_button_tag t(:button_save),
+ class: '-primary -with-icon icon-checkmark',
+ data: {
+ 'admin--custom-fields-target': 'submitButton'
+ } %>
<% end %>
diff --git a/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.ts
index 887fe5cece9..096686ba841 100644
--- a/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/admin/custom-fields.controller.ts
@@ -34,6 +34,7 @@ export default class CustomFieldsController extends Controller {
static targets = [
'format',
'dragContainer',
+ 'submitButton',
'customOptionDefaults',
'customOptionRow',
@@ -48,17 +49,22 @@ export default class CustomFieldsController extends Controller {
'regexp',
'searchable',
'textOrientation',
+
+ 'enterpriseBanner',
];
static values = {
formatConfig: Array,
+ enterpriseEdition: Boolean,
};
declare readonly formatConfigValue:[string, string, string[]][];
+ declare readonly enterpriseEditionValue:boolean;
declare readonly formatTarget:HTMLInputElement;
declare readonly dragContainerTarget:HTMLElement;
declare readonly hasDragContainerTarget:boolean;
+ declare readonly submitButtonTarget:HTMLButtonElement;
declare readonly customOptionDefaultsTargets:HTMLInputElement[];
declare readonly customOptionRowTargets:HTMLTableRowElement[];
@@ -74,6 +80,8 @@ export default class CustomFieldsController extends Controller {
declare readonly searchableTargets:HTMLInputElement[];
declare readonly textOrientationTargets:HTMLElement[];
+ declare readonly enterpriseBannerTarget:HTMLElement;
+
connect() {
if (this.hasDragContainerTarget) {
this.setupDragAndDrop();
@@ -242,8 +250,14 @@ export default class CustomFieldsController extends Controller {
}
private toggleFormat(format:string) {
+ this.submitButtonTarget.disabled = format === 'hierarchy' && !this.enterpriseEditionValue;
+
this.formatConfigValue.forEach(([targetsName, operator, formats]) => {
- const active = operator === 'only' ? formats.includes(format) : !formats.includes(format);
+ let active = operator === 'only' ? formats.includes(format) : !formats.includes(format);
+ if (targetsName === 'enterpriseBanner' && this.enterpriseEditionValue) {
+ active = false;
+ }
+
const targets = this[`${targetsName}Targets` as keyof typeof this] as HTMLElement[];
if (targets) {
this.setActive(targets, active);
diff --git a/lib/custom_field_form_builder.rb b/lib/custom_field_form_builder.rb
index ff618143401..2801f9a3043 100644
--- a/lib/custom_field_form_builder.rb
+++ b/lib/custom_field_form_builder.rb
@@ -64,7 +64,7 @@ class CustomFieldFormBuilder < TabularFormBuilder
name: custom_field_field_name,
id: custom_field_field_id)
- field_format = OpenProject::CustomFieldFormat.find_by_name(custom_field.field_format)
+ field_format = OpenProject::CustomFieldFormat.find_by(name: custom_field.field_format)
case field_format.try(:edit_as)
when "date"
diff --git a/lib/open_project/custom_field_format.rb b/lib/open_project/custom_field_format.rb
index 6fd26a94d43..eb76c049609 100644
--- a/lib/open_project/custom_field_format.rb
+++ b/lib/open_project/custom_field_format.rb
@@ -63,7 +63,7 @@ module OpenProject
@@available.keys
end
- def find_by_name(name)
+ def find_by(name:)
@@available[name.to_s]
end
diff --git a/lib/open_project/custom_field_format_dependent.rb b/lib/open_project/custom_field_format_dependent.rb
index 937920c6606..ef4c63ae94d 100644
--- a/lib/open_project/custom_field_format_dependent.rb
+++ b/lib/open_project/custom_field_format_dependent.rb
@@ -38,7 +38,8 @@ module OpenProject
possibleValues: [:only, %w[list]],
regexp: [:except, %w[list bool date user version hierarchy]],
searchable: [:except, %w[bool date float int user version]],
- textOrientation: [:only, %w[text]]
+ textOrientation: [:only, %w[text]],
+ enterpriseBanner: [:only, %w[hierarchy]]
}.freeze
def self.stimulus_config