Skip to content

Commit

Permalink
Add body to the dialog and build a form
Browse files Browse the repository at this point in the history
  • Loading branch information
klaustopher committed Nov 28, 2024
1 parent f5be3dc commit 7ba1c80
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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 %>
4 changes: 4 additions & 0 deletions modules/costs/app/components/time_entries/time_entry_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module TimeEntries
class TimeEntryForm < ApplicationForm
end
end
Original file line number Diff line number Diff line change
@@ -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
%>
Original file line number Diff line number Diff line change
@@ -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
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%= turbo_stream.dialog do
render(TimeEntries::EntryDialogComponent.new(time_entry: @entry))
render(TimeEntries::EntryDialogComponent.new(time_entry: @time_entry))
end %>

0 comments on commit 7ba1c80

Please sign in to comment.