From c8eaf293e7ba050c8e4b578e7e14b3a84ad5a1cc Mon Sep 17 00:00:00 2001 From: yuanke <249218296@qq.com> Date: Sun, 24 Apr 2016 10:49:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/blogs_controller.rb | 2 +- app/controllers/users_controller.rb | 45 +++++++++++++++- app/views/blogs/_article.html.erb | 4 +- app/views/layouts/new_base_user.html.erb | 3 +- app/views/users/_user_course_list.html.erb | 61 ++++++++++++++++++++++ app/views/users/user_courselist.html.erb | 3 ++ app/views/users/user_courselist.js.erb | 1 + config/routes.rb | 4 ++ 8 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 app/views/users/_user_course_list.html.erb create mode 100644 app/views/users/user_courselist.html.erb create mode 100644 app/views/users/user_courselist.js.erb diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index e3bb92b98..7bf122847 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -15,7 +15,7 @@ class BlogsController < ApplicationController @b_sort = 1 end - sort_name = "updated_on" + sort_name = "updated_at" sort_type = @b_sort == 1 ? "desc" : "asc" diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8e08508ed..c4f1de41e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -41,7 +41,7 @@ class UsersController < ApplicationController :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, :user_courses4show,:user_projects4show,: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_import_homeworks,:user_search_homeworks,:user_import_resource, :user_system_messages,:choose_user_course,:user_courselist] before_filter :auth_user_extension, only: :show #before_filter :rest_user_score, only: :show #before_filter :select_entry, only: :user_projects @@ -2845,6 +2845,49 @@ class UsersController < ApplicationController end end + def user_courselist + @order, @c_sort,@type = params[:order] || 1, params[:sort] || 2, params[:type] || 1 + + + #确定 sort_type + if @order.to_i == @type.to_i + @c_sort = @c_sort.to_i == 1 ? 2 : 1 #2降序 1升序 + else + @c_sort = 1 + end + + sort_name = "updated_at" + sort_type = @c_sort == 1 ? "desc" : "asc" + + if @user.courses.visible.count > 0 + course_order_ids = "(" + CourseActivity.find_by_sql("SELECT c.course_id, updated_at FROM(SELECT ca.course_id, MAX(ca.updated_at) AS updated_at FROM course_activities ca WHERE ca.course_id IN (" + @user.courses.visible.select('courses.id').map{|c| c.id}.join(',') + ") GROUP BY ca.course_id) AS c ").map {|c| c.course_id}.join(",") + ")" + @courses = Course.where("id in #{course_order_ids}").order("#{sort_name} #{sort_type}") + else + @courses = [] + end + + #根据 作业+资源数排序 + if @order.to_i == 2 + @type = 2 + @c_sort == 1 ? (@courses = @courses.sort{|x,y| (y.homework_commons.count + visable_attachemnts_incourse(y).count) <=> (x.homework_commons.count + visable_attachemnts_incourse(x).count) }) : (@courses.sort{|x,y| (x.homework_commons.count + visable_attachemnts_incourse(x).count) <=> (y.homework_commons.count + visable_attachemnts_incourse(y).count) }) + else + @type = 1 + end + + #分页 + @limit = 10 + @is_remote = true + @atta_count = @courses.count + @atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1 + @offset ||= @atta_pages.offset + @courses = paginateHelper @courses,@limit + + respond_to do |format| + format.js + format.html {render :layout => 'new_base_user'} + end + end + private def find_user diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 10ce3ee64..1b9ef992e 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -64,7 +64,7 @@ var rightHeight = $(".homepageRight").height(); if (rightHeight < leftHeight){ var diffHeight = leftHeight - rightHeight; - var blogHeight = $(".listbox").height()+diffHeight; - $(".listbox").css("height",blogHeight); + var tmpHeight = $(".listbox").height()+diffHeight; + $(".listbox").css("height",tmpHeight); } \ No newline at end of file diff --git a/app/views/layouts/new_base_user.html.erb b/app/views/layouts/new_base_user.html.erb index 4e1064b7f..5077ecab3 100644 --- a/app/views/layouts/new_base_user.html.erb +++ b/app/views/layouts/new_base_user.html.erb @@ -186,7 +186,8 @@ <%= link_to "动态",user_activities_path(@user.id),:class => "homepageMenuText"%>
- 课程 + <%= link_to '课程',{:controller => "users", :action => "user_courselist", :id => @user.id}, :class => "homepageMenuText" %> + <% if is_current_user%> <% if User.current.user_extensions && User.current.user_extensions.identity == 0 && User.current.allowed_to?(:add_course, nil, :global => true)%>
diff --git a/app/views/users/_user_course_list.html.erb b/app/views/users/_user_course_list.html.erb new file mode 100644 index 000000000..818c82e6e --- /dev/null +++ b/app/views/users/_user_course_list.html.erb @@ -0,0 +1,61 @@ +
+

课程列表

+
+ 排序: + <%= link_to "时间", {:controller => 'users', :action => 'user_courselist', :id =>@user.id, :type => @type, :sort => @c_sort, :order => 1 }, :class => "sortTxt", :remote => true %> + <% if @type.to_i == 1 %> + <%= link_to "", {:controller => 'users', :action => 'user_courselist', :id =>@user.id, :type => @type, :sort => @c_sort, :order => 1 }, :class => "#{@c_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %> + <% end %> + <%= link_to "人气", {:controller => 'users', :action => 'user_courselist', :id =>@user.id, :type => @type, :sort => @c_sort, :order => 2 }, :class => "sortTxt", :remote => true %> + <% if @type.to_i == 2 %> + <%= link_to "", {:controller => 'users', :action => 'user_courselist', :id =>@user.id, :type => @type, :sort => @c_sort, :order => 2 }, :class => "#{@c_sort.to_i == 1 ? 'sortupbtn' : 'sortdownbtn'} ", :remote => true %> + <% end %> +
+
+ +
+ <% @courses.each do |course|%> +
    +
  • + + <%= link_to course.name+"("+current_time_and_term_short(course)+")", course_path(course.id,:host=>Setting.host_course), :class => "course-title fl #{course_endTime_timeout?(course) ? 'c_dark_grey' : ''}", + :style => 'color:#000',:id => "show_course_#{course.id}", :target => '_blank', :title => (course.is_public? ? "公开课程:":"私有课程:")+course.name+"("+current_time_and_term(course)+")"%> + <% teacher = User.where("id=?",course.tea_id).first%> + + <%='主讲老师:'+(teacher.try(:realname) != " " ? teacher.lastname + teacher.firstname : teacher.try(:login)) %> + +
  • +
    +
  • + + <%= l(:label_main_term)%> :  <%= current_time_and_term course %> + + <% if User.current.admin? || User.current.allowed_to?(:as_teacher,@course) %> + <% homework_num = course.homework_commons.count %> + <% else %> + <% homework_num = course.homework_commons.where("publish_time <= '#{Date.today}'").count %> + <% end %> +

    <%= homework_num %>作业| <%= visable_attachemnts_incourse(course).count %>资源

    +
  • +
    +
+ <% end %> +
+
    + <%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %> +
+
+
+
+
+ + \ No newline at end of file diff --git a/app/views/users/user_courselist.html.erb b/app/views/users/user_courselist.html.erb new file mode 100644 index 000000000..6784c42cb --- /dev/null +++ b/app/views/users/user_courselist.html.erb @@ -0,0 +1,3 @@ +
+ <%= render :partial => 'users/user_course_list'%> +
\ No newline at end of file diff --git a/app/views/users/user_courselist.js.erb b/app/views/users/user_courselist.js.erb new file mode 100644 index 000000000..ca4674584 --- /dev/null +++ b/app/views/users/user_courselist.js.erb @@ -0,0 +1 @@ +$("#courses-list").html('<%= escape_javascript( render :partial => 'users/user_course_list') %>'); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index fd7546749..fcb3f5272 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -549,6 +549,10 @@ RedmineApp::Application.routes.draw do match 'code_submit_score_index', :to => 'projects#code_submit_score_index', :via => [:get, :post] match 'projects_topic_score_index', :to => 'projects#projects_topic_score_index', :via => [:get, :post] match 'user_act_issue_assign_to', :to => 'users#user_act_issue_assign_to', :via => [:get, :post] + + #addby yk + match 'user_courselist', :to => 'users#user_courselist', :via => :get, :as => "user_courselist" + get 'edit_brief_introduction' get "user_resource" get "import_resources"