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
fix form handling
Klaus Zanders858ca5771a4a
diff --git a/modules/costs/app/components/time_entries/time_entry_form.rb b/modules/costs/app/components/time_entries/time_entry_form.rbindex 43242765a04..44e6a9d44fc 100644--- a/modules/costs/app/components/time_entries/time_entry_form.rb+++ b/modules/costs/app/components/time_entries/time_entry_form.rb@@ -117,10 +117,12 @@ module TimeEntriesenddef activities+ return [] if project.blank?+TimeEntryActivity.active_in_project(project)end- def user_autocompleter_filter_options+ def user_completer_filter_optionsfilters = [{ name: "type", operator: "=", values: %w[User Group] },{ name: "status", operator: "=", values: [Principal.statuses[:active], Principal.statuses[:invited]] }diff --git a/modules/costs/app/components/time_entries/time_entry_form_component.rb b/modules/costs/app/components/time_entries/time_entry_form_component.rbindex 648b155980c..0069b5b3186 100644--- a/modules/costs/app/components/time_entries/time_entry_form_component.rb+++ b/modules/costs/app/components/time_entries/time_entry_form_component.rb@@ -53,13 +53,13 @@ module TimeEntriesif time_entry.persisted?base.merge({- url: project_time_entry_path(project, time_entry),+ url: time_entry_path(time_entry),method: :patch})elsebase.merge({- url: project_time_entries_path(project),+ url: time_entries_path,method: :post})enddiff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rbindex a3a71d5f264..2562415d637 100644--- a/modules/costs/app/controllers/time_entries_controller.rb+++ b/modules/costs/app/controllers/time_entries_controller.rb@@ -31,23 +31,30 @@ class TimeEntriesController < ApplicationControllerinclude OpTurbo::DialogStreamHelperbefore_action :require_login- before_action :find_project_by_project_id- authorization_checked! :dialog, :create, :update, :user_caption+ authorization_checked! :dialog, :create, :update, :user_tz_caption, :time_entry_activitiesdef dialog+ if params[:project_id].present?+ @project = begin+ Project.visible.find(params[:project_id])+ rescue ActiveRecord::NotFound+ nil+ end+ end+ @work_package = WorkPackage.visible.find_by(id: params[:work_package_id]) if params[:work_package_id].present?@time_entry = if params[:time_entry_id]# TODO: Properly handle authorizationTimeEntry.find_by(id: params[:time_entry_id])else- TimeEntry.new(project: @project, user: User.current)+ TimeEntry.new(project: @project, work_package: @work_package, user: User.current)endend- def user_caption+ def user_tz_captionuser = User.visible.find_by(id: params[:user_id])caption = if user && user.time_zone != User.current.time_zone- I18n.t("notice_different_time_zones", tz: user.time_zone.name)+ I18n.t("notice_different_time_zones", tz: helpers.friendly_timezone_name(user.time_zone))else""end@@ -58,10 +65,14 @@ class TimeEntriesController < ApplicationControllerrespond_with_turbo_streamsend+ def time_entry_activities+ respond_with_turbo_streams+ end+def createcall = TimeEntries::CreateService.new(user: current_user)- .call(time_entry_params)+ .call(permitted_params.time_entries)@time_entry = call.result@@ -80,7 +91,7 @@ class TimeEntriesController < ApplicationControllercall = TimeEntries::UpdateService.new(user: current_user, model: time_entry)- .call(time_entry_params)+ .call(permitted_params.time_entries)@time_entry = call.result@@ -93,12 +104,4 @@ class TimeEntriesController < ApplicationControllerrespond_with_turbo_streamsendend-- private-- def time_entry_params- permitted_params.time_entries.merge(- project_id: @project.id- )- endenddiff --git a/modules/costs/app/helpers/time_entries_helper.rb b/modules/costs/app/helpers/time_entries_helper.rbnew file mode 100644index 00000000000..c81f79f96ad--- /dev/null+++ b/modules/costs/app/helpers/time_entries_helper.rb@@ -0,0 +1,36 @@+#-- 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 TimeEntriesHelper+ def friendly_timezone_name(time_zone)+ tz_info = time_zone.tzinfo+ friendly_name = ActiveSupport::TimeZone::MAPPING.key(tz_info.canonical_zone.name)++ "(UTC#{ActiveSupport::TimeZone.seconds_to_utc_offset(tz_info.base_utc_offset)}) #{friendly_name}"+ end+enddiff --git a/modules/costs/app/views/projects/time_entries/dialog.turbo_stream.erb b/modules/costs/app/views/time_entries/dialog.turbo_stream.erbsimilarity index 100%rename from modules/costs/app/views/projects/time_entries/dialog.turbo_stream.erbrename to modules/costs/app/views/time_entries/dialog.turbo_stream.erbdiff --git a/modules/costs/config/routes.rb b/modules/costs/config/routes.rbindex de104c70601..451daa5b046 100644--- a/modules/costs/config/routes.rb+++ b/modules/costs/config/routes.rb@@ -29,8 +29,8 @@Rails.application.routes.draw doresources :time_entries, only: %i[create update] doget :dialog, on: :collection- get "users/:user_id/tz_caption", action: :user_caption, on: :collection- get "work_packages/:work_package_id/time_entry_activities", action: :change_activities_input, on: :collection+ get "/users/:user_id/tz_caption", action: :user_tz_caption, on: :collection+ get "/work_packages/:work_package_id/time_entry_activities", action: :change_activities_input, on: :collectionendscope "projects/:project_id", as: "projects" do@@ -39,6 +39,8 @@ Rails.application.routes.draw doresources :hourly_rates, only: %i[show edit update] dopost :set_rate, on: :memberend++ get "/time_entries/dialog" => "time_entries#dialog"endscope "my" do@@ -49,8 +51,6 @@ Rails.application.routes.draw donamespace "settings" doresource :time_entry_activities, only: %i[show update]end-- get "/time_entries/dialog" => "time_entries#dialog"endscope "work_packages/:work_package_id", as: "work_packages" dodiff --git a/modules/overviews/app/views/overviews/overviews/show.html.erb b/modules/overviews/app/views/overviews/overviews/show.html.erbindex ee739585a36..b802b646bea 100644--- a/modules/overviews/app/views/overviews/overviews/show.html.erb+++ b/modules/overviews/app/views/overviews/overviews/show.html.erb@@ -66,20 +66,4 @@endend %>- <%# TEMPORARY # %>- <%- if Rails.env.development? %>- <%= link_to "log time",- dialog_project_time_entries_path(@project),- data: {- controller: "async-dialog",- test_selector: "toggle-log-time-dialog-button",- } %>- <%= link_to "edit log time",- dialog_project_time_entries_path(@project, time_entry_id: TimeEntry.first.id),- data: {- controller: "async-dialog",- test_selector: "toggle-log-time-dialog-button",- } %>- <% end %>-<openproject-base></openproject-base>