alphanodes / additionals

Redmine plugin for easy customization of settings, text and content display by using personal or role-based dashboards (drag&drop), providing wiki macros and act as library for other plugins.
https://www.redmine.org/plugins/additionals
GNU General Public License v2.0
131 stars 43 forks source link

Include Subproject News Option #164

Open defsdoor opened 1 year ago

defsdoor commented 1 year ago

Hi

I'd find it really useful to have the option to include news articles on a dashboard for the current project and all sub-projects.

I might have a go at doing this myself - would this be a useful feature worth including ?

Cheers

defsdoor commented 1 year ago

Not sure if this is nice or optimal as I don't know the Redmine code very well and obviously this should be configurable -

diff --git a/app/helpers/dashboards_helper.rb b/app/helpers/dashboards_helper.rb
index d2cf89a6..63e17b36 100644
--- a/app/helpers/dashboards_helper.rb
+++ b/app/helpers/dashboards_helper.rb
@@ -344,8 +344,10 @@ module DashboardsHelper
     news = if dashboard.content_project.nil?
              News.latest User.current, max_entries
            else
-             dashboard.content_project
-                      .news
+             project_ids = [dashboard.content_project.id] +
+                           dashboard.content_project.descendants.where.not(status: Project::STATUS_ARCHIVED).ids
+             @subproject_ids = project_ids & User.current.memberships.collect(&:project_id)
+             News.where(project_id: @subproject_ids)
                       .limit(max_entries)
                       .includes(:author, :project)
                       .reorder(created_on: :desc)
diff --git a/app/views/dashboards/blocks/_news.html.slim b/app/views/dashboards/blocks/_news.html.slim
index 93d87f85..8f942876 100644
--- a/app/views/dashboards/blocks/_news.html.slim
+++ b/app/views/dashboards/blocks/_news.html.slim
@@ -15,7 +15,10 @@ h3.icon.icon-news = l :label_news_latest
         = link_to_function l(:button_cancel), "$('##{block}-settings').toggle()"

 - if news.any?
+  - saved_project = @project
+  - @project = nil if @subproject_ids && @subproject_ids.size > 1
   = render partial: 'news/news', collection: news
+  - @project = saved_project
   p
     - if @project
       = link_to l(:label_news_view_all), project_news_index_path(@project)