-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[#74366] Adapt PDF exports for semantic identifiers #23093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
judithroth
wants to merge
4
commits into
dev
Choose a base branch
from
feature/74366-adapt-pdf-export-for-semantic-identifiers
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e3453db
[#74366] Adapt PDF exports for semantic identifiers
judithroth 15647fe
[#74366] Adapt regular PDF export description contents for semantic i…
judithroth b26b1ef
[#74366] Adapt Contract PDF export for semantic identifiers
judithroth f8c29e8
[#74366] Adapt PDF gantt report for semantic identifiers
judithroth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,63 @@ | ||
| # 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 Exports::PDF::Common::WorkPackageMentions | ||
| include Redmine::I18n | ||
|
|
||
| def expand_wp_mention(work_package, content) | ||
| detail_level = content.count("#") | ||
| return work_package.formatted_id if detail_level == 1 | ||
|
|
||
| # ##: {Type} {formatted_id}: {Subject} | ||
| content = "#{work_package.type} #{work_package.formatted_id}: #{work_package.subject}" | ||
| return content if detail_level == 2 | ||
|
|
||
| # ###: {Status} {Type} {formatted_id}: {Subject} ({Start Date} - {End Date}) | ||
| "#{work_package.status.name} #{content}#{work_package_dates(work_package)}" | ||
| end | ||
|
|
||
| def work_package_dates(work_package) | ||
| return "" if work_package.start_date.blank? && work_package.due_date.blank? | ||
|
|
||
| if work_package.due_date.present? && work_package.start_date == work_package.due_date | ||
| return " (#{format_date(work_package.due_date)})" | ||
| end | ||
|
|
||
| work_package_date_range(work_package) | ||
| end | ||
|
|
||
| def work_package_date_range(work_package) | ||
| content = [ | ||
| work_package.start_date.present? ? format_date(work_package.start_date) : I18n.t("label_no_start_date"), | ||
| work_package.due_date.present? ? format_date(work_package.due_date) : I18n.t("label_no_due_date") | ||
| ].join(" - ") | ||
| " (#{content})" | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
108 changes: 108 additions & 0 deletions
108
spec/models/exports/pdf/common/markdown/md2_pdf_export_spec.rb
This file contains hidden or 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,108 @@ | ||
| # 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 "spec_helper" | ||
|
|
||
| RSpec.describe Exports::PDF::Common::Markdown::MD2PDFExport do | ||
| let(:exporter) { described_class.allocate } | ||
| let(:type) { build_stubbed(:type, name: "Bug") } | ||
| let(:status) { build_stubbed(:status, name: "In Progress") } | ||
| let(:work_package) do | ||
| build_stubbed(:work_package, type:, status:, subject: "Fix login") | ||
| end | ||
|
|
||
| describe "#wp_mention_macro" do | ||
| let(:admin) { create(:admin) } | ||
| let(:wp) { create(:work_package) } | ||
|
|
||
| before do | ||
| User.current = admin | ||
| end | ||
|
|
||
| context "in classic mode", | ||
| with_flag: { semantic_work_package_ids: false } do | ||
| it "generates a link URL with the numeric id" do | ||
| result = exporter.wp_mention_macro("##{wp.id}", wp.id.to_s, {}) | ||
| expect(result.first[:link]).to include(wp.id.to_s) | ||
| end | ||
| end | ||
|
|
||
| context "in semantic mode", | ||
| with_flag: { semantic_work_package_ids: true }, | ||
| with_settings: { work_packages_identifier: "semantic" } do | ||
| it "generates a link URL with the semantic identifier" do | ||
| result = exporter.wp_mention_macro("##{wp.id}", wp.id.to_s, {}) | ||
| expect(result.first[:link]).to include(wp.identifier) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "#expand_wp_mention" do | ||
| context "in classic mode", with_settings: { work_packages_identifier: "classic" } do | ||
| it "returns formatted_id for level 1" do | ||
| expect(exporter.expand_wp_mention(work_package, "##{work_package.id}")) | ||
| .to eq("##{work_package.id}") | ||
| end | ||
|
|
||
| it "uses formatted_id in level 2 expansion" do | ||
| result = exporter.expand_wp_mention(work_package, "###{work_package.id}") | ||
| expect(result).to eq("Bug ##{work_package.id}: Fix login") | ||
| end | ||
|
|
||
| it "uses formatted_id in level 3 expansion" do | ||
| allow(exporter).to receive(:work_package_dates).with(work_package).and_return("") | ||
| result = exporter.expand_wp_mention(work_package, "####{work_package.id}") | ||
| expect(result).to eq("In Progress Bug ##{work_package.id}: Fix login") | ||
| end | ||
| end | ||
|
|
||
| context "in semantic mode", | ||
| with_flag: { semantic_work_package_ids: true }, | ||
| with_settings: { work_packages_identifier: "semantic" } do | ||
| before { work_package.identifier = "PROJ-42" } | ||
|
|
||
| it "returns semantic formatted_id for level 1" do | ||
| expect(exporter.expand_wp_mention(work_package, "##{work_package.id}")) | ||
| .to eq("PROJ-42") | ||
| end | ||
|
|
||
| it "uses semantic formatted_id in level 2 expansion" do | ||
| result = exporter.expand_wp_mention(work_package, "###{work_package.id}") | ||
| expect(result).to eq("Bug PROJ-42: Fix login") | ||
| end | ||
|
|
||
| it "uses semantic formatted_id in level 3 expansion" do | ||
| allow(exporter).to receive(:work_package_dates).with(work_package).and_return("") | ||
| result = exporter.expand_wp_mention(work_package, "####{work_package.id}") | ||
| expect(result).to eq("In Progress Bug PROJ-42: Fix login") | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.