context_menus_controller.rb
89 lines
| 3.2 KiB
| text/x-ruby
|
RubyLexer
|
r9453 | # Redmine - project management software | ||
|
r14856 | # Copyright (C) 2006-2016 Jean-Philippe Lang | ||
|
r9453 | # | ||
# 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. | ||||
|
r3892 | class ContextMenusController < ApplicationController | ||
helper :watchers | ||||
|
r5375 | helper :issues | ||
|
r6677 | |||
|
r15273 | before_action :find_issues, :only => :issues | ||
|
r11731 | |||
|
r3892 | def issues | ||
if (@issues.size == 1) | ||||
@issue = @issues.first | ||||
end | ||||
|
r9779 | @issue_ids = @issues.map(&:id).sort | ||
|
r8706 | |||
|
r8707 | @allowed_statuses = @issues.map(&:new_statuses_allowed_to).reduce(:&) | ||
|
r3892 | |||
|
r15084 | @can = {:edit => @issues.all?(&:attributes_editable?), | ||
|
r3892 | :log_time => (@project && User.current.allowed_to?(:log_time, @project)), | ||
|
r13603 | :copy => User.current.allowed_to?(:copy_issues, @projects) && Issue.allowed_target_projects.any?, | ||
|
r14929 | :add_watchers => User.current.allowed_to?(:add_issue_watchers, @projects), | ||
|
r15084 | :delete => @issues.all?(&:deletable?) | ||
|
r3892 | } | ||
|
r15204 | |||
@assignables = @issues.map(&:assignable_users).reduce(:&) | ||||
|
r15048 | @trackers = @projects.map {|p| Issue.allowed_target_trackers(p) }.reduce(:&) | ||
|
r9778 | @versions = @projects.map {|p| p.shared_versions.open}.reduce(:&) | ||
|
r6677 | |||
|
r5950 | @priorities = IssuePriority.active.reverse | ||
|
r3892 | @back = back_url | ||
|
r6677 | |||
|
r8704 | @options_by_custom_field = {} | ||
if @can[:edit] | ||||
|
r15541 | custom_fields = @issues.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?).select {|field| field.format.bulk_edit_supported} | ||
|
r8704 | custom_fields.each do |field| | ||
values = field.possible_values_options(@projects) | ||||
|
r12127 | if values.present? | ||
|
r8704 | @options_by_custom_field[field] = values | ||
end | ||||
end | ||||
end | ||||
|
r9729 | @safe_attributes = @issues.map(&:safe_attribute_names).reduce(:&) | ||
|
r3892 | render :layout => false | ||
end | ||||
|
r5192 | |||
def time_entries | ||||
|
r11733 | @time_entries = TimeEntry.where(:id => params[:ids]).preload(:project).to_a | ||
|
r10996 | (render_404; return) unless @time_entries.present? | ||
|
r12981 | if (@time_entries.size == 1) | ||
@time_entry = @time_entries.first | ||||
end | ||||
|
r10996 | |||
|
r5192 | @projects = @time_entries.collect(&:project).compact.uniq | ||
@project = @projects.first if @projects.size == 1 | ||||
@activities = TimeEntryActivity.shared.active | ||||
|
r13860 | |||
edit_allowed = @time_entries.all? {|t| t.editable_by?(User.current)} | ||||
@can = {:edit => edit_allowed, :delete => edit_allowed} | ||||
|
r5192 | @back = back_url | ||
|
r12981 | |||
@options_by_custom_field = {} | ||||
if @can[:edit] | ||||
custom_fields = @time_entries.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?) | ||||
custom_fields.each do |field| | ||||
values = field.possible_values_options(@projects) | ||||
if values.present? | ||||
@options_by_custom_field[field] = values | ||||
end | ||||
end | ||||
end | ||||
|
r5192 | render :layout => false | ||
|
r6677 | end | ||
|
r3892 | end | ||