You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

context_menus_controller.rb 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class ContextMenusController < ApplicationController
  18. helper :watchers
  19. helper :issues
  20. before_action :find_issues, :only => :issues
  21. def issues
  22. if (@issues.size == 1)
  23. @issue = @issues.first
  24. end
  25. @issue_ids = @issues.map(&:id).sort
  26. @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&)
  27. @can = {:edit => @issues.all?(&:attributes_editable?),
  28. :log_time => (@project && User.current.allowed_to?(:log_time, @project)),
  29. :copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?,
  30. :add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects),
  31. :delete => @issues.all?(&:deletable?)
  32. }
  33. @assignables = @issues.map(&:assignable_users).reduce(:&)
  34. @trackers = @projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&)
  35. @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&)
  36. @priorities = IssuePriority.active.reverse
  37. @back = back_url
  38. @options_by_custom_field = {}
  39. if @can[:edit]
  40. custom_fields = @issues.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
  41. custom_fields.each do |field|
  42. values = field.possible_values_options(@projects)
  43. if values.present?
  44. @options_by_custom_field[field] = values
  45. end
  46. end
  47. end
  48. @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&)
  49. render :layout => false
  50. end
  51. def time_entries
  52. @time_entries = TimeEntry.where(:id => params[:ids]).
  53. preload(:project => :time_entry_activities).
  54. preload(:user).to_a
  55. (render_404; return) unless @time_entries.present?
  56. if (@time_entries.size == 1)
  57. @time_entry = @time_entries.first
  58. end
  59. @projects = @time_entries.collect(&:project).compact.uniq
  60. @project = @projects.first if @projects.size == 1
  61. @activities = @projects.map(&:activities).reduce(:&)
  62. edit_allowed = @time_entries.all? {|t| t.editable_by?(User.current)}
  63. @can = {:edit => edit_allowed, :delete => edit_allowed}
  64. @back = back_url
  65. @options_by_custom_field = {}
  66. if @can[:edit]
  67. custom_fields = @time_entries.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported}
  68. custom_fields.each do |field|
  69. values = field.possible_values_options(@projects)
  70. if values.present?
  71. @options_by_custom_field[field] = values
  72. end
  73. end
  74. end
  75. render :layout => false
  76. end
  77. end