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

Create basic form dialog

Oliver Günther833026e0ba99
diff --git a/app/components/work_package_relations_tab/index_component.rb b/app/components/work_package_relations_tab/index_component.rb
index 1360895a400..10a51d88c66 100644
--- a/app/components/work_package_relations_tab/index_component.rb
+++ b/app/components/work_package_relations_tab/index_component.rb
@@ -110,7 +110,7 @@ class WorkPackageRelationsTab::IndexComponent < ApplicationComponent
menu.with_item(
label: t("work_package_relations_tab.relations.new_child"),
- href: "#",
+ href: new_project_work_packages_dialog_path(work_package.project),
content_arguments: {
data: { turbo_stream: true }
}
diff --git a/app/components/work_packages/dialogs/create_dialog_component.html.erb b/app/components/work_packages/dialogs/create_dialog_component.html.erb
new file mode 100644
index 00000000000..92a48417a25
--- /dev/null
+++ b/app/components/work_packages/dialogs/create_dialog_component.html.erb
@@ -0,0 +1,37 @@
+<%=
+ render(Primer::Alpha::Dialog.new(
+ id: "create-work-package-dialog",
+ title: I18n.t(:label_work_package_new),
+ size: :xlarge,
+ data: { 'keep-open-on-submit': true }
+ )) do |dialog|
+ dialog.with_header(variant: :large)
+ dialog.with_body do
+ render(WorkPackages::Dialogs::CreateFormComponent.new(work_package:))
+ end
+
+ dialog.with_footer do
+ component_collection do |modal_footer|
+ modal_footer.with_component(
+ Primer::ButtonComponent.new(
+ data: { 'close-dialog-id': "create-work-package-dialog" }
+ )) do
+ I18n.t(:button_cancel)
+ end
+
+ modal_footer.with_component(
+ Primer::ButtonComponent.new(
+ scheme: :primary,
+ form: "create-work-package-form",
+ type: :submit
+ )) do
+ if @work_package.persisted?
+ I18n.t(:button_save)
+ else
+ I18n.t(:button_create)
+ end
+ end
+ end
+ end
+ end
+%>
diff --git a/app/components/work_packages/dialogs/create_dialog_component.rb b/app/components/work_packages/dialogs/create_dialog_component.rb
new file mode 100644
index 00000000000..bb009e10adc
--- /dev/null
+++ b/app/components/work_packages/dialogs/create_dialog_component.rb
@@ -0,0 +1,45 @@
+#-- 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 WorkPackages::Dialogs
+ class CreateDialogComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpenProject::FormTagHelper
+ include OpTurbo::Streamable
+ include OpPrimer::ComponentHelpers
+
+ attr_reader :work_package
+
+ def initialize(work_package:)
+ super
+
+ @work_package = work_package
+ @project = work_package.project
+ end
+ end
+end
diff --git a/app/components/work_packages/dialogs/create_form_component.html.erb b/app/components/work_packages/dialogs/create_form_component.html.erb
new file mode 100644
index 00000000000..1e46b743da5
--- /dev/null
+++ b/app/components/work_packages/dialogs/create_form_component.html.erb
@@ -0,0 +1,25 @@
+<%=
+ component_wrapper do
+ primer_form_with(
+ scope: :work_package,
+ model: @work_package,
+ html: {
+ id: 'create-work-package-form'
+ }
+ ) do |f|
+ flex_layout(mb: 3) do |modal_body|
+ if @work_package.errors[:base].present?
+ modal_body.with_row do
+ render(Primer::Alpha::Banner.new(mb: 3, icon: :stop, scheme: :danger)) { @work_package.errors[:base].join("\n") }
+ end
+ end
+
+ if @project.nil?
+ modal_body.with_row(mt: 3) do
+ render(WorkPackages::Dialogs::CreateForm.new(f, work_package: work_package, wrapper_id: "create-work-package-dialog"))
+ end
+ end
+ end
+ end
+ end
+%>
diff --git a/app/components/work_packages/dialogs/create_form_component.rb b/app/components/work_packages/dialogs/create_form_component.rb
new file mode 100644
index 00000000000..c748d485075
--- /dev/null
+++ b/app/components/work_packages/dialogs/create_form_component.rb
@@ -0,0 +1,43 @@
+#-- 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 WorkPackages::Dialogs
+ class CreateFormComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpTurbo::Streamable
+ include OpPrimer::ComponentHelpers
+
+ attr_reader :work_package
+
+ def initialize(work_package:)
+ super
+
+ @work_package = work_package
+ end
+ end
+end
diff --git a/app/controllers/work_packages/dialogs_controller.rb b/app/controllers/work_packages/dialogs_controller.rb
new file mode 100644
index 00000000000..f2e17578077
--- /dev/null
+++ b/app/controllers/work_packages/dialogs_controller.rb
@@ -0,0 +1,63 @@
+# 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.
+# ++
+
+class WorkPackages::DialogsController < ApplicationController
+ include OpTurbo::ComponentStream
+ include OpTurbo::DialogStreamHelper
+ layout false
+
+ before_action :find_project_by_project_id
+ before_action :build_work_package, only: %i[new]
+ before_action do
+ do_authorize :add_work_packages
+ end
+ authorization_checked! :new
+
+ def new
+ respond_with_dialog WorkPackages::Dialogs::CreateDialogComponent.new(work_package: @work_package)
+ end
+
+ private
+
+ def build_work_package
+ initial = WorkPackage.new(project: @project)
+
+ call = WorkPackages::SetAttributesService
+ .new(model: initial, user: current_user, contract_class: WorkPackages::CreateContract)
+ .call(create_params)
+
+ # Ignore call errors here, as we only want to build the work package
+ @work_package = call.result
+ end
+
+ def create_params
+ params.permit(*PermittedParams.permitted_attributes[:new_work_package])
+ end
+end
diff --git a/app/forms/work_packages/dialogs/create_form.rb b/app/forms/work_packages/dialogs/create_form.rb
new file mode 100644
index 00000000000..f0187592ca8
--- /dev/null
+++ b/app/forms/work_packages/dialogs/create_form.rb
@@ -0,0 +1,69 @@
+# -- 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 WorkPackages::Dialogs
+ class CreateForm < ApplicationForm
+ attr_reader :work_package, :wrapper_id, :contract
+
+ def initialize(work_package:, wrapper_id:)
+ super()
+
+ @work_package = work_package
+ @wrapper_id = wrapper_id
+ @contract = WorkPackages::CreateContract.new(work_package, User.current)
+ end
+
+ form do |f|
+ f.autocompleter(
+ name: :type_id,
+ required: true,
+ include_blank: false,
+ input_width: :small,
+ label: Type.model_name.human,
+ visually_hide_label: true,
+ autocomplete_options: {
+ multiple: false,
+ decorated: true,
+ append_to: "##{wrapper_id}"
+ }
+ ) do |select|
+ contract
+ .assignable_types
+ .pluck(:id, :name)
+ .map { |value, label| select.option(label:, value:) }
+ end
+
+ f.text_field(
+ name: :subject,
+ label: WorkPackage.human_attribute_name(:subject),
+ required: true,
+ input_width: :large
+ )
+ end
+ end
+end
diff --git a/config/routes.rb b/config/routes.rb
index b0ecba6582c..535973e40fe 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -339,12 +339,17 @@ Rails.application.routes.draw do
end
# states managed by client-side routing on work_package#index
- get "(/*state)" => "work_packages#index", on: :collection, as: ""
+ get "(/*state)" => "work_packages#index", on: :collection, as: "", constraints: { state: /(?!(dialog)).+/ }
+
get "/create_new" => "work_packages#index", on: :collection, as: "new_split"
get "/new" => "work_packages#index", on: :collection, as: "new"
# state for show view in project context
- get "(/*state)" => "work_packages#show", on: :member, as: ""
+ get "(/*state)" => "work_packages#show", on: :member, as: "", constraints: { id: /\d+/, state: /(?!(dialog)).+/ }
+ end
+
+ namespace :work_packages do
+ resource :dialog, only: %i[new create]
end
resources :activity, :activities, only: :index, controller: "activities" do