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
added client side project custom field mapping filter via stimulus
Jonas Jabari458cffa7167d
diff --git a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rbindex e2ac8ff65d4..4186ad637aa 100644--- a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb+++ b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb@@ -44,6 +44,10 @@ module Projectsprivate+ def wrapper_uniq_by+ @project_custom_field.id+ end+def active_in_project?@project_custom_field_project_mappings.any? do |mapping|mapping.custom_field_id == @project_custom_field.iddiff --git a/app/components/projects/settings/project_custom_field_sections/index_component.html.erb b/app/components/projects/settings/project_custom_field_sections/index_component.html.erbindex 0cf52308aad..9e23142ac9e 100644--- a/app/components/projects/settings/project_custom_field_sections/index_component.html.erb+++ b/app/components/projects/settings/project_custom_field_sections/index_component.html.erb@@ -1,6 +1,24 @@<%=- component_wrapper do+ component_wrapper(data: wrapper_data_attributes) doflex_layout do |flex|+ flex.with_row(mt: 3) do+ render(Primer::Alpha::TextField.new(+ name: "project-custom-fields-mapping-filter",+ label: t('projects.settings.project_custom_fields.filter.label'),+ visually_hide_label: true,+ placeholder: t('projects.settings.project_custom_fields.filter.label'),+ leading_visual: {+ icon: :search,+ size: :small+ },+ show_clear_button: true,+ clear_button_id: "project-custom-fields-mapping-filter-clear-button",+ data: {+ action: "input->projects--settings--project-custom-fields-mapping-filter#filterLists",+ "projects--settings--project-custom-fields-mapping-filter-target": "filter"+ }+ ))+ end@project_custom_fields_grouped_by_section.each do |section_id, project_custom_fields|flex.with_row dorender(Projects::Settings::ProjectCustomFieldSections::ShowComponent.new(diff --git a/app/components/projects/settings/project_custom_field_sections/index_component.rb b/app/components/projects/settings/project_custom_field_sections/index_component.rbindex bba76f062bd..d635000fc71 100644--- a/app/components/projects/settings/project_custom_field_sections/index_component.rb+++ b/app/components/projects/settings/project_custom_field_sections/index_component.rb@@ -50,6 +50,13 @@ module Projectsprivate+ def wrapper_data_attributes+ {+ controller: 'projects--settings--project-custom-fields-mapping-filter',+ 'application-target': 'dynamic'+ }+ end+def get_eager_loaded_project_custom_field_section(section_id)@project_custom_field_sections.find { |section| section.id == section_id }enddiff --git a/app/components/projects/settings/project_custom_field_sections/show_component.html.erb b/app/components/projects/settings/project_custom_field_sections/show_component.html.erbindex 75485fdaf7f..36bfcb3e4fd 100644--- a/app/components/projects/settings/project_custom_field_sections/show_component.html.erb+++ b/app/components/projects/settings/project_custom_field_sections/show_component.html.erb@@ -32,7 +32,7 @@endelsesorted_project_custom_fields.each do |project_custom_field|- component.with_row do+ component.with_row(data: { 'projects--settings--project-custom-fields-mapping-filter-target': 'searchItem' }) dorender(Projects::Settings::ProjectCustomFieldSections::CustomFieldRowComponent.new(project: @project,project_custom_field:,diff --git a/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb b/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rbindex 1e1f1cd5f2d..8bb0724cf73 100644--- a/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb+++ b/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb@@ -48,6 +48,20 @@ module Projects))end++ def update_custom_field_row_via_turbo_stream(+ project: @project,+ project_custom_field: @project_custom_field,+ project_custom_field_project_mappings: @project_custom_field_project_mappings+ )+ update_via_turbo_stream(+ component: ::Projects::Settings::ProjectCustomFieldSections::CustomFieldRowComponent.new(+ project:,+ project_custom_field:,+ project_custom_field_project_mappings:+ )+ )+ endendendenddiff --git a/app/controllers/projects/settings/project_custom_fields_controller.rb b/app/controllers/projects/settings/project_custom_fields_controller.rbindex 77fe7cdfe1a..bff13cc704e 100644--- a/app/controllers/projects/settings/project_custom_fields_controller.rb+++ b/app/controllers/projects/settings/project_custom_fields_controller.rb@@ -39,11 +39,14 @@ class Projects::Settings::ProjectCustomFieldsController < Projects::SettingsContdef show; enddef update+ @project_custom_field = ProjectCustomField.find(params[:project_custom_field_id])+mapping = ProjectCustomFieldProjectMapping.find_or_initialize_by(project_id: @project.id,- custom_field_id: params[:project_custom_field_id]+ custom_field_id: @project_custom_field.id)+ # toggle mappingif mapping.persisted?mapping.destroy!else@@ -52,7 +55,7 @@ class Projects::Settings::ProjectCustomFieldsController < Projects::SettingsConteager_load_project_custom_field_project_mappings # reload mappings- update_sections_via_turbo_stream+ update_custom_field_row_via_turbo_streamrespond_with_turbo_streamsenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 43b57a0997f..ecf07ecdd56 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -293,6 +293,8 @@ en:title: "Project attributes"description: "These project attributes will be displayed in your <a href=%{overview_url} target=\"_blank\">project overview page</a> under their respective sections. You can enable or disable individual attributes.Project attributes and sections are defined in the <a href=%{admin_settings_url} target=\"_blank\">administration settings</a> by the administrator of the instance. "+ filter:+ label: "Search project attribute"types:no_results_title_text: There are currently no types available.form:@@ -3136,7 +3138,7 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}help_texts:views:project: >- %{plural} are always attached to a project.+ %{plural} are always attached to a project.You can only select projects here where the %{plural} module is active.After creating a %{singular} you can add work packages from other projects to it.public: "Publish this view, allowing other users to access your view. Users with the 'Manage public views' permission can modify or remove public query. This does not affect the visibility of work package results in that view and depending on their permissions, users may see different results."diff --git a/frontend/src/stimulus/controllers/dynamic/projects/settings/project-custom-fields-mapping-filter.controller.ts b/frontend/src/stimulus/controllers/dynamic/projects/settings/project-custom-fields-mapping-filter.controller.tsnew file mode 100644index 00000000000..43a7b97aa39--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/projects/settings/project-custom-fields-mapping-filter.controller.ts@@ -0,0 +1,73 @@+/*+ * -- copyright+ * OpenProject is an open source project management software.+ * Copyright (C) 2023 the OpenProject GmbH+ *+ * This program is free software; you can redistribute it and/or+ * modify it under the terms of the GNU General Public License version 3.+ *+ * OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+ * Copyright (C) 2006-2013 Jean-Philippe Lang+ * Copyright (C) 2010-2013 the ChiliProject Team+ *+ * This program is free software; you can redistribute it and/or+ * modify it under the terms of the GNU General Public License+ * as published by the Free Software Foundation; either version 2+ * of the License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with this program; if not, write to the Free Software+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+ *+ * See COPYRIGHT and LICENSE files for more details.+ * +++ */++import { Controller } from '@hotwired/stimulus';++export default class ProjectCustomFieldsMappingFilterController extends Controller {+ static targets = [+ 'filter',+ 'searchItem',+ ];++ declare readonly filterTarget:HTMLInputElement;+ declare readonly searchItemTargets:HTMLInputElement[];++ connect(): void {+ this.element.querySelector('#project-custom-fields-mapping-filter-clear-button')?.addEventListener('click', () => {+ this.resetFilter();+ });+ }++ disconnect(): void {+ this.element.querySelector('#project-custom-fields-mapping-filter-clear-button')?.removeEventListener('click', () => {+ this.resetFilter();+ });+ }++ filterLists(event: Event) {+ const query = this.filterTarget.value.toLowerCase();++ this.searchItemTargets.forEach((item) => {+ const text = item.textContent!.toLowerCase();++ if (text.includes(query)) {+ (item as HTMLElement).style.display = "block";+ } else {+ (item as HTMLElement).style.display = "none";+ }+ });+ }++ resetFilter() {+ this.searchItemTargets.forEach((item) => {+ (item as HTMLElement).style.display = "block";+ });+ }+}