Skip to content

Commit 13cad6e

Browse files
committed
[#73356] show relation page links in the wiki tab
- https://community.openproject.org/work_packages/73356 - add new link group for relation page links - add button for adding links - still disabled - add action menu for link removal - no functionality
1 parent c5d196d commit 13cad6e

8 files changed

Lines changed: 123 additions & 3 deletions

config/locales/en.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,10 +1401,17 @@ en:
14011401
no_results_content_text: Add a new wiki page
14021402

14031403
wikis:
1404+
label_page: "Wiki page"
14041405
inline_page_links_component:
14051406
empty_heading: "No inline links"
14061407
empty_text: "Inline links to wiki pages in the work package description will automatically also show up here."
14071408
heading: "Inline page links"
1409+
page_link_component:
1410+
remove: "Remove page link"
1411+
relation_page_links_component:
1412+
empty_heading: "No related pages"
1413+
empty_text: "Manually add links to other related wiki pages."
1414+
heading: "Related pages"
14081415

14091416
workflows:
14101417
form:
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
<%=
2-
flex_layout(test_selector: "op-custom-fields--hierarchy-item") do |link_container|
2+
flex_layout(
3+
align_items: :center,
4+
test_selector: "op-custom-fields--hierarchy-item"
5+
) do |link_container|
36
link_container.with_column(flex_shrink: 0) do
47
render(Primer::Beta::Octicon.new(icon: :"op-file-doc", mr: 2))
58
end
69

7-
link_container.with_column(classes: "ellipsis") do
10+
link_container.with_column(style: "flex-grow: 1", classes: "ellipsis") do
811
render(Primer::Beta::Link.new(href: "#", scheme: :primary)) { page_title_service.read(link) }
912
end
13+
14+
if show_action_menu?
15+
link_container.with_column(flex_shrink: 0) do
16+
render(Primer::Alpha::ActionMenu.new) do |menu|
17+
menu.with_show_button(icon: :"kebab-horizontal", "aria-label": t(:label_more), scheme: :invisible)
18+
19+
menu.with_item(label: t(".remove"), scheme: :danger) do |item|
20+
item.with_leading_visual_icon(icon: :trash)
21+
end
22+
end
23+
end
24+
end
1025
end
1126
%>

modules/wikis/app/components/wikis/page_link_component.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,9 @@ class PageLinkComponent < ApplicationComponent
3838
def page_title_service
3939
@page_title_service ||= PageTitleService.new
4040
end
41+
42+
def show_action_menu?
43+
link.relation?
44+
end
4145
end
4246
end

modules/wikis/app/components/wikis/provider_link_group_component.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
render(Primer::Beta::Text.new(font_weight: :bold)) { provider.name }
55
end
66

7+
box.with_row { render(Wikis::RelationPageLinksComponent.new(provider, work_package: @work_package)) }
78
box.with_row { render(Wikis::InlinePageLinksComponent.new(provider, work_package: @work_package)) }
89
end
910
%>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<%=
2+
flex_layout do |container|
3+
container.with_row(mb: 2) do
4+
flex_layout(justify_content: :space_between, align_items: :center) do |header|
5+
header.with_column { render(Primer::Beta::Text.new(font_weight: :bold)) { t(".heading") } }
6+
7+
header.with_column do
8+
render(Primer::Alpha::ActionMenu.new) do |menu|
9+
menu.with_show_button(disabled: true) do |button|
10+
button.with_leading_visual_icon(icon: :plus)
11+
button.with_trailing_action_icon(icon: :"triangle-down")
12+
13+
t("wikis.label_page")
14+
end
15+
16+
menu.with_item(label: "placeholder item")
17+
end
18+
end
19+
end
20+
end
21+
22+
if page_links.empty?
23+
container.with_row do
24+
render(Primer::Beta::Blankslate.new(border: false)) do |empty_placeholder|
25+
empty_placeholder.with_heading(tag: :h2).with_content(t(".empty_heading"))
26+
empty_placeholder.with_description { t(".empty_text") }
27+
end
28+
end
29+
end
30+
31+
page_links.each do |page_link|
32+
container.with_row(mt: 3) { render(Wikis::PageLinkComponent.new(page_link)) }
33+
end
34+
end
35+
%>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# frozen_string_literal: true
2+
3+
#-- copyright
4+
# OpenProject is an open source project management software.
5+
# Copyright (C) the OpenProject GmbH
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License version 3.
9+
#
10+
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
11+
# Copyright (C) 2006-2013 Jean-Philippe Lang
12+
# Copyright (C) 2010-2013 the ChiliProject Team
13+
#
14+
# This program is free software; you can redistribute it and/or
15+
# modify it under the terms of the GNU General Public License
16+
# as published by the Free Software Foundation; either version 2
17+
# of the License, or (at your option) any later version.
18+
#
19+
# This program is distributed in the hope that it will be useful,
20+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
# GNU General Public License for more details.
23+
#
24+
# You should have received a copy of the GNU General Public License
25+
# along with this program; if not, write to the Free Software
26+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27+
#
28+
# See COPYRIGHT and LICENSE files for more details.
29+
#++
30+
31+
module Wikis
32+
class RelationPageLinksComponent < ApplicationComponent
33+
include ApplicationHelper
34+
include OpPrimer::ComponentHelpers
35+
36+
alias_method :provider, :model
37+
38+
def initialize(model = nil, work_package: nil, **options)
39+
@work_package = work_package
40+
super(model, **options)
41+
end
42+
43+
def page_links
44+
@page_links ||= provider.page_links
45+
.merge(RelationPageLink.all)
46+
.where(linkable: @work_package)
47+
.order(created_at: :desc)
48+
end
49+
end
50+
end

modules/wikis/app/components/wikis/work_package_wikis_tab_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ See COPYRIGHT and LICENSE files for more details.
3232
component_wrapper do
3333
flex_layout(test_selector: "op-work-package-wikis-tab-container") do |flex|
3434
providers.each do |provider|
35-
flex.with_row do
35+
flex.with_row(mb: 3) do
3636
render(Wikis::ProviderLinkGroupComponent.new(provider, work_package:))
3737
end
3838
end

modules/wikis/app/models/wikis/page_link.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,13 @@ class PageLink < ApplicationRecord
3434

3535
belongs_to :provider
3636
belongs_to :linkable, polymorphic: true
37+
38+
def relation?
39+
is_a?(RelationPageLink)
40+
end
41+
42+
def inline?
43+
is_a?(InlinePageLink)
44+
end
3745
end
3846
end

0 commit comments

Comments
 (0)