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

replace backlogs page overriding by cell

ulfertsbd4b59e32168
diff --git a/app/cells/versions/row_cell.rb b/app/cells/versions/row_cell.rb
new file mode 100644
index 00000000000..ff4355e2495
--- /dev/null
+++ b/app/cells/versions/row_cell.rb
@@ -0,0 +1,137 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.
+#++
+
+module Versions
+ class RowCell < ::RowCell
+ include VersionsHelper
+
+ # Overriding cell's method to set the project instance variable.
+ # A lot of helpers rely on the existence of it.
+ def setup!(model, options)
+ instance_variable_set(:@project, options[:table].project) if options[:table].project
+
+ super
+ end
+
+ def version
+ model
+ end
+
+ def project
+ version.project
+ end
+
+ def row_css_class
+ shared = "shared" if version.project != table.project
+
+ ["version", shared].compact.join(" ")
+ end
+
+ def name
+ link_to_version version, {}, project: version.project
+ end
+
+ def start_date
+ format_date(version.start_date)
+ end
+
+ def effective_date
+ format_date(version.effective_date)
+ end
+
+ def description
+ h(version.description)
+ end
+
+ def status
+ t("version_status_#{version.status}")
+ end
+
+ def sharing
+ h(format_version_sharing(version.sharing))
+ end
+
+ def wiki_page
+ return '' if wiki_page_title.blank? || version.project.wiki.nil?
+
+ link_to_if_authorized(wiki_page_title,
+ { controller: '/wiki',
+ action: 'show',
+ project_id: version.project,
+ id: wiki_page_title }) || h(wiki_page_title)
+ end
+
+ def button_links
+ [edit_link, delete_link, backlogs_edit_link].compact
+ end
+
+ private
+
+ def wiki_page_title
+ version.wiki_page_title
+ end
+
+ def edit_link
+ return unless version.project == table.project
+
+ link_to_if_authorized '',
+ { controller: '/versions', action: 'edit', id: version },
+ class: 'icon icon-edit',
+ title: t(:button_edit)
+ end
+
+ def delete_link
+ return unless version.project == table.project
+
+ link_to_if_authorized '',
+ { controller: '/versions', action: 'destroy', id: version },
+ data: { confirm: t(:text_are_you_sure) },
+ method: :delete,
+ class: 'icon icon-delete',
+ title: t(:button_delete)
+ end
+
+ def column_css_class(column)
+ if column == :name
+ super.to_s + name_css_class
+ else
+ super
+ end
+ end
+
+ def name_css_class
+ classes = " #{version.status}"
+
+ if version.project != table.project
+ classes += " icon-context icon-link"
+ end
+
+ classes
+ end
+ end
+end
diff --git a/app/cells/versions/table_cell.rb b/app/cells/versions/table_cell.rb
new file mode 100644
index 00000000000..cb888546ad5
--- /dev/null
+++ b/app/cells/versions/table_cell.rb
@@ -0,0 +1,23 @@
+module Versions
+ class TableCell < ::TableCell
+ columns :name, :project, :start_date, :effective_date, :description, :status, :sharing, :wiki_page_title
+
+ def sortable?
+ false
+ end
+
+ def headers
+ columns.reject { |col| col == :wiki_page_title }.map do |name|
+ [name.to_s, header_options(name)]
+ end + [wiki_page_header_options]
+ end
+
+ def header_options(name)
+ { caption: Version.human_attribute_name(name) }
+ end
+
+ def wiki_page_header_options
+ ['wiki_page_title', { caption: WikiPage.model_name.human }]
+ end
+ end
+end
diff --git a/app/controllers/project_settings/versions_controller.rb b/app/controllers/project_settings/versions_controller.rb
index ff3ecf77629..25c18f994ca 100644
--- a/app/controllers/project_settings/versions_controller.rb
+++ b/app/controllers/project_settings/versions_controller.rb
@@ -31,6 +31,8 @@ class ProjectSettings::VersionsController < ProjectSettingsController
menu_item :settings_versions
def show
+ @versions = @project.shared_versions.merge(Versions::Scopes::OrderBySemverName.fetch)
+
render template: 'project_settings/versions'
end
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 7d02ff0bbbf..090211cc186 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -124,10 +124,6 @@ module ApplicationHelper
.html_safe
end
- def format_version_name(version)
- h(version.to_s_for_project(@project))
- end
-
def due_date_distance_in_words(date)
if date
label = date < Date.today ? :label_roadmap_overdue : :label_roadmap_due_in
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 1df32b69937..aa717ddd83c 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -31,16 +31,6 @@
module ProjectsHelper
include WorkPackagesFilterHelper
- def link_to_version(version, html_options = {}, options = {})
- return '' unless version && version.is_a?(Version)
-
- link_name = options[:before_text].to_s.html_safe + format_version_name(version)
- link_to_if version.visible?,
- link_name,
- { controller: '/versions', action: 'show', id: version },
- html_options
- end
-
# Returns a set of options for a select field, grouped by project.
def version_options_for_select(versions, selected = nil)
grouped = Hash.new { |h, k| h[k] = [] }
diff --git a/app/helpers/versions_helper.rb b/app/helpers/versions_helper.rb
index 7a18a67dbe6..16ba600f969 100644
--- a/app/helpers/versions_helper.rb
+++ b/app/helpers/versions_helper.rb
@@ -27,6 +27,20 @@
#++
module VersionsHelper
+ def link_to_version(version, html_options = {}, options = {})
+ return '' unless version&.is_a?(Version)
+
+ link_name = options[:before_text].to_s.html_safe + format_version_name(version, options[:project] || @project)
+ link_to_if version.visible?,
+ link_name,
+ { controller: '/versions', action: 'show', id: version },
+ html_options
+ end
+
+ def format_version_name(version, project = @project)
+ h(version.to_s_for_project(project))
+ end
+
def version_contract(version)
if version.new_record?
Versions::CreateContract.new(version, User.current)
@@ -37,6 +51,6 @@ module VersionsHelper
def format_version_sharing(sharing)
sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
- l("label_version_sharing_#{sharing}")
+ t("label_version_sharing_#{sharing}")
end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 20e58cc84ba..10145bab74d 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -287,12 +287,10 @@ class Project < ActiveRecord::Base
# Returns a scope of the Versions used by the project
def shared_versions
- @shared_versions ||= begin
- if persisted?
- shared_versions_on_persisted
- else
- shared_versions_by_system
- end
+ if persisted?
+ shared_versions_on_persisted
+ else
+ shared_versions_by_system
end
end
diff --git a/app/views/project_settings/versions.html.erb b/app/views/project_settings/versions.html.erb
index db3914a864f..281c819d840 100644
--- a/app/views/project_settings/versions.html.erb
+++ b/app/views/project_settings/versions.html.erb
@@ -27,7 +27,7 @@ See docs/COPYRIGHT.rdoc for more details.
++#%>
-<%= toolbar title: l(:label_version_plural) do %>
+<%= toolbar title: t(:label_version_plural) do %>
<% if current_user.allowed_to?(:manage_versions, @project) %>
<li class="toolbar-item">
<%= link_to_if_authorized({ controller: '/versions', action: 'new', project_id: @project },
@@ -41,131 +41,12 @@ See docs/COPYRIGHT.rdoc for more details.
<% end %>
<% end %>
-<% if @project.shared_versions.any? %>
- <div class="generic-table--container">
- <div class="generic-table--results-container">
- <table class="generic-table">
- <colgroup>
- <col highlight-col>
- <col highlight-col>
- <col highlight-col>
- <col highlight-col>
- <col highlight-col>
- <col highlight-col>
- <col highlight-col>
- <col>
- </colgroup>
- <thead>
- <tr>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.model_name.human %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.human_attribute_name(:start_date) %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.human_attribute_name(:effective_date) %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.human_attribute_name(:description) %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.human_attribute_name(:status) %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.human_attribute_name(:sharing) %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= WikiPage.model_name.human %>
- </span>
- </div>
- </div>
- </th>
- <th><div class="generic-table--empty-header"></div></th>
- </tr>
- </thead>
- <tbody>
- <% @project.shared_versions.order_by_newest_date.each do |version| %>
- <tr class="version <%= 'shared' if version.project != @project %>">
- <td class="name <%=h version.status %><%= ' icon-context icon-link' if version.project != @project %>">
- <%= link_to_version version %>
- </td>
- <td class="date"><%= format_date(version.start_date) %></td>
- <td class="date"><%= format_date(version.effective_date) %></td>
- <td class="description"><%=h version.description %></td>
- <td class="status"><%= l("version_status_#{version.status}") %></td>
- <td class="sharing"><%=h format_version_sharing(version.sharing) %></td>
- <td>
- <%= link_to_if_authorized( h(version.wiki_page_title),
- { controller: '/wiki',
- action: 'show',
- project_id: version.project,
- id: version.wiki_page_title }) ||
- h(version.wiki_page_title) unless version.wiki_page_title.blank? || version.project.wiki.nil? %>
- </td>
- <td class="buttons">
- <% if version.project == @project %>
- <%= link_to_if_authorized '',
- { controller: '/versions', action: 'edit', id: version },
- class: 'icon icon-edit',
- title: t(:button_edit) %>
- <%= link_to_if_authorized '',
- { controller: '/versions', action: 'destroy', id: version },
- data: { confirm: l(:text_are_you_sure) },
- method: :delete,
- class: 'icon icon-delete',
- title: t(:button_delete) %>
- <% end %>
- </td>
- </tr>
- <% end %>
- </tbody>
- </table>
+<% if @versions.any? %>
+ <%= cell Versions::TableCell, @versions, project: @project %>
- </div>
- </div>
<% if @project.versions.any? %>
<div class="generic-table--action-buttons">
- <%= link_to l(:label_close_versions),
+ <%= link_to t(:label_close_versions),
close_completed_project_versions_path(@project),
method: :put,
class: 'button' %>
diff --git a/modules/backlogs/app/views/project_settings/versions.html.erb b/modules/backlogs/app/views/project_settings/versions.html.erb
deleted file mode 100644
index 987e8e17b28..00000000000
--- a/modules/backlogs/app/views/project_settings/versions.html.erb
+++ /dev/null
@@ -1,183 +0,0 @@
-<%#-- copyright
-OpenProject is an open source project management software.
-Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.
-
-++#%>
-<%= toolbar title: l(:label_version_plural) do %>
- <% if current_user.allowed_to?(:manage_versions, @project) %>
- <li class="toolbar-item">
- <%= link_to_if_authorized({ controller: '/versions', action: 'new', project_id: @project },
- { class: 'button -alt-highlight',
- aria: {label: t(:label_version_new)},
- title: t(:label_version_new)}) do %>
- <%= op_icon('button--icon icon-add') %>
- <span class="button--text"><%= t('activerecord.models.version') %></span>
- <% end %>
- </li>
- <% end %>
-<% end %>
-
-<% if @project.shared_versions.any? %>
- <div class="generic-table--container">
- <div class="generic-table--results-container">
- <table class="generic-table">
- <colgroup>
- <col highlight-col>
- <col highlight-col>
- <col highlight-col>
- <col highlight-col>
- <col highlight-col>
- <col highlight-col>
- <col highlight-col>
- <col>
- </colgroup>
- <thead>
- <tr>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.model_name.human %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.human_attribute_name(:start_date) %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.human_attribute_name(:effective_date) %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.human_attribute_name(:description) %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.human_attribute_name(:status) %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= Version.human_attribute_name(:sharing) %>
- </span>
- </div>
- </div>
- </th>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
- <span>
- <%= WikiPage.model_name.human %>
- </span>
- </div>
- </div>
- </th>
- <th><div class="generic-table--empty-header"></div></th>
- </tr>
- </thead>
- <tbody>
- <% @project.shared_versions.order_by_newest_date.each do |version| %>
- <tr class="version <%= 'shared' if version.project != @project %>">
- <td class="name <%=h version.status %><%= ' icon-context icon-link' if version.project != @project %>">
- <%= link_to_version version %>
- </td>
- <td class="date"><%= format_date(version.start_date) %></td>
- <td class="date"><%= format_date(version.effective_date) %></td>
- <td class="description"><%=h version.description %></td>
- <td class="status"><%= l("version_status_#{version.status}") %></td>
- <td class="sharing"><%=h format_version_sharing(version.sharing) %></td>
- <td>
- <%= link_to_if_authorized( h(version.wiki_page_title),
- { controller: '/wiki',
- action: 'show',
- project_id: version.project,
- id: version.wiki_page_title }) ||
- h(version.wiki_page_title) unless version.wiki_page_title.blank? || version.project.wiki.nil? %>
- </td>
- <td class="buttons">
- <% if version.project == @project %>
- <%= link_to_if_authorized '',
- { controller: '/versions', action: 'edit', id: version },
- class: 'icon icon-edit',
- title: t(:button_edit) %>
- <%= link_to_if_authorized '',
- { controller: '/versions', action: 'destroy', id: version },
- data: { confirm: l(:text_are_you_sure) },
- method: :delete,
- class: 'icon icon-delete',
- title: t(:button_delete) %>
- <% elsif @project.enabled_modules.collect(&:name).include?("backlogs") %>
- <%= link_to_if_authorized '',
- { :controller => '/versions', :action => 'edit', :id => version, :project_id => @project.id },
- :class => 'icon icon-edit',
- title: t(:button_edit) %>
- <% end %>
- </td>
- </tr>
- <% end %>
- </tbody>
- </table>
- </div>
- </div>
- <% if @project.versions.any? %>
- <div class="generic-table--action-buttons">
- <%= link_to l(:label_close_versions),
- close_completed_project_versions_path(@project),
- method: :put,
- class: 'button' %>
- </div>
- <% end %>
-<% else %>
- <%= no_results_box action_url: new_project_version_path(@project),
- display_action: authorize_for('versions', 'new'),
- custom_title: t('projects.settings.versions.no_results_title_text'),
- custom_action_text: t('projects.settings.versions.no_results_content_text')
- %>
-<% end %>
diff --git a/modules/backlogs/lib/open_project/backlogs/engine.rb b/modules/backlogs/lib/open_project/backlogs/engine.rb
index 22ee8f16ed6..1194a00d3f6 100644
--- a/modules/backlogs/lib/open_project/backlogs/engine.rb
+++ b/modules/backlogs/lib/open_project/backlogs/engine.rb
@@ -135,6 +135,7 @@ module OpenProject::Backlogs
patch_with_namespace :WorkPackages, :UpdateService
patch_with_namespace :WorkPackages, :SetAttributesService
patch_with_namespace :WorkPackages, :BaseContract
+ patch_with_namespace :Versions, :RowCell
config.to_prepare do
next if Versions::BaseContract.included_modules.include?(OpenProject::Backlogs::Patches::Versions::BaseContractPatch)
diff --git a/modules/backlogs/lib/open_project/backlogs/patches/versions/row_cell_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/versions/row_cell_patch.rb
new file mode 100644
index 00000000000..5ea59739e18
--- /dev/null
+++ b/modules/backlogs/lib/open_project/backlogs/patches/versions/row_cell_patch.rb
@@ -0,0 +1,44 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 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-2017 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 docs/COPYRIGHT.rdoc for more details.
+#++
+
+module OpenProject::Backlogs::Patches::Versions::RowCellPatch
+ def button_links
+ (super + [backlogs_edit_link]).compact
+ end
+
+ private
+
+ def backlogs_edit_link
+ return if version.project == table.project || !table.project.module_enabled?("backlogs")
+
+ link_to_if_authorized '',
+ { controller: '/versions', action: 'edit', id: version, project_id: table.project.id },
+ class: 'icon icon-edit',
+ title: t(:button_edit)
+ end
+end