Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/components/custom_fields/details_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ class DetailsComponent < ApplicationComponent

def form_url
if model.new_record?
model.type == "ProjectCustomField" ? admin_settings_project_custom_fields_path : custom_fields_path
case model.type
when "ProjectCustomField" then admin_settings_project_custom_fields_path
when "UserCustomField" then admin_settings_user_custom_fields_path
else custom_fields_path
end
else
model.type == "ProjectCustomField" ? admin_settings_project_custom_field_path(model) : custom_field_path(model)
case model.type
when "ProjectCustomField" then admin_settings_project_custom_field_path(model)
when "UserCustomField" then admin_settings_user_custom_field_path(model)
else custom_field_path(model)
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
{
model: @project_custom_field_section,
method: @project_custom_field_section.persisted? ? :put : :post,
url: @project_custom_field_section.persisted? ? admin_settings_project_custom_field_section_path(@project_custom_field_section) : admin_settings_project_custom_field_sections_path
url: @project_custom_field_section.persisted? ? admin_settings_project_custom_field_section_path(@project_custom_field_section) : admin_settings_project_custom_field_sections_path,

Check notice on line 54 in app/components/settings/project_custom_field_sections/dialog_body_form_component.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/components/settings/project_custom_field_sections/dialog_body_form_component.rb#L54 <Layout/LineLength>

Line is too long. [190/130]
Raw output
app/components/settings/project_custom_field_sections/dialog_body_form_component.rb:54:131: C: Layout/LineLength: Line is too long. [190/130]
data: { turbo_stream: true }
}
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Primer::Alpha::Dialog.new(
title: t("settings.project_attributes.label_new_section"),
size: :medium_portrait,
id: MODAL_ID
id: MODAL_ID,
data: { "keep-open-on-submit": true }
)
) do %>
<%= render(Settings::ProjectCustomFieldSections::DialogBodyFormComponent.new) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
render(
Primer::Alpha::Dialog.new(
id: "project-custom-field-section-dialog#{@project_custom_field_section.id}", title: t("settings.project_attributes.label_new_section"),
size: :medium_portrait
size: :medium_portrait,
data: { "keep-open-on-submit": true }
)
) do |_dialog|
render(Settings::ProjectCustomFieldSections::DialogBodyFormComponent.new(project_custom_field_section: @project_custom_field_section))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%=
component_wrapper(class: "op-user-custom-field-container", data: { test_selector: "user-custom-field-container-#{@user_custom_field.id}" }) do
flex_layout(justify_content: :space_between, align_items: :center) do |main_container|
main_container.with_column(flex_layout: true, align_items: :center) do |content_container|
content_container.with_column(mr: 2) do
render(Primer::OpenProject::DragHandle.new(classes: "handle"))
end
content_container.with_column(mr: 2) do
render(
Primer::Beta::Link.new(
href: edit_admin_settings_user_custom_field_path(@user_custom_field),
underline: false,
font_weight: :bold,
data: { turbo: "false" }
)
) do
@user_custom_field.name
end
end
content_container.with_column(mr: 2) do
render(Primer::Beta::Text.new(font_size: :small, color: :subtle)) do
helpers.label_for_custom_field_format(@user_custom_field.field_format)
end
end
if @user_custom_field.required?
content_container.with_column do
render(Primer::Beta::Label.new(scheme: :attention, size: :medium)) do
UserCustomField.human_attribute_name(:required)
end
end
end
end
main_container.with_column do
render(Primer::Alpha::ActionMenu.new(data: { test_selector: "user-custom-field-action-menu" })) do |menu|
menu.with_show_button(icon: "kebab-horizontal", "aria-label": t("settings.user_attributes.label_user_custom_field_actions"), scheme: :invisible)
edit_action_item(menu)
move_actions(menu)
delete_action_item(menu)
end
end
end
end
%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# 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 Settings
module UserCustomFieldSections
class CustomFieldRowComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable

def initialize(user_custom_field:, first_and_last:)
super

@user_custom_field = user_custom_field
@first_and_last = first_and_last
end

private

def edit_action_item(menu)
menu.with_item(label: t("label_edit"),
href: edit_admin_settings_user_custom_field_path(@user_custom_field),
data: { turbo: "false", test_selector: "user-custom-field-edit" }) do |item|
item.with_leading_visual_icon(icon: :pencil)
end
end

def move_actions(menu)
unless first?
move_action_item(menu, :highest, t("label_agenda_item_move_to_top"), "move-to-top")
move_action_item(menu, :higher, t("label_agenda_item_move_up"), "chevron-up")
end
unless last?
move_action_item(menu, :lower, t("label_agenda_item_move_down"), "chevron-down")
move_action_item(menu, :lowest, t("label_agenda_item_move_to_bottom"), "move-to-bottom")
end
end

def move_action_item(menu, move_to, label_text, icon)
menu.with_item(label: label_text,
href: move_admin_settings_user_custom_field_path(@user_custom_field, move_to:),
form_arguments: {
method: :put, data: { "turbo-stream": true, test_selector: "user-custom-field-move-#{move_to}" }
}) do |item|
item.with_leading_visual_icon(icon:)
end
end

def delete_action_item(menu)
menu.with_item(label: t("text_destroy"),
scheme: :danger,
href: admin_settings_user_custom_field_path(@user_custom_field),
form_arguments: {
method: :delete,
data: {
turbo_confirm: t(:text_are_you_sure),
turbo_stream: true,
test_selector: "user-custom-field-delete"
}
}) do |item|
item.with_leading_visual_icon(icon: :trash)
end
end

def first?
@first ||=
if @first_and_last.first
@first_and_last.first == @user_custom_field
else
@user_custom_field.first?
end
end

def last?
@last ||=
if @first_and_last.last
@first_and_last.last == @user_custom_field
else
@user_custom_field.last?
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<%=
component_wrapper do
primer_form_with(**form_config) do |f|
component_collection do |collection|
collection.with_component(Primer::Alpha::Dialog::Body.new) do
render(UserCustomFieldSections::NameForm.new(f))
end

collection.with_component(Primer::Alpha::Dialog::Footer.new) do
component_collection do |modal_footer|
modal_footer.with_component(Primer::Beta::Button.new(data: { "close-dialog-id": "user-custom-field-section-dialog#{@user_custom_field_section.id}" })) do
t("button_cancel")
end

modal_footer.with_component(Primer::Beta::Button.new(scheme: :primary, type: :submit)) do
t("button_save")
end
end
end
end
end
end
%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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 Settings
module UserCustomFieldSections
class DialogBodyFormComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable

def initialize(user_custom_field_section: UserCustomFieldSection.new)
super

@user_custom_field_section = user_custom_field_section
end

private

def wrapper_uniq_by
@user_custom_field_section.id
end

def form_config
{
model: @user_custom_field_section,
method: @user_custom_field_section.persisted? ? :put : :post,
url: @user_custom_field_section.persisted? ? admin_settings_user_custom_field_section_path(@user_custom_field_section) : admin_settings_user_custom_field_sections_path,

Check notice on line 54 in app/components/settings/user_custom_field_sections/dialog_body_form_component.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/components/settings/user_custom_field_sections/dialog_body_form_component.rb#L54 <Layout/LineLength>

Line is too long. [178/130]
Raw output
app/components/settings/user_custom_field_sections/dialog_body_form_component.rb:54:131: C: Layout/LineLength: Line is too long. [178/130]
data: { turbo_stream: true }
}
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%=
component_wrapper(data: wrapper_data_attributes) do
if @user_custom_field_sections.any?
flex_layout(classes: "dragula-container", data: { "allowed-drop-type": "section" }.merge(drop_target_config)) do |flex|
@user_custom_field_sections.each do |section|
flex.with_row(
data: draggable_item_config(section)
) do
render(row_component_class.new(user_custom_field_section: section, first_and_last:))
end
end
end
end
end
%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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 Settings
module UserCustomFieldSections
class IndexComponent < ApplicationComponent
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable

def initialize(user_custom_field_sections:)
super

@user_custom_field_sections = user_custom_field_sections
end

def row_component_class
Settings::UserCustomFieldSections::ShowComponent
end

def first_and_last
[@user_custom_field_sections.first, @user_custom_field_sections.last]
end

private

def wrapper_data_attributes
{
controller: "generic-drag-and-drop"
}
end

def drop_target_config
{
generic_drag_and_drop_target: "container",
"target-allowed-drag-type": "section"
}
end

def draggable_item_config(section)
{
"draggable-id": section.id,
"draggable-type": "section",
"drop-url": drop_admin_settings_user_custom_field_section_path(section)
}
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%= render(
Primer::Alpha::Dialog.new(
title: t("settings.user_attributes.label_new_section"),
size: :medium_portrait,
id: MODAL_ID,
data: { "keep-open-on-submit": true }
)
) do %>
<%= render(Settings::UserCustomFieldSections::DialogBodyFormComponent.new) %>
<% end %>
Loading
Loading