Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[43913] [wiki] Be able to link work-package views (#12204)

Svenee7db0f6bdb6
diff --git a/docs/user-guide/wiki/README.md b/docs/user-guide/wiki/README.md
index b67c7f4aded..6fd543725fa 100644
--- a/docs/user-guide/wiki/README.md
+++ b/docs/user-guide/wiki/README.md
@@ -108,22 +108,32 @@ In some resources such as work packages or comments, the editor does not exhibit
## Links to OpenProject resources
-As with the textile formatting syntax, you can link to other resources within OpenProject using the same shortcuts as before. Create links to a:
-
- wiki page: [[Wiki page]]
- wiki page with separate link name: [[Wiki page|The text of the link]]
- wiki page in the Sandbox project: [[Sandbox:Wiki page]]
- work package with ID12: #12
- version by ID or name: version#3, version:"Release 1.0.0"
- project by ID/name: project#12 , project:"My project name"
- attachment by filename: attachment:filename.zip
- user by id or login: user#4 , user:"johndoe"
+As with the textile formatting syntax, you can link to other resources within OpenProject using the same shortcuts as before. Create links to:
+
+ a wiki page: [[Wiki page]]
+ a wiki page with separate link name: [[Wiki page|The text of the link]]
+ a wiki page in the Sandbox project: [[Sandbox:Wiki page]]
+
+ a work package with ID12: #12
+ a work package with ID234: view#12
+ the default work package view: view:default
+
+ a version by ID or name: version#3, version:"Release 1.0.0"
+ a project by ID/name: project#12 , project:"My project name"
+ an attachment by filename: attachment:filename.zip
+ a user by id or login: user#4 , user:"johndoe"
a forum message by ID: message#1218
- repository revision 43: r43
- commit by hash: commit:f30e13e4
- To a source file in the repository: source:"some/file"
+ a repository revision 43: r43
+ a commit by hash: commit:f30e13e4
+ a source file in the repository: source:"some/file"
-To avoid processing these items, precede them with a bang ! character such as !#12 will prevent linking to a work package with ID 12.
+You can always prefix these links with a project identifier followed by a colon in order to reference resources from projects other than the one of the current wiki page:
+
+ my-project:view:default
+
+To avoid processing these items, precede them with a bang ! character such as !#12 will prevent linking to a work package with ID 12:
+
+ Wiki systems contain all the answers !#42
### Autocompletion for work packages
diff --git a/lib/open_project/object_linking.rb b/lib/open_project/object_linking.rb
index 5571ec3b769..c8fc0fc3072 100644
--- a/lib/open_project/object_linking.rb
+++ b/lib/open_project/object_linking.rb
@@ -90,6 +90,13 @@ module OpenProject
link_to(h(text), url_opts, html_options)
end
+ # Generates a link to a query
+ def link_to_query(query, options = {}, html_options = nil)
+ text = h(query.name)
+ url = project_work_packages_url([query.project.id], only_path: options.delete(:only_path) { true }, query_id: query.id)
+ link_to(text, url, html_options)
+ end
+
# Generates a link to a message
def link_to_message(message, options = {}, html_options = nil)
link_to(
diff --git a/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb b/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb
index c01dc021198..95c0a3bcbd2 100644
--- a/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb
+++ b/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb
@@ -30,7 +30,7 @@ module OpenProject::TextFormatting::Matchers
module LinkHandlers
class ColonSeparator < Base
def self.allowed_prefixes
- %w(commit source export version project user attachment document meeting)
+ %w(commit source export version project user attachment document meeting view)
end
##
@@ -170,6 +170,16 @@ module OpenProject::TextFormatting::Matchers
class: 'meeting'
end
end
+
+ # view is the user-facing name of work package queries
+ # query is the technical/internal name of the concept
+ def render_view
+ if oid == 'default'
+ link_to 'Work packages',
+ { controller: 'work_packages', action: 'index', project_id: project.id },
+ class: 'query'
+ end
+ end
end
end
end
diff --git a/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb b/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb
index 82bb7ddab18..45b0566c174 100644
--- a/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb
+++ b/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb
@@ -30,7 +30,7 @@ module OpenProject::TextFormatting::Matchers
module LinkHandlers
class HashSeparator < Base
def self.allowed_prefixes
- %w(version message project user group document meeting)
+ %w(version message project user group document meeting view)
end
##
@@ -120,6 +120,18 @@ module OpenProject::TextFormatting::Matchers
class: 'user-mention')
end
end
+
+ # view is the user-facing name of work package queries
+ # query is the technical/internal name of the concept
+ def render_view
+ query = Query.find_by(id: oid)
+
+ if query
+ link_to_query(query,
+ { only_path: context[:only_path] },
+ class: 'query')
+ end
+ end
end
end
end
diff --git a/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb b/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb
index 9869b85df61..70c98cd5020 100644
--- a/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb
+++ b/spec/lib/open_project/text_formatting/markdown/in_tool_links_spec.rb
@@ -177,6 +177,55 @@ describe OpenProject::TextFormatting,
end
end
+ context 'Query link' do
+ let!(:query) do
+ create(:query,
+ name: 'project plan with milestones',
+ project:)
+ end
+ let(:query_link) do
+ link_to(
+ 'project plan with milestones',
+ project_work_packages_path([query.project.id], query_id: query.id),
+ class: 'query op-uc-link'
+ )
+ end
+
+ context 'Link with query id' do
+ subject { format_text("view##{query.id}") }
+
+ it { is_expected.to be_html_eql("<p class='op-uc-p'>#{query_link}</p>") }
+ end
+
+ context 'Escaping link with view id' do
+ subject { format_text("!view##{query.id}") }
+
+ it { is_expected.to be_html_eql("<p class='op-uc-p'>view##{query.id}</p>") }
+ end
+ end
+
+ context 'Default work package query link' do
+ let(:default_query_link) do
+ link_to(
+ 'Work packages',
+ project_work_packages_path([project.id]),
+ class: 'query op-uc-link'
+ )
+ end
+
+ context 'Link to default work package query' do
+ subject { format_text("view:default") }
+
+ it { is_expected.to be_html_eql("<p class='op-uc-p'>#{default_query_link}</p>") }
+ end
+
+ context 'Escaping link to default work package query' do
+ subject { format_text("!view:default") }
+
+ it { is_expected.to be_html_eql("<p class='op-uc-p'>view:default</p>") }
+ end
+ end
+
context 'Message links' do
let(:forum) { create(:forum, project:) }
let(:message1) { create(:message, forum:) }