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

Use menu helper to generate tabs

Oliver Güntheref9480bbd600
diff --git a/app/components/work_packages/details/tab_component.html.erb b/app/components/work_packages/details/tab_component.html.erb
index 0c7b53a2972..ba8ea7365a5 100644
--- a/app/components/work_packages/details/tab_component.html.erb
+++ b/app/components/work_packages/details/tab_component.html.erb
@@ -1,9 +1,11 @@
<%=
render(Primer::Alpha::UnderlineNav.new(align: :left, label: "Tabs")) do |component|
- %i[overview activity files relations watchers github gitlab meetings].each do |tab|
- component.with_tab(selected: @tab == tab,
- href: url_for(tab: tab)) do |c|
- c.with_text { t("js.work_packages.tabs.#{tab}") }
+ menu_items.each do |node|
+ component.with_tab(selected: @tab == node.name,
+ href: url_for(node.url)) do |c|
+ c.with_text { t("js.work_packages.tabs.#{node.name}") }
+ count = node.badge(work_package:).to_i
+ c.with_counter(count:) if count > 0
end
end
end
diff --git a/app/components/work_packages/details/tab_component.rb b/app/components/work_packages/details/tab_component.rb
index 09fe0242f17..09cca8500ba 100644
--- a/app/components/work_packages/details/tab_component.rb
+++ b/app/components/work_packages/details/tab_component.rb
@@ -3,9 +3,28 @@
class WorkPackages::Details::TabComponent < ApplicationComponent
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
+ include Redmine::MenuManager::MenuHelper
- def initialize(id:, tab: :overview)
- @id = id
+ attr_reader :tab, :work_package
+
+ def initialize(work_package:, tab: :overview)
+ @work_package = work_package
@tab = tab.to_sym
end
+
+ delegate :project, to: :work_package
+
+ def menu = :work_package_split_view
+
+ def menu_items
+ @menu_items ||= begin
+ Redmine::MenuManager
+ .items(menu, nil)
+ .root
+ .children
+ .select do |node|
+ allowed_node?(node, User.current, project) && visible_node?(menu, node)
+ end
+ end
+ end
end
diff --git a/app/components/work_packages/split_view_component.html.erb b/app/components/work_packages/split_view_component.html.erb
index 5ae2ac28d1c..1b4657c7cc4 100644
--- a/app/components/work_packages/split_view_component.html.erb
+++ b/app/components/work_packages/split_view_component.html.erb
@@ -1,15 +1,19 @@
<%=
content_tag("turbo-frame", id: "work-package-details-#{@id}") do
- flex_layout(h: :full) do |flex|
- flex.with_row do
- render(WorkPackages::Details::TabComponent.new(id: @id, tab: @tab))
- end
- flex.with_row(flex: 1) do
- helpers.angular_component_tag "opce-wp-split-view",
- inputs: {
- work_package_id: params[:work_package_id],
- activeTab: @tab
- }
+ if @work_package.nil?
+ "Work Package #{@id} could not be found."
+ else
+ flex_layout(h: :full) do |flex|
+ flex.with_row do
+ render(WorkPackages::Details::TabComponent.new(work_package: @work_package, tab: @tab))
+ end
+ flex.with_row(flex: 1) do
+ helpers.angular_component_tag "opce-wp-split-view",
+ inputs: {
+ work_package_id: params[:work_package_id],
+ activeTab: @tab
+ }
+ end
end
end
end
diff --git a/app/components/work_packages/split_view_component.rb b/app/components/work_packages/split_view_component.rb
index 2fa98f63aff..8b47e26e365 100644
--- a/app/components/work_packages/split_view_component.rb
+++ b/app/components/work_packages/split_view_component.rb
@@ -7,5 +7,6 @@ class WorkPackages::SplitViewComponent < ApplicationComponent
def initialize(id:, tab: 'overview')
@id = id
@tab = tab
+ @work_package = WorkPackage.visible.find_by(id:)
end
end
diff --git a/app/mailers/sharing_mailer.rb b/app/mailers/sharing_mailer.rb
index 9a1a54b25e5..418bd0ba639 100644
--- a/app/mailers/sharing_mailer.rb
+++ b/app/mailers/sharing_mailer.rb
@@ -15,7 +15,7 @@ class SharingMailer < ApplicationMailer
@role_rights = derive_role_rights(role)
@allowed_work_package_actions = derive_allowed_work_package_actions(role)
@url = optionally_activated_url(work_package_url(@work_package.id), @invitation_token)
- @notification_url = optionally_activated_url(details_notifications_path(@work_package.id), @invitation_token)
+ @notification_url = optionally_activated_url(details_notifications_url(@work_package.id), @invitation_token)
set_open_project_headers(@work_package)
message_id(membership, sharer)
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index b443573e5bf..cedec66d1d5 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -640,3 +640,27 @@ Redmine::MenuManager.map :project_menu do |menu|
parent: :settings
end
end
+
+Redmine::MenuManager.map :work_package_split_view do |menu|
+ menu.push :overview,
+ { tab: :overview },
+ skip_permissions_check: true,
+ caption: :"js.work_packages.tabs.overview"
+ menu.push :activity,
+ { tab: :activity },
+ skip_permissions_check: true,
+ badge: ->(work_package:, **) { 123 },
+ caption: :"js.work_packages.tabs.activity"
+ menu.push :files,
+ { tab: :files },
+ skip_permissions_check: true,
+ caption: :"js.work_packages.tabs.files"
+ menu.push :relations,
+ { tab: :relations },
+ skip_permissions_check: true,
+ caption: :"js.work_packages.tabs.relations"
+ menu.push :watchers,
+ { tab: :watchers },
+ skip_permissions_check: true,
+ caption: :"js.work_packages.tabs.watchers"
+end
diff --git a/frontend/src/app/features/in-app-notifications/in-app-notifications.module.ts b/frontend/src/app/features/in-app-notifications/in-app-notifications.module.ts
index 69ca7c70ccb..f470abda791 100644
--- a/frontend/src/app/features/in-app-notifications/in-app-notifications.module.ts
+++ b/frontend/src/app/features/in-app-notifications/in-app-notifications.module.ts
@@ -2,10 +2,13 @@ import { NgModule } from '@angular/core';
import { OpSharedModule } from 'core-app/shared/shared.module';
import { CommonModule } from '@angular/common';
import { IconModule } from 'core-app/shared/components/icon/icon.module';
-import { InAppNotificationBellComponent } from 'core-app/features/in-app-notifications/bell/in-app-notification-bell.component';
-import { InAppNotificationEntryComponent } from 'core-app/features/in-app-notifications/entry/in-app-notification-entry.component';
+import {
+ InAppNotificationBellComponent
+} from 'core-app/features/in-app-notifications/bell/in-app-notification-bell.component';
+import {
+ InAppNotificationEntryComponent
+} from 'core-app/features/in-app-notifications/entry/in-app-notification-entry.component';
import { OpenprojectPrincipalRenderingModule } from 'core-app/shared/components/principal/principal-rendering.module';
-import { UIRouterModule } from '@uirouter/angular';
import { ScrollingModule } from '@angular/cdk/scrolling';
import {
InAppNotificationCenterComponent,
@@ -13,12 +16,17 @@ import {
import { OpenprojectWorkPackagesModule } from 'core-app/features/work-packages/openproject-work-packages.module';
import { DynamicModule } from 'ng-dynamic-component';
import { InAppNotificationStatusComponent } from './entry/status/in-app-notification-status.component';
-import { OpenprojectContentLoaderModule } from 'core-app/shared/components/op-content-loader/openproject-content-loader.module';
+import {
+ OpenprojectContentLoaderModule
+} from 'core-app/shared/components/op-content-loader/openproject-content-loader.module';
import { EmptyStateComponent } from './center/empty-state/empty-state.component';
import { IanBellService } from 'core-app/features/in-app-notifications/bell/state/ian-bell.service';
import { InAppNotificationActorsLineComponent } from './entry/actors-line/in-app-notification-actors-line.component';
import { InAppNotificationDateAlertComponent } from './entry/date-alert/in-app-notification-date-alert.component';
-import { InAppNotificationsDateAlertsUpsaleComponent } from 'core-app/features/in-app-notifications/date-alerts-upsale/ian-date-alerts-upsale.component';
+import {
+ InAppNotificationsDateAlertsUpsaleComponent
+} from 'core-app/features/in-app-notifications/date-alerts-upsale/ian-date-alerts-upsale.component';
+import { IanCenterService } from "core-app/features/in-app-notifications/center/state/ian-center.service";
@NgModule({
declarations: [
diff --git a/lib/redmine/menu_manager/menu_helper.rb b/lib/redmine/menu_manager/menu_helper.rb
index 6776e41d852..f733a2efbfa 100644
--- a/lib/redmine/menu_manager/menu_helper.rb
+++ b/lib/redmine/menu_manager/menu_helper.rb
@@ -236,7 +236,7 @@ module Redmine::MenuManager::MenuHelper
))
end
- badge_class = item.badge(project).present? ? " #{menu_class}--item-title_has-badge" : ""
+ badge_class = item.badge(project:).present? ? " #{menu_class}--item-title_has-badge" : ""
link_text << content_tag(:span,
class: "#{menu_class}--item-title#{badge_class}",
@@ -472,8 +472,9 @@ module Redmine::MenuManager::MenuHelper
def badge_for(item)
badge = "".html_safe
- if item.badge(@project).present?
- badge += content_tag("span", I18n.t(item.badge(@project)), class: "main-item--badge")
+ key = item.badge(project: @project)
+ if badge.present?
+ badge += content_tag("span", I18n.t(key), class: "main-item--badge")
end
badge
end
diff --git a/lib/redmine/menu_manager/menu_item.rb b/lib/redmine/menu_manager/menu_item.rb
index 8629fc2a0ed..60129955688 100644
--- a/lib/redmine/menu_manager/menu_item.rb
+++ b/lib/redmine/menu_manager/menu_item.rb
@@ -109,9 +109,9 @@ class Redmine::MenuManager::MenuItem < Redmine::MenuManager::TreeNode
@icon = new_icon
end
- def badge(project = nil)
+ def badge(**)
if @badge.is_a?(Proc)
- @badge.call(project).to_s
+ @badge.call(**).to_s
else
@badge
end
diff --git a/modules/github_integration/lib/open_project/github_integration/engine.rb b/modules/github_integration/lib/open_project/github_integration/engine.rb
index c8c8ff1cb13..4767b08874e 100644
--- a/modules/github_integration/lib/open_project/github_integration/engine.rb
+++ b/modules/github_integration/lib/open_project/github_integration/engine.rb
@@ -82,6 +82,16 @@ module OpenProject::GithubIntegration
parent: :admin_github_integration,
caption: :label_deploy_target_plural,
icon: "cloud"
+
+ menu :work_package_split_view,
+ :github,
+ { tab: :github },
+ if: ->(project) {
+ User.current.allowed_in_project?(:show_github_content, project)
+ },
+ parent: :admin_github_integration,
+ caption: :label_deploy_target_plural,
+ icon: "cloud"
end
initializer "github.register_hook" do