-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add body to the dialog and build a form
- Loading branch information
1 parent
f5be3dc
commit 7ba1c80
Showing
5 changed files
with
159 additions
and
4 deletions.
There are no files selected for viewing
5 changes: 2 additions & 3 deletions
5
modules/costs/app/components/time_entries/entry_dialog_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module TimeEntries | ||
class TimeEntryForm < ApplicationForm | ||
end | ||
end |
71 changes: 71 additions & 0 deletions
71
modules/costs/app/components/time_entries/time_entry_form_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
%> |
81 changes: 81 additions & 0 deletions
81
modules/costs/app/components/time_entries/time_entry_form_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 1 addition & 1 deletion
2
modules/costs/app/views/projects/time_entries/dialog.turbo_stream.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |