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

split form into seperate fields

Klaus Zanders7b65984c1962
diff --git a/modules/costs/app/components/time_entries/activity_form.rb b/modules/costs/app/components/time_entries/activity_form.rb
new file mode 100644
index 00000000000..7096d40528d
--- /dev/null
+++ b/modules/costs/app/components/time_entries/activity_form.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+#-- 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 TimeEntries
+ class ActivityForm < ApplicationForm
+ form do |f|
+ f.autocompleter(
+ name: :activity_id,
+ label: TimeEntry.human_attribute_name(:activity),
+ required: false,
+ include_blank: true,
+ autocomplete_options: {
+ focusDirectly: false,
+ multiple: false,
+ decorated: true,
+ append_to: "#time-entry-dialog"
+ }
+ ) do |select|
+ activities.each do |activity|
+ select.option(value: activity.id, label: activity.name, selected: (model.activity_id == activity.id))
+ end
+ end
+ end
+
+ private
+
+ delegate :project, to: :model
+
+ def activities
+ return [] if project.blank?
+
+ TimeEntryActivity.active_in_project(project)
+ end
+ end
+end
diff --git a/modules/costs/app/components/time_entries/comments_form.rb b/modules/costs/app/components/time_entries/comments_form.rb
new file mode 100644
index 00000000000..6a6a0afb757
--- /dev/null
+++ b/modules/costs/app/components/time_entries/comments_form.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+#-- 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 TimeEntries
+ class CommentsForm < ApplicationForm
+ form do |f|
+ f.text_area name: :comments, label: TimeEntry.human_attribute_name(:comments)
+ end
+ end
+end
diff --git a/modules/costs/app/components/time_entries/custom_fields_form.rb b/modules/costs/app/components/time_entries/custom_fields_form.rb
new file mode 100644
index 00000000000..739bbb78809
--- /dev/null
+++ b/modules/costs/app/components/time_entries/custom_fields_form.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+
+#-- 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 TimeEntries
+ class CustomFieldsForm < ApplicationForm
+ include CustomFields::CustomFieldRendering
+
+ form do |f|
+ render_custom_fields(form: f)
+ end
+
+ def additional_custom_field_input_arguments
+ { wrapper_id: "#time-entry-dialog" }
+ end
+
+ private
+
+ def custom_fields
+ @custom_fields ||= model.available_custom_fields
+ end
+ end
+end
diff --git a/modules/costs/app/components/time_entries/days_and_hours_form.rb b/modules/costs/app/components/time_entries/days_and_hours_form.rb
new file mode 100644
index 00000000000..c4a42b78832
--- /dev/null
+++ b/modules/costs/app/components/time_entries/days_and_hours_form.rb
@@ -0,0 +1,89 @@
+# frozen_string_literal: true
+
+#-- 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 TimeEntries
+ class DaysAndHoursForm < ApplicationForm
+ delegate :project, to: :model
+
+ form do |f|
+ f.single_date_picker name: :spent_on,
+ type: "date",
+ required: true,
+ datepicker_options: { inDialog: true },
+ value: model.spent_on&.iso8601,
+ label: TimeEntry.human_attribute_name(:spent_on)
+
+ if show_start_and_end_time_fields?
+ f.group(layout: :horizontal) do |g|
+ g.text_field name: :start_time,
+ type: "time",
+ required: true,
+ label: TimeEntry.human_attribute_name(:start_time),
+ value: model.start_timestamp&.strftime("%H:%M"),
+ data: {
+ "time-entry-target" => "startTimeInput",
+ "action" => "input->time-entry#timeInputChanged"
+ }
+
+ g.text_field name: :end_time,
+ type: "time",
+ required: true,
+ label: TimeEntry.human_attribute_name(:end_time),
+ value: model.end_timestamp&.strftime("%H:%M"),
+ data: {
+ "time-entry-target" => "endTimeInput",
+ "action" => "input->time-entry#timeInputChanged"
+ }
+ end
+ end
+
+ f.text_field name: :hours,
+ required: true,
+ label: TimeEntry.human_attribute_name(:hours),
+ value: hours_value,
+ data: { "time-entry-target" => "hoursInput",
+ "action" => "blur->time-entry#hoursChanged keypress.enter->time-entry#hoursKeyEnterPress" }
+ end
+
+ private
+
+ def show_start_and_end_time_fields?
+ TimeEntry.can_track_start_and_end_time?
+ end
+
+ def hours_value
+ if model.hours.present?
+ ChronicDuration.output(model.hours * 3600, format: :hours_only)
+ else
+ ""
+ end
+ end
+ end
+end
diff --git a/modules/costs/app/components/time_entries/time_entry_form.rb b/modules/costs/app/components/time_entries/time_entry_form.rb
deleted file mode 100644
index 44e6a9d44fc..00000000000
--- a/modules/costs/app/components/time_entries/time_entry_form.rb
+++ /dev/null
@@ -1,138 +0,0 @@
-module TimeEntries
- class TimeEntryForm < ApplicationForm
- include CustomFields::CustomFieldRendering
-
- form do |f|
- f.autocompleter(
- name: :user_id,
- id: "time_entry_user_id",
- label: TimeEntry.human_attribute_name(:user),
- required: true,
- autocomplete_options: {
- defaultData: true,
- hiddenFieldAction: "change->time-entry#userChanged",
- component: "opce-user-autocompleter",
- url: ::API::V3::Utilities::PathHelper::ApiV3Path.principals,
- filters: user_completer_filter_options,
- searchKey: "any_name_attribute",
- resource: "principals",
- focusDirectly: false,
- multiple: false,
- appendTo: "#time-entry-dialog",
- disabled: !show_user_field?
- }
- )
-
- f.single_date_picker name: :spent_on,
- type: "date",
- required: true,
- datepicker_options: { inDialog: true },
- value: model.spent_on&.iso8601,
- label: TimeEntry.human_attribute_name(:spent_on)
-
- if show_start_and_end_time_fields?
- f.group(layout: :horizontal) do |g|
- g.text_field name: :start_time,
- type: "time",
- required: true,
- label: TimeEntry.human_attribute_name(:start_time),
- value: model.start_timestamp&.strftime("%H:%M"),
- data: {
- "time-entry-target" => "startTimeInput",
- "action" => "input->time-entry#timeInputChanged"
- }
-
- g.text_field name: :end_time,
- type: "time",
- required: true,
- label: TimeEntry.human_attribute_name(:end_time),
- value: model.end_timestamp&.strftime("%H:%M"),
- data: {
- "time-entry-target" => "endTimeInput",
- "action" => "input->time-entry#timeInputChanged"
- }
- end
- end
-
- f.text_field name: :hours,
- required: true,
- label: TimeEntry.human_attribute_name(:hours),
- value: model.hours.present? ? ChronicDuration.output(model.hours * 3600, format: :hours_only) : "",
- data: { "time-entry-target" => "hoursInput",
- "action" => "blur->time-entry#hoursChanged keypress.enter->time-entry#hoursKeyEnterPress" }
-
- f.work_package_autocompleter name: :work_package_id,
- label: TimeEntry.human_attribute_name(:work_package),
- required: true,
- autocomplete_options: {
- focusDirectly: false,
- append_to: "#time-entry-dialog",
- filters: [
- { name: "project_id", operator: "=", values: [model.project_id] }
- ]
- }
-
- f.autocompleter(
- name: :activity_id,
- label: TimeEntry.human_attribute_name(:activity),
- required: false,
- include_blank: true,
- autocomplete_options: {
- focusDirectly: false,
- multiple: false,
- decorated: true,
- append_to: "#time-entry-dialog"
- }
- ) do |select|
- activities.each do |activity|
- select.option(value: activity.id, label: activity.name, selected: (model.activity_id == activity.id))
- end
- end
-
- f.text_area name: :comments, label: TimeEntry.human_attribute_name(:comments)
-
- render_custom_fields(form: f)
- end
-
- def additional_custom_field_input_arguments
- { wrapper_id: "#time-entry-dialog" }
- end
-
- private
-
- delegate :project, :work_package, to: :model
-
- def custom_fields
- @custom_fields ||= model.available_custom_fields
- end
-
- def show_user_field?
- # Only allow setting a different user, when the user has the
- # permission to log time for others in the project
- User.current.allowed_in_project?(:log_time, project)
- end
-
- def show_start_and_end_time_fields?
- TimeEntry.can_track_start_and_end_time?
- end
-
- def activities
- return [] if project.blank?
-
- TimeEntryActivity.active_in_project(project)
- end
-
- def user_completer_filter_options
- filters = [
- { name: "type", operator: "=", values: %w[User Group] },
- { name: "status", operator: "=", values: [Principal.statuses[:active], Principal.statuses[:invited]] }
- ]
-
- if model.project_id
- filters << { name: "member", operator: "=", values: [model.project_id] }
- end
-
- filters
- end
- end
-end
diff --git a/modules/costs/app/components/time_entries/time_entry_form_component.html.erb b/modules/costs/app/components/time_entries/time_entry_form_component.html.erb
index aa48dfc426c..51f396438dc 100644
--- a/modules/costs/app/components/time_entries/time_entry_form_component.html.erb
+++ b/modules/costs/app/components/time_entries/time_entry_form_component.html.erb
@@ -23,14 +23,19 @@ 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.
+ See COPYRIGHT and LICENSE files for more details.
-++#%>
+ ++# %>
-<%=
- component_wrapper do
+ <%= component_wrapper do
primer_form_with(**form_options) do |form|
- render(TimeEntries::TimeEntryForm.new(form))
- end
+ flex_layout do |body|
+ body.with_row(mb: 3) { render(TimeEntries::UserForm.new(form)) }
+ body.with_row(mb: 3) { render(TimeEntries::DaysAndHoursForm.new(form)) }
+ body.with_row(mb: 3) { render(TimeEntries::WorkPackageForm.new(form)) }
+ body.with_row(mb: 3) { render(TimeEntries::ActivityForm.new(form)) }
+ body.with_row(mb: 3) { render(TimeEntries::CommentsForm.new(form)) }
+ body.with_row(mb: 3) { render(TimeEntries::CustomFieldsForm.new(form)) }
end
-%>
+ end
+ end %>
diff --git a/modules/costs/app/components/time_entries/user_form.rb b/modules/costs/app/components/time_entries/user_form.rb
new file mode 100644
index 00000000000..5869292959a
--- /dev/null
+++ b/modules/costs/app/components/time_entries/user_form.rb
@@ -0,0 +1,80 @@
+# frozen_string_literal: true
+
+#-- 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 TimeEntries
+ class UserForm < ApplicationForm
+ form do |f|
+ if show_user_field?
+ f.autocompleter(
+ name: :user_id,
+ id: "time_entry_user_id",
+ label: TimeEntry.human_attribute_name(:user),
+ required: true,
+ autocomplete_options: {
+ defaultData: true,
+ hiddenFieldAction: "change->time-entry#userChanged",
+ component: "opce-user-autocompleter",
+ url: ::API::V3::Utilities::PathHelper::ApiV3Path.principals,
+ filters: user_completer_filters,
+ searchKey: "any_name_attribute",
+ resource: "principals",
+ focusDirectly: false,
+ multiple: false,
+ appendTo: "#time-entry-dialog",
+ disabled: !show_user_field?
+ }
+ )
+ end
+ end
+
+ private
+
+ delegate :project, to: :model
+
+ def show_user_field?
+ # Only allow setting a different user, when the user has the
+ # permission to log time for others in the project
+ User.current.allowed_in_project?(:log_time, project)
+ end
+
+ def user_completer_filters
+ filters = [
+ { name: "type", operator: "=", values: %w[User Group] },
+ { name: "status", operator: "=", values: [Principal.statuses[:active], Principal.statuses[:invited]] }
+ ]
+
+ if model.project_id
+ filters << { name: "member", operator: "=", values: [model.project_id] }
+ end
+
+ filters
+ end
+ end
+end
diff --git a/modules/costs/app/components/time_entries/work_package_form.rb b/modules/costs/app/components/time_entries/work_package_form.rb
new file mode 100644
index 00000000000..ee840affc25
--- /dev/null
+++ b/modules/costs/app/components/time_entries/work_package_form.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+#-- 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 TimeEntries
+ class WorkPackageForm < ApplicationForm
+ form do |f|
+ f.work_package_autocompleter name: :work_package_id,
+ label: TimeEntry.human_attribute_name(:work_package),
+ required: true,
+ autocomplete_options: {
+ focusDirectly: false,
+ append_to: "#time-entry-dialog",
+ filters: work_package_completer_filters
+ }
+ end
+
+ private
+
+ def work_package_completer_filters
+ filters = []
+
+ if model.project_id
+ filters << { name: "project_id", operator: "=", values: [model.project_id] }
+ end
+
+ filters
+ end
+ end
+end