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
Allow new filter comoponent to output filters in old JSON format
Klaus Zanders34548b4f63a1
diff --git a/app/components/filters_component.html.erb b/app/components/filters_component.html.erbindex f17e1568549..df920631dab 100644--- a/app/components/filters_component.html.erb+++ b/app/components/filters_component.html.erb@@ -1,5 +1,6 @@<div data-controller="filters"data-application-target="dynamic"+ data-filters-output-format-value="<%= output_format %>"data-filters-display-filters-value="<%= show_filters_section? %>"><div class="op-filters-header">diff --git a/app/components/filters_component.rb b/app/components/filters_component.rbindex 0383665ba67..2fb96da0548 100644--- a/app/components/filters_component.rb+++ b/app/components/filters_component.rb@@ -30,6 +30,7 @@class FiltersComponent < ApplicationComponentoptions :query+ options output_format: "params"renders_many :buttons, lambda { |**system_arguments|system_arguments[:ml] ||= 2diff --git a/frontend/src/stimulus/controllers/dynamic/filters.controller.ts b/frontend/src/stimulus/controllers/dynamic/filters.controller.tsindex 4f04f6038f0..422a03aceb5 100644--- a/frontend/src/stimulus/controllers/dynamic/filters.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/filters.controller.ts@@ -31,6 +31,12 @@import { Controller } from '@hotwired/stimulus';+interface InternalFilterValue {+ name:string;+ operator:string;+ value:string[];+}+export default class FiltersController extends Controller {static targets = ['filterFormToggle',@@ -60,9 +66,11 @@ export default class FiltersController extends Controller {static values = {displayFilters: { type: Boolean, default: false },+ outputFormat: { type: String, default: 'params' },};declare displayFiltersValue:boolean;+ declare outputFormatValue:string;toggleDisplayFilters() {this.displayFiltersValue = !this.displayFiltersValue;@@ -191,7 +199,16 @@ export default class FiltersController extends Controller {const orderParam = this.getUrlParameter('sortBy');const columnParam = this.getUrlParameter('columns');const idParam = this.getUrlParameter('query_id');- let queryString = `?filters=${encodeURIComponent(filters.join('&'))}`;+ let filterParam;++ if (this.outputFormatValue === 'json') {+ filterParam =JSON.stringify(filters.map((filter) => { return this.buildFilterJSON(filter); }));+ } else {+ filterParam = filters.map((filter) => { return this.buildFilterString(filter); }).join('&');+ }++ let queryString = `?filters=${encodeURIComponent(filterParam)}`;+if (orderParam) {queryString = `${queryString}&sortBy=${encodeURIComponent(orderParam)}`;}@@ -205,9 +222,9 @@ export default class FiltersController extends Controller {window.location.href = window.location.pathname + queryString;}- private parseFilters() {+ private parseFilters():InternalFilterValue[] {const advancedFilters = this.filterTargets.filter((filter) => !filter.classList.contains('hidden'));- const filters:string[] = [];+ const filters:InternalFilterValue[] = [];advancedFilters.forEach((filter) => {const filterName = filter.getAttribute('filter-name');@@ -218,9 +235,7 @@ export default class FiltersController extends Controller {const parsedValue = this.parseFilterValue(filterName, filterType, parsedOperator) as string[]|null;if (parsedValue) {- const valuesString = parsedValue.length > 1 ? `[${parsedValue.map((v) => `"${this.replaceDoubleQuotes(v)}"`).join(',')}]` : `"${this.replaceDoubleQuotes(parsedValue[0])}"`;-- filters.push(`${filterName} ${parsedOperator} ${valuesString}`);+ filters.push({ name: filterName, operator: parsedOperator, value: parsedValue });}}});@@ -228,6 +243,16 @@ export default class FiltersController extends Controller {return filters;}+ private buildFilterString(filter:InternalFilterValue) {+ const valuesString = filter.value.length > 1 ? `[${filter.value.map((v) => `"${this.replaceDoubleQuotes(v)}"`).join(',')}]` : `"${this.replaceDoubleQuotes(filter.value[0])}"`;++ return `${filter.name} ${filter.operator} ${valuesString}`;+ }++ private buildFilterJSON(filter:InternalFilterValue) {+ return { [filter.name]: { operator: filter.operator, values: filter.value } };+ }+private replaceDoubleQuotes(value:string) {return value && value.length > 0 ? value.replace(/"/g, '\\"') : '';}diff --git a/modules/meeting/app/views/meetings/index.html.erb b/modules/meeting/app/views/meetings/index.html.erbindex 52707983c0d..0524a1060aa 100644--- a/modules/meeting/app/views/meetings/index.html.erb+++ b/modules/meeting/app/views/meetings/index.html.erb@@ -32,7 +32,7 @@ See COPYRIGHT and LICENSE files for more details.<%= render Meetings::AddButtonComponent.new(current_project: @project) %><% end %>-<%= render(Meetings::MeetingFiltersComponent.new(query: @query)) %>+<%= render(Meetings::MeetingFiltersComponent.new(query: @query, output_format: 'json')) %><% if @meetings.empty? -%><%= no_results_box %>