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
add bulk actions to project custom field mapping UI
Jonas Jabari9e859cb540a6
diff --git a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erb b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erbindex 0afde3639e8..aae232542a0 100644--- a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erb+++ b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erb@@ -5,19 +5,19 @@if active_in_project?render(Primer::Beta::IconButton.new(tag: :a,- href: project_settings_project_custom_fields_path(project_id: @project.id, project_custom_field_id: @project_custom_field.id),+ href: toggle_project_settings_project_custom_fields_path(project_id: @project.id, project_custom_field_id: @project_custom_field.id),scheme: :invisible,icon: 'check-circle',- 'aria-label': 'Active in this project, click to disable',+ 'aria-label': t('projects.settings.project_custom_fields.actions.label_disable_single'),data: { 'turbo-method': :put, 'turbo-stream': true }))elserender(Primer::Beta::IconButton.new(tag: :a,- href: project_settings_project_custom_fields_path(project_id: @project.id, project_custom_field_id: @project_custom_field.id),+ href: toggle_project_settings_project_custom_fields_path(project_id: @project.id, project_custom_field_id: @project_custom_field.id),scheme: :invisible,icon: 'circle',- 'aria-label': 'Inactive in this project, click to enable',+ 'aria-label': t('projects.settings.project_custom_fields.actions.label_enable_single'),data: { 'turbo-method': :put, 'turbo-stream': true }))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 36bfcb3e4fd..8fc6db3e704 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@@ -1,27 +1,49 @@<%=component_wrapper dorender(Primer::Beta::BorderBox.new(mt: 3)) do |component|- component.with_header(font_weight: :bold) do+ component.with_header(font_weight: :bold, py: 2) doflex_layout(justify_content: :space_between, align_items: :center) do |section_header_container|- section_header_container.with_column(flex_layout: true, align_items: :center) do |content_container|- content_container.with_column do- render(Primer::Beta::Text.new(font_weight: :bold)) do- @project_custom_field_section.name- end+ section_header_container.with_column(py: 2) do |content_container|+ # adding py: 2 here to match the padding of the actions_container+ # otherwise the header height changes when the actions gets hidden when filtering+ render(Primer::Beta::Text.new(font_weight: :bold)) do+ @project_custom_field_section.nameendendsection_header_container.with_column(flex_layout: true, justify_content: :flex_end) do |actions_container|- actions_container.with_column do- # render(Primer::Alpha::ActionMenu.new) do |menu|- # menu.with_show_button(icon: "kebab-horizontal", 'aria-label': t("settings.project_attributes.label_section_actions"), scheme: :invisible)- # edit_action_item(menu)- # move_actions(menu)- # if @project_custom_fields.empty?- # delete_action_item(menu)- # else- # disabled_delete_action_item(menu)- # end- # end+ actions_container.with_column(data: { 'projects--settings--project-custom-fields-mapping-filter-target': 'bulkActionContainer' }) do+ render(Primer::Beta::Button.new(+ tag: :a,+ href: enable_all_of_section_project_settings_project_custom_fields_path(+ project_id: @project.id,+ project_custom_field_section_id: @project_custom_field_section.id+ ),+ scheme: :invisible,+ font_weight: :bold,+ color: :subtle,+ 'aria-label': t('projects.settings.project_custom_fields.actions.label_enable_all'),+ data: { 'turbo-method': :put, 'turbo-stream': true }+ )) do |button|+ button.with_leading_visual_icon(icon: 'check-circle', color: :subtle)+ t('projects.settings.project_custom_fields.actions.label_enable_all')+ end+ end+ actions_container.with_column(data: { 'projects--settings--project-custom-fields-mapping-filter-target': 'bulkActionContainer' }) do+ render(Primer::Beta::Button.new(+ tag: :a,+ href: disable_all_of_section_project_settings_project_custom_fields_path(+ project_id: @project.id,+ project_custom_field_section_id: @project_custom_field_section.id+ ),+ scheme: :invisible,+ font_weight: :bold,+ color: :subtle,+ 'aria-label': t('projects.settings.project_custom_fields.actions.label_disable_all'),+ data: { 'turbo-method': :put, 'turbo-stream': true }+ )) do |button|+ button.with_leading_visual_icon(icon: 'x-circle', color: :subtle)+ t('projects.settings.project_custom_fields.actions.label_disable_all')+ endendendenddiff --git a/app/controllers/projects/settings/project_custom_fields_controller.rb b/app/controllers/projects/settings/project_custom_fields_controller.rbindex bff13cc704e..cd71cfc6f45 100644--- a/app/controllers/projects/settings/project_custom_fields_controller.rb+++ b/app/controllers/projects/settings/project_custom_fields_controller.rb@@ -32,13 +32,15 @@ class Projects::Settings::ProjectCustomFieldsController < Projects::SettingsContmenu_item :settings_project_custom_fields- before_action :eager_load_project_custom_field_sections, only: %i[show update]- before_action :eager_load_project_custom_fields, only: %i[show update]- before_action :eager_load_project_custom_field_project_mappings, only: %i[show update]+ before_action :eager_load_project_custom_field_sections, only: %i[show toggle enable_all_of_section disable_all_of_section]+ before_action :eager_load_project_custom_fields, only: %i[show toggle enable_all_of_section disable_all_of_section]+ before_action :eager_load_project_custom_field_project_mappings,+ only: %i[show toggle enable_all_of_section disable_all_of_section]def show; end- def update+ def toggle+ # TODO: use service instead@project_custom_field = ProjectCustomField.find(params[:project_custom_field_id])mapping = ProjectCustomFieldProjectMapping.find_or_initialize_by(@@ -60,6 +62,26 @@ class Projects::Settings::ProjectCustomFieldsController < Projects::SettingsContrespond_with_turbo_streamsend+ def enable_all_of_section+ bulk_edit_mappings_per_section(params[:project_custom_field_section_id], :enable)++ eager_load_project_custom_field_project_mappings # reload mappings++ update_sections_via_turbo_stream # update all sections in order not to mess with stimulus target references++ respond_with_turbo_streams+ end++ def disable_all_of_section+ bulk_edit_mappings_per_section(params[:project_custom_field_section_id], :disable)++ eager_load_project_custom_field_project_mappings # reload mappings++ update_sections_via_turbo_stream # update all sections in order not to mess with stimulus target references++ respond_with_turbo_streams+ end+privatedef eager_load_project_custom_field_sections@@ -78,4 +100,27 @@ class Projects::Settings::ProjectCustomFieldsController < Projects::SettingsCont.where(project_id: @project.id).to_aend++ def bulk_edit_mappings_per_section(section_id, action = :enable)+ # TODO: use service instead+ section = ProjectCustomFieldSection.find(section_id)++ # TODO: refactor this to use a single database query+ section.custom_fields.each do |pcf|+ mapping = ProjectCustomFieldProjectMapping.find_or_initialize_by(+ project_id: @project.id,+ custom_field_id: pcf.id+ )++ if action == :enable+ unless mapping.persisted?+ mapping.save!+ end+ elsif action == :disable+ if mapping.persisted?+ mapping.destroy!+ end+ end+ end+ endenddiff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex 374ad7c98ee..c7ede71e125 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -111,7 +111,7 @@ Rails.application.reloader.to_prepare domap.permission :select_project_custom_fields,{- 'projects/settings/project_custom_fields': %i[show update]+ 'projects/settings/project_custom_fields': %i[show toggle enable_all_of_section disable_all_of_section]},permissible_on: :project,require: :memberdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 7c5582fbdb6..78f88aaa518 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -293,6 +293,11 @@ en: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"+ actions:+ label_enable_single: "Active in this project, click to disable"+ label_disable_single: "Inactive in this project, click to enable"+ label_enable_all: "Enable all"+ label_disable_all: "Disable all"types:no_results_title_text: There are currently no types available.form:diff --git a/config/routes.rb b/config/routes.rbindex 46d161f1fa4..772a2f7f7df 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -185,7 +185,15 @@ OpenProject::Application.routes.draw doresource :general, only: %i[show], controller: 'general'resource :modules, only: %i[show update]resource :types, only: %i[show update]- resource :project_custom_fields, only: %i[show update]+ resource :project_custom_fields, only: %i[show] do+ member do+ put :toggle+ end+ collection do+ put :enable_all_of_section+ put :disable_all_of_section+ end+ endresource :custom_fields, only: %i[show update]resource :repository, only: %i[show], controller: 'repository'resource :versions, only: %i[show]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.tsindex 43a7b97aa39..5f041521030 100644--- 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.ts@@ -34,26 +34,34 @@ export default class ProjectCustomFieldsMappingFilterController extends Controllstatic targets = ['filter','searchItem',+ 'bulkActionContainer'];declare readonly filterTarget:HTMLInputElement;declare readonly searchItemTargets:HTMLInputElement[];+ declare readonly bulkActionContainerTargets:HTMLInputElement[];connect(): void {this.element.querySelector('#project-custom-fields-mapping-filter-clear-button')?.addEventListener('click', () => {- this.resetFilter();+ this.resetFilterViaClearButton();});}disconnect(): void {this.element.querySelector('#project-custom-fields-mapping-filter-clear-button')?.removeEventListener('click', () => {- this.resetFilter();+ this.resetFilterViaClearButton();});}filterLists(event: Event) {const query = this.filterTarget.value.toLowerCase();+ if (query.length > 0) {+ this.hideBulkActionContainers();+ } else {+ this.showBulkActionContainers();+ }+this.searchItemTargets.forEach((item) => {const text = item.textContent!.toLowerCase();@@ -65,9 +73,23 @@ export default class ProjectCustomFieldsMappingFilterController extends Controll});}- resetFilter() {+ resetFilterViaClearButton() {+ this.showBulkActionContainers();+this.searchItemTargets.forEach((item) => {(item as HTMLElement).style.display = "block";});}++ hideBulkActionContainers() {+ this.bulkActionContainerTargets.forEach((item) => {+ (item as HTMLElement).style.display = "none";+ });+ }++ showBulkActionContainers() {+ this.bulkActionContainerTargets.forEach((item) => {+ (item as HTMLElement).style.display = "block";+ });+ }}