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
Add body to the dialog and build a form
Klaus Zanderse4ca72f172e1
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.erbindex 81c48c76136..aa1e7808f0a 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@@ -1,6 +1,5 @@<%= render(Primer::Alpha::Dialog.new(title: 'Log Time', size: :large, id: MODAL_ID)) do |d| %><% d.with_header(variant: :large, mb: 3) %>- <%= d.with_body do %>- <h1>Hello, World!</h1>- <% end %>+ <%- pp(time_entry) %>+ <%= render(TimeEntries::TimeEntryFormComponent.new(time_entry: time_entry)) %><% end %>diff --git a/modules/costs/app/components/time_entries/time_entry_form.rb b/modules/costs/app/components/time_entries/time_entry_form.rbnew file mode 100644index 00000000000..695f0d27ab0--- /dev/null+++ b/modules/costs/app/components/time_entries/time_entry_form.rb@@ -0,0 +1,4 @@+module TimeEntries+ class TimeEntryForm < ApplicationForm+ end+enddiff --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.erbnew file mode 100644index 00000000000..e81e59cee2c--- /dev/null+++ b/modules/costs/app/components/time_entries/time_entry_form_component.html.erb@@ -0,0 +1,71 @@+<%#-- 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.++++#%>++<%=+ component_wrapper do+ primer_form_with(**form_options) do |form|+ component_collection do |collection|+ collection.with_component(Primer::Alpha::Dialog::Body.new(+ aria: { label: I18n.t("my.access_token.new_access_token_dialog_title") }+ )) do+ flex_layout(my: 3) do |body|+ body.with_row do+ render(Primer::Alpha::Banner.new(scheme: :warning)) do+ I18n.t("my.access_token.new_access_token_dialog_attention_text")+ end+ end++ body.with_row(mt: 3) do+ render(Primer::Beta::Text.new(tag: :p)) do+ I18n.t("my.access_token.new_access_token_dialog_text")+ end+ end++ body.with_row do+ content_tag(:pre, time_entry.pretty_inspect)+ # render(My::AccessToken::NewAccessTokenForm.new(form))+ end+ end+ end++ collection.with_component(Primer::Alpha::Dialog::Footer.new) do+ component_collection do |footer|+ footer.with_component(Primer::ButtonComponent.new(data: { 'close-dialog-id': "time-entry-dialog" })) do+ I18n.t("button_cancel")+ end++ footer.with_component(Primer::ButtonComponent.new(scheme: :primary, type: :submit, test_selector: "create-api-token-button")) do+ I18n.t("my.access_token.new_access_token_dialog_submit_button_text")+ end+ end+ end+ end+ end+ end+%>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.rbnew file mode 100644index 00000000000..365c3c669e5--- /dev/null+++ b/modules/costs/app/components/time_entries/time_entry_form_component.rb@@ -0,0 +1,81 @@+# 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 TimeEntryFormComponent < ApplicationComponent+ include OpTurbo::Streamable+ include OpPrimer::ComponentHelpers++ def initialize(time_entry:)+ super()+ @time_entry = time_entry+ end++ private++ attr_reader :time_entry++ delegate :project, :work_package, to: :time_entry++ def show_work_package_field?+ work_package.blank?+ 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 form_options+ base = {+ model: time_entry,+ data: { turbo: true }+ }++ if time_entry.persisted?+ base.merge({+ url: project_time_entry_path(project, time_entry),+ method: :post+ })+ else++ base.merge({+ url: project_time_entries_path(project),+ method: :post+ })+ end+ end+ end+enddiff --git a/modules/costs/app/views/projects/time_entries/dialog.turbo_stream.erb b/modules/costs/app/views/projects/time_entries/dialog.turbo_stream.erbindex d3773dd67c9..bf0c4569978 100644--- a/modules/costs/app/views/projects/time_entries/dialog.turbo_stream.erb+++ b/modules/costs/app/views/projects/time_entries/dialog.turbo_stream.erb@@ -1,3 +1,3 @@<%= turbo_stream.dialog do- render(TimeEntries::EntryDialogComponent.new(time_entry: @entry))+ render(TimeEntries::EntryDialogComponent.new(time_entry: @time_entry))end %>