diff --git a/modules/wikis/app/components/wikis/inline_page_links_component.html.erb b/modules/wikis/app/components/wikis/inline_page_links_component.html.erb new file mode 100644 index 00000000000..b94eef69d28 --- /dev/null +++ b/modules/wikis/app/components/wikis/inline_page_links_component.html.erb @@ -0,0 +1,18 @@ +<%= + flex_layout do |container| + container.with_row(mb: 2) { render(Primer::Beta::Text.new(font_weight: :bold)) { t(".heading") } } + + if page_links.empty? + container.with_row do + render(Primer::Beta::Blankslate.new(border: false)) do |blankslate| + blankslate.with_heading(tag: :h2).with_content(t(".empty_heading")) + blankslate.with_description { t(".empty_text") } + end + end + end + + page_links.each do |page_link| + container.with_row(mt: 3) { render(Wikis::PageLinkComponent.new(page_link)) } + end + end +%> diff --git a/modules/wikis/app/components/wikis/inline_page_links_component.rb b/modules/wikis/app/components/wikis/inline_page_links_component.rb new file mode 100644 index 00000000000..9e5702cb932 --- /dev/null +++ b/modules/wikis/app/components/wikis/inline_page_links_component.rb @@ -0,0 +1,50 @@ +# 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 Wikis + class InlinePageLinksComponent < ApplicationComponent + include ApplicationHelper + include OpPrimer::ComponentHelpers + + alias_method :provider, :model + + def initialize(model = nil, work_package: nil, **) + @work_package = work_package + super(model, **) + end + + def page_links + @page_links ||= provider.page_links + .merge(InlinePageLink.all) + .where(linkable: @work_package) + .order(created_at: :desc) + end + end +end diff --git a/modules/wikis/app/components/wikis/page_link_component.html.erb b/modules/wikis/app/components/wikis/page_link_component.html.erb new file mode 100644 index 00000000000..0ed5ff143f2 --- /dev/null +++ b/modules/wikis/app/components/wikis/page_link_component.html.erb @@ -0,0 +1,11 @@ +<%= + flex_layout(test_selector: "op-custom-fields--hierarchy-item") do |link_container| + link_container.with_column(flex_shrink: 0) do + render(Primer::Beta::Octicon.new(icon: :"op-file-doc", mr: 2)) + end + + link_container.with_column(classes: "ellipsis") do + render(Primer::Beta::Link.new(href: "#", scheme: :primary)) { page_title_service.read(link) } + end + end +%> diff --git a/modules/wikis/app/components/wikis/page_link_component.rb b/modules/wikis/app/components/wikis/page_link_component.rb new file mode 100644 index 00000000000..b375e6e8448 --- /dev/null +++ b/modules/wikis/app/components/wikis/page_link_component.rb @@ -0,0 +1,42 @@ +# 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 Wikis + class PageLinkComponent < ApplicationComponent + include ApplicationHelper + include OpPrimer::ComponentHelpers + + alias_method :link, :model + + def page_title_service + @page_title_service ||= PageTitleService.new + end + end +end diff --git a/modules/wikis/app/components/wikis/provider_link_group_component.html.erb b/modules/wikis/app/components/wikis/provider_link_group_component.html.erb new file mode 100644 index 00000000000..ae3de6490ea --- /dev/null +++ b/modules/wikis/app/components/wikis/provider_link_group_component.html.erb @@ -0,0 +1,9 @@ +<%= + render(Primer::Beta::BorderBox.new) do |box| + box.with_header do + render(Primer::Beta::Text.new(font_weight: :bold)) { provider.name } + end + + box.with_row { render(Wikis::InlinePageLinksComponent.new(provider, work_package: @work_package)) } + end +%> diff --git a/modules/wikis/app/components/wikis/provider_link_group_component.rb b/modules/wikis/app/components/wikis/provider_link_group_component.rb new file mode 100644 index 00000000000..bb99600b8e0 --- /dev/null +++ b/modules/wikis/app/components/wikis/provider_link_group_component.rb @@ -0,0 +1,43 @@ +# 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 Wikis + class ProviderLinkGroupComponent < ApplicationComponent + include ApplicationHelper + include OpPrimer::ComponentHelpers + + alias_method :provider, :model + + def initialize(model = nil, work_package: nil, **) + @work_package = work_package + super(model, **) + end + end +end diff --git a/modules/wikis/app/components/wikis/work_package_wikis_tab_component.html.erb b/modules/wikis/app/components/wikis/work_package_wikis_tab_component.html.erb index febb94004d0..e19b9a17365 100644 --- a/modules/wikis/app/components/wikis/work_package_wikis_tab_component.html.erb +++ b/modules/wikis/app/components/wikis/work_package_wikis_tab_component.html.erb @@ -30,7 +30,13 @@ See COPYRIGHT and LICENSE files for more details. <%= content_tag("turbo-frame", id: "work-package-wikis-tab-content") do component_wrapper do - render(Primer::Beta::Text.new) { "Hi 👋" } + flex_layout(test_selector: "op-work-package-wikis-tab-container") do |flex| + providers.each do |provider| + flex.with_row do + render(Wikis::ProviderLinkGroupComponent.new(provider, work_package:)) + end + end + end end end %> diff --git a/modules/wikis/app/components/wikis/work_package_wikis_tab_component.rb b/modules/wikis/app/components/wikis/work_package_wikis_tab_component.rb index a3769c23a6d..254a45684e9 100644 --- a/modules/wikis/app/components/wikis/work_package_wikis_tab_component.rb +++ b/modules/wikis/app/components/wikis/work_package_wikis_tab_component.rb @@ -33,5 +33,11 @@ module Wikis include ApplicationHelper include OpPrimer::ComponentHelpers include OpTurbo::Streamable + + alias_method :work_package, :model + + def providers + Wikis::Provider.enabled + end end end diff --git a/modules/wikis/app/controllers/work_package_wikis_tab_controller.rb b/modules/wikis/app/controllers/work_package_wikis_tab_controller.rb index bb1b1d890b1..bb9f14139b9 100644 --- a/modules/wikis/app/controllers/work_package_wikis_tab_controller.rb +++ b/modules/wikis/app/controllers/work_package_wikis_tab_controller.rb @@ -36,7 +36,7 @@ class WorkPackageWikisTabController < ApplicationController before_action :set_work_package def index - render(Wikis::WorkPackageWikisTabComponent.new, layout: false) + render(Wikis::WorkPackageWikisTabComponent.new(@work_package), layout: false) end private diff --git a/modules/wikis/app/services/wikis/page_link_service.rb b/modules/wikis/app/services/wikis/page_link_service.rb new file mode 100644 index 00000000000..58b0b537848 --- /dev/null +++ b/modules/wikis/app/services/wikis/page_link_service.rb @@ -0,0 +1,44 @@ +# 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 Wikis + class PageLinkService + def count(linkable) + # Incomplete implementation until connection to Wikis API is done to fetch relation wiki page links + # from external providers. + # TODO: Replace with complete implementation + + Wikis::PageLink.joins(:provider) + .merge(Wikis::Provider.enabled) + .where(linkable:) + .count + end + end +end diff --git a/modules/wikis/app/services/wikis/page_title_service.rb b/modules/wikis/app/services/wikis/page_title_service.rb new file mode 100644 index 00000000000..9f96e6cc70a --- /dev/null +++ b/modules/wikis/app/services/wikis/page_title_service.rb @@ -0,0 +1,44 @@ +# 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 Wikis + class PageTitleService + def read(_page_link) + # Mock implementation until connection to Wikis API is done + # TODO: Replace with real implementation + + [ + "How to write wiki pages", + "Technical specifications", + "A brief introduction on how to write wiki page titles that are short enough to be memorable" + ].sample + end + end +end diff --git a/modules/wikis/config/locales/en.yml b/modules/wikis/config/locales/en.yml index 4a6c4e3067a..e5cea0fedf5 100644 --- a/modules/wikis/config/locales/en.yml +++ b/modules/wikis/config/locales/en.yml @@ -26,6 +26,10 @@ en: wikis: buttons: save_and_continue: Save and continue + inline_page_links_component: + empty_heading: No inline links + empty_text: Inline links to wiki pages in the work package description will automatically also show up here. + heading: Inline page links admin: wiki_providers: index_description: Add an external wiki service to link work packages to existing wiki pages or create new ones directly from OpenProject. diff --git a/modules/wikis/lib/open_project/wikis/engine.rb b/modules/wikis/lib/open_project/wikis/engine.rb index d0286376c14..c1bffc45166 100644 --- a/modules/wikis/lib/open_project/wikis/engine.rb +++ b/modules/wikis/lib/open_project/wikis/engine.rb @@ -68,6 +68,7 @@ module OpenProject::Wikis { tab: :wikis }, skip_permissions_check: true, after: :relations, + badge: ->(work_package:, **) { Wikis::PageLinkService.new.count(work_package) }, if: ->(_project) { Wikis::Provider.enabled.exists? && OpenProject::FeatureDecisions.wiki_enhancements_active?