-
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.
Merge pull request #17223 from opf/implementation/59288-add-stages-an…
…d-gates-to-the-project-overview-page Implementation/59288 add stages and gates to the project overview page
- Loading branch information
Showing
76 changed files
with
2,835 additions
and
127 deletions.
There are no files selected for viewing
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
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
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,79 @@ | ||
#-- 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 ProjectLifeCycleSteps | ||
class BaseContract < ::ModelContract | ||
validate :select_custom_fields_permission | ||
validate :consecutive_steps_have_increasing_dates | ||
|
||
def valid?(context = :saving_life_cycle_steps) | ||
super | ||
end | ||
|
||
def select_custom_fields_permission | ||
return if user.allowed_in_project?(:edit_project_stages_and_gates, model) | ||
|
||
errors.add :base, :error_unauthorized | ||
end | ||
|
||
def consecutive_steps_have_increasing_dates | ||
# Filter out steps with missing dates before proceeding with comparison | ||
filtered_steps = model.available_life_cycle_steps.select(&:start_date) | ||
|
||
# Only proceed with comparisons if there are at least 2 valid steps | ||
return if filtered_steps.size < 2 | ||
|
||
# Compare consecutive steps in pairs | ||
filtered_steps.each_cons(2) do |previous_step, current_step| | ||
if start_date_for(current_step) <= end_date_for(previous_step) | ||
step = previous_step.is_a?(Project::Stage) ? "Stage" : "Gate" | ||
field = current_step.is_a?(Project::Stage) ? :date_range : :date | ||
model.errors.import( | ||
current_step.errors.add(field, :non_continuous_dates, step:), | ||
attribute: :"available_life_cycle_steps.#{field}" | ||
) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def start_date_for(step) | ||
step.start_date | ||
end | ||
|
||
def end_date_for(step) | ||
case step | ||
when Project::Gate | ||
step.date | ||
when Project::Stage | ||
step.end_date || step.start_date # Use the start_date as fallback for single date stages | ||
end | ||
end | ||
end | ||
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,32 @@ | ||
#-- 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 ProjectLifeCycleSteps | ||
class UpdateContract < BaseContract | ||
end | ||
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
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
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,104 @@ | ||
#-- 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::LifeCycles | ||
class Form < ApplicationForm | ||
form do |f| | ||
life_cycle_input(f) | ||
end | ||
|
||
private | ||
|
||
def life_cycle_input(form) | ||
case model | ||
when Project::Stage | ||
multi_value_life_cycle_input(form) | ||
when Project::Gate | ||
single_value_life_cycle_input(form) | ||
else | ||
raise NotImplementedError, "Unknown life cycle definition type #{model.class.name}" | ||
end | ||
end | ||
|
||
def qa_field_name | ||
"life-cycle-step-#{model.id}" | ||
end | ||
|
||
def base_input_attributes | ||
{ | ||
label: "#{icon} #{text}".html_safe, # rubocop:disable Rails/OutputSafety | ||
leading_visual: { icon: :calendar }, | ||
datepicker_options: { | ||
inDialog: true, | ||
data: { action: "change->overview--project-life-cycles-form#handleChange" } | ||
}, | ||
wrapper_data_attributes: { | ||
"qa-field-name": qa_field_name | ||
} | ||
} | ||
end | ||
|
||
def single_value_life_cycle_input(form) | ||
input_attributes = { name: :date, value: model.date } | ||
|
||
form.single_date_picker **base_input_attributes, **input_attributes | ||
end | ||
|
||
def multi_value_life_cycle_input(form) | ||
value = [model.start_date, model.end_date].compact.join(" - ") | ||
|
||
input_attributes = { name: :date_range, value: } | ||
if model.working_days_count | ||
input_attributes[:caption] = | ||
I18n.t("project_stage.working_days_count", count: model.working_days_count) | ||
end | ||
|
||
form.range_date_picker **base_input_attributes, **input_attributes | ||
end | ||
|
||
def text | ||
model.name | ||
end | ||
|
||
def icon | ||
icon_name = case model | ||
when Project::Stage | ||
:"git-commit" | ||
when Project::Gate | ||
:diamond | ||
else | ||
raise NotImplementedError, "Unknown model #{model.class} to render a LifeCycleForm with" | ||
end | ||
|
||
render Primer::Beta::Octicon.new(icon: icon_name, classes: icon_color_class) | ||
end | ||
|
||
def icon_color_class | ||
helpers.hl_inline_class("life_cycle_step_definition", model.definition) | ||
end | ||
end | ||
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
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
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
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
Oops, something went wrong.