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
[#52147] i18n, rubocop styling
Tobias Dillmann01485db2709d
diff --git a/app/components/projects/table_component.html.erb b/app/components/projects/table_component.html.erbindex 1b16267dd13..26fc30b15c2 100644--- a/app/components/projects/table_component.html.erb+++ b/app/components/projects/table_component.html.erb@@ -27,7 +27,7 @@ See COPYRIGHT and LICENSE files for more details.++#%><%= component_wrapper(tag: 'turbo-frame') do %>- <div class="project-list-page--table">+ <div class="project-list-page--table" data-controller="table-action-menu" data-application-target="dynamic"><div class="generic-table--flex-container"><div class="generic-table--container <%= container_class %>"><div class="generic-table--results-container">@@ -55,7 +55,7 @@ See COPYRIGHT and LICENSE files for more details.</div></th><% elsif sortable_column?(column) %>- <%= build_sort_header column.attribute, order_options(column, turbo: true) %>+ <%= build_new_sort_header column.attribute, order_options(column, turbo: true) %><% elsif column.attribute == :favored %><th><div class="generic-table--header-outer">diff --git a/app/components/projects/table_component.rb b/app/components/projects/table_component.rbindex 751645cd2fb..518bf403094 100644--- a/app/components/projects/table_component.rb+++ b/app/components/projects/table_component.rb@@ -67,6 +67,11 @@ module Projectshelpers.projects_sort_header_tag(column, **options, param: :json)end+ def build_new_sort_header(column, options)+ helpers.projects_new_sort_header_tag(column, **options, param: :json)+ end++# We don't return the project row# but the [project, level] array from the helperdef rowsdiff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rbindex c9d8f2d0de3..053e7d10729 100644--- a/app/helpers/projects_helper.rb+++ b/app/helpers/projects_helper.rb@@ -44,6 +44,16 @@ module ProjectsHelper@sort_criteria.criteria = former_criteriaend+ def projects_new_sort_header_tag(column, **)+ former_criteria = @sort_criteria.criteria.dup++ @sort_criteria.criteria.reject! { |a, _| a == "lft" }++ sort_header_with_action_menu(column, **, allowed_params: projects_query_param_names_for_sort)+ ensure+ @sort_criteria.criteria = former_criteria+ end+def short_project_description(project, length = 255)if project.description.blank?return ""diff --git a/app/helpers/sort_helper.rb b/app/helpers/sort_helper.rbindex a5ec937ccaf..f94b57f2399 100644--- a/app/helpers/sort_helper.rb+++ b/app/helpers/sort_helper.rb@@ -328,6 +328,177 @@ module SortHelperendend+ def sort_header_with_action_menu(column, allowed_params: nil, **options)+ caption = get_caption(column, options)++ default_order = options.delete(:default_order) || "asc"+ lang = options.delete(:lang) || nil+ param = options.delete(:param) || :sort+ data = options.delete(:data) || {}++ options[:title] = sort_header_title(column, caption, options)++ within_sort_header_tag_hierarchy(options, sort_class(column)) do+ # FIXME: always render the action menu+ # if %w(name project_status public created_at).include?(column.to_s)+ action_menu(column, caption, default_order, allowed_params:, param:, lang:, title: options[:title], data:)+ # else+ # sort_link(column, caption, default_order, allowed_params:, param:, lang:, title: options[:title], data:)+ # end+ end+ end++ def sort_key(key)+ key == :json ? :sortBy : :sort+ end++ def sort_by_options(column, order, default_order, allowed_params: nil, **html_options)+ order ||= order_string(column, inverted: true) || default_order++ sort_by = html_options.delete(:param)++ sort_param = @sort_criteria.add(column.to_s, order).to_param(sort_by)+ sort_key = sort_key(sort_by)++ sort_options = { sort_key => sort_param }+ allowed_params ||= %w[filters per_page expand columns]++ safe_query_params(allowed_params).merge(sort_options)+ end++ # FIXME: copied from ConfigureViewModalComponent+ def selected_columns_for_action_menu+ @selected_columns ||= @query+ .selects+ .map(&:attribute)+ end++ def build_columns_link(columns, allowed_params: nil, **html_options)+ sort_by = html_options.delete(:param)+ sort_key = sort_key(sort_by)++ allowed_params ||= %w[filters per_page expand columns]+ projects_path(safe_query_params(allowed_params).merge(columns: columns.join(" "), sort_key => params[sort_key]))+ end++ def shift_element(arr, str, direction=:left)+ arr = arr.dup+ index = arr.index(str)+ return arr unless index++ case direction+ when :left+ if index > 0+ arr[index], arr[index - 1] = arr[index - 1], arr[index]+ end+ when :right+ if index < arr.size - 1+ arr[index], arr[index + 1] = arr[index + 1], arr[index]+ end+ end++ arr+ end++ def filter_conversion(column)+ col = column.to_s++ # FIXME: description and project_status_description have NO action menu right now. Should be nil here, too.+ {+ "name" => "id",+ "project_status" => "project_status_code",+ "identifier" => nil,+ "required_disk_space" => nil,+ }.fetch(col, col)+ end++ def action_menu(column, caption, default_order, allowed_params: nil, **html_options)+ caption ||= column.to_s.humanize++ desc_sort_link = projects_path(sort_by_options(column, "desc", default_order, allowed_params:, **html_options))+ asc_sort_link = projects_path(sort_by_options(column, "asc", default_order, allowed_params:, **html_options))++ selected_columns = selected_columns_for_action_menu++ left_shift = shift_element(selected_columns, column)+ shift_left_link = build_columns_link(left_shift, allowed_params:, **html_options)++ right_shift = shift_element(selected_columns, column, :right)+ shift_right_link = build_columns_link(right_shift, allowed_params:, **html_options)++ all_columns_except_this = selected_columns.reject { _1 == column }+ rm_column_link = build_columns_link(all_columns_except_this, allowed_params:, **html_options)++ filter = filter_conversion(column)++ html_options.delete(:param)++ content_args = html_options.merge(rel: :nofollow)++ render Primer::Alpha::ActionMenu.new(menu_id: "menu-#{column.to_s}") do |menu|+ menu.with_show_button(scheme: :link, color: :default, text_transform: :uppercase,+ underline: false, display: :inline_flex) do |button|+ button.with_trailing_action_icon(icon: :"triangle-down")+ "#{h(caption)}"+ end+ menu.with_item(label: t(:label_sort_descending),+ content_arguments: content_args.merge(title: t(:label_sort_descending)),+ href: desc_sort_link) do |item|+ item.with_leading_visual_icon(icon: "sort-desc")+ end+ # FIXME: the title must be unique per link! Else the href will be duplicated.+ # TODO: move the title creation to another method.+ menu.with_item(label: t(:label_sort_ascending),+ content_arguments: content_args.merge(title: t(:label_sort_ascending)),+ href: asc_sort_link) do |item|+ item.with_leading_visual_icon(icon: "sort-asc")+ end++ # Some columns do not offer a filter. Only show the option when filtering is possible.+ if filter+ menu.with_divider+ menu.with_item(label: t(:label_filter_by),+ content_arguments: content_args.merge(+ data: {+ action: "table-action-menu#filterBy",+ filter_name: filter+ },+ title: t(:label_filter_by)+ )) do |item|+ item.with_leading_visual_icon(icon: "filter")+ end+ end++ menu.with_divider+ menu.with_item(label: t(:label_move_column_left),+ content_arguments: content_args.merge(title: t(:label_move_column_left)),+ href: shift_left_link) do |item|+ item.with_leading_visual_icon(icon: "op-columns-left")+ end+ menu.with_item(label: t(:label_move_column_right),+ content_arguments: content_args.merge(title: t(:label_move_column_right)),+ href: shift_right_link) do |item|+ item.with_leading_visual_icon(icon: "op-columns-right")+ end+ # TODO: title?+ menu.with_item(label: t(:label_add_column),+ href: configure_view_modal_project_queries_path(projects_query_params),+ content_arguments: content_args.merge(+ data: { controller: "async-dialog" },+ title: t(:label_add_column)+ )) do |item|+ item.with_leading_visual_icon(icon: "columns")+ end+ menu.with_divider+ menu.with_item(label: t(:label_remove_column),+ scheme: :danger,+ content_arguments: content_args.merge(title: t(:label_remove_column)),+ href: rm_column_link) do |item|+ item.with_leading_visual_icon(icon: "trash")+ end+ end+ end+def sort_class(column)order = order_string(column)diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 6b07ea4f6a1..10b04d6e67f 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2097,6 +2097,7 @@ en:label_ical_access_key_generation_hint: "Automatically generated when subscribing to a calendar."label_ical_access_key_latest: "latest"label_ical_access_key_revoke: "Revoke"+ label_add_column: "Add column"label_applied_status: "Applied status"label_archive_project: "Archive project"label_ascending: "Ascending"@@ -2266,8 +2267,9 @@ en:label_feeds_access_key_created_on: "RSS access key created %{value} ago"label_feeds_access_key_type: "RSS"label_file_plural: "Files"- label_filter_add: "Add filter"label_filter: "Filters"+ label_filter_add: "Add filter"+ label_filter_by: "Filter by"label_filter_plural: "Filters"label_filters_toggle: "Show/hide filters"label_float: "Float"@@ -2390,6 +2392,8 @@ en:label_months_from: "months from"label_more: "More"label_more_than_ago: "more than days ago"+ label_move_column_left: "Move column left"+ label_move_column_right: "Move column right"label_move_work_package: "Move work package"label_my_account: "Account settings"label_my_activity: "My activity"@@ -2512,6 +2516,7 @@ en:label_relation_new: "New relation"label_release_notes: "Release notes"label_remaining_work: "Remaining work"+ label_remove_column: "Remove column"label_remove_columns: "Remove selected columns"label_renamed: "renamed"label_reply_plural: "Replies"@@ -2553,8 +2558,10 @@ en:label_show_completed_versions: "Show completed versions"label_columns: "Columns"label_sort: "Sort"+ label_sort_ascending: "Sort ascending"label_sort_by: "Sort by %{value}"label_sorted_by: "sorted by %{value}"+ label_sort_descending: "Sort descending"label_sort_higher: "Move up"label_sort_highest: "Move to top"label_sort_lower: "Move down"diff --git a/frontend/src/global_styles/content/_table.sass b/frontend/src/global_styles/content/_table.sassindex 4b866d27512..f5566d7657d 100644--- a/frontend/src/global_styles/content/_table.sass+++ b/frontend/src/global_styles/content/_table.sass@@ -104,6 +104,9 @@ table.generic-table// https://www.456bereastreet.com/archive/201305/firefox_and_the_magical_text-overflowellipsis_z-index/z-index: 1+ action-menu+ text-transform: none+&.-righttext-align: rightdiff --git a/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.ts b/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.tsindex 880ffe72a27..1a35b40d594 100644--- a/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/filter/filters-form.controller.ts@@ -142,6 +142,11 @@ export default class FiltersFormController extends Controller {this.displayFiltersValue = !this.displayFiltersValue;}+ showDisplayFilters() {+ this.displayFiltersValue = true;+ this.displayFiltersValueChanged();+ }+displayFiltersValueChanged() {this.toggleButtonActive();this.toggleFilterFormVisible();@@ -187,6 +192,10 @@ export default class FiltersFormController extends Controller {addFilter(event:Event) {const filterName = (event.target as HTMLSelectElement).value;+ this.addFilterByName(filterName);+ }++ addFilterByName(filterName:string) {const selectedFilter = this.findTargetByName(filterName, this.filterTargets);if (selectedFilter) {selectedFilter.classList.remove('hidden');diff --git a/frontend/src/stimulus/controllers/dynamic/table-action-menu.controller.ts b/frontend/src/stimulus/controllers/dynamic/table-action-menu.controller.tsnew file mode 100644index 00000000000..00feed62859--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/table-action-menu.controller.ts@@ -0,0 +1,63 @@+/*+ * -- copyright+ * OpenProject is an open source project management software.+ * Copyright (C) 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';+import FiltersFormController from './filter/filters-form.controller';++export default class TableActionMenuController extends Controller {+ declare filterController:FiltersFormController|null;++ connect():void {+ this.findFilterController();+ }++ private findFilterController() {+ if (this.filterController) return;++ const subHeader = document.getElementById('projects-index-sub-header')?.querySelector('sub-header');+ if (subHeader) {+ this.filterController = this.application.getControllerForElementAndIdentifier(subHeader, 'filter--filters-form') as FiltersFormController;+ }+ }++ filterBy(event: Event) {+ // Sometimes the filterController was not loaded during `connect`, so we try again here:+ if (!this.filterController) { this.findFilterController() }++ const button = event.currentTarget as HTMLElement;++ const filterName = button.getAttribute('data-filter-name');++ if (this.filterController && filterName) {+ this.filterController.showDisplayFilters();+ this.filterController.addFilterByName(filterName);+ }+ }+}