101 lines
2.4 KiB
Ruby
101 lines
2.4 KiB
Ruby
class MissionsController < ApplicationController
|
|
|
|
before_action :authenticate
|
|
|
|
#获取当前项目某状态的任务列表
|
|
|
|
def getlist
|
|
#Todo
|
|
pid = params[:project_id]
|
|
stu = params[:status_type]
|
|
missions = []
|
|
Mission.where(:project_id => pid).where(:status => stu) do |i|
|
|
missions += [{
|
|
:id => i.id,
|
|
:name => i.name,
|
|
:content => i.content
|
|
}]
|
|
end
|
|
render :json => {
|
|
:code => 0,
|
|
:data => missions
|
|
}
|
|
end
|
|
|
|
#获取任务详细信息
|
|
|
|
def detail
|
|
#Todo
|
|
id = params[:id]
|
|
mission = Mission.find(id)
|
|
userid = Mission_user.find_by_name("mission_id")
|
|
username = User.find(userid).pluck("name")
|
|
comments = []
|
|
Comments.where("mission_id" => id).each do |i|
|
|
name = User.find(i.user_id).name
|
|
comments += [{
|
|
:nickname => name,
|
|
:content => i.content,
|
|
:time => i.created_at
|
|
}]
|
|
end
|
|
render :json => {
|
|
:code => 0,
|
|
:data => {
|
|
:name => mission.name,
|
|
:content => mission.content,
|
|
:priority => mission.priority,
|
|
:status => mission.status,
|
|
:deadline => mission.deadline,
|
|
:users => username,
|
|
:comments => comments
|
|
}
|
|
}
|
|
end
|
|
|
|
#修改任务信息
|
|
|
|
def update
|
|
#Todo
|
|
id = params[:id]
|
|
body = request.body.read
|
|
mission = Mission.find(id)
|
|
mission.name = body[:name]
|
|
mission.content = body[:content]
|
|
mission.priority = body[:priority]
|
|
mission.status = body[:status]
|
|
mission.deadline = body[:deadline]
|
|
mission.save!
|
|
pid = mission.project_id
|
|
Mission_user.destory_all(:mission_id => id)
|
|
body[:users].each do |i|
|
|
uid = User.where(:email => i).id
|
|
mu = Mission_user.new
|
|
mu.mission_id = id
|
|
mu.user_id = uid
|
|
mu.save!
|
|
note = Note.new
|
|
note.project_id = pid
|
|
note.user_id = uid
|
|
note.category = 3
|
|
note.content = "任务信息发生了变化"
|
|
note.save!
|
|
end
|
|
render :json => {:code => 0}
|
|
end
|
|
|
|
#当前用户发表评论
|
|
|
|
def commentPublish
|
|
#Todo
|
|
body = request.body.read
|
|
put = Comments.new()
|
|
put.content = body[:content]
|
|
put.mission_id = body[:mission_id]
|
|
put.user_id = session[:user_id]
|
|
put.save!
|
|
render :json => {:code => 0}
|
|
end
|
|
|
|
|
|
end |