diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index d73606582..c37cd9443 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -111,6 +111,17 @@ class ContestsController < ApplicationController 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 if params[:tab] && params[:tab] == 'boards' @tab = 2 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a5b0dded6..1b2448d81 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -39,7 +39,7 @@ class UsersController < ApplicationController :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, :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_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] @@ -4041,7 +4041,7 @@ class UsersController < ApplicationController end end - #收藏班级/项目 + #收藏班级/项目/竞赛 def cancel_or_collect if 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}") end 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 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) @@ -4068,6 +4068,20 @@ class UsersController < ApplicationController 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 @order, @c_sort, @type, @list_type = 1, 2, 1, 1 #limit = 5 diff --git a/app/views/contests/set_contest_attribute.js.erb b/app/views/contests/set_contest_attribute.js.erb new file mode 100644 index 000000000..8932016b6 --- /dev/null +++ b/app/views/contests/set_contest_attribute.js.erb @@ -0,0 +1,2 @@ +/* +$("#contest_list_<%#= @contest.id %>").html("<%#= escape_javascript( render :partial => 'users/contest_list_contents', :locals => {:contest => @contest, :list_type => 1}) %>");*/ diff --git a/app/views/users/_collect_contest.html.erb b/app/views/users/_collect_contest.html.erb new file mode 100644 index 000000000..a76701ea0 --- /dev/null +++ b/app/views/users/_collect_contest.html.erb @@ -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 %> + + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/users/_contest_list.html.erb b/app/views/users/_contest_list.html.erb new file mode 100644 index 000000000..299699678 --- /dev/null +++ b/app/views/users/_contest_list.html.erb @@ -0,0 +1,30 @@ +
+ <%= @user == User.current ? "我" : "他" %><%= list_type == 1 ? "创建" : "参与" %>的竞赛 +
+
+
+ <% if contests.empty? %> +
+ <% if list_type == 1 %> +

<%=@user == User.current ? "您" : "他" %>还没有创建竞赛~~
+ <%= link_to "创建竞赛", new_contest_path(), :target => "_blank", :class => "sy_btn_green ml5 mt5" if @user == User.current %> +

+ <% else %> +

<%= @user == User.current ? "您" : "他" %>还没有加入竞赛~~
+ <%= link_to "加入竞赛", join_contest_contests_path(), :remote => true, :method => "get", :class => "sy_btn_green ml5 mt5" if @user == User.current %> +

+ <% end %> + <% else %> + <% contests.each_with_index do |contest, i| %> +
+ <%= render :partial => 'users/contest_list_contents', :locals => {:contest => contest, :list_type => list_type} %> +
+ <% end %> + <% if count > 5 %> +
+

共<%= count %>个竞赛,点击全部展开

+
+ <% end %> + <% end %> +
\ No newline at end of file diff --git a/app/views/users/_contest_list_contents.html.erb b/app/views/users/_contest_list_contents.html.erb new file mode 100644 index 000000000..3d02dd46c --- /dev/null +++ b/app/views/users/_contest_list_contents.html.erb @@ -0,0 +1,35 @@ +<% allow_visit = User.current.member_of_contest?(contest) || User.current.admin? || contest.is_public? %> +
+ + <%= render :partial => 'collect_contest', :locals => {:contest => contest} %> + +

<%= 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}" : "私有竞赛不可访问") %>

+ <%= contest.is_public? ? '公开' : '私有' %> +
+
+
+

+ 更新时间:<%= format_date(contest.updated_at) %>     + <% contestUser = User.where("id=?", contest.user_id).first %> + 单位:<%= contestUser.user_extensions.school_id.blank? ? "无" : contestUser.user_extensions.school.name %> +

+
+
+<%# if list_type == 1%> + + + + + + <%#= link_to contest.is_public? ? '设为私有' : '设为公开', set_contest_attribute_contests_path(:contest => contest, :user_id => @user.id), :class => 'postOptionLink',:target =>'_blank', :remote => 'true' %> + + + +<%# end %> \ No newline at end of file diff --git a/app/views/users/_my_contests.html.erb b/app/views/users/_my_contests.html.erb new file mode 100644 index 000000000..e94e48bd2 --- /dev/null +++ b/app/views/users/_my_contests.html.erb @@ -0,0 +1,3 @@ +
+ <%= render :partial => 'users/contest_list', :locals => {:contests => @my_contests, :list_type => 1, :count => @my_contests_count}%> +
\ No newline at end of file diff --git a/app/views/users/_my_joined_contests.html.erb b/app/views/users/_my_joined_contests.html.erb new file mode 100644 index 000000000..4c7973e96 --- /dev/null +++ b/app/views/users/_my_joined_contests.html.erb @@ -0,0 +1,3 @@ +
+ <%= render :partial => 'users/contest_list', :locals => {:contests => @my_joined_contests, :list_type => 2, :count => @my_joined_contests_count}%> +
\ No newline at end of file diff --git a/app/views/users/cancel_or_collect.js.erb b/app/views/users/cancel_or_collect.js.erb index ee0b3a04e..7db92e4e7 100644 --- a/app/views/users/cancel_or_collect.js.erb +++ b/app/views/users/cancel_or_collect.js.erb @@ -10,7 +10,7 @@ } <% elsif @contest %> $("#homepage_left_contest_list").html("<%= escape_javascript(render :partial => 'layouts/homepage_left_contest_list', :locals => {:contests => @contests}) %>"); - if($("#collect_project_icon_<%=@contest.id %>").length > 0){ - $("#collect_project_icon_<%=@contest.id %>").html("<%= escape_javascript(render :partial => 'users/collect_contest', :locals => {:contest => @contest}) %>"); + if($("#collect_project_icon_<%= @contest.id %>").length > 0){ + $("#collect_project_icon_<%= @contest.id %>").html("<%= escape_javascript(render :partial => 'users/collect_contest', :locals => {:contest => @contest}) %>"); } <% end %> \ No newline at end of file diff --git a/app/views/users/user_contestlist.html.erb b/app/views/users/user_contestlist.html.erb new file mode 100644 index 000000000..6acade05e --- /dev/null +++ b/app/views/users/user_contestlist.html.erb @@ -0,0 +1,39 @@ +
+

竞赛列表

+ <%= render :partial => 'users/my_contests'%> +
+ <%= render :partial => 'users/my_joined_contests'%> +
+ + + diff --git a/config/routes.rb b/config/routes.rb index 12dd992fa..91a627424 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -614,6 +614,7 @@ RedmineApp::Application.routes.draw do resources :contests do collection do get 'join_contest' + get 'set_contest_attribute' post 'join_contest_multi_role' end