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
Merge branch 'feature/54733-primerise-the-activity-panel' into feature/40437-emoji-reactions-to-work-package-comments
Jonas Jabari19f3669455bb
diff --cc app/components/work_packages/activities_tab/journals/item_component/show.html.erbindex 9f7574a1a9f,4a71f71166e..0b9aa9bee81--- a/app/components/work_packages/activities_tab/journals/item_component/show.html.erb+++ b/app/components/work_packages/activities_tab/journals/item_component/show.html.erb@@@ -1,21 -1,11 +1,19 @@@<%=component_wrapper do- if journal.notes.present? || (journal.details.any? && !journal.initial?)+ if journal.notes.present?flex_layout do |journal_container|- if journal.notes.present?- journal_container.with_row do- render(Primer::Box.new(mt: 1)) do- format_text(journal, :notes)- end+ journal_container.with_row do+ render(Primer::Box.new(mt: 1)) do+ format_text(journal, :notes)end+ journal_container.with_row(mt: 3, flex_layout: true) do |reactions_container|+ reactions_container.with_column do+ render(WorkPackages::ActivitiesTab::Journals::ItemComponent::AddReactions.new(journal:))+ end+ reactions_container.with_column do+ render(WorkPackages::ActivitiesTab::Journals::ItemComponent::Reactions.new(journal:))+ end+ endendendenddiff --cc app/controllers/work_packages/activities_tab_controller.rbindex 2c5ff8ae1e4,d2c15b22849..6477fc958cd--- a/app/controllers/work_packages/activities_tab_controller.rb+++ b/app/controllers/work_packages/activities_tab_controller.rb@@@ -33,7 -33,8 +33,8 @@@ class WorkPackages::ActivitiesTabControbefore_action :find_work_packagebefore_action :find_project- before_action :find_journal, only: %i[edit cancel_edit update]+ before_action :find_journal, only: %i[edit cancel_edit update toggle_reaction]+ before_action :set_filterbefore_action :authorizedef index@@@ -46,9 -47,17 +47,18 @@@)end- def update_filter- filter = params[:filter]&.to_sym || :all+ def update_streams+ if params[:last_update_timestamp].present?+ generate_time_based_update_streams(params[:last_update_timestamp])++ generate_time_based_reaction_update_streams(params[:last_update_timestamp])+ else+ @turbo_status = :bad_request+ end+ respond_with_turbo_streams+ end++ def update_filterupdate_via_turbo_stream(component: WorkPackages::ActivitiesTab::Journals::FilterAndSortingComponent.new(work_package: @work_package,@@@ -167,40 -153,40 +154,70 @@@respond_with_turbo_streamsend+ def toggle_reaction+ call = if @journal.emoji_reactions.exists?(user: User.current, emoji: params[:emoji])+ EmojiReactions::DeleteService.new(+ user: User.current,+ model: @journal.emoji_reactions.find_by(user: User.current, emoji: params[:emoji])+ ).call+ else+ EmojiReactions::CreateService.new(+ user: User.current+ ).call(+ user: User.current,+ reactable: @journal,+ emoji: params[:emoji]+ )+ end++ if call.success?+ update_via_turbo_stream(+ component: WorkPackages::ActivitiesTab::Journals::ItemComponent::Show.new(+ journal: @journal,+ filter: params[:filter]&.to_sym || :all+ )+ )+ else+ # TODO: handle errors+ end++ respond_with_turbo_streams+ end+private+ def respond_with_error(error_message)+ respond_to do |format|+ # turbo_frame requests (tab is initially rendered and an error occured) are handled below+ format.html do+ render(+ WorkPackages::ActivitiesTab::ErrorFrameComponent.new(+ error_message:+ ),+ layout: false,+ status: :not_found+ )+ end+ # turbo_stream requests (tab is already rendered and an error occured in subsequent requests) are handled below+ format.turbo_stream do+ @turbo_status = :not_found+ render_error_banner_via_turbo_stream(error_message)+ end+ end+ end++ def render_error_banner_via_turbo_stream(error_message)+ update_via_turbo_stream(+ component: WorkPackages::ActivitiesTab::ErrorStreamComponent.new(+ error_message:+ )+ )+ end+def find_work_package@work_package = WorkPackage.find(params[:work_package_id])+ rescue ActiveRecord::RecordNotFound+ respond_with_error(I18n.t("label_not_found"))enddef find_project@@@ -219,8 -213,86 +244,87 @@@params.require(:journal).permit(:notes)end- def generate_time_based_journal_update_streams(last_update_timestamp, filter)- filter = filter&.to_sym || :all+ def handle_successful_create_call(call)+ if @filter == :only_changes+ handle_only_changes_filter_on_create+ else+ handle_other_filters_on_create(call)+ end+ end++ def handle_only_changes_filter_on_create+ @filter = :all # reset filter+ # we need to update the whole tab in order to reset the filter+ # as the added journal would not be shown otherwise+ replace_whole_tab+ end++ def handle_other_filters_on_create(call)+ if call.result.initial?+ update_index_component # update the whole index component to reset empty state+ else+ generate_time_based_update_streams(params[:last_update_timestamp])++ generate_time_based_reaction_update_streams(params[:last_update_timestamp])+ end+ end++ def handle_failed_create_call(call)+ update_via_turbo_stream(+ component: WorkPackages::ActivitiesTab::Journals::NewComponent.new(+ work_package: @work_package,+ journal: call.result,+ form_hidden_initially: false+ )+ )+ end++ def handle_failed_update_call(call)+ @turbo_status = if call.errors&.first&.type == :error_unauthorized+ :forbidden+ else+ :bad_request+ end+ end++ def replace_whole_tab+ replace_via_turbo_stream(+ component: WorkPackages::ActivitiesTab::IndexComponent.new(+ work_package: @work_package,+ filter: @filter+ )+ )+ end++ def update_index_component+ update_via_turbo_stream(+ component: WorkPackages::ActivitiesTab::Journals::IndexComponent.new(+ work_package: @work_package,+ filter: @filter+ )+ )+ end++ def create_journal_service_call+ ### taken from ActivitiesByWorkPackageAPI+ AddWorkPackageNoteService+ .new(user: User.current,+ work_package: @work_package)+ .call(journal_params[:notes],+ send_notifications: !(params.has_key?(:notify) && params[:notify] == "false"))+ ###+ end++ def update_item_component(journal, state: :show)+ update_via_turbo_stream(+ component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(+ journal:,+ state:,+ filter: @filter+ )+ )+ end++ def generate_time_based_update_streams(last_update_timestamp)# TODO: prototypical implementationjournals = @work_package.journals@@@ -252,43 -320,14 +352,27 @@@endend+ def generate_time_based_reaction_update_streams(last_update_timestamp)+ # Current limitation: Only shows added reactions, not removed ones+ EmojiReaction+ .where(reactable_id: @work_package.journal_ids)+ .where("updated_at > ?", last_update_timestamp).find_each do |reaction|+ update_via_turbo_stream(+ component: WorkPackages::ActivitiesTab::Journals::ItemComponent::Reactions.new(+ journal: reaction.reactable+ )+ )+ end+ end+- def append_or_prepend_latest_journal_via_turbo_stream(journal, latest_journal, filter)- if latest_journal.created_at.to_date == journal.created_at.to_date- target_component = WorkPackages::ActivitiesTab::Journals::DayComponent.new(- work_package: @work_package,- day_as_date: journal.created_at.to_date,- journals: [journal], # we don't need to pass all actual journals of this day as we do not really render this component- filter:- )- component = WorkPackages::ActivitiesTab::Journals::ItemComponent.new(- journal:,- filter:- )- else- target_component = WorkPackages::ActivitiesTab::Journals::IndexComponent.new(- work_package: @work_package,- filter:- )- component = WorkPackages::ActivitiesTab::Journals::DayComponent.new(- work_package: @work_package,- day_as_date: journal.created_at.to_date,- journals: [journal],- filter:- )- end+ def append_or_prepend_latest_journal_via_turbo_stream(journal)+ target_component = WorkPackages::ActivitiesTab::Journals::IndexComponent.new(+ work_package: @work_package,+ filter: @filter+ )++ component = WorkPackages::ActivitiesTab::Journals::ItemComponent.new(journal:, filter: @filter)+stream_config = {target_component:,component:diff --cc app/models/journal.rbindex 9a62e756eee,d393198b913..25faa15ce05--- a/app/models/journal.rb+++ b/app/models/journal.rb@@@ -34,32 -34,29 +34,30 @@@ class Journal < ApplicationRecorinclude ::JournalFormatterinclude ::Acts::Journalized::FormatHooksinclude Journal::Timestamps+ include Reactable- register_journal_formatter :diff, OpenProject::JournalFormatter::Diff- register_journal_formatter :attachment, OpenProject::JournalFormatter::Attachment- register_journal_formatter :custom_field, OpenProject::JournalFormatter::CustomField- register_journal_formatter :schedule_manually, OpenProject::JournalFormatter::ScheduleManually- register_journal_formatter :ignore_non_working_days, OpenProject::JournalFormatter::IgnoreNonWorkingDays- register_journal_formatter :active_status, OpenProject::JournalFormatter::ActiveStatus- register_journal_formatter :project_status_code, OpenProject::JournalFormatter::ProjectStatusCode- register_journal_formatter :template, OpenProject::JournalFormatter::Template- register_journal_formatter :visibility, OpenProject::JournalFormatter::Visibility- register_journal_formatter :subproject_named_association, OpenProject::JournalFormatter::SubprojectNamedAssociation- register_journal_formatter :time_entry_hours, OpenProject::JournalFormatter::TimeEntryHours- register_journal_formatter :wiki_diff, OpenProject::JournalFormatter::WikiDiff- register_journal_formatter :time_entry_named_association, OpenProject::JournalFormatter::TimeEntryNamedAssociation- register_journal_formatter :cause, OpenProject::JournalFormatter::Cause- register_journal_formatter :file_link, OpenProject::JournalFormatter::FileLink- register_journal_formatter :meeting_start_time, OpenProject::JournalFormatter::MeetingStartTime- register_journal_formatter :agenda_item_position, OpenProject::JournalFormatter::AgendaItemPosition- register_journal_formatter :agenda_item_duration, OpenProject::JournalFormatter::AgendaItemDuration- register_journal_formatter :agenda_item_diff, OpenProject::JournalFormatter::AgendaItemDiff- register_journal_formatter :agenda_item_title, OpenProject::JournalFormatter::AgendaItemTitle- register_journal_formatter :meeting_work_package_id, OpenProject::JournalFormatter::MeetingWorkPackageId- register_journal_formatter :meeting_state, OpenProject::JournalFormatter::MeetingState- register_journal_formatter :agenda_item_diff, OpenProject::JournalFormatter::AgendaItemDiff- register_journal_formatter :agenda_item_title, OpenProject::JournalFormatter::AgendaItemTitle+ register_journal_formatter OpenProject::JournalFormatter::ActiveStatus+ register_journal_formatter OpenProject::JournalFormatter::AgendaItemDiff+ register_journal_formatter OpenProject::JournalFormatter::AgendaItemDuration+ register_journal_formatter OpenProject::JournalFormatter::AgendaItemPosition+ register_journal_formatter OpenProject::JournalFormatter::AgendaItemTitle+ register_journal_formatter OpenProject::JournalFormatter::Attachment+ register_journal_formatter OpenProject::JournalFormatter::Cause+ register_journal_formatter OpenProject::JournalFormatter::CustomField+ register_journal_formatter OpenProject::JournalFormatter::Diff+ register_journal_formatter OpenProject::JournalFormatter::FileLink+ register_journal_formatter OpenProject::JournalFormatter::IgnoreNonWorkingDays+ register_journal_formatter OpenProject::JournalFormatter::MeetingStartTime+ register_journal_formatter OpenProject::JournalFormatter::MeetingState+ register_journal_formatter OpenProject::JournalFormatter::MeetingWorkPackageId+ register_journal_formatter OpenProject::JournalFormatter::ProjectStatusCode+ register_journal_formatter OpenProject::JournalFormatter::ScheduleManually+ register_journal_formatter OpenProject::JournalFormatter::SubprojectNamedAssociation+ register_journal_formatter OpenProject::JournalFormatter::Template+ register_journal_formatter OpenProject::JournalFormatter::TimeEntryHours+ register_journal_formatter OpenProject::JournalFormatter::TimeEntryNamedAssociation+ register_journal_formatter OpenProject::JournalFormatter::Visibility+ register_journal_formatter OpenProject::JournalFormatter::WikiDiff# Attributes related to the cause are stored in a JSONB column so we can easily add new relations and related# attributes without a heavy database migration. Fields will be prefixed with `cause_` but are stored in the JSONBdiff --cc config/initializers/permissions.rbindex 0cd1ac18b7d,4860440a10d..75038efbb15--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@@ -244,7 -255,8 +255,8 @@@ Rails.application.reloader.to_prepare d{# FIXME: Although the endpoint is removed, the code checking whether a user# is eligible to add work packages through the API still seems to rely on this.- journals: [:new]+ journals: [:new],- "work_packages/activities_tab": %i[create]++ "work_packages/activities_tab": %i[create toggle_reaction]},permissible_on: %i[work_package project],dependencies: :view_work_packages