kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
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.
129 lines
5.0 KiB
129 lines
5.0 KiB
13 years ago
|
#-- encoding: UTF-8
|
||
14 years ago
|
#-- copyright
|
||
12 years ago
|
# OpenProject is a project management system.
|
||
11 years ago
|
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
|
||
14 years ago
|
#
|
||
14 years ago
|
# This program is free software; you can redistribute it and/or
|
||
12 years ago
|
# modify it under the terms of the GNU General Public License version 3.
|
||
14 years ago
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2013 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.
|
||
|
#
|
||
14 years ago
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
|
|
||
11 years ago
|
class WorkPackages::BulkController < ApplicationController
|
||
12 years ago
|
before_filter :disable_api
|
||
11 years ago
|
before_filter :find_work_packages, only: [:edit, :update]
|
||
11 years ago
|
before_filter :authorize
|
||
14 years ago
|
|
||
14 years ago
|
include JournalsHelper
|
||
14 years ago
|
include ProjectsHelper
|
||
18 years ago
|
include CustomFieldsHelper
|
||
11 years ago
|
include RelationsHelper
|
||
15 years ago
|
include QueriesHelper
|
||
17 years ago
|
include IssuesHelper
|
||
18 years ago
|
|
||
11 years ago
|
def edit
|
||
11 years ago
|
@work_packages.sort!
|
||
14 years ago
|
@available_statuses = @projects.map{|p|Workflow.available_statuses(p)}.inject{|memo,w|memo & w}
|
||
12 years ago
|
@custom_fields = @projects.map{|p|p.all_work_package_custom_fields}.inject{|memo,c|memo & c}
|
||
14 years ago
|
@assignables = @projects.map(&:assignable_users).inject{|memo,a| memo & a}
|
||
11 years ago
|
@types = @projects.map(&:types).inject{|memo,t| memo & t}
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
def update
|
||
11 years ago
|
@work_packages.sort!
|
||
11 years ago
|
attributes = parse_params_for_bulk_work_package_attributes(params)
|
||
14 years ago
|
|
||
11 years ago
|
unsaved_work_package_ids = []
|
||
|
@work_packages.each do |work_package|
|
||
|
work_package.reload
|
||
|
work_package.add_journal(User.current, params[:notes])
|
||
|
work_package.safe_attributes = attributes
|
||
|
call_hook(:controller_work_package_bulk_before_save, { params: params, work_package: work_package })
|
||
14 years ago
|
JournalObserver.instance.send_notification = params[:send_notification] == '0' ? false : true
|
||
11 years ago
|
unless work_package.save
|
||
|
unsaved_work_package_ids << work_package.id
|
||
14 years ago
|
end
|
||
|
end
|
||
11 years ago
|
set_flash_from_bulk_save(@work_packages, unsaved_work_package_ids)
|
||
|
redirect_back_or_default({controller: '/work_packages', action: :index, project_id: @project})
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
def destroy
|
||
|
@hours = TimeEntry.sum(:hours, :conditions => ['work_package_id IN (?)', @work_packages]).to_f
|
||
|
if @hours > 0
|
||
|
case params[:todo]
|
||
|
when 'destroy'
|
||
|
# nothing to do
|
||
|
when 'nullify'
|
||
|
update_time_entries('work_package_id = NULL', @work_packages)
|
||
|
when 'reassign'
|
||
|
reassign_to = @project.work_packages.find_by_id(params[:reassign_to_id])
|
||
|
if reassign_to.nil?
|
||
|
flash.now[:error] = l(:error_work_package_not_found_in_project)
|
||
|
return
|
||
|
else
|
||
|
update_time_entries("work_package_id = #{reassign_to_id.id}", @work_packages)
|
||
|
end
|
||
|
else
|
||
|
# display the destroy form if it's a user request
|
||
|
return unless api_request?
|
||
|
end
|
||
|
end
|
||
|
|
||
|
@work_packages.each do |work_package|
|
||
|
begin
|
||
|
work_package.reload.destroy
|
||
|
rescue ::ActiveRecord::RecordNotFound # raised by #reload if work package no longer exists
|
||
|
# nothing to do, work package was already deleted (eg. by a parent)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
respond_to do |format|
|
||
|
format.html { redirect_back_or_default(project_work_packages_path(@project)) }
|
||
|
end
|
||
|
end
|
||
|
|
||
18 years ago
|
private
|
||
14 years ago
|
|
||
11 years ago
|
def parse_params_for_bulk_work_package_attributes(params)
|
||
11 years ago
|
attributes = (params[:work_package] || {}).reject {|k,v| v.blank?}
|
||
14 years ago
|
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
|
||
|
attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
|
||
11 years ago
|
attributes.delete :custom_field_values if not attributes.has_key?(:custom_field_values) or attributes[:custom_field_values].empty?
|
||
14 years ago
|
attributes
|
||
|
end
|
||
11 years ago
|
|
||
|
# Sets the `flash` notice or error based the number of work packages that did not save
|
||
|
#
|
||
|
# @param [Array, WorkPackage] work_packages all of the saved and unsaved WorkPackages
|
||
|
# @param [Array, Integer] unsaved_work_package_ids the WorkPackage ids that were not saved
|
||
|
def set_flash_from_bulk_save(work_packages, unsaved_work_package_ids)
|
||
|
if unsaved_work_package_ids.empty?
|
||
|
flash[:notice] = l(:notice_successful_update) unless work_packages.empty?
|
||
|
else
|
||
|
flash[:error] = l(:notice_failed_to_save_work_packages,
|
||
|
:count => unsaved_work_package_ids.size,
|
||
|
:total => work_packages.size,
|
||
|
:ids => '#' + unsaved_work_package_ids.join(', #'))
|
||
|
end
|
||
|
end
|
||
19 years ago
|
end
|