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
Start implementing filters
Klaus Zandersfd67ce2985b0
diff --git a/frontend/src/global_styles/content/_index.sass b/frontend/src/global_styles/content/_index.sassindex 5497c4a6765..f6461890e47 100644--- a/frontend/src/global_styles/content/_index.sass+++ b/frontend/src/global_styles/content/_index.sass@@ -76,6 +76,7 @@@import sidebar@import activity_list@import activity_days+@import meetings@import menus/menu_blocks@import editor/indexdiff --git a/frontend/src/global_styles/content/_meetings.sass b/frontend/src/global_styles/content/_meetings.sassnew file mode 100644index 00000000000..c24bf37fc25--- /dev/null+++ b/frontend/src/global_styles/content/_meetings.sass@@ -0,0 +1,71 @@+//-- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-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.+//++++form.meeting-filters+ display: none+ &.-expanded+ display: block+ .advanced-filters--filter-value+ // visibility based on operator type+ &.hidden+ visibility: hidden+ height: 55px++ // visibility for list value selectors+ .multi-select+ display: none+ .single-select+ display: block+ &.multi-value+ .multi-select+ display: block+ .single-select+ display: none++ // visibility for datetime_past value selectors+ &.between-dates+ >.on-date,+ >.days+ display: none+ &.on-date+ >.between-dates,+ >.days+ display: none+ &.days+ >.on-date,+ >.between-dates+ display: none++ // Special input field styles+ &.between-dates+ input[type="text"]+ display: inline-block+ max-width: 6rem++ .advanced-filters--controls+ margin-top: 1remdiff --git a/frontend/src/stimulus/controllers/dynamic/meeting.controller.ts b/frontend/src/stimulus/controllers/dynamic/meeting.controller.tsnew file mode 100644index 00000000000..e16bb4f3346--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/meeting.controller.ts@@ -0,0 +1,336 @@+/*+ * -- 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 MeetingController extends Controller {+ static targets = [+ 'filterFormToggle',+ 'filterForm',+ 'filter',+ 'addFilterSelect',+ 'spacer',+ 'descriptionToggle',+ 'projectRow',+ 'descriptionRow',+ 'operator',+ 'filterValueContainer',+ 'filterValueSelect',+ 'days',+ 'singleDay',+ 'simpleValue',+ ];++ declare readonly filterFormToggleTarget:HTMLButtonElement;+ declare readonly filterFormTarget:HTMLFormElement;+ declare readonly filterTargets:HTMLElement[];+ declare readonly addFilterSelectTarget:HTMLSelectElement;+ declare readonly spacerTarget:HTMLElement;+ declare readonly descriptionToggleTargets:HTMLAnchorElement[];+ declare readonly projectRowTargets:HTMLTableRowElement[];+ declare readonly descriptionRowTargets:HTMLTableRowElement[];+ declare readonly operatorTargets:HTMLSelectElement[];+ declare readonly filterValueContainerTargets:HTMLElement[];+ declare readonly filterValueSelectTargets:HTMLSelectElement[];+ declare readonly daysTargets:HTMLInputElement[];+ declare readonly singleDayTargets:HTMLInputElement[];+ declare readonly simpleValueTargets:HTMLInputElement[];++ toggleFilterForm() {+ this.filterFormToggleTarget.classList.toggle('-active');+ this.filterFormTarget.classList.toggle('-expanded');+ }+ /*+ toggleMultiSelect({ params: { filterName } }: { params: { filterName: string } }) {+ const valueContainer = this.filterValueContainerTargets.find((filterValueContainer) => filterValueContainer.getAttribute('data-filter-name') === filterName);+ const singleSelect = this.filterValueSelectTargets.find((selectField) => !selectField.multiple && selectField.getAttribute('data-filter-name') === filterName);+ const multiSelect = this.filterValueSelectTargets.find((selectField) => selectField.multiple && selectField.getAttribute('data-filter-name') === filterName);+ if (valueContainer && singleSelect && multiSelect) {+ if (valueContainer.classList.contains('multi-value')) {+ const valueToSelect = this.getValueToSelect(multiSelect);+ this.setSelectOptions(singleSelect, valueToSelect);+ } else {+ const valueToSelect = this.getValueToSelect(singleSelect);+ this.setSelectOptions(multiSelect, valueToSelect);+ }++ valueContainer.classList.toggle('multi-value');+ }+ }++ private getValueToSelect(selectElement: HTMLSelectElement) {+ return selectElement.selectedOptions[0]?.value;+ }++ private setSelectOptions(selectElement: HTMLSelectElement, selectedValue: string) {+ Array.from(selectElement.options).forEach((option) => {+ option.selected = option.value === selectedValue;+ });+ }++ addFilter(event: Event) {+ const selectedFilterName = (event.target as HTMLSelectElement).value;+ const selectedFilter = this.filterTargets.find((filter) => filter.getAttribute('filter-name') === selectedFilterName);++ if (selectedFilter) {+ selectedFilter.classList.remove('hidden');+ }++ this.disableSelection();+ this.reselectPlaceholderOption();+ this.setSpacerVisibility();+ }++ private disableSelection() {+ this.addFilterSelectTarget.selectedOptions[0].setAttribute('disabled', 'disabled');+ }++ private reselectPlaceholderOption() {+ this.addFilterSelectTarget.options[0].setAttribute('selected', 'selected');+ }++ removeFilter({ params: { filterName } }: { params: { filterName: string } }) {+ const filterToRemove = this.filterTargets.find((filter) => filter.getAttribute('filter-name') === filterName);+ filterToRemove?.classList.add('hidden');++ const selectOptions = Array.from(this.addFilterSelectTarget.options);+ const removedFilterOption = selectOptions.find((option) => option.value === filterName);+ removedFilterOption?.removeAttribute('disabled');++ this.setSpacerVisibility();+ }++ private setSpacerVisibility() {+ if (this.anyFiltersStillVisible()) {+ this.spacerTarget.classList.remove('hidden');+ } else {+ this.spacerTarget.classList.add('hidden');+ }+ }++ private anyFiltersStillVisible() {+ return this.filterTargets.some((filter) => !filter.classList.contains('hidden'));+ }++ private readonly noValueOperators = ['*', '!*', 't', 'w'];+ private readonly daysOperators = ['>t-', '<t-', 't-', '<t+', '>t+', 't+'];+ private readonly onDateOperator = '=d';+ private readonly betweenDatesOperator = '<>d';++ setValueVisibility({ target, params: { filterName } }: { target: HTMLSelectElement, params: { filterName: string } }) {+ const selectedOperator = target.value;+ const valueContainer = this.filterValueContainerTargets.find((filterValueContainer) => filterValueContainer.getAttribute('data-filter-name') === filterName);+ if (valueContainer) {+ if (this.noValueOperators.includes(selectedOperator)) {+ valueContainer.classList.add('hidden');+ } else {+ valueContainer.classList.remove('hidden');+ }++ if (this.daysOperators.includes(selectedOperator)) {+ valueContainer.classList.add('days');+ valueContainer.classList.remove('on-date');+ valueContainer.classList.remove('between-dates');+ } else if (selectedOperator === this.onDateOperator) {+ valueContainer.classList.add('on-date');+ valueContainer.classList.remove('days');+ valueContainer.classList.remove('between-dates');+ } else if (selectedOperator === this.betweenDatesOperator) {+ valueContainer.classList.add('between-dates');+ valueContainer.classList.remove('days');+ valueContainer.classList.remove('on-date');+ }+ }+ }++ toggleDescription({ target, params: { projectId } }: { target: HTMLAnchorElement, params: { projectId: number } }) {+ const toggledTrigger = target;+ const otherTrigger = this.descriptionToggleTargets.find((trigger) => trigger !== toggledTrigger);+ // The projectId action parameter is automatically typecast to Number+ // and to compare it with a data attribute it needs to be converted to+ // a string.+ const clickedProjectRow = this.projectRowTargets.find((projectRow) => projectRow.getAttribute('data-project-id') === projectId.toString());+ const projectDescriptionRow = this.descriptionRowTargets.find((descriptionRow) => descriptionRow.getAttribute('data-project-id') === projectId.toString());++ if (clickedProjectRow && projectDescriptionRow) {+ clickedProjectRow.classList.toggle('-no-highlighting');+ clickedProjectRow.classList.toggle('-expanded');+ projectDescriptionRow.classList.toggle('-expanded');++ this.setAriaLive(projectDescriptionRow);+ }++ if (otherTrigger) {+ otherTrigger.focus();+ }+ }++ private setAriaLive(descriptionRow: HTMLElement) {+ if (descriptionRow.classList.contains('-expanded')) {+ descriptionRow.setAttribute('aria-live', 'polite');+ } else {+ descriptionRow.removeAttribute('aria-live');+ }+ }++ sendForm() {+ const ajaxIndicator = document.querySelector('#ajax-indicator') as HTMLElement;+ ajaxIndicator.style.display = '';++ const filters = this.parseFilters();+ const orderParam = this.getUrlParameter('sortBy');+ let queryString = `?filters=${encodeURIComponent(JSON.stringify(filters))}`;+ if (orderParam) {+ queryString = `${queryString}&sortBy=${encodeURIComponent(orderParam)}`;+ }++ window.location.href = window.location.pathname + queryString;+ }++ private parseFilters() {+ const advancedFilters = this.filterTargets.filter((filter) => !filter.classList.contains('hidden'));+ const filters: Filter[] = [];++ advancedFilters.forEach((filter) => {+ const filterName = filter.getAttribute('filter-name');+ const filterType = filter.getAttribute('filter-type');+ const parsedOperator = this.operatorTargets.find((operator) => operator.getAttribute('data-filter-name') === filterName)?.value;++ if (filterName && filterType && parsedOperator) {+ const parsedValue = this.parseFilterValue(filterName, filterType, parsedOperator);++ if (parsedValue) {+ const currentFilter: Filter = {+ [filterName]: { operator: parsedOperator, values: parsedValue as string[] },+ };+ filters.push(currentFilter);+ }+ }+ });++ return filters;+ }++ private readonly operatorsWithoutValues = ['*', '!*', 't', 'w'];+ private readonly selectFilterTypes = ['list', 'list_all', 'list_optional'];+ private readonly dateFilterTypes = ['datetime_past', 'date'];++ private parseFilterValue(filterName: string, filterType: string, operator: string) {+ const valueContainer = this.filterValueContainerTargets.find((filterValueContainer) => filterValueContainer.getAttribute('data-filter-name') === filterName);++ if (valueContainer) {+ const checkbox = valueContainer.querySelector('input[type="checkbox"]') as HTMLInputElement;++ if (checkbox) {+ return [checkbox.checked ? 't' : 'f'];+ }++ if (this.operatorsWithoutValues.includes(operator)) {+ return [];+ }++ if (this.selectFilterTypes.includes(filterType)) {+ return this.parseSelectFilterValue(valueContainer, filterName);+ }++ if (this.dateFilterTypes.includes(filterType)) {+ return this.parseDateFilterValue(valueContainer, filterName);+ }++ const value = this.simpleValueTargets.find((simpleValueInput) => simpleValueInput.getAttribute('data-filter-name') === filterName)?.value;++ if (value && value.length > 0) {+ return [value];+ }+ }++ return null;+ }++ private parseSelectFilterValue(valueContainer: HTMLElement, filterName: string) {+ let selectFields;++ if (valueContainer.classList.contains('multi-value')) {+ selectFields = this.filterValueSelectTargets.filter((selectField) => selectField.multiple && selectField.getAttribute('data-filter-name') === filterName);+ } else {+ selectFields = this.filterValueSelectTargets.filter((selectField) => !selectField.multiple && selectField.getAttribute('data-filter-name') === filterName);+ }++ const selectedValues = _.flatten(Array.from(selectFields).map((selectField) => Array.from(selectField.selectedOptions).map((option) => option.value)));++ if (selectedValues.length > 0) {+ return selectedValues;+ }++ return null;+ }++ private parseDateFilterValue(valueContainer: HTMLElement, filterName: string) {+ let value;++ if (valueContainer.classList.contains('days')) {+ const dateValue = this.daysTargets.find((daysField) => daysField.getAttribute('data-filter-name') === filterName)?.value;++ value = _.without([dateValue], '');+ } else if (valueContainer.classList.contains('on-date')) {+ const dateValue = this.singleDayTargets.find((dateInput) => dateInput.id === `on-date-value-${filterName}`)?.value;++ value = _.without([dateValue], '');+ } else if (valueContainer.classList.contains('between-dates')) {+ const fromValue = this.singleDayTargets.find((dateInput) => dateInput.id === `between-dates-from-value-${filterName}`)?.value;+ const toValue = this.singleDayTargets.find((dateInput) => dateInput.id === `between-dates-to-value-${filterName}`)?.value;++ value = [fromValue, toValue];+ }++ if (value && value.length > 0) {+ return value;+ }++ return null;+ }++ private getUrlParameter(sortParam: string) {+ const queryString = decodeURIComponent(window.location.search.substring(1));+ const queryParams = queryString.split('&');++ for (let i = 0; i < queryParams.length; i++) {+ const [key, value] = queryParams[i].split('=');++ if (key === sortParam) {+ return value || true;+ }+ }++ return null;+ }+ */+}diff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rbindex e6ade075411..4a785c74bb7 100644--- a/modules/meeting/app/controllers/meetings_controller.rb+++ b/modules/meeting/app/controllers/meetings_controller.rb@@ -45,13 +45,8 @@ class MeetingsController < ApplicationControllermenu_item :new_meeting, only: %i[new create]def index- @meetings = if @project- query = load_query- load_meetings(query)- else- global_upcoming_meetings- end-+ @query = load_query+ @meetings = load_meetings(@query)render 'index', locals: { menu_name: project_or_global_menu }end@@ -119,10 +114,16 @@ class MeetingsController < ApplicationControllerprivatedef load_query- ParamsToQueryService.new(+ query = ParamsToQueryService.new(Meeting,current_user).call(params)++ if @project+ query = query.where(:project_id, '=', @project.id)+ end++ queryenddef load_meetings(query)diff --git a/modules/meeting/app/models/queries/meetings.rb b/modules/meeting/app/models/queries/meetings.rbindex dcb1429d58d..384949bd392 100644--- a/modules/meeting/app/models/queries/meetings.rb+++ b/modules/meeting/app/models/queries/meetings.rb@@ -28,6 +28,7 @@module Queries::Meetings::Queries::Register.register(MeetingQuery) do- filter Queries::Filters::Shared::ProjectFilter+ filter Queries::Meetings::Filters::ProjectFilter+ filter Queries::Meetings::Filters::TimeFilterendenddiff --git a/modules/meeting/app/models/queries/meetings/filters/project_filter.rb b/modules/meeting/app/models/queries/meetings/filters/project_filter.rbnew file mode 100644index 00000000000..1b692115f52--- /dev/null+++ b/modules/meeting/app/models/queries/meetings/filters/project_filter.rb@@ -0,0 +1,31 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-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.+#++++class Queries::Meetings::Filters::ProjectFilter < Queries::Meetings::Filters::MeetingFilter+ include Queries::Filters::Shared::ProjectFilter+enddiff --git a/modules/meeting/app/models/queries/meetings/filters/time_filter.rb b/modules/meeting/app/models/queries/meetings/filters/time_filter.rbnew file mode 100644index 00000000000..9d04dd48033--- /dev/null+++ b/modules/meeting/app/models/queries/meetings/filters/time_filter.rb@@ -0,0 +1,58 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-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.+#++++class Queries::Meetings::Filters::TimeFilter < Queries::Meetings::Filters::MeetingFilter+ validate :validate_only_single_value++ def allowed_values+ %w[past future]+ end++ def where+ case values.first+ when 'past'+ "start_time < NOW() || start_time + duration * interval '1 hour' < NOW()"+ when 'future'+ "start_time > NOW()"+ end+ end++ def type+ :list+ end++ def available_operators+ [::Queries::Operators::Equals]+ end++ private++ def validate_only_single_value+ errors.add(:values, :invalid) if values.length != 1+ end+enddiff --git a/modules/meeting/app/views/meetings/filters/_form.html.erb b/modules/meeting/app/views/meetings/filters/_form.html.erbnew file mode 100644index 00000000000..9bf31b5e48e--- /dev/null+++ b/modules/meeting/app/views/meetings/filters/_form.html.erb@@ -0,0 +1,27 @@+<%= form_tag({},+ method: :get,+ class: "meeting-filters #{filter_set? ? '-expanded' : ''}",+ data: {+ 'meeting-target': 'filterForm',+ action: 'submit->meeting#sendForm:prevent'+ }) do %>+ <% operators_without_values = %w[* !* t w] %>+ <fieldset class="advanced-filters--container">+ <a title="<%= t('js.close_form_title') %>"+ class="advanced-filters--close icon-context icon-close"+ data-action="meeting#toggleFilterForm"></a>+ <legend><%= t(:label_filter_plural) %></legend>+ <ul class="advanced-filters--filters">+ <% allowed_filters(query).each do |filter| %>+ <% filter_active = query.find_active_filter(filter.name).present? %>+ <% filter_boolean = filter.is_a?(Queries::Filters::Shared::BooleanFilter) %>+ <li>+ <pre><%= filter %></pre>+ </li>+ <% end %>+ <li class="advanced-filters--controls">+ <%= submit_tag t('button_apply'), class: 'button -small -highlight', name: nil %>+ </li>+ </ul>+ </fieldset>+<% end %>diff --git a/modules/meeting/app/views/meetings/index.html.erb b/modules/meeting/app/views/meetings/index.html.erbindex e1dbe78001b..c7bf4ed12dd 100644--- a/modules/meeting/app/views/meetings/index.html.erb+++ b/modules/meeting/app/views/meetings/index.html.erb@@ -26,26 +26,35 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.See COPYRIGHT and LICENSE files for more details.++#%>-<% html_title t(:label_meeting_plural) %>--<%= toolbar title: t(:label_meeting_plural) do %>- <% if authorize_for(:meetings, :new) %>- <li class="toolbar-item">- <a href="<%= new_meeting_path %>"+<div data-controller="meeting"+ data-application-target="dynamic">+ <%= toolbar title: t(:label_meeting_plural) do %>+ <% if authorize_for(:meetings, :new) %>+ <li class="toolbar-item">+ <a href="<%= new_meeting_path %>"id="add-meeting-button"title="<%= I18n.t(:label_meeting_new) %>"arial-label="<%= I18n.t(:label_meeting_new) %>"class="button -alt-highlight">- <%= op_icon('button--icon icon-add') %>- <span class="button--text"><%= t(:label_meeting) %></span>- </a>+ <%= op_icon('button--icon icon-add') %>+ <span class="button--text"><%= t(:label_meeting) %></span>+ </a>+ </li>+ <% end %>+ <li class="toolbar-item">+ <button title="<%= t(:label_filters_toggle) %>"+ class="button toolbar-icon <%= filter_set? ? '-active' : '' %>"+ data-meeting-target="filterFormToggle"+ data-action="meeting#toggleFilterForm">+ <%= op_icon("icon-filter button--icon") %>+ </button></li><% end %>-<% end %>--<% if @meetings.empty? -%>- <%= no_results_box %>-<% else -%>-<%= render Meetings::TableComponent.new(rows: @meetings, current_project: @project) %>-<% end -%>+ <% if @meetings.empty? -%>+ <%= no_results_box %>+ <% else -%>+ <%= render partial: 'meetings/filters/form', locals: { query: @query } %>+ <%= render Meetings::TableComponent.new(rows: @meetings, current_project: @project) %>+ <% end -%>+</div>