Override "all open" query when BCF is active and redirect to new "all open" when clicking on module name

pull/7498/head
Henriette Dinger 5 years ago
parent 0663aa19d5
commit defdb27e09
  1. 2
      app/helpers/application_helper.rb
  2. 14
      app/helpers/work_packages_filter_helper.rb
  3. 29
      frontend/src/app/components/wp-query-select/wp-static-queries.service.ts
  4. 4
      lib/redmine/menu_manager/menu_controller.rb
  5. 14
      lib/redmine/menu_manager/menu_helper.rb
  6. 14
      lib/redmine/menu_manager/menu_item.rb
  7. 2
      lib/redmine/plugin.rb
  8. 9
      modules/bcf/app/controllers/bcf/issues_controller.rb
  9. 27
      modules/bcf/app/helpers/bcf_application_helper.rb
  10. 44
      modules/bcf/app/helpers/bcf_work_packages_filter_helper.rb
  11. 3
      modules/bcf/config/locales/js-en.yml
  12. 2
      modules/bcf/config/routes.rb
  13. 12
      modules/bcf/lib/open_project/bcf/engine.rb

@ -308,8 +308,6 @@ module ApplicationHelper
css << "ee-banners-#{EnterpriseToken.show_banners? ? 'visible' : 'hidden'}"
css << "bcf-#{@project&.module_enabled?(:bcf) ? 'activated' : 'deactivated'}"
# Add browser specific classes to aid css fixes
css += browser_specific_classes

@ -214,20 +214,6 @@ module WorkPackagesFilterHelper
project_work_packages_with_query_path(version.project, query, options)
end
def project_work_packages_bcf_issues_path(project)
query = {
f: [
filter_object('status_id', 'o')
],
hi: true,
hl: 'priority',
t: 'created_at:desc',
dr: 'card'
}
project_work_packages_with_query_path(project, query)
end
private
def default_sort

@ -59,7 +59,6 @@ export class WorkPackageStaticQueriesService {
recently_created: this.I18n.t('js.work_packages.default_queries.recently_created'),
all_open: this.I18n.t('js.work_packages.default_queries.all_open'),
summary: this.I18n.t('js.work_packages.default_queries.summary'),
bcf_issues: this.I18n.t('js.bcf.work_packages.default_queries.bcf'),
};
// Create all static queries manually
@ -81,14 +80,24 @@ export class WorkPackageStaticQueriesService {
identifier: 'recently_created',
label: this.text.recently_created,
query_props: '{"c":["id","subject","type","status","assignee","createdAt"],"hi":false,"g":"","t":"createdAt:desc","f":[{"n":"status","o":"o","v":[]}]}'
},
{
identifier: 'all_open',
label: this.text.all_open,
query_props: null
}
] as IAutocompleteItem[];
// Modify default "all open" query for BCF
if (this.BcfDetectorService.isBcfActivated) {
items.push({
identifier: 'all_open',
label: this.text.all_open,
query_props: '{"hi":true,"hl":"priority","f":[{"n":"status","o":"o","v":[]}],"dr":"card"}'
});
} else {
items.push({
identifier: 'all_open',
label: this.text.all_open,
query_props: null
});
}
const projectIdentifier = this.CurrentProject.identifier;
if (projectIdentifier) {
items.push({
@ -113,14 +122,6 @@ export class WorkPackageStaticQueriesService {
]);
}
if (this.BcfDetectorService.isBcfActivated) {
items.push({
identifier: 'bcf_issues',
label: this.text.bcf_issues,
query_props: '{"hi":true,"hl":"priority","g":"","t":"createdAt:desc","f":[{"n":"status","o":"o","v":[]}],"dr":"card"}'
});
}
return items;
}

@ -93,8 +93,8 @@ module Redmine::MenuManager::MenuController
# Returns false if user is not authorized
def redirect_to_project_menu_item(project, name)
item = Redmine::MenuManager.items(:project_menu).detect { |i| i.name.to_s == name.to_s }
if item && User.current.allowed_to?(item.url, project) && (item.condition.nil? || item.condition.call(project))
redirect_to({ item.param => project }.merge(item.url))
if item && User.current.allowed_to?(item.url(project), project) && (item.condition.nil? || item.condition.call(project))
redirect_to({ item.param => project }.merge(item.url(project)))
return true
end
false

@ -201,9 +201,9 @@ module Redmine::MenuManager::MenuHelper
def render_unattached_menu_item(menu_item, project)
raise Redmine::MenuManager::MenuError, ':child_menus must be an array of MenuItems' unless menu_item.is_a? Redmine::MenuManager::MenuItem
if User.current.allowed_to?(menu_item.url, project)
if User.current.allowed_to?(menu_item.url(project), project)
link_to(menu_item.caption,
menu_item.url,
menu_item.url(project),
menu_item.html_options)
end
end
@ -244,13 +244,13 @@ module Redmine::MenuManager::MenuHelper
def extract_node_details(node, project = nil)
item = node
url = case item.url
url = case item.url(project)
when Hash
project.nil? ? item.url : { item.param => project }.merge(item.url)
project.nil? ? item.url(project) : { item.param => project }.merge(item.url(project))
when Symbol
main_app.send(item.url)
main_app.send(item.url(project))
else
item.url
item.url(project)
end
caption = item.caption(project)
@ -271,7 +271,7 @@ module Redmine::MenuManager::MenuHelper
end
if project
user && user.allowed_to?(node.url, project)
user && user.allowed_to?(node.url(project), project)
else
# outside a project, all menu items allowed
true

@ -29,7 +29,7 @@
class Redmine::MenuManager::MenuItem < Redmine::MenuManager::TreeNode
include Redmine::I18n
attr_reader :name, :url, :param, :icon_after, :context, :condition, :parent, :child_menus, :last, :partial
attr_reader :name, :param, :icon_after, :context, :condition, :parent, :child_menus, :last, :partial
def initialize(name, url, options)
raise ArgumentError, "Invalid option :if for menu item '#{name}'" if options[:if] && !options[:if].respond_to?(:call)
@ -99,6 +99,18 @@ class Redmine::MenuManager::MenuItem < Redmine::MenuManager::TreeNode
@badge = new_badge
end
def url(project = nil)
if @url.is_a?(Proc)
@url.call(project)
else
@url
end
end
def url=(new_url)
@url = new_url
end
def html_options(options = {})
if options[:selected]
o = @html_options.dup

@ -279,7 +279,7 @@ module Redmine #:nodoc:
menu_item.caption = options[:caption]
menu_item.icon = options[:icon]
menu_item.badge = options[:badge]
menu_item.url = options[:url]
end
end

@ -30,8 +30,9 @@
module ::Bcf
class IssuesController < BaseController
include WorkPackagesFilterHelper
include PaginationHelper
include WorkPackagesFilterHelper
include BcfWorkPackagesFilterHelper
before_action :find_project_by_project_id
before_action :authorize
@ -88,6 +89,10 @@ module ::Bcf
@bcf_attachment.destroy
end
def redirect_to_bcf_issues_list
redirect_to project_work_packages_bcf_issues_path(@project)
end
private
def import_canceled?
@ -97,7 +102,7 @@ module ::Bcf
unknown_mails_action
non_members_action].map { |key| params.dig(:import_options, key) }.include? 'cancel'
flash[:notice] = I18n.t('bcf.bcf_xml.import_canceled')
redirect_to project_work_packages_bcf_issues_path(@project)
redirect_to_bcf_issues_list
end
end

@ -0,0 +1,27 @@
#-- copyright
# OpenProject Costs Plugin
#
# Copyright (C) 2009 - 2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 3.
#
# 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.
#++
#
module BcfApplicationHelper
def body_css_classes
classes = super
classes = classes + " bcf-#{@project&.module_enabled?(:bcf) ? 'activated' : 'deactivated'}"
classes
end
end

@ -0,0 +1,44 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# 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 BcfWorkPackagesFilterHelper
def project_work_packages_bcf_issues_path(project)
query = {
f: [
filter_object('status_id', 'o')
],
hi: true,
hl: 'priority',
dr: 'card'
}
project_work_packages_with_query_path(project, query)
end
end

@ -4,6 +4,3 @@ en:
bcf:
import: 'Import'
export: 'Export'
work_packages:
default_queries:
bcf: 'BCF issues'

@ -42,6 +42,8 @@ OpenProject::Application.routes.draw do
post :configure_import, action: :configure_import, on: :collection
post :import, action: :perform_import, on: :collection
end
get 'bcf_issues', to: 'bcf/issues#redirect_to_bcf_issues_list', as: :work_packages
end
end
end

@ -45,7 +45,10 @@ module OpenProject::Bcf
project_module :bcf do
permission :view_linked_issues,
'bcf/issues': :index
'bcf/issues': %i[index redirect_to_bcf_issues_list]
permission :view_work_packages,
'bcf/issues': :redirect_to_bcf_issues_list
permission :manage_bcf,
'bcf/issues': %i[index upload prepare_import configure_import perform_import]
@ -53,8 +56,11 @@ module OpenProject::Bcf
rename_menu_item :project_menu,
:work_packages,
{ caption: Proc.new { |project| project.module_enabled?(:bcf) ? I18n.t(:'bcf.label_bcf') : I18n.t(:label_work_package_plural) },
icon: Proc.new { |project| project.module_enabled?(:bcf) ? 'icon2 icon-bcf' : 'icon2 icon-view-timeline' },
{ url: Proc.new { |project| project.module_enabled?(:bcf) ?
{ controller: 'bcf/issues', action: 'redirect_to_bcf_issues_list' } :
{ controller: 'work_packages', action: 'index' } },
caption: Proc.new { |project| project.module_enabled?(:bcf) ? I18n.t(:'bcf.label_bcf') : I18n.t(:label_work_package_plural) },
icon: Proc.new { |project| project.module_enabled?(:bcf) ? 'icon2 icon-bcf' : 'icon2 icon-view-timeline' },
badge: Proc.new { |project| project.module_enabled?(:bcf) ? 'bcf.experimental_badge' : nil } }
end

Loading…
Cancel
Save