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

enable editing

Jonas Jabaribae03172a7a1
diff --git a/app/components/work_packages/activities_tab/journals/form_component.html.erb b/app/components/work_packages/activities_tab/journals/form_component.html.erb
index c17f19237af..ec4bcd0a4b8 100644
--- a/app/components/work_packages/activities_tab/journals/form_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/form_component.html.erb
@@ -2,7 +2,7 @@
primer_form_with(
id: "work-package-journal-form",
model: journal,
- method: :post,
+ method: method,
data: { turbo: true, turbo_stream: true },
url: submit_path,
) do |f|
@@ -12,15 +12,7 @@
end
form_container.with_row(flex_layout: true, mt: 3, justify_content: :flex_end) do |submit_container|
submit_container.with_column(mr: 2) do
- render(Primer::Beta::Button.new(
- scheme: :default,
- size: :medium,
- data: {
- "action": "click->work-packages--activities-tab--new#hideForm"
- }
- )) do
- render(Primer::Beta::Text.new()) { I18n.t("button_cancel") }
- end
+ cancel_button
end
submit_container.with_column do
render(WorkPackages::ActivitiesTab::Journals::Submit.new(f))
diff --git a/app/components/work_packages/activities_tab/journals/form_component.rb b/app/components/work_packages/activities_tab/journals/form_component.rb
index 25525fcd28c..4159f5f6a46 100644
--- a/app/components/work_packages/activities_tab/journals/form_component.rb
+++ b/app/components/work_packages/activities_tab/journals/form_component.rb
@@ -33,14 +33,42 @@ module WorkPackages
include ApplicationHelper
include OpPrimer::ComponentHelpers
- def initialize(journal:, submit_path:)
+ def initialize(journal:, submit_path:, cancel_path: nil)
super
@journal = journal
@submit_path = submit_path
+ @cancel_path = cancel_path
+ @method = journal.new_record? ? :post : :put
end
- attr_reader :journal, :submit_path
+ private
+
+ attr_reader :journal, :submit_path, :cancel_path, :method
+
+ def cancel_button
+ if cancel_path
+ render(Primer::Beta::Button.new(
+ scheme: :secondary,
+ size: :medium,
+ tag: :a,
+ href: cancel_path,
+ data: { "turbo-stream": true }
+ )) do
+ t("button_cancel")
+ end
+ else
+ render(Primer::Beta::Button.new(
+ scheme: :default,
+ size: :medium,
+ data: {
+ action: "click->work-packages--activities-tab--new#hideForm"
+ }
+ )) do
+ I18n.t("button_cancel")
+ end
+ end
+ end
end
end
end
diff --git a/app/components/work_packages/activities_tab/journals/index_component.html.erb b/app/components/work_packages/activities_tab/journals/index_component.html.erb
index c31a60b7d8b..cac5cbf0c04 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
@@ -4,7 +4,7 @@
journals.each do |journal|
journals_index_container.with_row do
render(
- WorkPackages::ActivitiesTab::Journals::ShowComponent.new(journal:)
+ WorkPackages::ActivitiesTab::Journals::ItemComponent.new(journal:)
)
end
end
diff --git a/app/components/work_packages/activities_tab/journals/show_component.html.erb b/app/components/work_packages/activities_tab/journals/item_component.html.erb
similarity index 70%
rename from app/components/work_packages/activities_tab/journals/show_component.html.erb
rename to app/components/work_packages/activities_tab/journals/item_component.html.erb
index 387bcd99864..0ebcf162efb 100644
--- a/app/components/work_packages/activities_tab/journals/show_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/item_component.html.erb
@@ -1,22 +1,22 @@
<%=
component_wrapper(data: wrapper_data_attributes) do
- render(Primer::Box.new(id: "activity-#{@journal.version}", border: true, border_radius: 2, p: 3, my: 2)) do
+ render(Primer::Box.new(id: "activity-#{journal.version}", border: true, border_radius: 2, p: 3, my: 2)) do
flex_layout do |journal_container|
journal_container.with_row(flex_layout: true, align_items: :center, justify_content: :space_between) do |header_container|
header_container.with_column(flex_layout: true) do |header_start_container|
header_start_container.with_column(mr: 2) do
- render Users::AvatarComponent.new(user: @journal.user, show_name: false)
+ render Users::AvatarComponent.new(user: journal.user, show_name: false)
end
header_start_container.with_column(flex_layout: true) do |header_text_container|
header_text_container.with_row do
render(Primer::Beta::Link.new(
- href: user_url(@journal.user),
+ href: user_url(journal.user),
target: "_blank",
scheme: :primary,
underline: false,
font_weight: :bold
)) do
- @journal.user.name
+ journal.user.name
end
end
header_text_container.with_row(flex_layout: true) do |header_text_timestamp_container|
@@ -30,7 +30,7 @@
end
end
header_text_timestamp_container.with_column do
- render(Primer::Beta::Text.new(color: :subtle, mt: 1, font_size: :small)) { format_time(@journal.updated_at) }
+ render(Primer::Beta::Text.new(color: :subtle, mt: 1, font_size: :small)) { format_time(journal.updated_at) }
end
end
end
@@ -44,7 +44,7 @@
font_size: :small,
data: { turbo: false }
)) do
- "##{@journal.version}"
+ "##{journal.version}"
end
end
header_end_container.with_column(ml: 2) do
@@ -58,21 +58,8 @@
end
end
end
- if @journal.notes.present?
- journal_container.with_row(mt: 3) do
- render(Primer::Box.new(mt: 1)) do
- format_text(@journal, :notes)
- end
- end
- end
- if @journal.details.any? && @journal.version != 1
- journal_container.with_row(flex_layout: true, border_radius: 2, p: 3, my: 3, bg: :subtle) do |details_container|
- @journal.details.each do |detail|
- details_container.with_row(mt: 1, font_size: :small) do
- render(Primer::Beta::Text.new) { @journal.render_detail(detail) }
- end
- end
- end
+ journal_container.with_row do
+ content
end
end
end
diff --git a/app/components/work_packages/activities_tab/journals/show_component.rb b/app/components/work_packages/activities_tab/journals/item_component.rb
similarity index 67%
rename from app/components/work_packages/activities_tab/journals/show_component.rb
rename to app/components/work_packages/activities_tab/journals/item_component.rb
index bad947775f7..bbca942ec0c 100644
--- a/app/components/work_packages/activities_tab/journals/show_component.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component.rb
@@ -29,57 +29,67 @@
module WorkPackages
module ActivitiesTab
module Journals
- class ShowComponent < ApplicationComponent
+ class ItemComponent < ApplicationComponent
include ApplicationHelper
- include AvatarHelper
- include JournalFormatter
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(journal:)
+ def initialize(journal:, state: :show)
super
@journal = journal
+ @state = state
+ end
+
+ def content
+ case state
+ when :show
+ render(WorkPackages::ActivitiesTab::Journals::ItemComponent::Show.new(**child_component_params))
+ when :edit
+ render(WorkPackages::ActivitiesTab::Journals::ItemComponent::Edit.new(**child_component_params))
+ end
end
private
+ attr_reader :journal, :state
+
def wrapper_uniq_by
- @journal.id
+ journal.id
+ end
+
+ def child_component_params
+ { journal: }.compact
end
def wrapper_data_attributes
{
- controller: "work-packages--activities-tab--show",
+ controller: "work-packages--activities-tab--item",
"application-target": "dynamic",
- "work-packages--activities-tab--show-activity-url-value": activity_url
+ "work-packages--activities-tab--item-activity-url-value": activity_url
}
end
def activity_url
- "#{project_work_package_url(@journal.journable.project, @journal.journable)}/activity#{activity_anchor}"
+ "#{project_work_package_url(journal.journable.project, journal.journable)}/activity#{activity_anchor}"
end
def activity_anchor
- "#activity-#{@journal.version}"
- end
-
- def data_type
- @journal.data_type
+ "#activity-#{journal.version}"
end
def editable?
- @journal.user == User.current
+ journal.user == User.current
end
def initial_version?
- @journal.version == 1
+ journal.version == 1
end
def updated?
return false if initial_version?
- @journal.updated_at - @journal.created_at > 5.seconds
+ journal.updated_at - journal.created_at > 5.seconds
end
def copy_url_action_item(menu)
@@ -87,7 +97,7 @@ module WorkPackages
tag: :button,
content_arguments: {
data: {
- action: "click->work-packages--activities-tab--show#copyActivityUrlToClipboard"
+ action: "click->work-packages--activities-tab--item#copyActivityUrlToClipboard"
}
}) do |item|
item.with_leading_visual_icon(icon: :copy)
@@ -95,19 +105,10 @@ module WorkPackages
end
def edit_action_item(menu)
- # menu.with_item(label: t("label_edit"),
- # href: edit_work_package_activity_path(@journal.journable, @journal),
- # content_arguments: {
- # data: { "turbo-stream": true }
- # }) do |item|
- # item.with_leading_visual_icon(icon: :pencil)
- # end
menu.with_item(label: t("label_edit"),
- tag: :button,
+ href: edit_work_package_activity_path(journal.journable, journal),
content_arguments: {
- data: {
- action: "click->work-packages--activities-tab--show#edit"
- }
+ data: { "turbo-stream": true }
}) do |item|
item.with_leading_visual_icon(icon: :pencil)
end
diff --git a/app/components/work_packages/activities_tab/journals/item_component/edit.html.erb b/app/components/work_packages/activities_tab/journals/item_component/edit.html.erb
new file mode 100644
index 00000000000..41ccbab3dc7
--- /dev/null
+++ b/app/components/work_packages/activities_tab/journals/item_component/edit.html.erb
@@ -0,0 +1,13 @@
+<%=
+ component_wrapper do
+ render(Primer::Box.new(mt: 3)) do
+ render(
+ WorkPackages::ActivitiesTab::Journals::FormComponent.new(
+ journal:,
+ submit_path: work_package_activity_path(work_package_id: work_package.id, id: journal.id),
+ cancel_path: cancel_edit_work_package_activity_path(work_package.id, id: journal.id)
+ )
+ )
+ end
+ end
+%>
diff --git a/app/components/work_packages/activities_tab/journals/item_component/edit.rb b/app/components/work_packages/activities_tab/journals/item_component/edit.rb
new file mode 100644
index 00000000000..8bf22a5f7a8
--- /dev/null
+++ b/app/components/work_packages/activities_tab/journals/item_component/edit.rb
@@ -0,0 +1,54 @@
+#-- 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.
+#++
+
+module WorkPackages
+ module ActivitiesTab
+ module Journals
+ class ItemComponent::Edit < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ def initialize(journal:)
+ super
+
+ @journal = journal
+ @work_package = journal.journable
+ end
+
+ private
+
+ attr_reader :journal, :work_package
+
+ def wrapper_uniq_by
+ journal.id
+ end
+ end
+ end
+ end
+end
diff --git 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
new file mode 100644
index 00000000000..a45b3637707
--- /dev/null
+++ b/app/components/work_packages/activities_tab/journals/item_component/show.html.erb
@@ -0,0 +1,24 @@
+<%=
+ component_wrapper do
+ if journal.notes.present? || (journal.details.any? && journal.version != 1)
+ flex_layout do |journal_container|
+ if journal.notes.present?
+ journal_container.with_row(mt: 3) do
+ render(Primer::Box.new(mt: 1)) do
+ format_text(journal, :notes)
+ end
+ end
+ end
+ if journal.details.any? && journal.version != 1
+ journal_container.with_row(flex_layout: true, border_radius: 2, p: 3, my: 3, bg: :subtle) do |details_container|
+ journal.details.each do |detail|
+ details_container.with_row(mt: 1, font_size: :small) do
+ render(Primer::Beta::Text.new) { journal.render_detail(detail) }
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+%>
diff --git a/app/components/work_packages/activities_tab/journals/item_component/show.rb b/app/components/work_packages/activities_tab/journals/item_component/show.rb
new file mode 100644
index 00000000000..a461cd5e43e
--- /dev/null
+++ b/app/components/work_packages/activities_tab/journals/item_component/show.rb
@@ -0,0 +1,55 @@
+#-- 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.
+#++
+
+module WorkPackages
+ module ActivitiesTab
+ module Journals
+ class ItemComponent::Show < ApplicationComponent
+ include ApplicationHelper
+ include AvatarHelper
+ include JournalFormatter
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ def initialize(journal:)
+ super
+
+ @journal = journal
+ end
+
+ private
+
+ attr_reader :journal
+
+ def wrapper_uniq_by
+ journal.id
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index 2d801d4df11..1ca6b6bfd6b 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -33,6 +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]
before_action :authorize
def index
@@ -55,6 +56,29 @@ class WorkPackages::ActivitiesTabController < ApplicationController
respond_with_turbo_streams
end
+ def edit
+ # check if allowed to edit at all
+ update_via_turbo_stream(
+ component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
+ journal: @journal,
+ state: :edit
+ )
+ )
+
+ respond_with_turbo_streams
+ end
+
+ def cancel_edit
+ update_via_turbo_stream(
+ component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
+ journal: @journal,
+ state: :show
+ )
+ )
+
+ respond_with_turbo_streams
+ end
+
def create
latest_journal_version = @work_package.journals.last.try(:version) || 0
@@ -71,6 +95,24 @@ class WorkPackages::ActivitiesTabController < ApplicationController
respond_with_turbo_streams
end
+ def update
+ call = Journals::UpdateService.new(model: @journal, user: User.current).call(
+ notes: journal_params[:notes]
+ )
+
+ if call.success? && call.result
+ update_via_turbo_stream(
+ component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
+ journal: call.result,
+ state: :show
+ )
+ )
+ end
+ # TODO: handle errors
+
+ respond_with_turbo_streams
+ end
+
private
def find_work_package
@@ -81,6 +123,10 @@ class WorkPackages::ActivitiesTabController < ApplicationController
@project = @work_package.project
end
+ def find_journal
+ @journal = Journal.find(params[:id])
+ end
+
def journal_sorting
User.current.preference&.comments_sorting || "desc"
end
@@ -104,7 +150,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
target_component: WorkPackages::ActivitiesTab::Journals::IndexComponent.new(
work_package: @work_package
),
- component: WorkPackages::ActivitiesTab::Journals::ShowComponent.new(
+ component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
journal:
)
}
@@ -119,7 +165,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
def update_journal_via_turbo_stream(journal)
update_via_turbo_stream(
- component: WorkPackages::ActivitiesTab::Journals::ShowComponent.new(journal:)
+ component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(journal:)
)
end
diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rb
index 67611c5970a..54d3881a66e 100644
--- a/config/initializers/permissions.rb
+++ b/config/initializers/permissions.rb
@@ -187,7 +187,7 @@ Rails.application.reloader.to_prepare do
work_packages: %i[show index],
work_packages_api: [:get],
"work_packages/reports": %i[report report_details],
- "work_packages/activities_tab": %i[index create journal_streams]
+ "work_packages/activities_tab": %i[index create journal_streams edit cancel_edit update]
},
permissible_on: %i[work_package project],
contract_actions: { work_packages: %i[read] }
diff --git a/config/routes.rb b/config/routes.rb
index c5d6cc885b9..14c973551b8 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -528,7 +528,10 @@ Rails.application.routes.draw do
end
end
- resources :activities, controller: "work_packages/activities_tab", only: %i[index create edit] do
+ resources :activities, controller: "work_packages/activities_tab", only: %i[index create edit update] do
+ member do
+ get :cancel_edit
+ end
collection do
get :journal_streams
end
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/show.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/item.controller.ts
similarity index 93%
rename from frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/show.controller.ts
rename to frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/item.controller.ts
index 047c04efe70..e4e11764d28 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/show.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/item.controller.ts
@@ -30,7 +30,7 @@
import { Controller } from '@hotwired/stimulus';
-export default class ShowController extends Controller {
+export default class ItemController extends Controller {
static values = {
activityUrl: String,
};
@@ -40,8 +40,4 @@ export default class ShowController extends Controller {
async copyActivityUrlToClipboard() {
await navigator.clipboard.writeText(this.activityUrlValue);
}
-
- edit() {
- alert('Not yet implemented');
- }
}