Skip to content

Commit

Permalink
Merge pull request #16627 from opf/implementation/57579-define-add-pr…
Browse files Browse the repository at this point in the history
…ojects-dialog-for-multi-project-activation

Implementation/57579 define custom fields add projects dialog for multi project activation
  • Loading branch information
akabiru authored Sep 11, 2024
2 parents 8261bc8 + 179829e commit 8b9987d
Show file tree
Hide file tree
Showing 23 changed files with 834 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ See COPYRIGHT and LICENSE files for more details.
<%=
component_wrapper do
primer_form_with(
class: "op-new-project-mapping-form",
model: @project_mapping,
url: link_admin_settings_project_custom_field_path(@project_custom_field),
model: ,
url:,
data: { turbo: true },
method: :post
) do |form|
concat(render(Primer::Alpha::Dialog::Body.new(
id: DIALOG_BODY_ID, test_selector: DIALOG_BODY_ID, aria: { label: title },
id: dialog_body_id, test_selector: dialog_body_id, aria: { label: title },
style: "min-height: 300px"
)) do
render(Projects::CustomFields::CustomFieldMappingForm.new(form, project_mapping: @project_mapping))
render(Projects::CustomFields::CustomFieldMappingForm.new(form, project_mapping: @custom_field_project_mapping))
end)

concat(render(Primer::Alpha::Dialog::Footer.new(show_divider: false)) do
concat(render(Primer::ButtonComponent.new(data: { 'close-dialog-id': DIALOG_ID })) { cancel_button_text })
concat(render(Primer::ButtonComponent.new(data: { 'close-dialog-id': dialog_id })) { cancel_button_text })
concat(render(Primer::ButtonComponent.new(scheme: :primary, type: :submit)) { submit_button_text })
end)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#-- 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 Admin
module CustomFields
module CustomFieldProjects
class NewCustomFieldProjectsFormModalComponent < ApplicationComponent
include OpTurbo::Streamable

DIALOG_ID = "new-custom-field-projects-modal".freeze
DIALOG_BODY_ID = "new-custom-field-projects-modal-body".freeze

def initialize(custom_field_project_mapping:, custom_field:, **)
@custom_field_project_mapping = custom_field_project_mapping
@custom_field = custom_field

super(@custom_field_project_mapping, **)
end

private

def url
url_helpers.custom_field_projects_path(@custom_field)
end

def dialog_id = DIALOG_ID
def dialog_body_id = DIALOG_BODY_ID

attr_reader :custom_field_project_mapping, :custom_field

def title
I18n.t(:label_add_projects)
end

def cancel_button_text
I18n.t("button_cancel")
end

def submit_button_text
I18n.t("button_add")
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%=
render(
Primer::Alpha::Dialog.new(
id: dialog_id,
title:,
test_selector: dialog_id,
size: :large
)
) do |dialog|
dialog.with_header(
show_divider: false,
visually_hide_title: false,
variant: :large
)

render(form_modal_component)
end
%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#-- 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 Admin
module CustomFields
module CustomFieldProjects
class NewCustomFieldProjectsModalComponent < ApplicationComponent
include OpTurbo::Streamable

def initialize(custom_field_project_mapping:, custom_field:, **)
@custom_field_project_mapping = custom_field_project_mapping
@custom_field = custom_field
super(@custom_field_project_mapping, **)
end

def render?
!custom_field.is_for_all?
end

private

attr_reader :custom_field_project_mapping, :custom_field

def dialog_id = NewCustomFieldProjectsFormModalComponent::DIALOG_ID
def dialog_body_id = NewCustomFieldProjectsFormModalComponent::DIALOG_BODY_ID

def title
I18n.t(:label_add_projects)
end

def form_modal_component
Admin::CustomFields::CustomFieldProjects::NewCustomFieldProjectsFormModalComponent.new(
custom_field_project_mapping:, custom_field:
)
end
end
end
end
end

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,18 @@
module Settings
module ProjectCustomFields
module ProjectCustomFieldMapping
class NewProjectMappingComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include OpTurbo::Streamable

def initialize(project_mapping:, project_custom_field:, **)
@project_mapping = project_mapping
@project_custom_field = project_custom_field
super(@project_mapping, **)
end

class NewProjectMappingComponent < Admin::CustomFields::CustomFieldProjects::NewCustomFieldProjectsModalComponent
def render?
!@project_custom_field.required?
!custom_field.required?
end

private

def title
I18n.t(:label_add_projects)
def form_modal_component
Settings::ProjectCustomFields::ProjectCustomFieldMapping::NewProjectMappingFormComponent.new(
custom_field_project_mapping:,
custom_field:
)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,11 @@
module Settings
module ProjectCustomFields
module ProjectCustomFieldMapping
class NewProjectMappingFormComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include OpTurbo::Streamable

DIALOG_ID = "settings--new-project-custom-field-mapping-component".freeze
DIALOG_BODY_ID = "settings--new-project-custom-field-mapping-body-component".freeze

def initialize(project_mapping:, project_custom_field:)
super
@project_mapping = project_mapping
@project_custom_field = project_custom_field
end

class NewProjectMappingFormComponent < Admin::CustomFields::CustomFieldProjects::NewCustomFieldProjectsFormModalComponent
private

def title
I18n.t(:label_add_projects)
end

def cancel_button_text
I18n.t("button_cancel")
end

def submit_button_text
I18n.t("button_add")
def url
url_helpers.link_admin_settings_project_custom_field_path(@custom_field)
end
end
end
Expand Down
52 changes: 52 additions & 0 deletions app/contracts/custom_fields/custom_field_projects/base_contract.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#-- 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 CustomFields
module CustomFieldProjects
class BaseContract < ::ModelContract
attribute :project_id
attribute :custom_field_id

validate :select_custom_fields_permission
validate :not_for_all

def select_custom_fields_permission
return if user.allowed_in_project?(:select_custom_fields, model.project)

errors.add :base, :error_unauthorized
end

def not_for_all
# Only mappings of custom fields which are not enabled for all projects can be manipulated by the user
return if model.custom_field.nil? || !model.custom_field.is_for_all?

errors.add :custom_field_id, :is_for_all_cannot_modify
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#-- 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 CustomFields
module CustomFieldProjects
class UpdateContract < BaseContract
end
end
end
Loading

0 comments on commit 8b9987d

Please sign in to comment.