Add PIR status

This commit is contained in:
Oliver Günther
2025-11-26 10:46:44 +01:00
parent 977c65ab3b
commit 88c7c66fa4
5 changed files with 244 additions and 12 deletions
@@ -1,7 +1,18 @@
<% if artifact_id %>
<% if artifact_work_package %>
<% end %>
<% else %>
<%= render Primer::Beta::Text.new(tag: :p, font_weight: :bold) { t("settings.project_initiation_request.status.not_completed") } %>
<%= render Primer::Beta::Text.new { t("settings.project_initiation_request.status.not_completed_description") } %>
<%= render(Primer::Beta::Text.new(tag: :p, font_weight: :bold)) { @status_text } %>
<% if @status_explanation %>
<%= render(Primer::Beta::Text.new(tag: :p)) { @status_explanation } %>
<% end %>
<% if artifact_work_package %>
<%= render(Primer::Beta::Button.new(
mt: 2,
tag: :a,
href: project_work_packages_path(project, artifact_work_package),
)) { t("settings.project_initiation_request.status.submitted_button")} %>
<% elsif artifact_id.blank? %>
<%= render(Primer::Beta::Button.new(
mt: 2,
tag: :a,
href: project_creation_wizard_path(project)
)) { t("settings.project_initiation_request.wizard_status_button.#{project.project_creation_wizard_artifact_name}")} %>
<% end %>
@@ -28,11 +28,9 @@
# See COPYRIGHT and LICENSE files for more details.
#++
class Projects::ProjectInitiationStatusComponent < ApplicationComponent
class Projects::CreationWizardStatusComponent < ApplicationComponent
include ApplicationHelper
include OpTurbo::Streamable
include OpPrimer::ComponentHelpers
include ProjectStatusHelper
include ProjectHelper
attr_reader :project, :current_user,
:artifact_id, :artifact_work_package
@@ -42,14 +40,40 @@ class Projects::ProjectInitiationStatusComponent < ApplicationComponent
@project = project
@current_user = current_user
@artifact_id = project.project_creation_wizard_artifact_work_package_id
@artifact_id = project.project_creation_wizard_artifact_work_package_id.presence
@artifact_work_package = find_artifact if artifact_id.present?
end
def before_render
@status_text = set_status_text
@status_explanation = set_status_explanation
end
def render?
project.project_creation_wizard_enabled
end
private
def set_status_text
if artifact_id
t("settings.project_initiation_request.status.submitted",
wizard_name: project_creation_wizard_name(project))
else
t("settings.project_initiation_request.status.not_completed",
wizard_name: project_creation_wizard_name(project))
end
end
def set_status_explanation
if artifact_work_package
t("settings.project_initiation_request.status.submitted_description")
elsif !artifact_id
t("settings.project_initiation_request.status.not_completed_description")
end
end
def find_artifact
WorkPackage.visible.find_by(id:)
WorkPackage.visible.find_by(id: artifact_id)
end
end
+10
View File
@@ -4725,6 +4725,16 @@ en:
description: "Add all the project attributes in a section inside the right side panel in the project overview."
project_initiation_request:
header_description: "OpenProject can generate a step-by-step wizard to help project managers fill out a project initiation request. You can chose which project attributes should be included and what to do with the output document."
status:
submitted: "%{wizard_name} has been submitted"
submitted_description: "Click the button below to go to the work package for the submission process."
submitted_button: "Open submission request"
not_completed: "%{wizard_name} not yet completed"
not_completed_description: "Provide the necessary information by filling the attributes and get the project started."
wizard_status_button:
project_initiation_request: "Open project initiation request"
project_creation_wizard: "Open project creation wizard"
project_mandate: "Open project mandate"
blankslate:
title: "Initiation request not enabled"
description: "OpenProject can generate a step-by-step wizard to help project managers fill out a project initiation request. You can chose which project attributes should be included and what to do with the output document. Enable it here to start configuring the wizard."
@@ -38,6 +38,12 @@ See COPYRIGHT and LICENSE files for more details.
flex.with_row do
format_text(project, :status_explanation)
end
if project.project_creation_wizard_enabled
flex.with_row(mt: 2) do
render(Projects::CreationWizardStatusComponent.new(project:, current_user:))
end
end
end
end
end
@@ -0,0 +1,181 @@
# 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.
#++
require "rails_helper"
RSpec.describe Projects::CreationWizardStatusComponent, type: :component do
include ApplicationHelper
include ProjectHelper
include Rails.application.routes.url_helpers
let(:current_user) { build_stubbed(:user) }
let(:project) { build_stubbed(:project, project_creation_wizard_enabled:, project_creation_wizard_artifact_work_package_id:) }
let(:project_creation_wizard_enabled) { true }
let(:project_creation_wizard_artifact_work_package_id) { nil }
let(:wizard_name) { "Project creation wizard" }
subject(:component) { described_class.new(project:, current_user:) }
describe "#render?" do
context "when project_creation_wizard_enabled is false" do
let(:project_creation_wizard_enabled) { false }
it "returns false" do
expect(component.render?).to be false
end
it "does not render the component" do
rendered = render_inline(component)
expect(rendered.to_s).to be_empty
end
end
context "when project_creation_wizard_enabled is true" do
let(:project_creation_wizard_enabled) { true }
it "returns true" do
expect(component.render?).to be true
end
end
end
describe "rendered status text" do
context "when artifact_id is not present" do
let(:project_creation_wizard_artifact_work_package_id) { nil }
it "renders not_completed status text" do
rendered = render_inline(component)
expected_text = I18n.t("settings.project_initiation_request.status.not_completed", wizard_name:)
expect(rendered.text).to include(expected_text)
end
end
context "when artifact_id is present" do
let(:project_creation_wizard_artifact_work_package_id) { 123 }
before do
allow(WorkPackage).to receive_message_chain(:visible, :find_by).with(id: 123).and_return(nil) # rubocop:disable RSpec/MessageChain
end
it "renders submitted status text" do
rendered = render_inline(component)
expected_text = I18n.t("settings.project_initiation_request.status.submitted", wizard_name:)
expect(rendered.text).to include(expected_text)
end
end
end
describe "rendered status explanation" do
context "when artifact_id is not present" do
let(:project_creation_wizard_artifact_work_package_id) { nil }
it "renders not_completed_description" do
rendered = render_inline(component)
expected_text = I18n.t("settings.project_initiation_request.status.not_completed_description")
expect(rendered.text).to include(expected_text)
end
it "renders a button linking to the project creation wizard" do
rendered = render_inline(component)
expect(rendered).to have_link(href: project_creation_wizard_path(project))
end
end
context "when artifact_work_package is found" do
let(:project_creation_wizard_artifact_work_package_id) { 123 }
let(:work_package) { build_stubbed(:work_package, id: 123) }
before do
allow(WorkPackage).to receive_message_chain(:visible, :find_by).with(id: 123).and_return(work_package) # rubocop:disable RSpec/MessageChain
end
it "renders submitted_description" do
rendered = render_inline(component)
expected_text = I18n.t("settings.project_initiation_request.status.submitted_description")
expect(rendered.text).to include(expected_text)
end
it "sets artifact_work_package" do
expect(component.artifact_work_package).to eq(work_package)
end
it "renders a button linking to the work package" do
rendered = render_inline(component)
expect(rendered).to have_link(href: project_work_packages_path(project, work_package))
end
end
context "when artifact_id is present but work package is not visible" do
let(:project_creation_wizard_artifact_work_package_id) { 123 }
it "does not render submitted_description" do
rendered = render_inline(component)
submitted_text = I18n.t("settings.project_initiation_request.status.submitted_description")
expect(rendered.text).not_to include(submitted_text)
end
it "sets artifact_work_package to nil" do
expect(component.artifact_work_package).to be_nil
end
it "does not render any button" do
rendered = render_inline(component)
expect(rendered).to have_no_link(href: project_creation_wizard_path(project))
expect(rendered).to have_no_css("a[href*='work_packages']")
end
end
end
describe "initialization" do
it "sets project" do
expect(component.project).to eq(project)
end
it "sets current_user" do
expect(component.current_user).to eq(current_user)
end
it "sets artifact_id from project" do
expect(component.artifact_id).to eq(project_creation_wizard_artifact_work_package_id)
end
context "when current_user is not provided" do
subject(:component) { described_class.new(project:) }
before do
allow(User).to receive(:current).and_return(current_user)
end
it "defaults to User.current" do
expect(component.current_user).to eq(current_user)
end
end
end
end