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
put prefilling of time entry in a seperate method
Klaus Zanders31110c43c90f
diff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rbindex 370801d2eca..7e5f15ab3d1 100644--- a/modules/costs/app/controllers/time_entries_controller.rb+++ b/modules/costs/app/controllers/time_entries_controller.rb@@ -49,31 +49,7 @@ class TimeEntriesController < ApplicationController@show_user = show_user_input_in_dialog@limit_to_project_id = @project&.id- @time_entry.time_zone = User.current.time_zone.name-- # TODO: Move this into a service-- if params[:date].present?- @time_entry.spent_on = params[:date]- elsif params[:startTime].present? && params[:endTime].present?- parsed_start_time = DateTime.parse(params[:startTime]).in_time_zone(User.current.time_zone)- parsed_end_time = DateTime.parse(params[:endTime]).in_time_zone(User.current.time_zone)-- @time_entry.spent_on = parsed_start_time.to_date-- # full day events have the same start and end time- puts "****", parsed_start_time, parsed_end_time, (parsed_start_time != parsed_end_time), "****"- if parsed_start_time != parsed_end_time- @time_entry.start_time = (parsed_start_time.hour * 60) + parsed_start_time.min- @time_entry.hours = ((parsed_end_time - parsed_start_time) / 1.hour).round(2)- end- else- @time_entry.spent_on ||= Time.zone.today- end-- if params[:removeTime] == "true"- @time_entry.start_time = nil- end+ prefill_time_entry_from_paramsenddef user_tz_caption@@ -155,6 +131,33 @@ class TimeEntriesController < ApplicationControllerprivate+ def prefill_time_entry_from_params # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity+ # correct time calcuation needs a time zone+ @time_entry.time_zone ||= User.current.time_zone.name++ if params[:date].present?+ @time_entry.spent_on = params[:date]+ elsif params[:startTime].present? && params[:endTime].present?+ parsed_start_time = DateTime.parse(params[:startTime]).in_time_zone(User.current.time_zone)+ parsed_end_time = DateTime.parse(params[:endTime]).in_time_zone(User.current.time_zone)++ @time_entry.spent_on = parsed_start_time.to_date++ # FullCalendar sends the same time for start and end if the event is an "all-day event" or+ # in our case "no speicific time"+ if parsed_start_time != parsed_end_time+ @time_entry.start_time = (parsed_start_time.hour * 60) + parsed_start_time.min+ @time_entry.hours = ((parsed_end_time - parsed_start_time) / 1.hour).round(2)+ end+ else+ @time_entry.spent_on ||= Time.zone.today+ end++ if params[:removeTime] == "true"+ @time_entry.start_time = nil+ end+ end+def show_user_input_in_dialogreturn false if params[:onlyMe] == "true"