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.
355 lines
13 KiB
355 lines
13 KiB
# Redmine - project management software
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
|
#
|
|
# 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.
|
|
|
|
class VersionsController < ApplicationController
|
|
layout "base_projects"
|
|
menu_item :roadmap
|
|
model_object Version
|
|
before_filter :find_model_object, :except => [:index, :new, :create, :close_completed,:judge_version_title]
|
|
#before_filter :find_model_object_contest, :except => [:index, :new, :create]
|
|
before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed, :judge_version_title]
|
|
before_filter :find_project_by_project_id, :only => [:index, :new, :create, :close_completed,:judge_version_title]
|
|
before_filter :authorize, :except => [:judge_version_title]
|
|
|
|
accept_api_auth :index, :show, :create, :update, :destroy
|
|
|
|
helper :custom_fields
|
|
helper :projects
|
|
helper :project_score
|
|
|
|
def index
|
|
# 顶部导航
|
|
@project_menu_type = 7
|
|
type = params[:type]
|
|
case type
|
|
when nil,"1"
|
|
@versions = @project.versions.reorder('updated_on desc')
|
|
when "2"
|
|
@versions = @project.versions.where(:status => 'open').reorder('updated_on desc')
|
|
when "3"
|
|
@versions = @project.versions.where(:status => 'locked').reorder('updated_on desc')
|
|
when "4"
|
|
@versions = @project.versions.where(:status => 'closed').reorder('updated_on desc')
|
|
end
|
|
@versions_count = Version.where(:project_id => @project.id).count
|
|
@versions_open_count = Version.where(:project_id => @project.id, :status => "open").count
|
|
@versions_locked_count = Version.where(:project_id => @project.id, :status => "locked").count
|
|
@versions_closed_count = Version.where(:project_id => @project.id, :status => "closed").count
|
|
@versions_count = version_type_count(type, @versions_count, @versions_open_count, @versions_locked_count, @versions_closed_count)
|
|
@limit = 10
|
|
@is_remote = true
|
|
@version_pages = Paginator.new @versions_count, @limit, params['page'] || 1
|
|
@offset ||= @version_pages.offset
|
|
@versions = paginateHelper @versions, @limit
|
|
respond_to do |format|
|
|
format.html
|
|
format.js
|
|
format.api
|
|
# format.html {
|
|
# @trackers = @project.trackers.sorted.all
|
|
# retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
|
|
# @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
|
|
# project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
|
|
#
|
|
# @versions = @project.shared_versions || []
|
|
# @versions += @project.rolled_up_versions.visible if @with_subprojects
|
|
# #added by young
|
|
# @versions = @versions.uniq.reverse#Modified by young
|
|
# unless params[:completed]
|
|
# @completed_versions = @versions.select {|version| version.closed? || version.completed? }
|
|
# @versions -= @completed_versions
|
|
# end
|
|
# @offset, @limit = api_offset_and_limit({:limit => 4})
|
|
# @versions_count = @versions.count
|
|
# @versions_pages = Paginator.new @versions_count, @limit, params['page']
|
|
# @offset ||= @versions_pages.offset
|
|
# @versions = @versions.slice(@offset, @limit)
|
|
# #end by young
|
|
#
|
|
# @issues_by_version = {}
|
|
# if @selected_tracker_ids.any? && @versions.any?
|
|
# issues = Issue.visible.all(
|
|
# :include => [:project, :status, :tracker, :priority, :fixed_version],
|
|
# :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)},
|
|
# :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id"
|
|
# )
|
|
# @issues_by_version = issues.group_by(&:fixed_version)
|
|
# end
|
|
# @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
|
|
# }
|
|
# format.api {
|
|
# @versions = @project.shared_versions.all
|
|
# }
|
|
end
|
|
end
|
|
|
|
# 统计各种类型数量
|
|
def version_type_count type, all_count, opened_count, locked_count, closed_count
|
|
case type
|
|
when nil, "1"
|
|
all_count
|
|
when "2"
|
|
opened_count
|
|
when "3"
|
|
locked_count
|
|
when "4"
|
|
closed_count
|
|
end
|
|
end
|
|
|
|
def show
|
|
# 顶部导航
|
|
@project_menu_type = 7
|
|
|
|
respond_to do |format|
|
|
@version_issues = @version.fixed_issues.visible.
|
|
includes(:status, :tracker, :priority).
|
|
reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
|
|
all
|
|
@issue_count = @version_issues.count
|
|
@limit = 20
|
|
@issue_pages = Paginator.new @issue_count, @limit, params['page'] || 1
|
|
# @offset ||= @issue_pages.offset
|
|
@issues = paginateHelper @version_issues, @limit
|
|
@version_issue_assigned_name = @version_issues.sort_by{ |i| Issue.where(:project_id => @project.id ,
|
|
:assigned_to_id => i.assigned_to_id, :fixed_version_id => @version.id).count }.reverse.group_by(&:assigned_to_id)
|
|
format.html {
|
|
# @issues = @version.fixed_issues.visible.
|
|
# includes(:status, :tracker, :priority).
|
|
# reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
|
|
# all
|
|
}
|
|
format.api
|
|
format.xls {
|
|
@issues = @version.fixed_issues.visible.includes(:status, :tracker, :priority).reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").all
|
|
filename = "#{@version.name.to_s}_#{l(:label_issue_list_xls)}.xls"
|
|
send_data(issue_list_xls(@issues), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
|
|
}
|
|
end
|
|
end
|
|
|
|
def new
|
|
# @version = @project.versions.build
|
|
# @version.safe_attributes = params[:version]
|
|
#
|
|
respond_to do |format|
|
|
@is_setting = params[:is_setting]
|
|
@is_create = params[:is_create]
|
|
@is_issue = params[:is_issue]
|
|
@issue_project_id = params[:issue_project_id]
|
|
#@@issue = Issue.find(params[:issue].to_i)
|
|
format.js
|
|
end
|
|
end
|
|
|
|
def create
|
|
# 项目配置中新建
|
|
@is_setting = params[:is_setting]
|
|
@is_issue = params[:is_issue]
|
|
@is_create = params[:is_create]
|
|
@issue_project_id = params[:issue_project_id]
|
|
# @issue = current_issue
|
|
|
|
@version = @project.versions.build
|
|
|
|
if params[:version]
|
|
attributes = params[:version].dup
|
|
attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
|
|
@version.safe_attributes = attributes
|
|
@version.user_id = User.current.id
|
|
end
|
|
if request.post?
|
|
if @version.save
|
|
respond_to do |format|
|
|
format.html{
|
|
if @is_create
|
|
redirect_to project_versions_path(@project)
|
|
elsif @is_issue
|
|
redirect_to new_project_issue_path(@project)
|
|
end
|
|
}
|
|
format.js
|
|
format.api do
|
|
render :action => 'show', :status => :created, :location => version_url(@version)
|
|
end
|
|
end
|
|
else
|
|
respond_to do |format|
|
|
# format.html { flash[:error] = @version.errors.full_messages.flatten.to_s
|
|
# redirect_to settings_project_url(@project, :tab => 'versions') }
|
|
format.js { @error = @version.errors.full_messages.flatten.to_s }
|
|
format.api { render_validation_errors(@version) }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@is_setting = params[:is_setting]
|
|
@is_create = params[:is_create]
|
|
@is_index = params[:is_index]
|
|
@version_id = params[:id]
|
|
end
|
|
|
|
def update
|
|
@is_setting = params[:is_setting]
|
|
@is_create = params[:is_create]
|
|
@is_index = params[:is_index]
|
|
@flag = params[:flag]
|
|
|
|
if request.put? && params[:version]
|
|
# 处理里程碑里面的更新
|
|
if @flag.to_i == 1
|
|
@version.update_attribute(:status, params[:status])
|
|
if @version.save
|
|
respond_to do |format|
|
|
format.html {
|
|
flash[:notice] = l(:notice_successful_update)
|
|
redirect_to settings_project_path(@project, :tab => 'versions')
|
|
}
|
|
format.js
|
|
format.api { render_api_ok }
|
|
end
|
|
else
|
|
respond_to do |format|
|
|
format.html { render :action => 'edit' }
|
|
format.api { render_validation_errors(@version) }
|
|
end
|
|
end
|
|
else
|
|
attributes = params[:version].dup
|
|
attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
|
|
@version.safe_attributes = attributes
|
|
@is_setting = params[:is_setting]
|
|
if @version.save
|
|
# 为了再setting里面局部刷新
|
|
if @is_setting
|
|
@versions = @version.project.shared_versions.sort
|
|
end
|
|
respond_to do |format|
|
|
format.html {
|
|
if @is_create
|
|
redirect_to version_path(@version)
|
|
elsif @is_index
|
|
redirect_to project_versions_path(@project)
|
|
end
|
|
}
|
|
format.js
|
|
format.api { render_api_ok }
|
|
end
|
|
else
|
|
respond_to do |format|
|
|
format.html { render :action => 'edit' }
|
|
format.js
|
|
format.api { render_validation_errors(@version) }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
def close_completed
|
|
if request.put?
|
|
@project.close_completed_versions
|
|
end
|
|
redirect_to settings_project_url(@project, :tab => 'versions')
|
|
end
|
|
|
|
def close_completed_contest
|
|
if request.put?
|
|
@contest.close_completed_versions
|
|
end
|
|
redirect_to settings_contest_url(@contest, :tab => 'versions')
|
|
end
|
|
|
|
# 判断里程碑是否重名
|
|
# 项目内的里程碑不能重名,项目之间的里程碑能重名
|
|
def judge_version_title
|
|
begin
|
|
version = Version.where(:name => params[:version_name], :project_id => @project.id).first
|
|
if version.blank? || version.id == params[:version_id].to_i
|
|
result = {:result => true}
|
|
else
|
|
result = {:result => false}
|
|
end
|
|
rescue Exception => e
|
|
puts e
|
|
end
|
|
render :json => result
|
|
end
|
|
|
|
def destroy
|
|
begin
|
|
project = @version.project
|
|
issues = Issue.where(:fixed_version_id => @version.id)
|
|
@version.destroy
|
|
issues.update_all(:fixed_version_id, nil)
|
|
rescue Exception => e
|
|
puts e
|
|
end
|
|
respond_to do |format|
|
|
format.js
|
|
format.html { redirect_to project_versions_path(project)}
|
|
format.api { render_api_ok }
|
|
end
|
|
end
|
|
|
|
def status_by
|
|
respond_to do |format|
|
|
format.html { render :action => 'show' }
|
|
format.js
|
|
end
|
|
end
|
|
|
|
private
|
|
def issue_list_xls issues
|
|
xls_report = StringIO.new
|
|
book = Spreadsheet::Workbook.new
|
|
sheet1 = book.create_worksheet :name => "issues"
|
|
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
|
|
sheet1.row(0).default_format = blue
|
|
sheet1.row(0).concat([l(:issue_xls_id),l(:issue_xls_tracker_id),l(:issue_xls_title),l(:issue_xls_description),l(:issue_xls_status),l(:issue_xls_assign),l(:issue_xls_priority),l(:issue_xls_author),l(:issue_xls_created_at),l(:milestone),l(:issue_xls_start),l(:issue_xls_due),l(:issue_xls_ratio)])
|
|
count_row = 1
|
|
issues.each do |issue|
|
|
sheet1[count_row,0] = issue.id
|
|
sheet1[count_row,1] = issue_tracker_change(issue.tracker_id)
|
|
sheet1[count_row,2] = issue.subject
|
|
sheet1[count_row,3] = (issue.description.gsub(/<\/?.*?>/,"")).html_safe
|
|
sheet1[count_row,4] = issue_status_change(issue.status_id)
|
|
sheet1[count_row,5] = issue.assigned_to.try(:show_name)
|
|
sheet1[count_row,6] = issue_priority_change(issue.priority_id)
|
|
sheet1[count_row,7] = issue.author.show_name
|
|
sheet1[count_row,8] = issue.created_on.nil? ? issue.created_on : issue.created_on.strftime('%Y-%m-%d %H:%M:%S')
|
|
sheet1[count_row,9] = issue.fixed_version.try(:name)
|
|
sheet1[count_row,10] = issue.start_date.nil? ? issue.start_date : issue.start_date.strftime('%Y-%m-%d')
|
|
sheet1[count_row,11] = issue.due_date.nil? ? issue.due_date : issue.due_date.strftime('%Y-%m-%d')
|
|
sheet1[count_row,12] = issue_ratio_change(issue.done_ratio, issue.status_id)
|
|
count_row += 1
|
|
end
|
|
book.write xls_report
|
|
xls_report.string
|
|
end
|
|
|
|
def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
|
|
if ids = params[:tracker_ids]
|
|
@selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
|
|
else
|
|
@selected_tracker_ids = (selectable_trackers).collect {|t| t.id.to_s }
|
|
end
|
|
end
|
|
end
|