diff --git a/app/components/add_button_component.html.erb b/app/components/add_button_component.html.erb
index bfe3065020dc..d3ce5ab1bbd6 100644
--- a/app/components/add_button_component.html.erb
+++ b/app/components/add_button_component.html.erb
@@ -1,9 +1,10 @@
-
- <%= icon %>
- <%= label %>
-
-
+<%= render(Primer::ButtonComponent.new(scheme: :primary,
+ aria: { label: aria_label },
+ title: aria_label,
+ data: { "test-selector": test_selector},
+ tag: :a,
+ href: href) ) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ label_text
+end
+%>
diff --git a/app/components/add_button_component.rb b/app/components/add_button_component.rb
index 3b971f87af90..d2097099ae68 100644
--- a/app/components/add_button_component.rb
+++ b/app/components/add_button_component.rb
@@ -30,47 +30,5 @@
#
class AddButtonComponent < ApplicationComponent
- options :current_project
-
- def render?
- raise "Implement the conditions for which the component should render or not"
- end
-
- def dynamic_path
- raise "Implement the path for this component's href"
- end
-
- def id
- raise "Implement the id for this component"
- end
-
- def title
- accessibility_label_text
- end
-
- def label
- content_tag(:span,
- label_text,
- class: "button--text")
- end
-
- def aria_label
- accessibility_label_text
- end
-
- def accessibility_label_text
- raise "Specify the aria label and title text to be used for this component"
- end
-
- def label_text
- raise "Specify the label text to be used for this component"
- end
-
- def link_css_class
- "button -primary"
- end
-
- def icon
- helpers.op_icon("button--icon icon-add")
- end
+ options :test_selector, :href, :aria_label, :label_text
end
diff --git a/app/components/notifications/index_page_header_component.rb b/app/components/notifications/index_page_header_component.rb
index 2589da0ccec6..3af873f9b5db 100644
--- a/app/components/notifications/index_page_header_component.rb
+++ b/app/components/notifications/index_page_header_component.rb
@@ -47,7 +47,7 @@ def breadcrumb_items
end
def parent_element
- { href: home_path, text: I18n.t(:label_home) }
+ { href: home_path, text: helpers.organization_name }
end
end
end
diff --git a/app/components/projects/index_page_header_component.rb b/app/components/projects/index_page_header_component.rb
index d11e00642136..a9af6c186967 100644
--- a/app/components/projects/index_page_header_component.rb
+++ b/app/components/projects/index_page_header_component.rb
@@ -112,6 +112,7 @@ def currently_favored? = query.favored_by?(current_user)
def breadcrumb_items
[
+ { href: home_path, text: helpers.organization_name },
{ href: projects_path, text: t(:label_project_plural) },
current_breadcrumb_element
]
diff --git a/app/views/homescreen/index.html.erb b/app/views/homescreen/index.html.erb
index cd717e8e4442..83f8a84873b0 100644
--- a/app/views/homescreen/index.html.erb
+++ b/app/views/homescreen/index.html.erb
@@ -33,11 +33,6 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-
- <%= organization_icon %>
- <%= organization_name %>
-
-
<%= render partial: 'announcements/show' %>
<% if @homescreen[:blocks].any? %>
diff --git a/modules/boards/app/components/boards/add_button_component.rb b/modules/boards/app/components/boards/add_button_component.rb
deleted file mode 100644
index fb2eac3cf06e..000000000000
--- a/modules/boards/app/components/boards/add_button_component.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-# 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 Boards
- class AddButtonComponent < ::AddButtonComponent
- def render?
- if current_project
- User.current.allowed_in_project?(:manage_board_views, current_project)
- else
- User.current.allowed_in_any_project?(:manage_board_views)
- end
- end
-
- def dynamic_path
- polymorphic_path([:new, current_project, :work_package_board])
- end
-
- def id
- "add-board-button"
- end
-
- def accessibility_label_text
- I18n.t("boards.label_create_new_board")
- end
-
- def label_text
- I18n.t("boards.label_board")
- end
- end
-end
diff --git a/modules/boards/app/controllers/boards/boards_controller.rb b/modules/boards/app/controllers/boards/boards_controller.rb
index b9a271d5d539..134eb78ad35a 100644
--- a/modules/boards/app/controllers/boards/boards_controller.rb
+++ b/modules/boards/app/controllers/boards/boards_controller.rb
@@ -16,6 +16,7 @@ class BoardsController < BaseController
menu_item :boards
def index
+ @show_create_button = show_create_button
render "index", locals: { menu_name: project_or_global_menu }
end
@@ -23,6 +24,14 @@ def show
render layout: "angular/angular"
end
+ def show_create_button
+ if @project
+ User.current.allowed_in_project?(:manage_board_views, @project)
+ else
+ User.current.allowed_in_any_project?(:manage_board_views)
+ end
+ end
+
def default_breadcrumb; end
def show_local_breadcrumb
diff --git a/modules/boards/app/views/boards/boards/index.html.erb b/modules/boards/app/views/boards/boards/index.html.erb
index 33c4d40e6ec7..09823b81bc67 100644
--- a/modules/boards/app/views/boards/boards/index.html.erb
+++ b/modules/boards/app/views/boards/boards/index.html.erb
@@ -32,19 +32,28 @@ See COPYRIGHT and LICENSE files for more details.
<%=
render Primer::OpenProject::PageHeader.new do |header|
header.with_title { t("boards.label_boards") }
- header.with_breadcrumbs([{ href: home_path, text: organization_name},
+ header.with_breadcrumbs([{ href: home_path, text: organization_name },
*([href: project_overview_path(@project.id), text: @project.name] if @project),
t("boards.label_boards")])
end
%>
-<%=
- render Primer::OpenProject::SubHeader.new do |subheader|
- subheader.with_action_component(data: { "test-selector": "add-board-button"}) do
- render Boards::AddButtonComponent.new(current_project: @project)
+<% if @show_create_button %>
+ <%=
+ render Primer::OpenProject::SubHeader.new do |subheader|
+ subheader.with_action_button(scheme: :primary,
+ aria: { label: I18n.t("boards.label_create_new_board") },
+ title: I18n.t("boards.label_board"),
+ tag: :a,
+ id: "add-board-button",
+ href: polymorphic_path([:new, @project, :work_package_board]),
+ data: { "test-selector": "add-board-button"}) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ I18n.t("boards.label_board")
+ end
end
- end
-%>
+ %>
+<% end %>
<% if @board_grids.empty? -%>
<%= no_results_box %>
diff --git a/modules/boards/app/views/boards/boards/overview.html.erb b/modules/boards/app/views/boards/boards/overview.html.erb
index 95736aa6903f..b013ef652636 100644
--- a/modules/boards/app/views/boards/boards/overview.html.erb
+++ b/modules/boards/app/views/boards/boards/overview.html.erb
@@ -29,8 +29,30 @@ See COPYRIGHT and LICENSE files for more details.
<% html_title(t('boards.label_boards')) -%>
-<%= toolbar title: t('boards.label_boards') do %>
- <%= render Boards::AddButtonComponent.new %>
+<%=
+ render Primer::OpenProject::PageHeader.new do |header|
+ header.with_title { t("boards.label_boards") }
+ header.with_breadcrumbs([{ href: home_path, text: organization_name},
+ *([href: project_overview_path(@project.id), text: @project.name] if @project),
+ t("boards.label_boards")])
+ end
+%>
+
+<% if @show_create_button %>
+ <%=
+ render Primer::OpenProject::SubHeader.new do |subheader|
+ subheader.with_action_button(scheme: :primary,
+ aria: { label: I18n.t("boards.label_create_new_board") },
+ title: I18n.t("boards.label_board"),
+ tag: :a,
+ id: "add-board-button",
+ href: polymorphic_path([:new, @project, :work_package_board]),
+ data: { "test-selector": "add-board-button"}) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ I18n.t("boards.label_board")
+ end
+ end
+ %>
<% end %>
<% if @board_grids.empty? -%>
diff --git a/modules/boards/spec/features/support/board_index_page.rb b/modules/boards/spec/features/support/board_index_page.rb
index 96083f2371c8..666fcfd6632c 100644
--- a/modules/boards/spec/features/support/board_index_page.rb
+++ b/modules/boards/spec/features/support/board_index_page.rb
@@ -59,9 +59,7 @@ def expect_board(name, present: true)
def create_board(action: "Basic", title: "#{action} Board", expect_empty: false, via_toolbar: true)
if via_toolbar
- within '[data-test-selector="add-board-button"]' do
- click_link "Board"
- end
+ find('[data-test-selector="add-board-button"]').click
else
find('[data-test-selector="boards--create-button"]').click
end
diff --git a/modules/boards/spec/features/support/board_list_page.rb b/modules/boards/spec/features/support/board_list_page.rb
index 921ae9ad1340..d8bef8101b76 100644
--- a/modules/boards/spec/features/support/board_list_page.rb
+++ b/modules/boards/spec/features/support/board_list_page.rb
@@ -35,15 +35,11 @@ def visit!
end
def expect_create_button
- within '[data-test-selector="add-board-button"]' do
- expect(page).to have_link "Board"
- end
+ expect(page).to have_css('[data-test-selector="add-board-button"]', text: "Board")
end
def expect_no_create_button
- within '[data-test-selector="add-board-button"]' do
- expect(page).to have_no_link "Board"
- end
+ expect(page).to have_no_css('[data-test-selector="add-board-button"]', text: "Board")
end
def expect_delete_buttons(*boards)
diff --git a/modules/boards/spec/features/support/board_new_page.rb b/modules/boards/spec/features/support/board_new_page.rb
index 869040a692ed..5ddde9f2d878 100644
--- a/modules/boards/spec/features/support/board_new_page.rb
+++ b/modules/boards/spec/features/support/board_new_page.rb
@@ -13,9 +13,7 @@ def visit!
def navigate_by_create_button
visit work_package_boards_path unless page.current_path == work_package_boards_path
- within '[data-test-selector="add-board-button"]' do
- click_link "Board"
- end
+ find('[data-test-selector="add-board-button"]').click
end
def set_title(title)
diff --git a/modules/calendar/app/components/calendar/add_button_component.html.erb b/modules/calendar/app/components/calendar/add_button_component.html.erb
deleted file mode 100644
index b1da75b2a660..000000000000
--- a/modules/calendar/app/components/calendar/add_button_component.html.erb
+++ /dev/null
@@ -1,8 +0,0 @@
-
- <%= icon %>
- <%= label %>
-
diff --git a/modules/calendar/app/components/calendar/add_button_component.rb b/modules/calendar/app/components/calendar/add_button_component.rb
deleted file mode 100644
index 95d23f979aaa..000000000000
--- a/modules/calendar/app/components/calendar/add_button_component.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-# 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 Calendar
- class AddButtonComponent < ::AddButtonComponent
- def render?
- if current_project
- User.current.allowed_in_project?(:manage_calendars, current_project)
- else
- User.current.allowed_in_any_project?(:manage_calendars)
- end
- end
-
- def dynamic_path
- if current_project
- new_project_calendars_path(current_project)
- else
- new_calendar_path
- end
- end
-
- def id
- "add-calendar-button"
- end
-
- def accessibility_label_text
- I18n.t("js.calendar.create_new")
- end
-
- def label_text
- I18n.t(:label_calendar)
- end
- end
-end
diff --git a/modules/calendar/app/controllers/calendar/calendars_controller.rb b/modules/calendar/app/controllers/calendar/calendars_controller.rb
index 5b8280d60d17..c8898c685b00 100644
--- a/modules/calendar/app/controllers/calendar/calendars_controller.rb
+++ b/modules/calendar/app/controllers/calendar/calendars_controller.rb
@@ -42,6 +42,8 @@ class CalendarsController < ApplicationController
def index
@views = visible_views
+ @show_create_button = show_create_button?
+ @dynamic_path = dynamic_path
render "index", locals: { menu_name: project_or_global_menu }
end
@@ -109,5 +111,21 @@ def find_calendar
rescue ActiveRecord::RecordNotFound
render_404
end
+
+ def show_create_button?
+ if @project
+ User.current.allowed_in_project?(:manage_calendars, @project)
+ else
+ User.current.allowed_in_any_project?(:manage_calendars)
+ end
+ end
+
+ def dynamic_path
+ if @project
+ new_project_calendars_path(@project)
+ else
+ new_calendar_path
+ end
+ end
end
end
diff --git a/modules/calendar/app/views/calendar/calendars/index.html.erb b/modules/calendar/app/views/calendar/calendars/index.html.erb
index 36ac02c23962..148fb922a8a4 100644
--- a/modules/calendar/app/views/calendar/calendars/index.html.erb
+++ b/modules/calendar/app/views/calendar/calendars/index.html.erb
@@ -37,13 +37,17 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<%=
- render Primer::OpenProject::SubHeader.new do |subheader|
- subheader.with_action_component(data: { "test-selector": "add-calendar-button"}) do
- render Calendar::AddButtonComponent.new(current_project: @project)
+<% if @show_create_button %>
+ <%=
+ render Primer::OpenProject::SubHeader.new do |subheader|
+ subheader.with_action_component do
+ render AddButtonComponent.new(test_selector: "add-calendar-button",
+ href: @dynamic_path,
+ aria_label: I18n.t("js.calendar.create_new"),
+ label_text: I18n.t(:label_calendar))
+ end
end
- end
-%>
-
+ %>
+<% end %>
<%= render ::Calendar::TableComponent.new(rows: @views, current_project: @project, current_user: current_user) %>
diff --git a/modules/calendar/spec/features/calendar_sharing_spec.rb b/modules/calendar/spec/features/calendar_sharing_spec.rb
index 46dd7c32aecc..24c4717636cf 100644
--- a/modules/calendar/spec/features/calendar_sharing_spec.rb
+++ b/modules/calendar/spec/features/calendar_sharing_spec.rb
@@ -140,7 +140,7 @@
it "shows disabled sharing menu item" do
visit project_calendars_path(project)
- click_link "Create new calendar"
+ find('[data-test-selector="add-calendar-button"]').click
# wait for settings button to become visible
expect(page).to have_css("#work-packages-settings-button")
diff --git a/modules/calendar/spec/support/pages/calendar.rb b/modules/calendar/spec/support/pages/calendar.rb
index 1f04bb41fc4a..63a7fd438983 100644
--- a/modules/calendar/spec/support/pages/calendar.rb
+++ b/modules/calendar/spec/support/pages/calendar.rb
@@ -140,9 +140,7 @@ def click_on_submit
end
def click_on_create_button
- within '[data-test-selector="add-calendar-button"]' do
- click_link "Calendar"
- end
+ find('[data-test-selector="add-calendar-button"]').click
end
def click_on_cancel_button
@@ -150,11 +148,11 @@ def click_on_cancel_button
end
def expect_create_button
- expect(page).to have_css ".button", text: "Calendar"
+ expect(page).to have_css '[data-test-selector="add-calendar-button"]', text: "Calendar"
end
def expect_no_create_button
- expect(page).to have_no_css ".button", text: "Calendar"
+ expect(page).to have_no_css '[data-test-selector="add-calendar-button"]', text: "Calendar"
end
def expect_delete_button(query)
diff --git a/modules/meeting/app/components/meetings/header_component.rb b/modules/meeting/app/components/meetings/header_component.rb
index 08bcba7912fa..4aba72081558 100644
--- a/modules/meeting/app/components/meetings/header_component.rb
+++ b/modules/meeting/app/components/meetings/header_component.rb
@@ -66,7 +66,7 @@ def parent_element
if @project.present?
{ href: project_overview_path(@project.id), text: @project.name }
else
- { href: home_path, text: I18n.t(:label_home) }
+ { href: home_path, text: helpers.organization_name }
end
end
end
diff --git a/modules/meeting/app/components/meetings/index_page_header_component.rb b/modules/meeting/app/components/meetings/index_page_header_component.rb
index 33c19d89547c..1d9403a99960 100644
--- a/modules/meeting/app/components/meetings/index_page_header_component.rb
+++ b/modules/meeting/app/components/meetings/index_page_header_component.rb
@@ -42,16 +42,32 @@ def page_title
end
def breadcrumb_items
- [parent_element,
- page_title]
+ [
+ { href: home_path, text: helpers.organization_name },
+ *([{ href: project_overview_path(@project.id), text: @project.name }] if @project.present?),
+ { href: @project.present? ? project_meetings_path(@project.id) : meetings_path, text: I18n.t(:label_meeting_plural) },
+ current_breadcrumb_element
+ ]
end
- def parent_element
- if @project.present?
- { href: project_overview_path(@project.id), text: @project.name }
+ def current_breadcrumb_element
+ if current_section
+ selected_menu = current_section.children.find(&:selected)
+ if current_section.header.present?
+ I18n.t("menus.breadcrumb.nested_element", section_header: current_section.header, title: selected_menu.title).html_safe
+ else
+ selected_menu.title
+ end
else
- { href: home_path, text: I18n.t(:label_home) }
+ page_title
end
end
+
+ def current_section
+ return @current_section if defined?(@current_section)
+
+ meetings_menu = Meetings::Menu.new(params:)
+ @current_section = meetings_menu.menu_items.find { |section| section.children.any?(&:selected) }
+ end
end
end
diff --git a/modules/meeting/app/views/meetings/new.html.erb b/modules/meeting/app/views/meetings/new.html.erb
index 4f732bb526dc..6a1abeaa7b2e 100644
--- a/modules/meeting/app/views/meetings/new.html.erb
+++ b/modules/meeting/app/views/meetings/new.html.erb
@@ -42,7 +42,7 @@ See COPYRIGHT and LICENSE files for more details.
header.with_title { page_title }
header.with_breadcrumbs([@project.present? ?
{ href: project_overview_path(@project.id), text: @project.name } :
- { href: home_path, text: I18n.t(:label_home) },
+ { href: home_path, text: organization_name },
{ href: @project.present? ? project_meetings_path(@project.id) : meetings_path,
text: I18n.t(:label_meeting_plural) },
breadcrumb_element.html_safe])
diff --git a/modules/reporting/app/views/cost_reports/index.html.erb b/modules/reporting/app/views/cost_reports/index.html.erb
index bfef6d0b984a..7ee8d29e6bd0 100644
--- a/modules/reporting/app/views/cost_reports/index.html.erb
+++ b/modules/reporting/app/views/cost_reports/index.html.erb
@@ -40,25 +40,25 @@ See COPYRIGHT and LICENSE files for more details.
header.with_title { render_widget Widget::Controls::QueryName, @query, :can_rename => allowed_in_report?(:rename, @query, current_user) }
header.with_breadcrumbs([{ href: home_path, text: organization_name},
*([href: project_overview_path(@project.id), text: @project.name] if @project),
- t(:label_news_plural)])
- end
-%>
-<% if User.current.allowed_in_any_work_package?(:export_work_packages, in_project: @project) %>
- <%=
- render(Primer::OpenProject::SubHeader.new) do |subheader|
- subheader.with_action_button(scheme: :default,
- aria: { label: t(:export_to_excel)},
- title: t(:export_to_excel),
- tag: :a,
- href: url_for({ controller: "cost_reports" , action: :index, format: 'xls', project_id: @project })
- ) do |button|
+ { href: url_for({ controller: "cost_reports" , action: :index, project_id: @project }), text: I18n.t(:cost_reports_title)},
+ (@query.persisted? ? "#{@query.name}" : t(:label_new_report))])
+
+ if User.current.allowed_in_any_work_package?(:export_work_packages, in_project: @project)
+ header.with_action_button(scheme: :default,
+ aria: { label: t(:export_to_excel)},
+ title: t(:export_to_excel),
+ mobile_icon: "op-file-xls-descriptions",
+ mobile_label: t(:export_to_excel),
+ tag: :a,
+ href: url_for({ controller: "cost_reports" , action: :index, format: 'xls', project_id: @project })
+ ) do |button|
button.with_leading_visual_icon(icon: "op-file-xls-descriptions")
t(:export_to_excel)
end
+ call_hook(:view_cost_report_toolbar)
end
- %>
- <%= call_hook(:view_cost_report_toolbar) %>
-<% end %>
+ end
+%>
<%= render_widget Widget::Settings, @query, :cost_types => @cost_types, :selected_type_id => @unit_id %>
diff --git a/modules/team_planner/app/components/team_planner/add_button_component.rb b/modules/team_planner/app/components/team_planner/add_button_component.rb
deleted file mode 100644
index 3724dee5c52b..000000000000
--- a/modules/team_planner/app/components/team_planner/add_button_component.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-# 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 TeamPlanner
- class AddButtonComponent < ::AddButtonComponent
- def render?
- if current_project
- User.current.allowed_in_project?(:manage_team_planner, current_project)
- else
- User.current.allowed_in_any_project?(:manage_team_planner)
- end
- end
-
- def dynamic_path
- polymorphic_path([:new, current_project, :team_planners])
- end
-
- def id
- "add-team-planner-button"
- end
-
- def accessibility_label_text
- I18n.t("team_planner.label_create_new_team_planner")
- end
-
- def label_text
- t(:"team_planner.label_team_planner")
- end
- end
-end
diff --git a/modules/team_planner/app/controllers/team_planner/team_planner_controller.rb b/modules/team_planner/app/controllers/team_planner/team_planner_controller.rb
index a2e08ebef42a..b289a3f805eb 100644
--- a/modules/team_planner/app/controllers/team_planner/team_planner_controller.rb
+++ b/modules/team_planner/app/controllers/team_planner/team_planner_controller.rb
@@ -10,10 +10,12 @@ class TeamPlannerController < BaseController
menu_item :team_planner_view
def index
+ @show_create_button = show_create_button
@views = visible_plans(@project)
end
def overview
+ @show_create_button = show_create_button
@views = visible_plans
render layout: "global"
end
@@ -104,5 +106,13 @@ def visible_plans(project = nil)
query
end
+
+ def show_create_button
+ if @project
+ User.current.allowed_in_project?(:manage_team_planner, @project)
+ else
+ User.current.allowed_in_any_project?(:manage_team_planner)
+ end
+ end
end
end
diff --git a/modules/team_planner/app/views/team_planner/team_planner/index.html.erb b/modules/team_planner/app/views/team_planner/team_planner/index.html.erb
index a8e6d21fd431..7a994061b5fb 100644
--- a/modules/team_planner/app/views/team_planner/team_planner/index.html.erb
+++ b/modules/team_planner/app/views/team_planner/team_planner/index.html.erb
@@ -8,13 +8,20 @@
t('team_planner.label_team_planner_plural')])
end
%>
-
-<%=
- render Primer::OpenProject::SubHeader.new do |subheader|
- subheader.with_action_component(data: { "test-selector": "add-team-planner-button"}) do
- render ::TeamPlanner::AddButtonComponent.new(current_project: @project)
+<% if @show_create_button %>
+ <%=
+ render Primer::OpenProject::SubHeader.new do |subheader|
+ subheader.with_action_button(scheme: :primary,
+ aria: { label: I18n.t("team_planner.label_create_new_team_planner") },
+ title: t(:"team_planner.label_team_planner"),
+ tag: :a,
+ id: "add-team-planner-button",
+ href: polymorphic_path([:new, @project, :team_planners]),
+ data: { "test-selector": "add-team-planner-button"}) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ t(:"team_planner.label_team_planner")
+ end
end
- end
-%>
-
+ %>
+<% end %>
<%= render ::TeamPlanner::TableComponent.new(rows: @views, current_user: current_user) %>
diff --git a/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb b/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb
index 0cfe3fd8cd6e..42955ee52cab 100644
--- a/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb
+++ b/modules/team_planner/app/views/team_planner/team_planner/overview.html.erb
@@ -6,13 +6,20 @@
t('team_planner.label_team_planner_plural')])
end
%>
-
-<%=
- render Primer::OpenProject::SubHeader.new do |subheader|
- subheader.with_action_component(data: { "test-selector": "add-team-planner-button"}) do
- render ::TeamPlanner::AddButtonComponent.new
+<% if @show_create_button %>
+ <%=
+ render Primer::OpenProject::SubHeader.new do |subheader|
+ subheader.with_action_button(scheme: :primary,
+ aria: { label: I18n.t("team_planner.label_create_new_team_planner") },
+ title: t(:"team_planner.label_team_planner"),
+ tag: :a,
+ id: "add-team-planner-button",
+ href: polymorphic_path([:new, @project, :team_planners]),
+ data: { "test-selector": "add-team-planner-button"}) do |button|
+ button.with_leading_visual_icon(icon: :plus)
+ t(:"team_planner.label_team_planner")
+ end
end
- end
-%>
-
+ %>
+<% end %>
<%= render ::TeamPlanner::Overview::TableComponent.new(rows: @views, current_user: current_user) %>
diff --git a/modules/team_planner/spec/features/team_planner_spec.rb b/modules/team_planner/spec/features/team_planner_spec.rb
index 5fd1465fc866..35cba6223429 100644
--- a/modules/team_planner/spec/features/team_planner_spec.rb
+++ b/modules/team_planner/spec/features/team_planner_spec.rb
@@ -43,7 +43,7 @@
end
expect(page).to have_content "There is currently nothing to display."
- click_on "Create", match: :first
+ find('[data-test-selector="add-team-planner-button"]').click
team_planner.expect_title
diff --git a/modules/team_planner/spec/support/pages/team_planner.rb b/modules/team_planner/spec/support/pages/team_planner.rb
index 99cbfb085911..7188a360ead6 100644
--- a/modules/team_planner/spec/support/pages/team_planner.rb
+++ b/modules/team_planner/spec/support/pages/team_planner.rb
@@ -172,15 +172,11 @@ def expect_view_not_rendered(query)
end
def expect_create_button
- within '[data-test-selector="add-team-planner-button"]' do
- expect(page).to have_link text: "Team planner"
- end
+ expect(page).to have_css('[data-test-selector="add-team-planner-button"]', text: "Team planner")
end
def expect_no_create_button
- within '[data-test-selector="add-team-planner-button"]' do
- expect(page).to have_no_link text: "Team planner"
- end
+ expect(page).to have_no_css('[data-test-selector="add-team-planner-button"]', text: "Team planner")
end
def expect_views_listed_in_order(*queries)
@@ -192,9 +188,7 @@ def expect_views_listed_in_order(*queries)
end
def click_on_create_button
- within '[data-test-selector="add-team-planner-button"]' do
- click_link "Team planner"
- end
+ find('[data-test-selector="add-team-planner-button"]').click
end
def click_on_cancel_button