From 84d5b5bc4a02a9780e4eb9da9857e71d014f9058 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 24 Dec 2016 16:29:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=9E=E8=B5=9B=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/contests_controller.rb | 11 ++++++ app/controllers/users_controller.rb | 20 ++++++++-- .../contests/set_contest_attribute.js.erb | 2 + app/views/users/_collect_contest.html.erb | 10 +++++ app/views/users/_contest_list.html.erb | 30 ++++++++++++++ .../users/_contest_list_contents.html.erb | 35 +++++++++++++++++ app/views/users/_my_contests.html.erb | 3 ++ app/views/users/_my_joined_contests.html.erb | 3 ++ app/views/users/cancel_or_collect.js.erb | 4 +- app/views/users/user_contestlist.html.erb | 39 +++++++++++++++++++ config/routes.rb | 1 + 11 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 app/views/contests/set_contest_attribute.js.erb create mode 100644 app/views/users/_collect_contest.html.erb create mode 100644 app/views/users/_contest_list.html.erb create mode 100644 app/views/users/_contest_list_contents.html.erb create mode 100644 app/views/users/_my_contests.html.erb create mode 100644 app/views/users/_my_joined_contests.html.erb create mode 100644 app/views/users/user_contestlist.html.erb diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index 5087a16c4..b5a2b75b1 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -110,6 +110,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 @roles = ["管理人员","开发者","报告人员"] @members = @contest.member_principals.includes(:roles, :principal).all.sort diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 129fe911d..b5d26044c 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 ? "您" : "他" %>还没有创建竞赛~~
+ <%= link_to "创建竞赛", new_contest_path(), :target => "_blank", :class => "sy_btn_green ml5 mt5" if @user == User.current %>
+
<%= @user == User.current ? "您" : "他" %>还没有加入竞赛~~
+ <%= link_to "加入竞赛", join_contest_contests_path(), :remote => true, :method => "get", :class => "sy_btn_green ml5 mt5" if @user == User.current %>
+
+ 更新时间:<%= format_date(contest.updated_at) %> + <% contestUser = User.where("id=?", contest.user_id).first %> + 单位:<%= contestUser.user_extensions.school_id.blank? ? "无" : contestUser.user_extensions.school.name %> +
+