Skip to content

Commit

Permalink
add form and new/edit actions
Browse files Browse the repository at this point in the history
  • Loading branch information
toy committed Dec 10, 2024
1 parent 2255c17 commit 401a0d8
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<%#-- 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.
++#%>

<% html_title t(:label_administration),
t("settings.project_life_cycle_step_definitions.heading"),
t("settings.project_life_cycle_step_definitions.#{heading_scope}.heading") %>

<%= component_wrapper do
render Primer::OpenProject::PageHeader.new do |header|
header.with_title { t("settings.project_life_cycle_step_definitions.#{heading_scope}.heading") }
header.with_description { t("settings.project_life_cycle_step_definitions.new.description") }
header.with_breadcrumbs(breadcrumbs_items)
end
end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#-- 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 ProjectLifeCycleStepDefinitions
class FormHeaderComponent < ApplicationComponent
include ApplicationHelper
include MetaTagsHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable

def heading_scope
action = model.persisted? ? :edit : :new

type = model.is_a?(Project::StageDefinition) ? :stage : :gate

"#{action}_#{type}"
end

def breadcrumbs_items
[
{ href: admin_index_path, text: t("label_administration") },
{ href: admin_settings_project_custom_fields_path, text: t("label_project_plural") },
{ href: admin_settings_project_life_cycle_step_definitions_path, text: t("settings.project_life_cycle_step_definitions.heading") },

Check notice on line 49 in app/components/settings/project_life_cycle_step_definitions/form_header_component.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] app/components/settings/project_life_cycle_step_definitions/form_header_component.rb#L49 <Layout/LineLength>

Line is too long. [141/130]
Raw output
app/components/settings/project_life_cycle_step_definitions/form_header_component.rb:49:131: C: Layout/LineLength: Line is too long. [141/130]
t("settings.project_life_cycle_step_definitions.#{heading_scope}.heading")
]
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#-- 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::Settings
class ProjectLifeCycleStepDefinitionsController < ::Admin::SettingsController
menu_item :project_life_cycle_step_definitions_settings

before_action :check_feature_flag

before_action :find_definition, only: %i[edit update]

def new_stage
@definition = Project::StageDefinition.new

render :form
end

def new_gate
@definition = Project::GateDefinition.new

render :form
end

def edit
render :form
end

def create
@definition = Project::LifeCycleStepDefinition.new(definition_params)

if @definition.save
flash[:notice] = I18n.t(:notice_successful_create)
redirect_to action: :index
else
render :form, status: :unprocessable_entity
end
end

def update
if @definition.update(definition_params)
flash[:notice] = I18n.t(:notice_successful_update)
redirect_to action: :index
else
render :form, status: :unprocessable_entity
end
end

private

def check_feature_flag
render_404 unless OpenProject::FeatureDecisions.stages_and_gates_active?
end

def find_definition
@definition = Project::LifeCycleStepDefinition.find(params[:id])
end

def definition_params
params.require(:project_life_cycle_step_definition).permit(:type, :name, :color_id)
end
end
end
58 changes: 58 additions & 0 deletions app/forms/projects/life_cycle_step_definitions/form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#-- 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 Projects::LifeCycleStepDefinitions
class Form < ApplicationForm
form do |f|
f.hidden(name: :type) unless model.persisted?

f.text_field(
label: attribute_name(:name),
name: :name,
required: true,
input_width: :medium
)

f.color_select_list(
label: attribute_name(:color),
name: :color,
required: true
)

f.submit(
scheme: :primary,
name: :submit,
label: submit_label
)
end

def submit_label
I18n.t(model.persisted? ? :button_update : :button_create)
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<%#-- 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.
++#%>

<%= render Settings::ProjectLifeCycleStepDefinitions::FormHeaderComponent.new(@definition) %>

<%= error_messages_for @definition %>

<%=
primer_form_with(
model: [:admin, :settings, @definition.becomes(Project::LifeCycleStepDefinition)]
) do |f|
render Projects::LifeCycleStepDefinitions::Form.new(f)
end
%>
13 changes: 13 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,9 @@ en:
project_custom_field:
is_required: "Required for all projects"
custom_field_section: Section
project/life_cycle_step_definition:
name: "Name"
color: "Color"
query:
column_names: "Columns"
relations_to_type_column: "Relations to %{type}"
Expand Down Expand Up @@ -3704,6 +3707,16 @@ en:
label_add_description: "Add lifecycle definition"
label_add_stage: "Stage"
label_add_gate: "Gate"
new:
description: "Changes to this project step will be reflected in all projects where it is enabled."
new_stage:
heading: "New stage"
new_gate:
heading: "New gate"
edit_stage:
heading: "Edit stage"
edit_gate:
heading: "Edit gate"
projects:
missing_dependencies: "Project module %{module} was checked which depends on %{dependencies}. You need to check these dependencies as well."
section_new_projects: "Settings for new projects"
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@
resource :projects, controller: "/admin/settings/projects_settings", only: %i[show update]
resource :new_project, controller: "/admin/settings/new_project_settings", only: %i[show update]
resources :project_life_cycle_step_definitions, controller: "/admin/settings/project_life_cycle_step_definitions",
only: %i[index] do
only: %i[index create edit update] do
collection do
get :new_stage
get :new_gate
Expand Down

0 comments on commit 401a0d8

Please sign in to comment.