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

Allow news widget to appear globally

Oliver Günther1cfa921d455a
diff --git a/frontend/src/app/core/path-helper/path-helper.service.ts b/frontend/src/app/core/path-helper/path-helper.service.ts
index 31148c81783..390aeddda2a 100644
--- a/frontend/src/app/core/path-helper/path-helper.service.ts
+++ b/frontend/src/app/core/path-helper/path-helper.service.ts
@@ -282,6 +282,10 @@ export class PathHelperService {
return `${this.staticBase}/versions/${id}`;
}
+ public widgetPath(widgetName:string) {
+ return `${this.staticBase}/widgets/${widgetName}`;
+ }
+
public workPackagePath(id:string|number) {
return `${this.staticBase}/work_packages/${id}`;
}
diff --git a/frontend/src/app/shared/components/grids/widgets/abstract-turbo-widget.component.ts b/frontend/src/app/shared/components/grids/widgets/abstract-turbo-widget.component.ts
index 32ed255f1a2..6f6935a25f5 100644
--- a/frontend/src/app/shared/components/grids/widgets/abstract-turbo-widget.component.ts
+++ b/frontend/src/app/shared/components/grids/widgets/abstract-turbo-widget.component.ts
@@ -39,9 +39,12 @@ export abstract class AbstractTurboWidgetComponent extends AbstractWidgetCompone
abstract readonly frameId:string;
abstract readonly name:string;
- protected get src():string|null {
- if (!this.currentProject.identifier) return null;
- return this.pathHelper.projectWidgetPath(this.currentProject.identifier, this.name);
+ protected get src():string {
+ if (this.currentProject.identifier) {
+ return this.pathHelper.projectWidgetPath(this.currentProject.identifier, this.name);
+ } else {
+ return this.pathHelper.widgetPath(this.name);
+ }
}
public override get isEditable():boolean {
diff --git a/modules/grids/app/controllers/grids/base_in_optional_project_controller.rb b/modules/grids/app/controllers/grids/base_in_optional_project_controller.rb
new file mode 100644
index 00000000000..3e4d12004c0
--- /dev/null
+++ b/modules/grids/app/controllers/grids/base_in_optional_project_controller.rb
@@ -0,0 +1,39 @@
+# 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 ::Grids
+ class BaseInOptionalProjectController < ::ApplicationController
+ before_action :load_and_authorize_in_optional_project
+
+ def show
+ render
+ end
+ end
+end
diff --git a/modules/overviews/app/components/overviews/widgets/news_component.html.erb b/modules/overviews/app/components/overviews/widgets/news_component.html.erb
index 69d2810f903..e267c49b623 100644
--- a/modules/overviews/app/components/overviews/widgets/news_component.html.erb
+++ b/modules/overviews/app/components/overviews/widgets/news_component.html.erb
@@ -34,7 +34,33 @@ See COPYRIGHT and LICENSE files for more details.
box.with_box(mt: 2, pb: 2, border: i == @newest.count - 1 ? false : :bottom) do
component_collection do |body|
body.with_component(
- render(Primer::Beta::Link.new(font_weight: :bold, underline: true, href: news_path(news))) { news.title }
+ if @project
+ render(
+ Primer::Beta::Link.new(
+ font_weight: :bold,
+ underline: true,
+ href: news_path(news)
+ )
+ ) { news.title }
+ else
+ render(Primer::OpenProject::FlexLayout.new) do |layout|
+ layout.with_column do
+ render(
+ Primer::Beta::Link.new(
+ font_weight: :bold,
+ scheme: :secondary,
+ underline: false,
+ href: project_path(news.project)
+ )
+ ) { "#{news.project.name}:" }
+ end
+
+ layout.with_column do
+ render(Primer::Beta::Link.new(ml: 1, font_weight: :bold, underline: true, href: news_path(news))) { news.title }
+ end
+ end
+
+ end
)
body.with_component(
render(Primer::Beta::Text.new(tag: :p, color: :subtle)) { helpers.authoring_at(format_time(news.created_at), news.author) }
diff --git a/modules/overviews/app/components/overviews/widgets/news_component.rb b/modules/overviews/app/components/overviews/widgets/news_component.rb
index 3cf517c8b12..060f7960b47 100644
--- a/modules/overviews/app/components/overviews/widgets/news_component.rb
+++ b/modules/overviews/app/components/overviews/widgets/news_component.rb
@@ -44,7 +44,16 @@ module Overviews
@project = project
@current_user = current_user
- @news = project.news.visible.newest_first
+ @news =
+ if project
+ project.news.visible(current_user).newest_first
+ else
+ News
+ .visible(current_user)
+ .newest_first
+ .includes(:project)
+ end
+
@newest = @news.limit(NEWS_LIMIT).to_a
end
end
diff --git a/modules/overviews/app/controllers/overviews/project_widget_controller.rb b/modules/overviews/app/controllers/overviews/project_widget_controller.rb
new file mode 100644
index 00000000000..184306c5aa1
--- /dev/null
+++ b/modules/overviews/app/controllers/overviews/project_widget_controller.rb
@@ -0,0 +1,36 @@
+# 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.
+#++
+
+class Overviews::ProjectWidgetController < Grids::BaseInProjectController
+ include OpTurbo::ComponentStream
+ include OpTurbo::FlashStreamHelper
+
+ layout -> { "turbo_rails/frame" }
+end
diff --git a/modules/overviews/app/controllers/overviews/widget_controller.rb b/modules/overviews/app/controllers/overviews/widget_controller.rb
index 7c5c3ece6c8..342f3fcf7e8 100644
--- a/modules/overviews/app/controllers/overviews/widget_controller.rb
+++ b/modules/overviews/app/controllers/overviews/widget_controller.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Overviews::WidgetController < Grids::BaseInProjectController
+class Overviews::WidgetController < Grids::BaseInOptionalProjectController
include OpTurbo::ComponentStream
include OpTurbo::FlashStreamHelper
diff --git a/modules/overviews/app/controllers/overviews/widgets/project_statuses_controller.rb b/modules/overviews/app/controllers/overviews/widgets/project_statuses_controller.rb
index 9019ffbd0d9..b4c02a4898d 100644
--- a/modules/overviews/app/controllers/overviews/widgets/project_statuses_controller.rb
+++ b/modules/overviews/app/controllers/overviews/widgets/project_statuses_controller.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Overviews::Widgets::ProjectStatusesController < Overviews::WidgetController
+class Overviews::Widgets::ProjectStatusesController < Overviews::ProjectWidgetController
def update
call = Projects::UpdateService
.new(model: @project, user: current_user)
diff --git a/modules/overviews/config/routes.rb b/modules/overviews/config/routes.rb
index 84786065bd2..e681ea96123 100644
--- a/modules/overviews/config/routes.rb
+++ b/modules/overviews/config/routes.rb
@@ -23,6 +23,12 @@ Rails.application.routes.draw do
end
end
+ scope module: "overviews" do
+ namespace :widgets do
+ resource :news, only: %i[show]
+ end
+ end
+
resources :project_phases, controller: "overviews/project_phases", only: %i[edit update] do
put :preview, on: :member
end