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.
145 lines
3.8 KiB
145 lines
3.8 KiB
class VersionsController < ApplicationController
|
|
before_action :require_login
|
|
before_action :find_project
|
|
before_action :check_issue_permission, except: [:show, :index]
|
|
before_action :set_version, only: [:edit, :update, :destroy, :show,:update_status]
|
|
|
|
def index
|
|
order_name = params[:order_name] || "created_on"
|
|
order_type = params[:order_type] || "desc"
|
|
status = params[:status]
|
|
versions = @project.versions.version_includes
|
|
if status.present?
|
|
versions = versions.where(status: status.to_s.strip)
|
|
end
|
|
|
|
versions = versions.order("#{order_name} #{order_type}")
|
|
|
|
@page = params[:page] || 1
|
|
@limit = params[:limit] || 15
|
|
@versions_size = versions.size
|
|
@versions = versions.page(@page).per(@limit)
|
|
end
|
|
|
|
def show
|
|
order_name = params[:order_name] || "created_on"
|
|
order_type = params[:order_type] || "desc"
|
|
|
|
version_issues = @version.issues.issue_includes.order("#{order_name} #{order_type}")
|
|
@close_issues_size = version_issues.where(status_id: 5).size
|
|
|
|
@page = params[:page] || 1
|
|
@limit = params[:limit] || 15
|
|
@version_issues_size = version_issues.size
|
|
@version_issues = version_issues.page(@page).per(@limit)
|
|
end
|
|
|
|
def create
|
|
name = params[:name].to_s.strip
|
|
desc = params[:description]
|
|
effective_date = params[:effective_date]
|
|
status = params[:status] || "open"
|
|
sharing = params[:sharing] || ""
|
|
wiki_page_title = params[:wiki_page_title] || ""
|
|
|
|
tag_params = {
|
|
name: name,
|
|
description: desc,
|
|
effective_date: effective_date,
|
|
status: status,
|
|
sharing: sharing,
|
|
wiki_page_title: wiki_page_title
|
|
}
|
|
|
|
if name.present?
|
|
if Version.exists?(name: name, project_id: @project.id)
|
|
normal_status(-1, "里程碑已存在")
|
|
else
|
|
version = Version.new(tag_params.merge(project_id: @project.id, user_id: current_user.id))
|
|
if version.save
|
|
normal_status(0, "里程碑创建成功")
|
|
else
|
|
normal_status(-1, "里程碑创建失败")
|
|
end
|
|
end
|
|
|
|
else
|
|
normal_status(-1, "里程碑名称不能为空")
|
|
end
|
|
|
|
end
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
def update
|
|
name = params[:name].to_s.strip
|
|
desc = params[:description]
|
|
effective_date = params[:effective_date]
|
|
status = params[:status] || "open"
|
|
sharing = params[:sharing] || ""
|
|
wiki_page_title = params[:wiki_page_title] || ""
|
|
|
|
tag_params = {
|
|
name: name,
|
|
description: desc,
|
|
effective_date: effective_date,
|
|
status: status,
|
|
sharing: sharing,
|
|
wiki_page_title: wiki_page_title
|
|
}
|
|
|
|
if name.present?
|
|
if Version.exists?(name: name, project_id: @project.id) && (@version.name != name)
|
|
normal_status(-1, "里程碑已存在")
|
|
else
|
|
if @version.update_attributes(tag_params)
|
|
normal_status(0, "里程碑更新成功")
|
|
else
|
|
normal_status(-1, "里程碑更新失败")
|
|
end
|
|
end
|
|
else
|
|
normal_status(-1, "里程碑名称不能为空")
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
if @version.destroy
|
|
normal_status(0, "里程碑删除成功")
|
|
else
|
|
normal_status(-1, "里程碑删除失败")
|
|
end
|
|
end
|
|
|
|
def update_status
|
|
status = params[:status] || "open"
|
|
all_status = %w(open closed locked)
|
|
if all_status.include?(status)
|
|
if @version.update_attribute(:status, status)
|
|
normal_status(0, "操作成功")
|
|
else
|
|
normal_status(-1, "操作失败")
|
|
end
|
|
else
|
|
normal_status(-1, "status状态值错误")
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def check_issue_permission
|
|
unless @project.member?(current_user) || current_user.admin?
|
|
normal_status(-1, "您没有权限")
|
|
end
|
|
end
|
|
|
|
def set_version
|
|
@version = Version.find_by_id(params[:id])
|
|
unless @version.present?
|
|
normal_status(-1, "里程碑不存在")
|
|
end
|
|
end
|
|
|
|
end |