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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
User autocompleter for custom actions
Oliver Günther11ca912542e3
diff --git a/app/models/custom_actions/actions/assigned_to.rb b/app/models/custom_actions/actions/assigned_to.rbindex 1aee8d1f99d..f0791bd6693 100644--- a/app/models/custom_actions/actions/assigned_to.rb+++ b/app/models/custom_actions/actions/assigned_to.rb@@ -33,6 +33,10 @@ class CustomActions::Actions::AssignedTo < CustomActions::Actions::Base:assigned_toend+ def type+ :user+ end+def available_principlesprincipal_class.not_lockeddiff --git a/app/models/custom_actions/actions/custom_field.rb b/app/models/custom_actions/actions/custom_field.rbindex 374b3406218..91c381f3054 100644--- a/app/models/custom_actions/actions/custom_field.rb+++ b/app/models/custom_actions/actions/custom_field.rb@@ -35,6 +35,14 @@ class CustomActions::Actions::CustomField < CustomActions::Actions::Baseraise NotImplementedErrorend+ def type+ if custom_field.field_format == "user"+ :user+ else+ super+ end+ end+def custom_fieldself.class.custom_fieldenddiff --git a/app/models/custom_actions/actions/project.rb b/app/models/custom_actions/actions/project.rbindex d4d42bf6f02..1db070454ce 100644--- a/app/models/custom_actions/actions/project.rb+++ b/app/models/custom_actions/actions/project.rb@@ -35,6 +35,10 @@ class CustomActions::Actions::Project < CustomActions::Actions::Base:projectend+ def type+ :project+ end+def required?trueenddiff --git a/app/models/custom_actions/actions/responsible.rb b/app/models/custom_actions/actions/responsible.rbindex 862a0e069e3..8deff3ed4e8 100644--- a/app/models/custom_actions/actions/responsible.rb+++ b/app/models/custom_actions/actions/responsible.rb@@ -29,6 +29,10 @@class CustomActions::Actions::Responsible < CustomActions::Actions::Baseinclude CustomActions::Actions::Strategies::MeAssociated+ def type+ :user+ end+def available_principlesUser.not_lockeddiff --git a/app/models/custom_actions/actions/strategies/me_associated.rb b/app/models/custom_actions/actions/strategies/me_associated.rbindex ba73d23f0f3..3e28fde7d11 100644--- a/app/models/custom_actions/actions/strategies/me_associated.rb+++ b/app/models/custom_actions/actions/strategies/me_associated.rb@@ -29,9 +29,11 @@module CustomActions::Actions::Strategies::MeAssociatedinclude ::CustomActions::Actions::Strategies::Associated- def associated- me_value = [current_user_value_key, I18n.t("custom_actions.actions.assigned_to.executing_user_value")]+ def me_value+ [current_user_value_key, current_user_name]+ end+ def associated[me_value] + available_principlesend@@ -61,6 +63,10 @@ module CustomActions::Actions::Strategies::MeAssociated"current_user".freezeend+ def current_user_name+ I18n.t("custom_actions.actions.assigned_to.executing_user_value")+ end+def has_me_value?values.first == current_user_value_keyenddiff --git a/app/views/custom_actions/_form.html.erb b/app/views/custom_actions/_form.html.erbindex fb2e176277e..8dc2f99e13a 100644--- a/app/views/custom_actions/_form.html.erb+++ b/app/views/custom_actions/_form.html.erb@@ -66,10 +66,11 @@<%= styled_label_tag("custom_action_actions_#{action.key}", action.human_name, class: "-top") %><% input_name = "custom_action[actions][#{action.key}]" %>- <% if %i(associated_property boolean).include?(action.type) %>+ <% if %i(associated_property boolean user project).include?(action.type) %><div class="form--field-container"><div class="form--select-container -middle">- <% if action.key == :project %>+ <% case action.type %>+ <% when :project %><%= angular_component_tag "opce-project-autocompleter",inputs: {multiple: false,@@ -80,6 +81,29 @@labelForId: "custom_action_actions_#{action.key}",inputValue: action.values.first} %>+ <% when :user %>+ <% selected = action.value_objects.map { |v| { id: v[:value], name: v[:label] } } %>+ <%= angular_component_tag "opce-user-autocompleter",+ inputs: {+ hideSelected: true,+ defaultData: false,+ placeholder: I18n.t(:label_user_search),+ resource: "principals",+ url: ::API::V3::Utilities::PathHelper::ApiV3Path.principals,+ model: action.multi_value? ? selected : selected.first,+ inputName: input_name,+ filters: [+ { name: "status", operator: "!", values: [Principal.statuses["locked"].to_s] },+ ],+ appendTo: "body",+ additionalOptions: [+ { id: nil, name: I18n.t("placeholders.default") },+ { id: action.current_user_value_key, name: action.current_user_name }+ ],+ searchKey: "any_name_attribute",+ labelForId: "custom_action_actions_#{action.key}",+ focusDirectly: false+ } %><% else %><% selected = action.value_objects.map { |v| { id: v[:value], name: v[:label] } } %><%= angular_component_tag "opce-autocompleter",@@ -149,7 +173,7 @@<div class="form--space"></div><div class="form--field">- <label class="form--label" for="custom-actions-form--add-action">+ <label class="form--label" for="add-custom-action-select"><%= op_icon("icon-add icon4") %><%= I18n.t(:"custom_actions.actions.add") %></label>@@ -157,9 +181,10 @@<span class="form--select-container -middle"><%= select_tag "add_action",options_for_select(- @custom_action.all_actions.map { |a| { key: a.key, label: a.human_name } },+ @custom_action.all_actions.map { |a| [a.human_name, a.key] },disabled: active_section_keys),+ id: "add-custom-action-select",prompt: t(:"custom_actions.actions.add"),data: {"hide-sections-target": "select",diff --git a/frontend/src/app/shared/components/autocompleter/user-autocompleter/user-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/user-autocompleter/user-autocompleter.component.tsindex c7188cb09cf..5c5e00d6ef8 100644--- a/frontend/src/app/shared/components/autocompleter/user-autocompleter/user-autocompleter.component.ts+++ b/frontend/src/app/shared/components/autocompleter/user-autocompleter/user-autocompleter.component.ts@@ -92,6 +92,8 @@ export class UserAutocompleterComponent extends OpAutocompleterComponent<IUserAu@Input() public url:string = this.apiV3Service.users.path;+ @Input() public additionalOptions:IUserAutocompleteItem[]|null = null;+@Output() public userInvited = new EventEmitter<HalResource>();@InjectField(OpInviteUserModalService) opInviteUserModalService:OpInviteUserModalService;@@ -131,9 +133,15 @@ export class UserAutocompleterComponent extends OpAutocompleterComponent<IUserAu.pipe(map((res) => _.uniqBy(res._embedded.elements, (el) => el._links.self?.href || el.id)),map((users) => {- return users.map((user) => {+ const mapped:IUserAutocompleteItem[] = users.map((user) => {return { id: user.id, name: user.name, href: user._links.self?.href, email: user.email };});++ if (this.additionalOptions) {+ return this.additionalOptions.concat(mapped);+ }++ return mapped;}),);}diff --git a/spec/models/custom_actions/actions/assigned_to_spec.rb b/spec/models/custom_actions/actions/assigned_to_spec.rbindex 0c4f01fdf4b..8c062f184de 100644--- a/spec/models/custom_actions/actions/assigned_to_spec.rb+++ b/spec/models/custom_actions/actions/assigned_to_spec.rb@@ -30,7 +30,7 @@ require_relative "../shared_expectations"RSpec.describe CustomActions::Actions::AssignedTo dolet(:key) { :assigned_to }- let(:type) { :associated_property }+ let(:type) { :user }let(:allowed_values) dousers = [build_stubbed(:user),build_stubbed(:group)]diff --git a/spec/models/custom_actions/actions/project_spec.rb b/spec/models/custom_actions/actions/project_spec.rbindex e4864673f87..6fbb30b23ec 100644--- a/spec/models/custom_actions/actions/project_spec.rb+++ b/spec/models/custom_actions/actions/project_spec.rb@@ -30,7 +30,7 @@ require_relative "../shared_expectations"RSpec.describe CustomActions::Actions::Project dolet(:key) { :project }- let(:type) { :associated_property }+ let(:type) { :project }let(:priority) { 10 }let(:allowed_values) dodiff --git a/spec/models/custom_actions/actions/responsible_spec.rb b/spec/models/custom_actions/actions/responsible_spec.rbindex 475c5fa2567..56be6f81f7d 100644--- a/spec/models/custom_actions/actions/responsible_spec.rb+++ b/spec/models/custom_actions/actions/responsible_spec.rb@@ -30,7 +30,7 @@ require_relative "../shared_expectations"RSpec.describe CustomActions::Actions::Responsible dolet(:key) { :responsible }- let(:type) { :associated_property }+ let(:type) { :user }let(:allowed_values) doprincipals = [build_stubbed(:user),build_stubbed(:group)]diff --git a/spec/support/pages/admin/custom_actions/form.rb b/spec/support/pages/admin/custom_actions/form.rbindex e2cf67d9b2a..b552c77dc53 100644--- a/spec/support/pages/admin/custom_actions/form.rb+++ b/spec/support/pages/admin/custom_actions/form.rb@@ -44,13 +44,14 @@ module Pagesenddef add_action(name, value)- ignore_ferrum_javascript_error do+ retry_block doselect name, from: "Add action"+ within "#custom-actions-form--active-actions" do+ expect(page).to have_css(".form--label", text: name)+ endend+set_action_value(name, value)- within "#custom-actions-form--active-actions" do- expect(page).to have_css(".form--label", text: name)- endenddef remove_action(name)@@ -118,7 +119,7 @@ module Pagesif has_selector?(".form--selected-value--container", wait: 0)find(".form--selected-value--container").clickautocomplete = true- elsif has_selector?("opce-autocompleter", wait: 0) || has_selector?("opce-project-autocompleter", wait: 0)+ elsif autocomplete?autocomplete = trueend@@ -134,6 +135,10 @@ module Pagesendendend++ def autocomplete?+ has_selector?(".ng-input")+ endendendend