分享创建和分享列表功能完成;分享的两个接口修改
This commit is contained in:
parent
273234ddaa
commit
498a52d65d
|
@ -1,33 +1,30 @@
|
||||||
class SharesController < ApplicationController
|
class SharesController < ApplicationController
|
||||||
|
|
||||||
before_action :authenticate
|
before_action :authenticate
|
||||||
|
skip_before_action :verify_authenticity_token, :only => [
|
||||||
|
:create,
|
||||||
|
:getShareList
|
||||||
|
]
|
||||||
#当前用户创建分享
|
#当前用户创建分享
|
||||||
|
|
||||||
def create
|
def create
|
||||||
#Todo
|
|
||||||
uid = session[:user_id].to_i
|
uid = session[:user_id].to_i
|
||||||
pid = params[:project_id].to_i
|
share=Share.new(share_params)
|
||||||
now = Datetime.now
|
share.user_id=uid
|
||||||
put = Share.new()
|
if share.save
|
||||||
put.content = params[:content]
|
|
||||||
put.project_id = pid
|
|
||||||
put.user_id = uid
|
|
||||||
put.created_at = now
|
|
||||||
put.updated_at = now
|
|
||||||
put.save!
|
|
||||||
content = User.find(uid).name + "分享了一些事"
|
content = User.find(uid).name + "分享了一些事"
|
||||||
Project_user.where(:project_id => pid).each do |tuid|
|
pid=share.project_id
|
||||||
note = Note.new
|
|
||||||
note.user_id = tuid
|
Projects_user.where(:project_id => pid).each do |i|
|
||||||
note.project_id = pid
|
params_note = {user_id: i.user_id,content: content,category: 1,project_id: pid}
|
||||||
note.category = 1
|
note = Note.new(params_note)
|
||||||
note.content = content
|
|
||||||
note.created_at = now
|
|
||||||
note.updated_at = now
|
|
||||||
note.save!
|
note.save!
|
||||||
end
|
end
|
||||||
render :json => {:code => 0}
|
render status: :created, nothing: true
|
||||||
|
else
|
||||||
|
render json: project.errors, status: :unprocessable_entity
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#获取项目的分享列表
|
#获取项目的分享列表
|
||||||
|
@ -36,10 +33,11 @@ class SharesController < ApplicationController
|
||||||
#Todo
|
#Todo
|
||||||
pid = params[:project_id]
|
pid = params[:project_id]
|
||||||
data = []
|
data = []
|
||||||
Share.where(:project_id => pid) do |i|
|
Share.where(:project_id => pid).order("created_at desc").each do |i|
|
||||||
|
puts i.content
|
||||||
name = User.find(i.user_id).name
|
name = User.find(i.user_id).name
|
||||||
data += [{
|
data += [{
|
||||||
:nickname => name,
|
:name => name,
|
||||||
:time => i.created_at,
|
:time => i.created_at,
|
||||||
:content => i.content
|
:content => i.content
|
||||||
}]
|
}]
|
||||||
|
@ -50,4 +48,8 @@ class SharesController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def share_params
|
||||||
|
params.require(:share).permit(:project_id,:content)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,7 +1,12 @@
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
|
|
||||||
before_action :authenticate, except: [ :emailExist, :usernameExist, :create ]
|
before_action :authenticate, except: [ :emailExist, :usernameExist, :create ]
|
||||||
skip_before_action :verify_authenticity_token, :only => [:emailExist,:usernameExist,:create,:update]
|
skip_before_action :verify_authenticity_token, :only => [
|
||||||
|
:emailExist,
|
||||||
|
:usernameExist,
|
||||||
|
:create,
|
||||||
|
:update
|
||||||
|
]
|
||||||
|
|
||||||
def emailExist
|
def emailExist
|
||||||
if checkExist?(:email, params[:email])
|
if checkExist?(:email, params[:email])
|
||||||
|
|
|
@ -64,7 +64,7 @@ Rails.application.routes.draw do
|
||||||
get 'session' => 'sessions#show'
|
get 'session' => 'sessions#show'
|
||||||
|
|
||||||
post 'shares' => 'shares#create'
|
post 'shares' => 'shares#create'
|
||||||
get 'shares' => 'share#getShareList'
|
get 'shares' => 'shares#getShareList'
|
||||||
|
|
||||||
get 'projects' => 'projects#index'
|
get 'projects' => 'projects#index'
|
||||||
post 'projects' => 'projects#create'
|
post 'projects' => 'projects#create'
|
||||||
|
|
|
@ -43,203 +43,29 @@
|
||||||
<section class="content">
|
<section class="content">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-8 col-lg-offset-2">
|
<div class="col-lg-8 col-lg-offset-2">
|
||||||
<div class="row">
|
<div class="row" id="share_container">
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<div class="box box-primary">
|
<div class="box box-primary">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">添加分享</h3>
|
<h3 class="box-title">添加分享</h3>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.box-header -->
|
<!-- /.box-header -->
|
||||||
<!-- form start -->
|
|
||||||
<form role="form">
|
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>分享内容</label>
|
<label>分享内容</label>
|
||||||
<textarea class="form-control" rows="3" placeholder="输入分享内容"></textarea>
|
<textarea id="share_content" class="form-control" rows="3" placeholder="输入分享内容"></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- /.box-body -->
|
<!-- /.box-body -->
|
||||||
|
|
||||||
<div class="box-footer">
|
<div class="box-footer">
|
||||||
<button type="submit" class="btn btn-primary pull-right">提交</button>
|
<button onclick="submit_share()" class="btn btn-primary pull-right">提交</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- col -->
|
<!-- col -->
|
||||||
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<div class="box box-widget">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<div class="user-block">
|
|
||||||
<img class="img-circle" src="../dist/img/avatar5.png" alt="user image">
|
|
||||||
<span class="username"><a href="#">杨诏</a></span>
|
|
||||||
<span class="description">向大家分享 - 7:30 PM 今日</span>
|
|
||||||
</div>
|
|
||||||
<!-- /.user-block -->
|
|
||||||
</div>
|
|
||||||
<!-- /.box-header -->
|
|
||||||
<div class="box-body">
|
|
||||||
<!-- post text -->
|
|
||||||
<p>这几天心里颇不宁静。今晚在院子里坐着乘凉,忽然想起日日走过的荷塘,在这满月的光里,总该另有一番样子吧。月亮渐渐地升高了, 墙外马路上孩子们的欢笑,已经听不见了;妻在屋里拍着闰儿,迷迷糊糊地哼着眠歌。我悄悄地披了大衫,带上门出去。
|
|
||||||
</p>
|
|
||||||
<p>沿着荷塘,是一条曲折的小煤屑路。这是一条幽僻的路;白天也少人走,夜晚更加寂寞。荷塘四面,长着许多树,蓊蓊郁郁的。路的一旁 ,是些杨柳,和一些不知道名字的树。没有月光的晚上,这路上阴森森的,有些怕人。今晚却很好,虽然月光也还是淡淡的。
|
|
||||||
</p>
|
|
||||||
<p>路上只我一个人,背着手着。这一片天地好像是我的;我也像超出了平常的自己,到了另一个世界里。我爱热闹,也爱冷静;爱群居, 也爱独处。像今晚上,一个人在这苍茫的月下,什么都可以想,什么都可以不想,便觉是个自由的人。白天里一定要做的事,一定要说的话,
|
|
||||||
现 在都可不理。这是独处的妙处,我且受用这无边的荷香月色好了。</p>
|
|
||||||
|
|
||||||
<!-- Social sharing buttons -->
|
|
||||||
<button class="btn btn-default btn-xs"><i class="fa fa-thumbs-o-up"></i> 赞</button>
|
|
||||||
<span class="pull-right text-muted">45 赞 - 2 评论</span>
|
|
||||||
</div>
|
|
||||||
<!-- /.box-body -->
|
|
||||||
<div class="box-footer box-comments">
|
|
||||||
<div class="box-comment">
|
|
||||||
<!-- User image -->
|
|
||||||
<img class="img-circle img-sm" src="../dist/img/avatar5.png" alt="user image">
|
|
||||||
<div class="comment-text">
|
|
||||||
<span class="username">
|
|
||||||
陈翊
|
|
||||||
<span class="text-muted pull-right">8:03 PM 今天</span>
|
|
||||||
</span>
|
|
||||||
<!-- /.username -->
|
|
||||||
很强 </div>
|
|
||||||
<!-- /.comment-text -->
|
|
||||||
</div>
|
|
||||||
<!-- /.box-comment -->
|
|
||||||
<div class="box-comment">
|
|
||||||
<!-- User image -->
|
|
||||||
<img class="img-circle img-sm" src="../dist/img/avatar5.png" alt="user image">
|
|
||||||
<div class="comment-text">
|
|
||||||
<span class="username">
|
|
||||||
崔承旭
|
|
||||||
<span class="text-muted pull-right">8:03 PM 今天</span>
|
|
||||||
</span>
|
|
||||||
<!-- /.username -->
|
|
||||||
高级软件工程使我快乐!
|
|
||||||
</div>
|
|
||||||
<!-- /.comment-text -->
|
|
||||||
</div>
|
|
||||||
<!-- /.box-comment -->
|
|
||||||
</div>
|
|
||||||
<!-- /.box-footer -->
|
|
||||||
<div class="box-footer">
|
|
||||||
<form action="#" method="post">
|
|
||||||
<div class="input-group">
|
|
||||||
<input type="text" name="message" placeholder="输入评论内容" class="form-control">
|
|
||||||
<span class="input-group-btn">
|
|
||||||
<button type="button" class="btn btn-primary btn-flat">提交</button>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<!-- /.box-footer -->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- col -->
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<div class="box box-widget">
|
|
||||||
<div class="box-header with-border">
|
|
||||||
<div class="user-block">
|
|
||||||
<img class="img-circle" src="../dist/img/avatar5.png" alt="user image">
|
|
||||||
<span class="username"><a href="#">杨诏</a></span>
|
|
||||||
<span class="description">向大家分享 - 7:30 PM 今日</span>
|
|
||||||
</div>
|
|
||||||
<!-- /.user-block -->
|
|
||||||
</div>
|
|
||||||
<!-- /.box-header -->
|
|
||||||
<div class="box-body">
|
|
||||||
<!-- post text -->
|
|
||||||
<p>这几天心里颇不宁静。今晚在院子里坐着乘凉,忽然想起日日走过的荷塘,在这满月的光里,总该另有一番样子吧。月亮渐渐地升高了, 墙外马路上孩子们的欢笑,已经听不见了;妻在屋里拍着闰儿,迷迷糊糊地哼着眠歌。我悄悄地披了大衫,带上门出去。
|
|
||||||
</p>
|
|
||||||
<p>沿着荷塘,是一条曲折的小煤屑路。这是一条幽僻的路;白天也少人走,夜晚更加寂寞。荷塘四面,长着许多树,蓊蓊郁郁的。路的一旁 ,是些杨柳,和一些不知道名字的树。没有月光的晚上,这路上阴森森的,有些怕人。今晚却很好,虽然月光也还是淡淡的。
|
|
||||||
</p>
|
|
||||||
<p>路上只我一个人,背着手着。这一片天地好像是我的;我也像超出了平常的自己,到了另一个世界里。我爱热闹,也爱冷静;爱群居, 也爱独处。像今晚上,一个人在这苍茫的月下,什么都可以想,什么都可以不想,便觉是个自由的人。白天里一定要做的事,一定要说的话,
|
|
||||||
现 在都可不理。这是独处的妙处,我且受用这无边的荷香月色好了。</p>
|
|
||||||
|
|
||||||
<!-- Social sharing buttons -->
|
|
||||||
<button class="btn btn-default btn-xs"><i class="fa fa-thumbs-o-up"></i> 赞</button>
|
|
||||||
<span class="pull-right text-muted">45 赞 - 2 评论</span>
|
|
||||||
</div>
|
|
||||||
<!-- /.box-body -->
|
|
||||||
<div class="box-footer box-comments">
|
|
||||||
<div class="box-comment">
|
|
||||||
<!-- User image -->
|
|
||||||
<img class="img-circle img-sm" src="../dist/img/avatar5.png" alt="user image">
|
|
||||||
<div class="comment-text">
|
|
||||||
<span class="username">
|
|
||||||
陈翊
|
|
||||||
<span class="text-muted pull-right">8:03 PM 今天</span>
|
|
||||||
</span>
|
|
||||||
<!-- /.username -->
|
|
||||||
很强 </div>
|
|
||||||
<!-- /.comment-text -->
|
|
||||||
</div>
|
|
||||||
<!-- /.box-comment -->
|
|
||||||
<div class="box-comment">
|
|
||||||
<!-- User image -->
|
|
||||||
<img class="img-circle img-sm" src="../dist/img/avatar5.png" alt="user image">
|
|
||||||
<div class="comment-text">
|
|
||||||
<span class="username">
|
|
||||||
崔承旭
|
|
||||||
<span class="text-muted pull-right">8:03 PM 今天</span>
|
|
||||||
</span>
|
|
||||||
<!-- /.username -->
|
|
||||||
高级软件工程使我快乐!
|
|
||||||
</div>
|
|
||||||
<!-- /.comment-text -->
|
|
||||||
</div>
|
|
||||||
<!-- /.box-comment -->
|
|
||||||
<div class="box-comment">
|
|
||||||
<!-- User image -->
|
|
||||||
<img class="img-circle img-sm" src="../dist/img/avatar5.png" alt="user image">
|
|
||||||
<div class="comment-text">
|
|
||||||
<span class="username">
|
|
||||||
马旭桐
|
|
||||||
<span class="text-muted pull-right">8:03 PM 今天</span>
|
|
||||||
</span>
|
|
||||||
<!-- /.username -->
|
|
||||||
瞄~
|
|
||||||
</div>
|
|
||||||
<!-- /.comment-text -->
|
|
||||||
</div>
|
|
||||||
<!-- /.box-comment -->
|
|
||||||
<div class="box-comment">
|
|
||||||
<!-- User image -->
|
|
||||||
<img class="img-circle img-sm" src="../dist/img/avatar5.png" alt="user image">
|
|
||||||
<div class="comment-text">
|
|
||||||
<span class="username">
|
|
||||||
胡家煊
|
|
||||||
<span class="text-muted pull-right">8:03 PM 今天</span>
|
|
||||||
</span>
|
|
||||||
<!-- /.username -->
|
|
||||||
嘿嘿嘿嘿;-)
|
|
||||||
</div>
|
|
||||||
<!-- /.comment-text -->
|
|
||||||
</div>
|
|
||||||
<!-- /.box-comment -->
|
|
||||||
</div>
|
|
||||||
<!-- /.box-footer -->
|
|
||||||
<div class="box-footer">
|
|
||||||
<form action="#" method="post">
|
|
||||||
<div class="input-group">
|
|
||||||
<input type="text" name="message" placeholder="输入评论内容" class="form-control">
|
|
||||||
<span class="input-group-btn">
|
|
||||||
<button type="button" class="btn btn-primary btn-flat">提交</button>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<!-- /.box-footer -->
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- col -->
|
|
||||||
</div>
|
|
||||||
<!-- row -->
|
|
||||||
</div>
|
|
||||||
<!-- col -->
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!-- row -->
|
<!-- row -->
|
||||||
</section>
|
</section>
|
||||||
|
@ -259,26 +85,87 @@
|
||||||
<!-- AdminLTE for demo purposes -->
|
<!-- AdminLTE for demo purposes -->
|
||||||
<script src="../dist/js/demo.js"></script>
|
<script src="../dist/js/demo.js"></script>
|
||||||
<!-- date select and query -->
|
<!-- date select and query -->
|
||||||
<!-- Custom Scripts -->
|
|
||||||
<script src="include/main.js"></script>
|
|
||||||
<script>
|
<script>
|
||||||
//alert("111");
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "get",
|
type: "get",
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
url:"/shares.json",
|
url:"/shares.json",
|
||||||
|
data:{
|
||||||
|
"project_id":parent.LoginUserInfo.selectProject
|
||||||
|
},
|
||||||
statusCode: {
|
statusCode: {
|
||||||
200: function(data) {// 请求成功
|
200: function(response) {// 请求成功
|
||||||
alert(data);
|
var data=response.data;
|
||||||
|
for( var i=0;i<data.length;i++ ){
|
||||||
|
$("\
|
||||||
|
<div class='col-lg-12'>\
|
||||||
|
<div class='box box-widget'>\
|
||||||
|
<div class='box-header with-border'>\
|
||||||
|
<div class='user-block'>\
|
||||||
|
<img class='img-circle' src='../dist/img/avatar5.png' alt='user image'>\
|
||||||
|
<span class='username'><a href='#'>"+data[i].name+"</a></span>\
|
||||||
|
<span class='description'>向大家分享 - "+data[i].time.substring(0,10)+"  "+data[i].time.substring(11,16)+"</span>\
|
||||||
|
</div>\
|
||||||
|
</div>\
|
||||||
|
<div class='box-body'>\
|
||||||
|
<p>"+data[i].content+"</p>\
|
||||||
|
<button class='btn btn-default btn-xs'>\
|
||||||
|
<i class='fa fa-thumbs-o-up'></i> 赞</button>\
|
||||||
|
<span class='pull-right text-muted'>45 赞 - 2 评论</span>\
|
||||||
|
</div>\
|
||||||
|
<div class='box-footer box-comments'>\
|
||||||
|
<div class='box-comment'>\
|
||||||
|
<img class='img-circle img-sm' src='../dist/img/avatar5.png' alt='user image'>\
|
||||||
|
<div class='comment-text'>\
|
||||||
|
<span class='username'>崔承旭<span class='text-muted pull-right'>8:03 PM 今天</span></span>高级软件工程使我快乐!\
|
||||||
|
</div>\
|
||||||
|
</div>\
|
||||||
|
</div>\
|
||||||
|
<div class='box-footer'>\
|
||||||
|
<div class='input-group'>\
|
||||||
|
<input type='text' name='message' placeholder='输入评论内容' class='form-control'>\
|
||||||
|
<span class='input-group-btn'>\
|
||||||
|
<button type='button' class='btn btn-primary btn-flat'>提交</button>\
|
||||||
|
</span>\
|
||||||
|
</div>\
|
||||||
|
</div>\
|
||||||
|
</div>\
|
||||||
|
</div>").appendTo("#share_container");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
401:function(){// 未授权
|
401:function(){// 未授权
|
||||||
alert("未登录!");
|
alert("未登录!");
|
||||||
window.location.href="pages/login.html";
|
//window.location.href="pages/login.html";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
function submit_share(){
|
||||||
|
var share_content=$("#share_content").val();
|
||||||
|
if( share_content.length>0 ){
|
||||||
|
$.ajax({
|
||||||
|
type:"post",
|
||||||
|
dataType:"json",
|
||||||
|
url:"/shares.json",
|
||||||
|
data:{
|
||||||
|
"share[project_id]":parent.LoginUserInfo.selectProject,
|
||||||
|
"share[content]":share_content
|
||||||
|
},
|
||||||
|
statusCode: {
|
||||||
|
201: function(response) {// 请求成功
|
||||||
|
alert("提交成功!");
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
422:function(){
|
||||||
|
alert("请重新输入!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
alert("请输入完整!");
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue