修改课程基础页面逻辑(base_courses.html.erb)

This commit is contained in:
nwb 2014-06-05 11:55:46 +08:00
parent de201ae8f6
commit 6ff26d06ab
6 changed files with 171 additions and 78 deletions

View File

@ -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'}

View File

@ -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

View File

@ -1,3 +1,3 @@
class CourseInfos < ActiveRecord::Base
attr_accessible :typeId, :typeName
attr_accessible :user_id, :course_id
end

View File

@ -0,0 +1,108 @@
<% if @events_by_day.size >0 %>
<div class="content-title-top-avtive">
<!-- <h3><%= @author.nil? ? l(:label_activity) : l(:label_user_activity, link_to_user(@author)).html_safe %></h3> -->
<p class="subtitle">
<%= l(:label_date_from_to, :start => format_date(@date_to - @days), :end => format_date(@date_to-1)) %>
</p>
<% @events_by_day.keys.sort.reverse.each do |day| %>
<div>
<% sort_activity_events(@events_by_day[day]).each do |e, in_group| -%>
<div>
<table class="underline-evreycontent" style="font-size: 14px;">
<tr>
<td colspan="2" valign="top" width="50" ><%= image_tag(url_to_avatar(e.event_author), :class => "avatar")%></td>
<td>
<table width="580px" border="0">
<tr>
<td colspan="2" valign="top">
<strong> <%= h(e.project) if @project.nil? || @project.id != e.project.id %></strong>
<span class="font_lighter">
<% 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) %> </span>
<%= 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 %>
</td>
</tr>
<tr>
<td colspan="2" width="580px" >
<p class="info-break">
<%= h(truncate(strip_tags(e.event_description).gsub(/&nbsp;/,' '), length: 30, omission:'...')) %>
</p></td>
</tr>
<tr>
<td align="left"><span class="font_lighter"> <%= l :label_activity_time %>&nbsp; <%= format_activity_day(day) %> <%= format_time(e.event_datetime, false) %></span></td>
<% if e.event_type == "issue" %>
<td align="right"><span> <%= link_to l(:label_find_all_comments), issue_path(e) %> </span><span class="font_lighter"><%= l(:label_comments_count, :count => e.journals.count)%></span></td>
<% end %>
</tr>
</table></td>
</tr>
</table>
</div>
<% end %>
</div>
<!-- Added by Longjun 在最后一页显示创建信息 -->
<% if format_date(day) == format_date(@date_to - @days) %>
<h1>Test</h1>
<div >
<table width="660">
<tr>
<td><%= image_tag(url_to_avatar(@user), :class => "avatar") %></td>
<td colspan="2">
<table width="580">
<tr>
<td > <%= link_to (h @user.try(:name)), user_path(@user) if @user %> <%= l(:label_user_create_project) %> <%= link_to @project.name %><strong> !</strong></td>
</tr>
<tr>
<td class="font_lighter" style="float: right"><%= l :label_update_time %>: <%= format_time(@project.created_on) %>
</table></td>
</tr>
</table>
</div>
<% end %>
<% end -%>
<div class="pagination">
<ul>
<%= pagination_links_full @events_pages%>
</ul>
</div>
</div>
<% else %>
<div class="font_description">
<table width="660">
<tr>
<td><%= image_tag(url_to_avatar(@user), :class => "avatar") %></td>
<td colspan="2">
<table width="580">
<tr>
<td >
<%
#判断是否显示真名
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 %><strong> !</strong></td>
</tr>
<tr>
<td class="font_lighter" style="float: right"><%= l :label_update_time %>: <%= format_time(@course.created_at) %>
</table></td>
</tr>
</table>
</div>
<% end %>

View File

@ -26,71 +26,62 @@
<div id="main">
<!--added by huang-->
<div class="top-content">
<% @project = Project.find_by_id(@project.id) %>
<% @course = Course.find_by_extra(@project.identifier) %>
<table>
<tr>
<td class="info_font" style="width: 240px; color: #15bccf">高校课程实践社区</td>
<td style="color: #15bccf"><strong><%= l(:label_user_location) %> : </strong></td>
<td rowspan="2" width="250px">
<div class="top-content-search">
<%= form_tag(:controller => 'projects', :action => 'search', :method => :get) do %>
<%= form_tag(:controller => 'courses', :action => 'search', :method => :get) do %>
<%= text_field_tag 'name', params[:name], :size => 20 %>
<%= hidden_field_tag 'project_type', @project.project_type %>
<%= submit_tag l(:label_search), :class => "enterprise", :name => nil %>
<% end %>
</div>
</td>
</tr>
<tr>
<td style="padding-left: 8px"><%= link_to request.host()+"/course", :controller => 'projects', :action => 'course' %></td>
<td style="padding-left: 8px"><%= link_to request.host()+"/course", :controller => 'courses', :action => 'course' %></td>
<td><p class="top-content-list"><%= link_to "主页", home_path %>
> <%= link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %>
> <%= link_to @project.name, nil %></p></td>
> <%= link_to l(:label_course_practice), :controller => 'courses', :action => 'course' %>
> <%= link_to @course.name, nil %></p></td>
</tr>
</table>
</div>
<!-- end -->
<!--project page-->
<!--course page-->
<div id="sidebar">
<div class="spaceleft">
<!--informations-->
<div class="inf_user_image">
<% @project = Project.find_by_id(@project.id) %>
<% @course = Course.find_by_extra(@project.identifier) %>
<table>
<tr>
<td valign="top">
<% if (@project.project_type==1) %>
<% if get_avatar?(@project) %>
<%= image_tag(url_to_avatar(@project), :class => "avatar2") %>
<% if get_avatar?(@course) %>
<%= image_tag(url_to_avatar(@course), :class => "avatar2") %>
<% else %>
<%= link_to image_tag('../images/avatars/Project/course.jpg', :class => "avatar2"), project_path(@project) %>
<%= link_to image_tag('../images/avatars/course/course.jpg', :class => "avatar2"), course_path(@course) %>
<% end %>
<% else %>
<%= image_tag(url_to_avatar(@project), :class => "avatar2") %>
<% end %> </td>
<td>
<table>
<tr>
<td class="info-course"><%= @project.name %></td>
<td class="info-course"><%= @course.name %></td>
</tr>
<tr>
<td align="center">
<div id="join_in_course">
<% if User.current.logged? %>
<% if @course.teacher.id == User.current.id %>
<%= link_to l(:label_course_modify_settings), {:controller => 'projects', :action => 'settings', :id => @project} %>
<%= render :partial => 'courses/set_course_time', :locals => {:project => @project} %>
<%= link_to l(:label_course_modify_settings), {:controller => 'courses', :action => 'settings', :id => @course} %>
<%= render :partial => 'courses/set_course_time', :locals => {:course => @course} %>
<% else %>
<%= join_in_course(@project, User.current) %>
<%= join_in_course(@course, User.current) %>
<% end %>
<% unless User.current.member_of?(@project) %>
<% unless User.current.member_of?(@course) %>
<!-- <%= image_tag "/images/fav.png" %> -->
<div style="padding-right: 10px">
<span class="icon-fav icon"></span><span>
<%= watcher_link(@project, User.current) %></span></div>
<%= watcher_link(@course, User.current) %></span></div>
<% end %>
<% end %>
</div>
@ -107,34 +98,34 @@
<table width="240" border="0">
<tr align="center" width="80px">
<% files_count = @project.attachments.count %>
<% @project.versions.each do |version| %>
<% files_count = @course.attachments.count %>
<% @course.versions.each do |version| %>
<% files_count += version.attachments.count %>
<% end %>
<td class="font_index">
<!-- 1 教师; 2 学生0 全部-->
<% if User.current.member_of?(@project) %>
<%= link_to "#{teacherCount(@project)}", project_member_path(@project, :role => 1), :course => '1' %>
<% if User.current.member_of?(@course) %>
<%= link_to "#{teacherCount(@course)}", course_member_path(@course, :role => 1), :course => '1' %>
<% else %>
<span><%= teacherCount(@project)%></span> <!--<%= link_to "#{teacherCount(@project)}", "javascript:void(0)", :course => '1' %>-->
<span><%= teacherCount(@course)%></span> <!--<%= link_to "#{teacherCount(@course)}", "javascript:void(0)", :course => '1' %>-->
<% end%>
</td>
<td class="font_index">
<% if User.current.member_of?(@project) %>
<%= link_to "#{studentCount(@project)}", project_member_path(@project, :role => 2), :course => '1' %>
<% if User.current.member_of?(@course) %>
<%= link_to "#{studentCount(@course)}", course_member_path(@course, :role => 2), :course => '1' %>
<% else %>
<span><%= studentCount(@project)%></span>
<span><%= studentCount(@course)%></span>
<% end %>
</td>
<td class="font_index"><%= link_to files_count, project_files_path(@project) %></td>
<td class="font_index"><%= link_to files_count, course_files_path(@course) %></td>
<tr class="font_aram">
<td align="center" width="80px" id="teacherCount">
<!-- %= l(:label_x_base_courses_member, :count => @project.members.count) % -->
<%= l(:label_x_base_courses_teacher, :count => teacherCount(@project)) %>
<!-- %= l(:label_x_base_courses_member, :count => @course.members.count) % -->
<%= l(:label_x_base_courses_teacher, :count => teacherCount(@course)) %>
</td>
<td align="center" width="80px" id="studentCount">
<%= l(:label_x_base_courses_student, :count => studentCount(@project)) %>
<%= l(:label_x_base_courses_student, :count => studentCount(@course)) %>
<!-- %= l(:label_x_course_data, :count => files_count) % -->
</td>
<td align="center" width="80px">
@ -196,22 +187,22 @@
<!--description-->
<div class="inf_user_context">
<div class="font_title_left">
<%= l(:label_project_overview) %>
<%= l(:label_course_overview) %>
</div>
<div style="padding-bottom: 8px">
<% if @project.description.size>0 %>
<% if @course.description.size>0 %>
<div class="font_lighter_sidebar">
<%= textilizable @project.description %>
<%= textilizable @course.description %>
</div>
<% else %>
<div class="font_lighter_sidebar">
<%= l(:label_course_description_no) %>
</div>
<% end %>
<div class="created_on_project">
<strong style="color: #068d9c"><%= l(:label_create_time) %></strong><%= format_time(@project.created_on) %>
<div class="created_on_course">
<strong style="color: #068d9c"><%= l(:label_create_time) %></strong><%= format_time(@course.created_on) %>
</div>
</div>
<div class="user_underline"></div>
@ -222,7 +213,7 @@
<!-- added by william -for tag -->
<div class="user_tags">
<div id="tags">
<%= render :partial => 'tags/tag', :locals => {:obj => @project, :object_flag => "2"} %>
<%= render :partial => 'tags/tag', :locals => {:obj => @course, :object_flag => "2"} %>
</div>
</div>
</div>
@ -234,25 +225,25 @@
<div class="tabs_new">
<ul>
<li>
<%= link_to l(:label_course_overview), project_path(@project), :class => link_class(:overview) %>
<%= link_to l(:label_course_overview), course_path(@course), :class => link_class(:overview) %>
</li>
<li>
<%= link_to l(:label_homework), homework_project_path(@project), :class => link_class(:homework), :project_type => 1 %>
<%= link_to l(:label_homework), homework_course_path(@course), :class => link_class(:homework), :course_type => 1 %>
</li>
<li>
<%= link_to l(:label_course_file), project_files_path(@project), :class => link_class(:files) %>
<%= link_to l(:label_course_file), course_files_path(@course), :class => link_class(:files) %>
</li>
<li>
<%= link_to l(:label_course_news), {:controller => 'news', :action => 'index', :project_id => @project}, :class => link_class(:news) %>
<%= link_to l(:label_course_news), {:controller => 'news', :action => 'index', :course_id => @course}, :class => link_class(:news) %>
</li>
<li>
<%= link_to l(:label_course_board), {:controller => 'boards', :action => 'index', :project_id => @project}, :class => link_class(:boards) %>
<%= link_to l(:label_course_board), {:controller => 'boards', :action => 'index', :course_id => @course}, :class => link_class(:boards) %>
</li>
<li>
<%= link_to l(:label_course_feedback), project_feedback_path(@project), :class => link_class(:feedback) %>
<%= link_to l(:label_course_feedback), course_feedback_path(@course), :class => link_class(:feedback) %>
</li>
<!-- <li><%= link_to(l(:label_course_repository), {:controller => 'repositories', :action => 'show', :id => @project, :repository_id => nil, :path => nil, :rev => nil, :course => 1}) %></li> -->
<% if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and project_id = ?', User.current.id, @project.id).first.nil? && (Member.where('user_id = ? and project_id = ?', User.current.id, @project.id).first.roles&Role.where('id = ? or id = ?', 7, 9)).size >0)) %>
<!-- <li><%= link_to(l(:label_course_repository), {:controller => 'repositories', :action => 'show', :id => @course, :repository_id => nil, :path => nil, :rev => nil, :course => 1}) %></li> -->
<% if User.current.logged? && (User.current.admin? || (!Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.nil? && (Member.where('user_id = ? and course_id = ?', User.current.id, @course.id).first.roles&Role.where('id = ? or id = ?', 7, 9)).size >0)) %>
<% end %>
</ul>

View File

@ -19,15 +19,21 @@ module Redmine
module Activity
# Class used to retrieve activity events
class Fetcher
attr_reader :user, :project, :scope
attr_reader :user, :project, :scope,:course
# Needs to be unloaded in development mode
@@constantized_providers = Hash.new {|h,k| h[k] = Redmine::Activity.providers[k].collect {|t| t.constantize } }
def initialize(user, options={})
if options.has_key?(:project)
options.assert_valid_keys(:project, :with_subprojects, :author)
@user = user
@project = options[:project]
else
options.assert_valid_keys(:course, :with_subprojects, :author)
@user = user
@course = options[:course]
end
@options = options
@scope = event_types
@ -38,7 +44,11 @@ module Redmine
return @event_types unless @event_types.nil?
@event_types = Redmine::Activity.available_event_types
@event_types = @event_types.select {|o| @project.self_and_descendants.detect {|p| @user.allowed_to?("view_#{o}".to_sym, p)}} if @project
if @project
@event_types = @event_types.select {|o| @project.self_and_descendants.detect {|p| @user.allowed_to?("view_#{o}".to_sym, p)}}
else
@event_types = @event_types.select {|o| @course.self_and_descendants.detect {|p| @user.allowed_to?("view_#{o}".to_sym, p)}} if @course
end
@event_types
end