From 6ff26d06ab215d0ca3731cbc229019be98cc5562 Mon Sep 17 00:00:00 2001 From: nwb Date: Thu, 5 Jun 2014 11:55:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=BE=E7=A8=8B=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E9=A1=B5=E9=9D=A2=E9=80=BB=E8=BE=91(base=5Fcourses.ht?= =?UTF-8?q?ml.erb)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 25 +----- app/models/course.rb | 3 + app/models/course_infos.rb | 2 +- app/views/courses/show.html.erb | 108 ++++++++++++++++++++++++ app/views/layouts/base_courses.html.erb | 91 +++++++++----------- lib/redmine/activity/fetcher.rb | 20 +++-- 6 files changed, 171 insertions(+), 78 deletions(-) create mode 100644 app/views/courses/show.html.erb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 4cd22677..7fd5518c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -338,16 +338,10 @@ class CoursesController < ApplicationController end @users_by_role = @course.users_by_role - if(User.find_by_id(CourseInfo.find_by_course_id(@course.id).try(:user_id))) - @user = User.find_by_id(CourseInfo.find_by_course_id(@course.id).user_id) + if(User.find_by_id(CourseInfos.find_by_course_id(@course.id).try(:user_id))) + @user = User.find_by_id(CourseInfos.find_by_course_id(@course.id).user_id) end - cond = @course.course_condition(Setting.display_subcourses_issues?) - @open_issues_by_tracker = Issue.visible.open.where(cond).count(:group => :tracker) - @total_issues_by_tracker = Issue.visible.where(cond).count(:group => :tracker) - if User.current.allowed_to?(:view_time_entries, @course) - @total_hours = TimeEntry.visible.sum(:hours, :include => :course, :conditions => cond).to_f - end @key = User.current.rss_key #新增内容 @@ -366,11 +360,10 @@ class CoursesController < ApplicationController } @date_to ||= Date.today + 1 @date_from = @date_to - @days-1.years - @with_subcourses = params[:with_subcourses].nil? ? Setting.display_subcourses_issues? : (params[:with_subcourses] == '1') @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) # 决定显示所用用户或单个用户活动 @activity = Redmine::Activity::Fetcher.new(User.current, :course => @course, - :with_subcourses => @with_subcourses, + :with_subprojects => false, :author => @author) @activity.scope_select {|t| !has["show_#{t}"].nil?} # logger.debug "=========================================#{@activity.scope}" @@ -387,18 +380,6 @@ class CoursesController < ApplicationController @events_by_day = events.group_by {|event| User.current.time_to_date(event.event_datetime)} # documents @sort_by = %w(category date title author).include?(params[:sort_by]) ? params[:sort_by] : 'category' - documents = @course.documents.includes(:attachments, :category).all - case @sort_by - when 'date' - @grouped = documents.group_by {|d| d.updated_on.to_date } - when 'title' - @grouped = documents.group_by {|d| d.title.first.upcase} - when 'author' - @grouped = documents.select{|d| d.attachments.any?}.group_by {|d| d.attachments.last.author} - else - @grouped = documents.group_by(&:category) - end - @document = @course.documents.build # respond_to do |format| format.html{render :layout => 'base_courses'} diff --git a/app/models/course.rb b/app/models/course.rb index 2252577c..df063cec 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -21,6 +21,9 @@ class Course < ActiveRecord::Base has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :homework_for_courses, :dependent => :destroy has_many :student, :through => :students_for_courses, :source => :user + has_many :course_infos, :dependent => :destroy + + acts_as_nested_set :order => 'name', :dependent => :destroy validates_presence_of :password, :term diff --git a/app/models/course_infos.rb b/app/models/course_infos.rb index 265cdccf..d841c2eb 100644 --- a/app/models/course_infos.rb +++ b/app/models/course_infos.rb @@ -1,3 +1,3 @@ class CourseInfos < ActiveRecord::Base - attr_accessible :typeId, :typeName + attr_accessible :user_id, :course_id end diff --git a/app/views/courses/show.html.erb b/app/views/courses/show.html.erb new file mode 100644 index 00000000..64eba20e --- /dev/null +++ b/app/views/courses/show.html.erb @@ -0,0 +1,108 @@ +<% if @events_by_day.size >0 %> +
+ +

+ <%= l(:label_date_from_to, :start => format_date(@date_to - @days), :end => format_date(@date_to-1)) %> +

+ + <% @events_by_day.keys.sort.reverse.each do |day| %> +
+ <% sort_activity_events(@events_by_day[day]).each do |e, in_group| -%> +
+ + + + + +
<%= image_tag(url_to_avatar(e.event_author), :class => "avatar")%> + + + + + + + + + + <% if e.event_type == "issue" %> + + <% end %> + +
+ <%= h(e.project) if @project.nil? || @project.id != e.project.id %> + + <% if @canShowRealName %> + <%= link_to_user(e.event_author) if e.respond_to?(:event_author) %>(<%= link_to_user(e.event_author,@canShowRealName) if e.respond_to?(:event_author) %>) + <% else %> + <%= link_to_user(e.event_author) if e.respond_to?(:event_author) %> + <% end %> + + <%= l(:label_new_activity) %> + + <%= link_to "#{eventToLanguageCourse(e.event_type, @project)}: "<< format_activity_title(e.event_title), (e.event_type.eql?("attachment")&&e.container.kind_of?(Project)) ? project_files_path(e.container) : e.event_url %> +
+

+ <%= h(truncate(strip_tags(e.event_description).gsub(/ /,' '), length: 30, omission:'...')) %> +

<%= l :label_activity_time %>:  <%= format_activity_day(day) %> <%= format_time(e.event_datetime, false) %> <%= link_to l(:label_find_all_comments), issue_path(e) %> <%= l(:label_comments_count, :count => e.journals.count)%>
+
+ + <% end %> +
+ + + <% if format_date(day) == format_date(@date_to - @days) %> +

Test

+
+ + + + + +
<%= image_tag(url_to_avatar(@user), :class => "avatar") %> + + + + + +
<%= link_to (h @user.try(:name)), user_path(@user) if @user %> <%= l(:label_user_create_project) %> <%= link_to @project.name %> !
<%= l :label_update_time %>: <%= format_time(@project.created_on) %> +
+
+ <% end %> + <% end -%> + + + + +
+<% else %> +
+ + + + + +
<%= image_tag(url_to_avatar(@user), :class => "avatar") %> + + + + + +
+ <% + #判断是否显示真名 + if @canShowRealName + %> + <%= link_to (h @user.try(:name)), user_path(@user) if @user %>(<%= link_to (h @user.try(:realname)), user_path(@user) if @user %>) + <% else %> + <%= link_to (h @user.try(:name)), user_path(@user) if @user %> + <% end %> + <%= l(:label_user_create_project) %> <%= link_to @course.name %> !
<%= l :label_update_time %>: <%= format_time(@course.created_at) %> +
+
+<% end %> + + diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 4e0135ea..e4a52826 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -26,71 +26,62 @@
- <% @project = Project.find_by_id(@project.id) %> - <% @course = Course.find_by_extra(@project.identifier) %> - + + > <%= link_to l(:label_course_practice), :controller => 'courses', :action => 'course' %> + > <%= link_to @course.name, nil %>

高校课程实践社区 <%= l(:label_user_location) %> :
<%= link_to request.host()+"/course", :controller => 'projects', :action => 'course' %><%= link_to request.host()+"/course", :controller => 'courses', :action => 'course' %>

<%= link_to "主页", home_path %> - > <%= link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> - > <%= link_to @project.name, nil %>

- +