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

add the delete button for ongoing time entries Please enter the commit message for your changes. Lines starting

Klaus Zanders4c6f0e9feea5
diff --git a/modules/costs/app/components/time_entries/entry_dialog_component.html.erb b/modules/costs/app/components/time_entries/entry_dialog_component.html.erb
index 5833bcbc83b..f7d09c5bb4e 100644
--- a/modules/costs/app/components/time_entries/entry_dialog_component.html.erb
+++ b/modules/costs/app/components/time_entries/entry_dialog_component.html.erb
@@ -4,6 +4,18 @@
<%= render(TimeEntries::TimeEntryFormComponent.new(time_entry: time_entry, show_user: show_user, show_work_package: show_work_package)) %>
<% end %>
<% d.with_footer(variant: :large) do %>
+ <% if time_entry.ongoing? %>
+ <%= render(Primer::ButtonComponent.new(
+ scheme: :danger,
+ test_selector: "destroy-time-entry-button",
+ data: {
+ "turbo" => true,
+ "turbo-method" => :delete
+ },
+ href: time_entry_path(time_entry),
+ tag: :a
+ )) { t('button_delete') } %>
+ <% end %>
<%= render(Primer::ButtonComponent.new(data: { 'close-dialog-id': "time-entry-dialog" })) { I18n.t("button_cancel") } %>
<%= render(Primer::ButtonComponent.new(scheme: :primary, type: :submit, test_selector: "create-time-entry-button", form: 'time-entry-form')) { t('button_log_time') } %>
<% end %>
diff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rb
index cef4e230288..2964165ba51 100644
--- a/modules/costs/app/controllers/time_entries_controller.rb
+++ b/modules/costs/app/controllers/time_entries_controller.rb
@@ -40,7 +40,7 @@ class TimeEntriesController < ApplicationController
before_action :load_or_build_and_authorize_time_entry
end
- authorization_checked! :dialog, :create, :update, :user_tz_caption, :refresh_form
+ authorization_checked! :dialog, :create, :update, :user_tz_caption, :refresh_form, :destroy
def dialog
@show_work_package = params[:work_package_id].blank?
@@ -117,6 +117,21 @@ class TimeEntriesController < ApplicationController
end
end
+ def destroy
+ time_entry = TimeEntry.find_by(id: params[:id])
+
+ call = TimeEntries::DestroyService.new(user: current_user, model: time_entry).call
+
+ @time_entry = call.result
+
+ unless call.success?
+ form_component = TimeEntries::TimeEntryFormComponent.new(time_entry: @time_entry, **form_config_options)
+ update_via_turbo_stream(component: form_component, status: :bad_request)
+
+ respond_with_turbo_streams
+ end
+ end
+
private
def form_config_options
diff --git a/modules/costs/config/routes.rb b/modules/costs/config/routes.rb
index 47f43e3093a..4dd18a1f3b7 100644
--- a/modules/costs/config/routes.rb
+++ b/modules/costs/config/routes.rb
@@ -29,7 +29,7 @@
#++
Rails.application.routes.draw do
- resources :time_entries, only: %i[create update] do
+ resources :time_entries, only: %i[create update destroy] do
get :dialog, on: :collection
get "/users/:user_id/tz_caption", action: :user_tz_caption, on: :collection
post :refresh_form, on: :collection
diff --git a/modules/costs/spec/features/timer_spec.rb b/modules/costs/spec/features/timer_spec.rb
index 52209da567a..a96f557303f 100644
--- a/modules/costs/spec/features/timer_spec.rb
+++ b/modules/costs/spec/features/timer_spec.rb
@@ -65,13 +65,13 @@ RSpec.describe "Work Package timer", :js do
time_logging_modal.is_visible true
- time_logging_modal.has_field_with_value "spentOn", Date.current.strftime
+ time_logging_modal.has_field_with_value "spent_on", Date.current.strftime
time_logging_modal.has_field_with_value "hours", /(\d\.)?\d+/
time_logging_modal.activity_input_disabled_because_work_package_missing? false
# wait for available_work_packages query to finish before saving
time_logging_modal.expect_work_package(work_package_a.subject)
- time_logging_modal.perform_action "Save"
+ time_logging_modal.submit
time_logging_modal.is_visible false
wp_view_a.expect_and_dismiss_toaster message: I18n.t(:notice_successful_update)
@@ -103,13 +103,13 @@ RSpec.describe "Work Package timer", :js do
page.within(".spot-modal") { click_button "Stop current timer" }
time_logging_modal.is_visible true
- time_logging_modal.has_field_with_value "spentOn", Date.current.strftime
+ time_logging_modal.has_field_with_value "spent_on", Date.current.strftime
time_logging_modal.has_field_with_value "hours", /(\d\.)?\d+/
time_logging_modal.activity_input_disabled_because_work_package_missing? false
# wait for available_work_packages query to finish before saving
time_logging_modal.expect_work_package(work_package_a.subject)
- time_logging_modal.perform_action "Save"
+ time_logging_modal.submit
# Closing the modal starts the next timer
wp_view_b.expect_and_dismiss_toaster message: I18n.t(:notice_successful_update)
@@ -168,26 +168,26 @@ RSpec.describe "Work Package timer", :js do
page.within(".spot-modal") { click_button "Stop current timer" }
time_logging_modal.is_visible true
- time_logging_modal.has_field_with_value "spentOn", Date.current.strftime
+ time_logging_modal.has_field_with_value "spent_on", Date.current.strftime
time_logging_modal.has_field_with_value "hours", /(\d\.)?\d+/
time_logging_modal.activity_input_disabled_because_work_package_missing? false
# wait for available_work_packages query to finish before saving
time_logging_modal.expect_work_package(work_package_a.subject)
- time_logging_modal.perform_action "Save"
+ time_logging_modal.submit
wp_view_b.expect_and_dismiss_toaster message: I18n.t(:notice_successful_update)
time_logging_modal.is_visible false
timer_button.expect_active
timer_button.stop
time_logging_modal.is_visible true
- time_logging_modal.has_field_with_value "spentOn", Date.current.strftime
+ time_logging_modal.has_field_with_value "spent_on", Date.current.strftime
time_logging_modal.has_field_with_value "hours", /(\d\.)?\d+/
time_logging_modal.activity_input_disabled_because_work_package_missing? false
# wait for available_work_packages query to finish before saving
time_logging_modal.expect_work_package(work_package_a.subject)
- time_logging_modal.perform_action "Save"
+ time_logging_modal.submit
wp_view_b.expect_and_dismiss_toaster message: I18n.t(:notice_successful_update)
time_logging_modal.is_visible false
timer_button.expect_inactive
diff --git a/modules/my_page/spec/features/my/time_entries_current_user_spec.rb b/modules/my_page/spec/features/my/time_entries_current_user_spec.rb
index c8905e89d7e..0bf29cc7a28 100644
--- a/modules/my_page/spec/features/my/time_entries_current_user_spec.rb
+++ b/modules/my_page/spec/features/my/time_entries_current_user_spec.rb
@@ -195,15 +195,15 @@ RSpec.describe "My page time entries current user widget spec", :js, :selenium d
time_logging_modal.activity_input_disabled_because_work_package_missing? true
- time_logging_modal.has_field_with_value "spentOn", (Date.current.beginning_of_week(:sunday) + 3.days).strftime
+ time_logging_modal.has_field_with_value "spent_on", (Date.current.beginning_of_week(:sunday) + 3.days).strftime
- time_logging_modal.shows_field "user", false
+ time_logging_modal.shows_field "user_id", false
expect(page)
.to have_no_css(".ng-spinner-loader")
# Expect filtering works
- time_logging_modal.work_package_field.autocomplete work_package.subject, select: false
+ time_logging_modal.update_field "work_package_id", work_package.subject
expect(page).to have_test_selector("op-autocompleter-item-subject", text: work_package.subject)
expect(page).not_to have_test_selector("op-autocompleter-item-subject", text: other_work_package.subject)
diff --git a/spec/features/support/components/time_logging_modal.rb b/spec/features/support/components/time_logging_modal.rb
index 99df8baf158..d8e53c17b8d 100644
--- a/spec/features/support/components/time_logging_modal.rb
+++ b/spec/features/support/components/time_logging_modal.rb
@@ -78,21 +78,23 @@ module Components
def shows_field(field, visible)
within modal_container do
if visible
- expect(page).to have_css "##{field_identifier(field)}"
+ expect(page).to have_field "time_entry_#{field}"
else
- expect(page).to have_no_css "##{field_identifier(field)}"
+ expect(page).to have_no_field "time_entry_#{field}"
end
end
end
def update_field(field_name, value)
- field = field_object field_name
- if field_name == "user"
- field.unset_value
- field.autocomplete value
+ if field_name.in?(["work_package_id", "user_id", "activity_id"])
+ select_autocomplete modal_container.find("#time_entry_#{field_name}"),
+ query: value,
+ select_text: value,
+ results_selector: "#time-entry-dialog"
else
- field.input_element.click
- field.set_value value
+ within modal_container do
+ fill_in "time_entry_#{field_name}", with: value
+ end
end
end
@@ -117,9 +119,10 @@ module Components
def activity_input_disabled_because_work_package_missing?(missing)
if missing
expect(modal_container).to have_field "time_entry_activity_id",
- with: I18n.t("placeholder_activity_select_work_package_first"),
visible: :all,
disabled: true
+
+ expect(modal_container).to have_css(".ng-placeholder", text: I18n.t("placeholder_activity_select_work_package_first"))
else
expect(modal_container).to have_field "time_entry_activity_id",
visible: :all,
diff --git a/spec/features/work_packages/display_fields/spent_time_display_spec.rb b/spec/features/work_packages/display_fields/spent_time_display_spec.rb
index d8388a1eb79..60d2d1d7ea9 100644
--- a/spec/features/work_packages/display_fields/spent_time_display_spec.rb
+++ b/spec/features/work_packages/display_fields/spent_time_display_spec.rb
@@ -47,16 +47,12 @@ RSpec.describe "Logging time within the work package view", :js do
# the fields are visible
time_logging_modal.has_field_with_value "spent_on", Time.zone.today.strftime("%Y-%m-%d")
- time_logging_modal.shows_field "work_package", false
- time_logging_modal.shows_field "user", user_field_visible
+ time_logging_modal.shows_field "work_package_id", false
+ time_logging_modal.shows_field "user_id", user_field_visible
# Update the fields
- time_logging_modal.update_field "activity", activity.name
-
- Components::BasicDatepicker.update_field(
- "##{time_logging_modal.field_identifier('spent_on')}",
- date.strftime("%Y-%m-%d")
- )
+ time_logging_modal.update_field "activity_id", activity.name
+ time_logging_modal.update_field "spent_on", date.strftime("%Y-%m-%d")
if log_for_user
time_logging_modal.update_field "user", log_for_user.name