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 comments only filter
Jonas Jabaria0b5141c2220
diff --git a/app/components/_index.sass b/app/components/_index.sassindex 9bbe0035237..6c75bec3c32 100644--- a/app/components/_index.sass+++ b/app/components/_index.sass@@ -1,4 +1,5 @@@import "work_packages/activities_tab/journals/new_component"+@import "work_packages/activities_tab/journals/filter_component"@import "work_packages/share/modal_body_component"@import "work_packages/share/invite_user_form_component"@import "work_packages/progress/modal_body_component"diff --git a/app/components/work_packages/activities_tab/index_component.html.erb b/app/components/work_packages/activities_tab/index_component.html.erbindex cc375be53e1..2a30cac7d24 100644--- a/app/components/work_packages/activities_tab/index_component.html.erb+++ b/app/components/work_packages/activities_tab/index_component.html.erb@@ -2,6 +2,14 @@content_tag("turbo-frame", id: "work-package-activities-tab-content") docomponent_wrapper(data: wrapper_data_attributes) doflex_layout do |activties_tab_container|+ activties_tab_container.with_row(mb: 2) do+ render(+ WorkPackages::ActivitiesTab::Journals::FilterComponent.new(+ work_package: work_package,+ only_comments: only_comments+ )+ )+ endif journal_sorting == "desc"activties_tab_container.with_row dorender(@@ -11,7 +19,7 @@endactivties_tab_container.with_row dorender(- WorkPackages::ActivitiesTab::Journals::IndexComponent.new(work_package:)+ WorkPackages::ActivitiesTab::Journals::IndexComponent.new(work_package:, only_comments:))endif journal_sorting == "asc"diff --git a/app/components/work_packages/activities_tab/index_component.rb b/app/components/work_packages/activities_tab/index_component.rbindex 8a721948448..ab448876af3 100644--- a/app/components/work_packages/activities_tab/index_component.rb+++ b/app/components/work_packages/activities_tab/index_component.rb@@ -35,22 +35,24 @@ module WorkPackagesinclude OpPrimer::ComponentHelpersinclude OpTurbo::Streamable- def initialize(work_package:)+ def initialize(work_package:, only_comments: false)super@work_package = work_package+ @only_comments = only_commentsendprivate- attr_reader :work_package+ attr_reader :work_package, :only_commentsdef wrapper_data_attributes{controller: "work-packages--activities-tab--index","application-target": "dynamic",- "work-packages--activities-tab--index-journal-streams-url-value": journal_streams_work_package_activities_url(work_package),+ "work-packages--activities-tab--index-update-streams-url-value": update_streams_work_package_activities_url(work_package),"work-packages--activities-tab--index-sorting-value": journal_sorting,+ "work-packages--activities-tab--index-only-comments-value": only_comments,"work-packages--activities-tab--index-polling-interval-in-ms-value": 60000 # protoypical implementation}end@@ -58,18 +60,6 @@ module WorkPackagesdef journal_sortingUser.current.preference&.comments_sorting || "desc"end-- def only_comments?- false # TODO: Implement this- end-- def journals- result = work_package.journals.includes(:user).reorder(version: journal_sorting)-- result = result.where.not(notes: "") if only_comments?-- result- endendendenddiff --git a/app/components/work_packages/activities_tab/journals/filter_component.html.erb b/app/components/work_packages/activities_tab/journals/filter_component.html.erbnew file mode 100644index 00000000000..405da009464--- /dev/null+++ b/app/components/work_packages/activities_tab/journals/filter_component.html.erb@@ -0,0 +1,23 @@+<%=+ component_wrapper do+ if journals_with_notes_present?+ render(Primer::Alpha::SegmentedControl.new(id: "only-comments-filter", "aria-label": "File view")) do |component|+ component.with_item(+ tag: :a,+ href: filter_streams_work_package_activities_url(work_package),+ label: "All activities",+ icon: :pulse,+ selected: !only_comments,+ data: { "turbo-stream": true, "action": "click->work-packages--activities-tab--index#unsetOnlyComments" }+ )+ component.with_item(+ tag: :a,+ href: filter_streams_work_package_activities_url(work_package, only_comments: true),+ label: "Only comments",+ icon: :"comment-discussion", selected: only_comments,+ data: { "turbo-stream": true, "action": "click->work-packages--activities-tab--index#setOnlyComments" }+ )+ end+ end+ end+%>diff --git a/app/components/work_packages/activities_tab/journals/filter_component.rb b/app/components/work_packages/activities_tab/journals/filter_component.rbnew file mode 100644index 00000000000..b20558f82dc--- /dev/null+++ b/app/components/work_packages/activities_tab/journals/filter_component.rb@@ -0,0 +1,56 @@+# frozen_string_literal: true++# -- 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.+# ++++module WorkPackages+ module ActivitiesTab+ module Journals+ class FilterComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers+ include OpTurbo::Streamable++ def initialize(work_package:, only_comments: false)+ super++ @work_package = work_package+ @only_comments = only_comments+ end++ private++ attr_reader :work_package, :only_comments++ def journals_with_notes_present?+ work_package.journals.where.not(notes: "").any?+ end+ end+ end+ end+enddiff --git a/app/components/work_packages/activities_tab/journals/filter_component.sass b/app/components/work_packages/activities_tab/journals/filter_component.sassnew file mode 100644index 00000000000..8ea0ae7f252--- /dev/null+++ b/app/components/work_packages/activities_tab/journals/filter_component.sass@@ -0,0 +1,3 @@+#work-packages-activities-tab-journals-filter-component+ #only-comments-filter+ margin-left: 0pxdiff --git a/app/components/work_packages/activities_tab/journals/index_component.html.erb b/app/components/work_packages/activities_tab/journals/index_component.html.erbindex cac5cbf0c04..65ace85f92a 100644--- a/app/components/work_packages/activities_tab/journals/index_component.html.erb+++ b/app/components/work_packages/activities_tab/journals/index_component.html.erb@@ -1,11 +1,21 @@<%=component_wrapper doflex_layout(id: insert_target_modifier_id) do |journals_index_container|- journals.each do |journal|- journals_index_container.with_row do- render(- WorkPackages::ActivitiesTab::Journals::ItemComponent.new(journal:)- )+ if journals.any?+ journals.each do |journal|+ journals_index_container.with_row do+ render(+ WorkPackages::ActivitiesTab::Journals::ItemComponent.new(journal:)+ )+ end+ end+ else+ journals_index_container.with_row(mt: 2) do+ render(Primer::Beta::Blankslate.new(border: true)) do |component|+ component.with_visual_icon(icon: :pulse)+ component.with_heading(tag: :h2).with_content(t("activities.work_packages.activity_tab.no_results_title_text"))+ component.with_description { t("activities.work_packages.activity_tab.no_results_description_text") }+ endendendenddiff --git a/app/components/work_packages/activities_tab/journals/index_component.rb b/app/components/work_packages/activities_tab/journals/index_component.rbindex 5eb71d2cbcc..bf51b4f313e 100644--- a/app/components/work_packages/activities_tab/journals/index_component.rb+++ b/app/components/work_packages/activities_tab/journals/index_component.rb@@ -36,15 +36,16 @@ module WorkPackagesinclude OpPrimer::ComponentHelpersinclude OpTurbo::Streamable- def initialize(work_package:)+ def initialize(work_package:, only_comments: false)super@work_package = work_package+ @only_comments = only_commentsendprivate- attr_reader :work_package+ attr_reader :work_package, :only_commentsdef insert_target_modified?true@@ -58,14 +59,10 @@ module WorkPackagesUser.current.preference&.comments_sorting || "desc"end- def only_comments?- false # TODO: Implement this- end-def journalsresult = work_package.journals.includes(:user).reorder(version: journal_sorting)- result = result.where.not(notes: "") if only_comments?+ result = result.where.not(notes: "") if only_commentsresultenddiff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rbindex c015ef1a8f6..191843b3d7e 100644--- a/app/controllers/work_packages/activities_tab_controller.rb+++ b/app/controllers/work_packages/activities_tab_controller.rb@@ -39,15 +39,41 @@ class WorkPackages::ActivitiesTabController < ApplicationControllerdef indexrender(WorkPackages::ActivitiesTab::IndexComponent.new(- work_package: @work_package+ work_package: @work_package,+ only_comments: params[:only_comments] || false),layout: false)end- def journal_streams+ def filter_streams+ only_comments = params[:only_comments] || false++ update_via_turbo_stream(+ component: WorkPackages::ActivitiesTab::Journals::FilterComponent.new(+ work_package: @work_package,+ only_comments:+ )+ )+ update_via_turbo_stream(+ component: WorkPackages::ActivitiesTab::Journals::IndexComponent.new(+ work_package: @work_package,+ only_comments:+ )+ )++ respond_with_turbo_streams+ end++ def update_streams+ journals = @work_package.journals++ if params[:only_comments] == "true"+ journals = journals.where.not(notes: "")+ end+# TODO: prototypical implementation- @work_package.journals.where("updated_at > ?", params[:last_update_timestamp]).find_each do |journal|+ journals.where("updated_at > ?", params[:last_update_timestamp]).find_each do |journal|update_via_turbo_stream(# only use the show component in order not to loose an edit statecomponent: WorkPackages::ActivitiesTab::Journals::ItemComponent::Show.new(@@ -56,7 +82,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController)end- @work_package.journals.where("created_at > ?", params[:last_update_timestamp]).find_each do |journal|+ journals.where("created_at > ?", params[:last_update_timestamp]).find_each do |journal|append_or_prepend_latest_journal_via_turbo_stream(journal)enddiff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex 0bc235bee18..f8601bc2a3b 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -196,7 +196,7 @@ Rails.application.reloader.to_prepare dowork_packages: %i[show index],work_packages_api: [:get],"work_packages/reports": %i[report report_details],- "work_packages/activities_tab": %i[index create journal_streams edit cancel_edit update]+ "work_packages/activities_tab": %i[index create update_streams filter_streams edit cancel_edit update]},permissible_on: %i[work_package project],contract_actions: { work_packages: %i[read] }diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 8c3d8b8f422..ae17335d4ed 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -32,6 +32,10 @@ en:activities:index:no_results_title_text: There has not been any activity for the project within this time frame.+ work_packages:+ activity_tab:+ no_results_title_text: Nothing to display+ no_results_description_text: "Try to update your filter to see more."admin:plugins:diff --git a/config/routes.rb b/config/routes.rbindex 4066f7c6cc3..c2a4bfee921 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -543,7 +543,8 @@ Rails.application.routes.draw doget :cancel_editendcollection do- get :journal_streams+ get :filter_streams+ get :update_streamsendenddiff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.tsindex 5ccfdebdaee..6421bee4eeb 100644--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts@@ -33,16 +33,18 @@ import { Controller } from '@hotwired/stimulus';export default class IndexController extends Controller {static values = {- journalStreamsUrl: String,+ updateStreamsUrl: String,sorting: String,pollingIntervalInMs: Number,+ onlyComments: Boolean,};- declare journalStreamsUrlValue:string;+ declare updateStreamsUrlValue:string;declare sortingValue:string;declare lastUpdateTimestamp:string;declare intervallId:number;declare pollingIntervalInMsValue:number;+ declare onlyCommentsValue:boolean;connect() {this.lastUpdateTimestamp = new Date().toISOString();@@ -88,8 +90,9 @@ export default class IndexController extends Controller {}async updateActivitiesList() {- const url = new URL(this.journalStreamsUrlValue);+ const url = new URL(this.updateStreamsUrlValue);url.searchParams.append('last_update_timestamp', this.lastUpdateTimestamp);+ url.searchParams.append('only_comments', this.onlyCommentsValue.toString());const response = await fetch(url,@@ -116,4 +119,12 @@ export default class IndexController extends Controller {this.updateActivitiesList();}, this.pollingIntervalInMsValue);}++ setOnlyComments() {+ this.onlyCommentsValue = true;+ }++ unsetOnlyComments() {+ this.onlyCommentsValue = false;+ }}