Skip to content

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

Revert "prototypical implementation of the toggle singel notifications feature, specs and refactoring required"

Jonas Jabari0f6070419c3f
diff --git a/app/components/work_packages/activities_tab/journals/item_component.html.erb b/app/components/work_packages/activities_tab/journals/item_component.html.erb
index 8707ca13da8..c1c0f60d7db 100644
--- a/app/components/work_packages/activities_tab/journals/item_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/item_component.html.erb
@@ -32,38 +32,11 @@
header_container.with_column(flex_layout: true, align_items: :center) do |header_end_container|
if has_unread_notifications?
header_end_container.with_column(mr: 2, pt: 1) do
- render(Primer::Beta::IconButton.new(
- scheme: :invisible, # color is set via CSS as requested by UI/UX Team
+ render(Primer::Beta::Octicon.new(
+ :"dot-fill", # color is set via CSS as requested by UI/UX Team
classes: "work-packages-activities-tab-journals-item-component--notification-dot-icon",
- icon: "dot-fill",
- "aria-label": "mark notification as read",
- show_tooltip: true,
- href: toggle_notification_read_status_work_package_activity_path(work_package_id: journal.journable_id, id: journal.id ),
- tag: :a,
- data: {
- test_selector: "op-journal-unread-notification",
- turbo: true,
- turbo_stream: true,
- turbo_method: :put
- }
- ))
- end
- end
- if has_read_notifications?
- header_end_container.with_column(mr: 2, pt: 1) do
- render(Primer::Beta::IconButton.new(
- scheme: :invisible, # color is set via CSS as requested by UI/UX Team
- icon: "dot-fill",
- "aria-label": "mark notification as unread",
- show_tooltip: true,
- href: toggle_notification_read_status_work_package_activity_path(work_package_id: journal.journable_id, id: journal.id ),
- tag: :a,
- data: {
- test_selector: "op-journal-read-notification",
- turbo: true,
- turbo_stream: true,
- turbo_method: :put
- }
+ size: :medium,
+ data: { test_selector: "op-journal-unread-notification" }
))
end
end
@@ -114,13 +87,7 @@
end
end
journal_container.with_row do
- render(WorkPackages::ActivitiesTab::Journals::ItemComponent::Details.new(
- journal:,
- show_notifications: show_notification_on_details?,
- has_unread_notifications: has_unread_notifications?,
- has_read_notifications: has_read_notifications?,
- filter:
- ))
+ render(WorkPackages::ActivitiesTab::Journals::ItemComponent::Details.new(journal:, has_unread_notifications: notification_on_details?, filter:))
end
end
end
diff --git a/app/components/work_packages/activities_tab/journals/item_component.rb b/app/components/work_packages/activities_tab/journals/item_component.rb
index e9366749cf5..e79ecc2c766 100644
--- a/app/components/work_packages/activities_tab/journals/item_component.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component.rb
@@ -85,12 +85,8 @@ module WorkPackages
journal.notifications.where(read_ian: false, recipient_id: User.current.id).any?
end
- def has_read_notifications?
- journal.notifications.where(read_ian: true, recipient_id: User.current.id).any?
- end
-
- def show_notification_on_details?
- journal.notes.blank?
+ def notification_on_details?
+ has_unread_notifications? && journal.notes.blank?
end
def allowed_to_edit?
diff --git a/app/components/work_packages/activities_tab/journals/item_component.sass b/app/components/work_packages/activities_tab/journals/item_component.sass
index f1568cdd5a4..31c09142304 100644
--- a/app/components/work_packages/activities_tab/journals/item_component.sass
+++ b/app/components/work_packages/activities_tab/journals/item_component.sass
@@ -8,8 +8,7 @@
@media screen and (min-width: $breakpoint-sm)
max-width: 40%
&--notification-dot-icon
- svg
- color: var(--bgColor-accent-emphasis)!important
+ color: var(--bgColor-accent-emphasis)
&--header-start-container
flex-grow: 1
diff --git a/app/components/work_packages/activities_tab/journals/item_component/details.rb b/app/components/work_packages/activities_tab/journals/item_component/details.rb
index a9d7206475b..4fd23af862b 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/details.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component/details.rb
@@ -37,20 +37,17 @@ module WorkPackages
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(journal:, filter:, show_notifications: false, has_unread_notifications: false,
- has_read_notifications: false)
+ def initialize(journal:, filter:, has_unread_notifications: false)
super
@journal = journal
- @show_notifications = show_notifications
@has_unread_notifications = has_unread_notifications
- @has_read_notifications = has_read_notifications
@filter = filter
end
private
- attr_reader :journal, :show_notifications, :has_unread_notifications, :has_read_notifications, :filter
+ attr_reader :journal, :has_unread_notifications, :filter
def wrapper_uniq_by
journal.id
@@ -147,52 +144,19 @@ module WorkPackages
def render_header_end(header_container)
header_container.with_column(flex_layout: true) do |header_end_container|
- render_notification_bubble(header_end_container)
+ render_notification_bubble(header_end_container) if has_unread_notifications
render_activity_link(header_end_container)
end
end
def render_notification_bubble(container)
- return unless show_notifications
-
- if has_unread_notifications
- container.with_column(mr: 2) do
- render(Primer::Beta::IconButton.new(
- scheme: :invisible, # color is set via CSS as requested by UI/UX Team
- classes: "work-packages-activities-tab-journals-item-component--notification-dot-icon",
- icon: "dot-fill",
- "aria-label": "mark notification as read",
- show_tooltip: true,
- href: toggle_notification_read_status_work_package_activity_path(work_package_id: journal.journable_id,
- id: journal.id),
- tag: :a,
- data: {
- test_selector: "op-journal-unread-notification",
- turbo: true,
- turbo_stream: true,
- turbo_method: :put
- }
- ))
- end
- end
- if has_read_notifications
- container.with_column(mr: 2) do
- render(Primer::Beta::IconButton.new(
- scheme: :invisible, # color is set via CSS as requested by UI/UX Team
- icon: "dot-fill",
- "aria-label": "mark notification as unread",
- show_tooltip: true,
- href: toggle_notification_read_status_work_package_activity_path(work_package_id: journal.journable_id,
- id: journal.id),
- tag: :a,
- data: {
- test_selector: "op-journal-read-notification",
- turbo: true,
- turbo_stream: true,
- turbo_method: :put
- }
- ))
- end
+ container.with_column(mr: 2) do
+ render(Primer::Beta::Octicon.new(
+ :"dot-fill", # color is set via CSS as requested by UI/UX Team
+ classes: "work-packages-activities-tab-journals-item-component-details--notification-dot-icon",
+ size: :medium,
+ data: { test_selector: "op-journal-unread-notification" }
+ ))
end
end
diff --git a/app/contracts/notifications/update_contract.rb b/app/contracts/notifications/update_contract.rb
deleted file mode 100644
index 921b3cfee48..00000000000
--- a/app/contracts/notifications/update_contract.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-#-- 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.
-#++
-
-module Notifications
- class UpdateContract < ::ModelContract
- attribute :read_ian
- end
-end
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index 11087e726b3..6aec4724d5f 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -33,7 +33,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
before_action :find_work_package
before_action :find_project
- before_action :find_journal, only: %i[edit cancel_edit update toggle_notification_read_status]
+ before_action :find_journal, only: %i[edit cancel_edit update]
before_action :set_filter
before_action :authorize
@@ -153,23 +153,6 @@ class WorkPackages::ActivitiesTabController < ApplicationController
respond_with_turbo_streams
end
- def toggle_notification_read_status
- notification = Notification.find_by(recipient: User.current, journal: @journal)
-
- call = Notifications::UpdateService.new(model: notification, user: User.current).call(
- read_ian: !notification.read_ian
- )
-
- if call.success?
- update_item_component(@journal.reload, state: :show)
- update_activity_counter
- else
- handle_failed_update_call(call)
- end
-
- respond_with_turbo_streams
- end
-
private
def respond_with_error(error_message)
@@ -310,44 +293,32 @@ class WorkPackages::ActivitiesTabController < ApplicationController
end
def generate_time_based_update_streams(last_update_timestamp)
+ # TODO: prototypical implementation
journals = @work_package.journals
if @filter == :only_comments
journals = journals.where.not(notes: "")
end
- rerender_updated_journals(journals, last_update_timestamp)
-
- rerender_journals_with_updated_notification(journals, last_update_timestamp)
-
- append_or_prepend_new_journals(journals, last_update_timestamp)
-
- if journals.any?
- remove_potential_empty_state
- update_activity_counter
- end
- end
-
- def rerender_updated_journals(journals, last_update_timestamp)
journals.where("updated_at > ?", last_update_timestamp).find_each do |journal|
- # we need to update the whole component as the show part is not rendered for journals which originally have no notes
- update_journal_item(journal:)
- end
- end
-
- def rerender_journals_with_updated_notification(journals, last_update_timestamp)
- journals
- .joins(:notifications)
- .where("notifications.updated_at > ?", last_update_timestamp)
- .find_each do |journal|
- update_journal_item(journal:)
+ update_via_turbo_stream(
+ # we need to update the whole component as the show part is not rendered for journals which originally have no notes
+ component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
+ journal:,
+ filter: @filter
+ )
+ )
+ # TODO: is it possible to loose an edit state this way?
end
- end
- def append_or_prepend_new_journals(journals, last_update_timestamp)
journals.where("created_at > ?", last_update_timestamp).find_each do |journal|
append_or_prepend_latest_journal_via_turbo_stream(journal)
end
+
+ if journals.any?
+ remove_potential_empty_state
+ update_activity_counter
+ end
end
def append_or_prepend_latest_journal_via_turbo_stream(journal)
@@ -386,16 +357,6 @@ class WorkPackages::ActivitiesTabController < ApplicationController
)
end
- def update_journal_item(journal:, filter: @filter, state: :show)
- update_via_turbo_stream(
- component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
- journal:,
- filter:,
- state:
- )
- )
- end
-
def allowed_to_edit?(journal)
journal.editable_by?(User.current)
end
diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rb
index 8afa0bc5e18..4860440a10d 100644
--- a/config/initializers/permissions.rb
+++ b/config/initializers/permissions.rb
@@ -263,7 +263,7 @@ Rails.application.reloader.to_prepare do
wpt.permission :edit_work_package_notes,
{
- "work_packages/activities_tab": %i[edit cancel_edit update toggle_notification_read_status]
+ "work_packages/activities_tab": %i[edit cancel_edit update]
},
permissible_on: :project,
require: :loggedin,
@@ -271,7 +271,7 @@ Rails.application.reloader.to_prepare do
wpt.permission :edit_own_work_package_notes,
{
- "work_packages/activities_tab": %i[edit cancel_edit update toggle_notification_read_status]
+ "work_packages/activities_tab": %i[edit cancel_edit update]
},
permissible_on: %i[work_package project],
require: :loggedin,
diff --git a/config/routes.rb b/config/routes.rb
index aeba8365da0..dff7f9c1449 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -577,11 +577,9 @@ Rails.application.routes.draw do
# states managed by client-side routing on work_package#index
get "details/*state" => "work_packages#index", on: :collection, as: :details
- resources :activities, controller: "work_packages/activities_tab",
- only: %i[index create edit update] do
+ resources :activities, controller: "work_packages/activities_tab", only: %i[index create edit update] do
member do
get :cancel_edit
- put :toggle_notification_read_status
end
collection do
get :update_streams