fix conflict 2
This commit is contained in:
commit
774c7a5fa8
|
@ -106,6 +106,7 @@ class MissionsController < ApplicationController
|
||||||
|
|
||||||
def commentPublish
|
def commentPublish
|
||||||
#Todo
|
#Todo
|
||||||
|
puts "I'm in"
|
||||||
content = params[:content]
|
content = params[:content]
|
||||||
mission_id = params[:mission_id]
|
mission_id = params[:mission_id]
|
||||||
user_id = session[:user_id]
|
user_id = session[:user_id]
|
||||||
|
|
|
@ -4,27 +4,20 @@ class ProjectsController < ApplicationController
|
||||||
skip_before_action :verify_authenticity_token, :only => [:index,:create,:addUsers,:detail]
|
skip_before_action :verify_authenticity_token, :only => [:index,:create,:addUsers,:detail]
|
||||||
|
|
||||||
#=============================================>获取我的项目列表,user_id保存在session中.
|
#=============================================>获取我的项目列表,user_id保存在session中.
|
||||||
|
|
||||||
def index
|
def index
|
||||||
#Todo
|
#Todo
|
||||||
uid = session[:user_id]
|
uid = session[:user_id]
|
||||||
#pid = Projects_user.find_by(project_id: uid)
|
data=[]
|
||||||
pids = []
|
Projects_user.where(:user_id => uid).each do |i|
|
||||||
projects = Projects_user.where("user_id = ?",uid).all
|
pid=i.project_id
|
||||||
projects.each do |projects_user|
|
p=Project.find_by(id:pid)
|
||||||
pids << projects_user.project_id
|
|
||||||
end
|
|
||||||
data = []
|
|
||||||
pids.each do |pid|
|
|
||||||
mc = Mission.where(:project_id => pid).size
|
mc = Mission.where(:project_id => pid).size
|
||||||
uc = Projects_user.where(:project_id => pid).size
|
uc = Projects_user.where(:project_id => pid).size
|
||||||
sc = Share.where(:project_id => pid).size
|
sc = Share.where(:project_id => pid).size
|
||||||
puts pid
|
data+=[{
|
||||||
i = Project.find_by(id: pid)
|
:id => pid,
|
||||||
data += [{
|
:name => p.name,
|
||||||
:id => i.id,
|
:content => p.content,
|
||||||
:name => i.name,
|
|
||||||
:content => i.content,
|
|
||||||
:mission_count => mc,
|
:mission_count => mc,
|
||||||
:users_count => uc,
|
:users_count => uc,
|
||||||
:shares_count => sc
|
:shares_count => sc
|
||||||
|
@ -46,14 +39,13 @@ class ProjectsController < ApplicationController
|
||||||
project = Project.new(params_project)
|
project = Project.new(params_project)
|
||||||
project.users << user
|
project.users << user
|
||||||
project.save
|
project.save
|
||||||
|
if project.save
|
||||||
#project save的时候会保存 projects_users
|
Projects_user.create(project_id:project.id,user_id:uid)
|
||||||
|
render status: :created, nothing: true
|
||||||
# params_pu = {project_id: project.id,user_id: user.id}
|
else
|
||||||
# puts params_pu
|
render json: project.errors, status: :unprocessable_entity
|
||||||
# pu = Projects_user.new(params_pu)
|
end
|
||||||
# pu.save
|
#render :json => {:code => 0}
|
||||||
render :json => {:code => 0}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,5 +107,8 @@ class ProjectsController < ApplicationController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
private
|
||||||
|
def project_params
|
||||||
|
params.require(:project).permit(:name,:content)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,8 +1,12 @@
|
||||||
class Project < ActiveRecord::Base
|
class Project < ActiveRecord::Base
|
||||||
has_and_belongs_to_many :users
|
has_and_belongs_to_many :users
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
validate :require_at_least_on_user,on: :update # 项目中最少要有一个用户
|
validate :require_at_least_on_user,on: :update # 项目中最少要有一个用户
|
||||||
|
|
||||||
|
=======
|
||||||
|
validate :require_at_least_on_user,on: :update # 项目中最少要有一个用户
|
||||||
|
>>>>>>> 27ebee595014926419b6ccba922ad39450b73f6b
|
||||||
validates :name, presence: true, length: { minimum: 1, maximum: 50 }, uniqueness: true
|
validates :name, presence: true, length: { minimum: 1, maximum: 50 }, uniqueness: true
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -9,9 +9,6 @@ users = [
|
||||||
{:name => '杨诏', :password => '123123123', :email => 'lucio.yang@qq.com', :phone => '15652591529', :created_at => "2016/12/27", :updated_at => "2016/12/27"},
|
{:name => '杨诏', :password => '123123123', :email => 'lucio.yang@qq.com', :phone => '15652591529', :created_at => "2016/12/27", :updated_at => "2016/12/27"},
|
||||||
{:name => '陈翊', :password => '123456', :email => '1085730215@qq.com', :phone => '18269771988', :created_at => "2016/12/28", :updated_at => "2016/12/27"}
|
{:name => '陈翊', :password => '123456', :email => '1085730215@qq.com', :phone => '18269771988', :created_at => "2016/12/28", :updated_at => "2016/12/27"}
|
||||||
]
|
]
|
||||||
projects = [
|
|
||||||
{:id=>'1001',:name => 'AAAA',:content => 'i like helloworld',:mission_count => '20',:users_count => '15',:shares_count => '15'}
|
|
||||||
]
|
|
||||||
|
|
||||||
users.each do |user|
|
users.each do |user|
|
||||||
User.create!(user)
|
User.create!(user)
|
||||||
|
|
|
@ -174,6 +174,7 @@
|
||||||
type: "get",
|
type: "get",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
url:"/session.json",
|
url:"/session.json",
|
||||||
|
async: false,
|
||||||
statusCode: {
|
statusCode: {
|
||||||
200: function(data) {// 请求成功
|
200: function(data) {// 请求成功
|
||||||
$("#name1").text(data.name);
|
$("#name1").text(data.name);
|
||||||
|
@ -192,6 +193,9 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if(getProjectId()==null){
|
||||||
|
window.location="pages/project_select.html";
|
||||||
|
}
|
||||||
function logout(){
|
function logout(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "delete",
|
type: "delete",
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
function initCurrent(){
|
function initCurrent(){
|
||||||
if(getProjectId()==null){
|
|
||||||
window.location="pages/project_select.html";
|
|
||||||
}
|
|
||||||
LoginUserInfo={
|
LoginUserInfo={
|
||||||
selectProject:getProjectId(),
|
selectProject:getProjectId(),
|
||||||
name:'',
|
name:'',
|
||||||
|
|
|
@ -230,22 +230,27 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$("#creat_project").click(function(){
|
$("#creat_project").click(function(){
|
||||||
|
var pName=$("#exampleName").val();
|
||||||
|
var pContent=$("#exampleTextarea").val();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type:"post",
|
type:"post",
|
||||||
dataType:"json",
|
dataType:"json",
|
||||||
url:"/projects.json",
|
url:"/projects.json",
|
||||||
data:{
|
data:{
|
||||||
"name":$("#exampleName").val(),
|
"project[name]":pName,
|
||||||
"content":$("#exampleTextarea").val()
|
"project[content]":pContent
|
||||||
},
|
},
|
||||||
statusCode: {
|
statusCode: {
|
||||||
200: function() {// 请求成功
|
201: function() {// 请求成功
|
||||||
alert("创建成功!");
|
alert("创建成功!");
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
},
|
},
|
||||||
401:function(){// 未授权
|
401:function(){// 未授权
|
||||||
alert("未登录!");
|
alert("未登录!");
|
||||||
window.location.href="login.html";
|
window.location.href="login.html";
|
||||||
|
},
|
||||||
|
422:function(){
|
||||||
|
alert("项目名重复!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -68,7 +68,8 @@ RSpec.describe MissionsController, type: :controller do
|
||||||
mission = Mission.new(params_mission)
|
mission = Mission.new(params_mission)
|
||||||
mission.save
|
mission.save
|
||||||
|
|
||||||
post :commentPublish,mission_id: mission.id,content: "用户评论"
|
post :comments , mission_id: mission.id,content: "用户评论"
|
||||||
|
|
||||||
puts "hello world"
|
puts "hello world"
|
||||||
puts response.body
|
puts response.body
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue