展示项目列表接口

This commit is contained in:
chenyi 2016-12-29 08:11:27 +00:00
parent 4fbac0332c
commit addf740d3d
3 changed files with 69 additions and 80 deletions

View File

@ -8,9 +8,9 @@ class ProjectsController < ApplicationController
def index def index
#Todo #Todo
uid = session[:user_id] uid = session[:user_id]
pid = Project_user.find(uid) pid = Projects_user.find_by(project_id: uid)
mc = Mission.where(:project_id => pid).size mc = Mission.where(:project_id => pid).size
uc = Project_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
data = [] data = []
Project.find(pid) do |i| Project.find(pid) do |i|
@ -46,7 +46,7 @@ class ProjectsController < ApplicationController
def addUsers def addUsers
#Todo #Todo
body = request.body.read body = request.body.read
pu = Project_user.new() pu = Projects_user.new()
pu.project_id = body[:project_id] pu.project_id = body[:project_id]
#pu.user_id = body[:user_id] #pu.user_id = body[:user_id]
pu.save! pu.save!
@ -58,8 +58,8 @@ class ProjectsController < ApplicationController
def detail def detail
#Todo #Todo
pid = params[:id] pid = params[:id]
project = Project.find(pid) project = Project.find_by(id: pid)
uid = Project_user.where(:project_id => pid) uid = Projects_user.where(:project_id => pid)
users = [] users = []
Users.find(uid).each do |i| Users.find(uid).each do |i|
users += [{ users += [{

View File

@ -6,7 +6,8 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first) # Mayor.create(name: 'Emanuel', city: cities.first)
users = [ 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"}
] ]
users.each do |user| users.each do |user|

View File

@ -77,94 +77,30 @@
</div> </div>
<!-- col --> <!-- col -->
<div class="col-lg-8 col-lg-offset-2"> <div class="col-lg-8 col-lg-offset-2">
<div class="row"> <div id="cy_container" class="row">
<div class="col-lg-4"> <div id="cy_template" class="col-lg-4" style="display:none;">
<div class="box box-widget widget-user"> <div class="box box-widget widget-user">
<!-- Add the bg color to the header using any of the bg-* classes --> <!-- Add the bg color to the header using any of the bg-* classes -->
<div class="widget-user-header bg-yellow"> <div id="cy_template_bg" class="widget-user-header bg-yellow">
<!-- /.widget-user-image --> <!-- /.widget-user-image -->
<h3 class="widget-user-username">网吧五连座</h3> <h3 id="cy_template_name" class="widget-user-username">网吧五连座</h3>
<h5 class="widget-user-desc">Ruby开发项目</h5> <h5 id="cy_template_content" class="widget-user-desc">Ruby开发项目</h5>
<a class="btn btn-default pull-right project-enter" href="../index.html"> <a class="btn btn-default pull-right project-enter" href="../index.html">
<i class="fa fa-sign-in"></i> <i class="fa fa-sign-in"></i>
</a> </a>
</div> </div>
<div class="box-footer no-padding"> <div class="box-footer no-padding">
<ul class="nav nav-stacked"> <ul class="nav nav-stacked">
<li><a href="#">任务数 <span class="pull-right badge bg-blue">31</span></a></li> <li><a href="#">任务数 <span id="cy_template_mission_count" class="pull-right badge bg-blue">31</span></a></li>
<li><a href="#">参与人数 <span class="pull-right badge bg-aqua">5</span></a></li> <li><a href="#">参与人数 <span id="cy_template_users_count" class="pull-right badge bg-aqua">5</span></a></li>
<li><a href="#">通知数 <span class="pull-right badge bg-green">12</span></a></li> <li><a href="#">通知数 <span id="cy_template_shares_count" class="pull-right badge bg-green">12</span></a></li>
</ul> </ul>
</div> </div>
</div> </div>
<!-- /.widget-user --> <!-- /.widget-user -->
</div> </div>
<!-- col --> <!-- col -->
<div class="col-lg-4">
<div class="box box-widget widget-user">
<!-- Add the bg color to the header using any of the bg-* classes -->
<div class="widget-user-header bg-aqua">
<!-- /.widget-user-image -->
<h3 class="widget-user-username">网吧五连座</h3>
<h5 class="widget-user-desc">Ruby开发项目</h5>
<a class="btn btn-default pull-right project-enter" href="../index.html">
<i class="fa fa-sign-in"></i>进入
</a>
</div>
<div class="box-footer no-padding">
<ul class="nav nav-stacked">
<li><a href="#">任务数 <span class="pull-right badge bg-blue">31</span></a></li>
<li><a href="#">参与人数 <span class="pull-right badge bg-aqua">5</span></a></li>
<li><a href="#">通知数 <span class="pull-right badge bg-green">12</span></a></li>
</ul>
</div>
</div>
<!-- /.widget-user -->
</div>
<!-- col -->
<div class="col-lg-4">
<div class="box box-widget widget-user">
<!-- Add the bg color to the header using any of the bg-* classes -->
<div class="widget-user-header bg-blue">
<!-- /.widget-user-image -->
<h3 class="widget-user-username">网吧五连座</h3>
<h5 class="widget-user-desc">Ruby开发项目</h5>
<a class="btn btn-default pull-right project-enter">
<i class="fa fa-sign-in"></i>进入
</a>
</div>
<div class="box-footer no-padding">
<ul class="nav nav-stacked">
<li><a href="#">任务数 <span class="pull-right badge bg-blue">31</span></a></li>
<li><a href="#">参与人数 <span class="pull-right badge bg-aqua">5</span></a></li>
<li><a href="#">通知数 <span class="pull-right badge bg-green">12</span></a></li>
</ul>
</div>
</div>
<!-- /.widget-user -->
</div>
<!-- col -->
<div class="col-lg-4">
<div class="box box-widget widget-user">
<!-- Add the bg color to the header using any of the bg-* classes -->
<div class="widget-user-header bg-purple">
<!-- /.widget-user-image -->
<h3 class="widget-user-username">网吧五连座</h3>
<h5 class="widget-user-desc">Ruby开发项目</h5>
<a class="btn btn-default pull-right project-enter">
<i class="fa fa-sign-in"></i>进入
</a>
</div>
<div class="box-footer no-padding">
<ul class="nav nav-stacked">
<li><a href="#">任务数 <span class="pull-right badge bg-blue">31</span></a></li>
<li><a href="#">参与人数 <span class="pull-right badge bg-aqua">5</span></a></li>
<li><a href="#">通知数 <span class="pull-right badge bg-green">12</span></a></li>
</ul>
</div>
</div>
<!-- /.widget-user -->
</div>
<div class="col-lg-4" style="height:242px;width:252px;margin-left:15px;background-color:white"> <div class="col-lg-4" style="height:242px;width:252px;margin-left:15px;background-color:white">
<!-- Add the bg color to the header using any of the bg-* classes --> <!-- Add the bg color to the header using any of the bg-* classes -->
@ -205,7 +141,7 @@
</div><!-- /.box-body --> </div><!-- /.box-body -->
</form> </form>
</div> </div>
<div class="modal-footer"> <div id="creat_project" class="modal-footer">
<button type="button" class="btn btn-primary"> <button type="button" class="btn btn-primary">
创建 创建
</button> </button>
@ -238,6 +174,58 @@
<script src="../dist/js/app.min.js"></script> <script src="../dist/js/app.min.js"></script>
<!-- AdminLTE for demo purposes --> <!-- AdminLTE for demo purposes -->
<script src="../dist/js/demo.js"></script> <script src="../dist/js/demo.js"></script>
<script>
$(document).ready(function(){
htmlobj=$.ajax(
{
type:"GET",
dataType:"json",
url:"/projects.json",
statusCode: {
200: function() {// 请求成功
var bg_color = ["bg-yellow","bg-blue","bg-purple","bg-red"];
var jstr = htmlobj.responseText;
var robj = eval('('+jstr+')');
if(robj["code"]==0){
var data = robj["data"];
for(var i=data.length-1;i>=0;--i){
var template = $("#cy_template");
var tp = template.clone("true");
tp.find("#cy_template_name").html(data[i]["name"]);
tp.find("#cy_template_content").html(data[i]["content"]);
tp.find("#cy_template_mission_count").html(data[i]["mission_count"]);
tp.find("#cy_template_users_count").html(data[i]["users_count"]);
tp.find("#cy_template_shares_count").html(data[i]["shares_count"]);
tp.find("#cy_template_name").attr("id","cy_name_"+i);
tp.find("#cy_template_content").attr("id","cy_content_"+i);
tp.find("#cy_template_mission_count").attr("id","cy_mission_count_"+i);
tp.find("#cy_template_users_count").attr("id","cy_users_count_"+i);
tp.find("#cy_template_shares_count").attr("id","cy_shares_count_"+i);
tp.find("#cy_template_bg").attr("class","widget-user-header "+bg_color[Math.floor(Math.random()*4)]);
tp.find("#cy_template_bg").attr("id","cy_bg_"+i);
tp.attr("id","cy_project_"+i);
tp.css("display","block");
$("#cy_container").prepend(tp);
}
}
else{
//todo
}
},
401:function(){// 未授权
alert("用户名或密码错误!");
}
}
});
});
</script>
</body> </body>
</html> </html>