Merge branch 'cxt_course' of https://git.trustie.net/jacknudt/trustieforge into develop

This commit is contained in:
cxt 2016-12-24 16:30:30 +08:00
commit de9f5131b6
11 changed files with 153 additions and 5 deletions

View File

@ -111,6 +111,17 @@ class ContestsController < ApplicationController
end end
end end
#设置竞赛公开或私有
def set_contest_attribute
contest_id = params[:contest].to_i
@contest = Contest.find(contest_id)
@user = User.find(params[:user_id])
@contest.is_public? ? @contest.update_attribute(:is_public, false) : @contest.update_attribute(:is_public, true)
respond_to do |format|
format.js
end
end
def settings def settings
if params[:tab] && params[:tab] == 'boards' if params[:tab] && params[:tab] == 'boards'
@tab = 2 @tab = 2

View File

@ -39,7 +39,7 @@ class UsersController < ApplicationController
:unfinished_poll_list, :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments, :unfinished_poll_list, :user_homeworks,:student_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
:anonymous_evaluation_list,:unfinished_test_list, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index, :anonymous_evaluation_list,:unfinished_test_list, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:unapproval_applied_list, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index, :unapproval_applied_list, :activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource, :activity_new_score_index, :influence_new_score_index, :score_new_index,:user_projects_index,:user_resource,:user_contestlist,
:user_courses4show,:user_projects4show,:user_contests4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction, :user_courses4show,:user_projects4show,:user_contests4show,:user_course_activities,:user_project_activities,:user_feedback4show,:user_visitorlist,:user_messages,:edit_brief_introduction,
:user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list, :user_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist,:user_projectlist,:sort_syllabus_list,
:sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community, :contest_community] :sort_project_list,:my_homeworks,:manage_or_receive_homeworks,:search_m_r_homeworks, :cancel_or_collect,:expand_courses,:homepage, :user_issues, :course_community, :project_community, :contest_community]
@ -4041,7 +4041,7 @@ class UsersController < ApplicationController
end end
end end
#收藏班级/项目 #收藏班级/项目/竞赛
def cancel_or_collect def cancel_or_collect
if params[:project] if params[:project]
@project = Project.find params[:project] @project = Project.find params[:project]
@ -4054,7 +4054,7 @@ class UsersController < ApplicationController
member = ContestMember.where("user_id = #{@user.id} and contest_id = #{@contest.id}") member = ContestMember.where("user_id = #{@user.id} and contest_id = #{@contest.id}")
end end
unless member.empty? unless member.empty?
member.first.update_attribute(:is_collect, member.first.is_collect == 0 ? 1 : 0) member.first.update_attribute(:is_collect, member.first.is_collect == false ? 1 : 0)
end end
if @project if @project
@projects = @user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10) @projects = @user.favorite_projects.visible.select("projects.*, (SELECT MAX(updated_at) FROM `forge_activities` WHERE forge_activities.project_id = projects.id) AS a").order("a desc").limit(10)
@ -4068,6 +4068,20 @@ class UsersController < ApplicationController
end end
end end
# 用户竞赛列表
def user_contestlist
# 我创建的竞赛
@my_contests = @user.contests.where(:user_id => @user.id).order("created_at desc")
@my_contests_count = @my_contests.count
# 我参与的竞赛
my_all_contests = @user.contest_members.where(:user_id => @user.id).blank? ? "(-1)" : "(" + @user.contest_members.where(:user_id => @user.id).map{ |cm| cm.contest_id }.join(",") + ")"
@my_joined_contests = Contest.where("id in #{my_all_contests} and user_id != #{@user.id}").order("created_at desc")
@my_joined_contests_count = @my_joined_contests.count
respond_to do |format|
format.html {render :layout => 'base_contest_community'}
end
end
def user_projectlist def user_projectlist
@order, @c_sort, @type, @list_type = 1, 2, 1, 1 @order, @c_sort, @type, @list_type = 1, 2, 1, 1
#limit = 5 #limit = 5

View File

@ -0,0 +1,2 @@
/*
$("#contest_list_<%#= @contest.id %>").html("<%#= escape_javascript( render :partial => 'users/contest_list_contents', :locals => {:contest => @contest, :list_type => 1}) %>");*/

View File

@ -0,0 +1,10 @@
<% member = ContestMember.where("user_id = #{@user.id} and contest_id = #{contest.id}").first %>
<% if User.current == @user %>
<% if member %>
<%= link_to "", cancel_or_collect_user_path(@user, :contest => contest.id), :class => "#{member.is_collect == true ? 'icons_project_favorite mt3' : 'icons_project_star mt3'}", :target => '_blank', :remote => true, :title => "#{member.is_collect == true ? '点击将其从个人主页的项目列表中移除' : '点击将其添加至个人主页的项目列表中'}" %>
<% end %>
<% else %>
<% if member %>
<span class="<%= member.is_collect == true ? 'icons_project_favorite mt3' : 'icons_project_star mt3'%>"></span>
<% end %>
<% end %>

View File

@ -0,0 +1,30 @@
<div class="syllabus_category">
<span class="grayTxt fl "><%= @user == User.current ? "我" : "他" %><%= list_type == 1 ? "创建" : "参与" %>的竞赛</span>
<div class="cl"></div>
</div>
<div class="syllabus_courses_box" id="contest_li_<%= list_type %>">
<% if contests.empty? %>
<div class="icons_tishi"><img src="/images/sy/icons_tan.png" width="110" height="110" alt="" ></div>
<% if list_type == 1 %>
<p class="sy_tab_con_p"><%=@user == User.current ? "您" : "他" %>还没有创建竞赛~~<br />
<%= link_to "创建竞赛", new_contest_path(), :target => "_blank", :class => "sy_btn_green ml5 mt5" if @user == User.current %>
</p>
<% else %>
<p class="sy_tab_con_p"><%= @user == User.current ? "您" : "他" %>还没有加入竞赛~~<br />
<%= link_to "加入竞赛", join_contest_contests_path(), :remote => true, :method => "get", :class => "sy_btn_green ml5 mt5" if @user == User.current %>
</p>
<% end %>
<% else %>
<% contests.each_with_index do |contest, i| %>
<div class="syllabus_courses_list <%= i > 4 ? 'none' : ''%> syllabus_courses_box" style="cursor: default;" id="contest_list_<%= contest.id %>">
<%= render :partial => 'users/contest_list_contents', :locals => {:contest => contest, :list_type => list_type} %>
</div>
<% end %>
<% if count > 5 %>
<div class="syllabus_courses_list">
<p class="new_projectlist_more"><a id="contest_more_<%= list_type %>" href="javascript:void(0);" data-count="<%= count %>" data-init="0" onclick="expand_projects('#contest_more_<%= list_type %>',
'#contest_li_<%=list_type %>', <%= count %>);">共<%= count %>个竞赛,点击全部展开</a></p>
</div>
<% end %>
<% end %>
</div>

View File

@ -0,0 +1,35 @@
<% allow_visit = User.current.member_of_contest?(contest) || User.current.admin? || contest.is_public? %>
<div class="sy_courses_open">
<span id="collect_project_icon_<%= contest.id %>">
<%= render :partial => 'collect_contest', :locals => {:contest => contest} %>
</span>
<h3><%= link_to contest.name, allow_visit ? contest_path(contest.id, :host => Setting.host_name) : 'javascript:void(0)', :target => '_blank',
:class => "new_project_title fl",:id => "show_project_#{contest.id}", :title => (allow_visit ? "#{contest.name}" : "私有竞赛不可访问") %></h3>
<span class="<%= contest.is_public? ? 'syllabus_class_open' : 'syllabus_class_private' %> fl ml10 mt3 syllabus_class_property"><%= contest.is_public? ? '公开' : '私有' %></span>
<div class="cl"></div>
</div>
<div>
<p class="fl sy_p_grey">
更新时间:<%= format_date(contest.updated_at) %> &nbsp;&nbsp;&nbsp;
<% contestUser = User.where("id=?", contest.user_id).first %>
单位:<%= contestUser.user_extensions.school_id.blank? ? "无" : contestUser.user_extensions.school.name %>
</p>
</div>
<div class="cl"></div>
<%# if list_type == 1%>
<!-- <div class="homepagePostSetting">
<ul>
<li class="icons_sy_setting">
<ul class="homepagePostSettiongText">-->
<!--<li>-->
<!--<%#= link_to "暂停加入", "javascript:void(0)", :class => "postOptionLink", :target => '_blank', :remote => 'true', :title => "暂停加入"%>-->
<!--</li>-->
<!-- <li>-->
<%#= link_to contest.is_public? ? '设为私有' : '设为公开', set_contest_attribute_contests_path(:contest => contest, :user_id => @user.id), :class => 'postOptionLink',:target =>'_blank', :remote => 'true' %>
<!-- </li>-->
<!--<li><%#= link_to '删除竞赛', "javascript:void(0)", :class => 'postOptionLink', :remote => 'true' %></li>-->
<!-- </ul>
</li>
</ul>
</div>-->
<%# end %>

View File

@ -0,0 +1,3 @@
<div id="user_contest_list">
<%= render :partial => 'users/contest_list', :locals => {:contests => @my_contests, :list_type => 1, :count => @my_contests_count}%>
</div>

View File

@ -0,0 +1,3 @@
<div id="user_join_projects_list">
<%= render :partial => 'users/contest_list', :locals => {:contests => @my_joined_contests, :list_type => 2, :count => @my_joined_contests_count}%>
</div>

View File

@ -0,0 +1,39 @@
<div class="syllabus_box">
<h2 class="syllabus_h2_top"><span class="icon_course fl mt7 mr5"></span>竞赛列表</h2>
<%= render :partial => 'users/my_contests'%>
<div class="" style="height:20px; background:#eaebec;"></div>
<%= render :partial => 'users/my_joined_contests'%>
</div>
<script type="text/javascript">
//如果右边的列表比左边的高度低则将右边的高度设为与左边对齐
$(function() {
var leftHeight = $("#LSide").height() - $(".fontGrey5").height() - 20;
var rightHeight = $(".homepageRight").height();
if (rightHeight < leftHeight) {
var diffHeight = leftHeight - rightHeight;
var tmpHeight = $(".syllabus_box").height() + diffHeight;
$(".syllabus_box").css("minHeight", tmpHeight);
}
});
function expand_projects(btnid,container,count){
var target = $(container).children('.syllabus_courses_list');
var btn = $(btnid);
if(btn.data('init')=='0'){
btn.data('init',1);
btn.html('点击收起');
target.show();
}else{
btn.data('init',0);
btn.html('共' + count + '个项目,点击全部展开');
target.hide();
target.eq(0).show();
target.eq(1).show();
target.eq(2).show();
target.eq(3).show();
target.eq(4).show();
btn.parent().parent().show();
}
}
</script>

View File

@ -614,6 +614,7 @@ RedmineApp::Application.routes.draw do
resources :contests do resources :contests do
collection do collection do
get 'join_contest' get 'join_contest'
get 'set_contest_attribute'
post 'join_contest_multi_role' post 'join_contest_multi_role'
end end