diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index b35d7f3db..8c8d8bae4 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -56,10 +56,14 @@ class OrganizationsController < ApplicationController if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization) @organization = Organization.find(params[:id]) project_ids = @organization.projects.map(&:id) << 0 + course_ids = @organization.courses.map(&:id) << 0 + course_types = "('Message','News','HomeworkCommon','Poll','Course')" case params[:type] when nil - @org_activities = OrgActivity.where("(container_id =? and container_type =?) or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')}))", - @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) + @org_activities = OrgActivity.where("(container_id =? and container_type =?) " + + "or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+ + "or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))", + @organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10) when 'project_issue' @org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10) when 'project_message' @@ -145,7 +149,16 @@ class OrganizationsController < ApplicationController def more_org_projects @organization = Organization.find params[:id] @page = params[:page] - @org_projects = @organization.org_projects.reorder('created_at').page((params[:page].to_i || 1) +1).per(5) + @org_projects = @organization.projects.reorder('created_at').page((params[:page].to_i || 1) +1).per(5) + respond_to do |format| + format.js + end + end + + def more_org_courses + @organization = Organization.find(params[:id]) + @page = params[:page] + @org_courses = @organization.courses.reorder('created_at').page((params[:page].to_i || 1) + 1 ).per(5) respond_to do |format| format.js end diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb index 4e74142ad..cd3234196 100644 --- a/app/models/course_activity.rb +++ b/app/models/course_activity.rb @@ -5,7 +5,7 @@ class CourseActivity < ActiveRecord::Base belongs_to :course belongs_to :user has_many :user_acts, :class_name => 'UserAcivity',:as =>:act - after_save :add_user_activity + after_save :add_user_activity, :add_course_activity before_destroy :destroy_user_activity #在个人动态里面增加当前动态 @@ -30,6 +30,27 @@ class CourseActivity < ActiveRecord::Base end end + def add_course_activity + org_activity = OrgActivity.where("org_act_type = '#{self.course_act_type.to_s}' and org_act_id = '#{self.course_act_id}'").first + if org_activity + org_activity.save + else + if self.course_act_type == 'Message' && !self.course_act.parent_id.nil? + org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{self.course_act.parent.id}").first + org_activity.created_at = self.created_at + org_activity.save + else + OrgActivity.create(:user_id => self.user_id, + :org_act_id => self.course_act_id, + :org_act_type => self.course_act_type, + :container_id => self.course_id, + :container_type => 'Course', + :created_at => self.created_at, + :updated_at => self.updated_at) + end + end + end + def destroy_user_activity user_activity = UserActivity.where("act_type = '#{self.course_act_type.to_s}' and act_id = '#{self.course_act_id}'") user_activity.destroy_all diff --git a/app/views/layouts/_org_courses.html.erb b/app/views/layouts/_org_courses.html.erb new file mode 100644 index 000000000..2837ef71f --- /dev/null +++ b/app/views/layouts/_org_courses.html.erb @@ -0,0 +1,12 @@ +<% courses.each do |course|%> + <%# pro = Project.find course.course_id %> +
  • + <%= link_to course.name, course_path(course.id,:host=>Setting.host_name), :class => "coursesLineGrey hidden", :title => course.name%> +
  • +<% end %> +<% if courses.size == 5%> +
  • + + +
  • +<% end%> \ No newline at end of file diff --git a/app/views/layouts/_org_projects.html.erb b/app/views/layouts/_org_projects.html.erb index be65fd516..687b54ecd 100644 --- a/app/views/layouts/_org_projects.html.erb +++ b/app/views/layouts/_org_projects.html.erb @@ -1,7 +1,7 @@ <% projects.each do |project|%> - <% pro = Project.find project.project_id %> + <%# pro = Project.find project.project_id %>
  • - <%= link_to pro.name, project_path(pro.id,:host=>Setting.host_name), :class => "coursesLineGrey hidden", :title => pro.name%> + <%= link_to project.name, project_path(project.id,:host=>Setting.host_name), :class => "coursesLineGrey hidden", :title => project.name%>
  • <% end %> <% if projects.size == 5%> diff --git a/app/views/layouts/base_org.html.erb b/app/views/layouts/base_org.html.erb index d59cf8ee2..84edf02e1 100644 --- a/app/views/layouts/base_org.html.erb +++ b/app/views/layouts/base_org.html.erb @@ -86,17 +86,25 @@ <%= link_to "动态",organization_path(@organization), :class => "homepageMenuText" %>
    项目 - -
    + +
    +
    课程 + +
    +
    + +
    diff --git a/app/views/organizations/_org_activities.html.erb b/app/views/organizations/_org_activities.html.erb index 9523a0a15..aa48fedf1 100644 --- a/app/views/organizations/_org_activities.html.erb +++ b/app/views/organizations/_org_activities.html.erb @@ -35,6 +35,20 @@ <%= render :partial => 'organizations/project_create', :locals => {:activity => act,:user_activity_id =>act.id} %> <% end %> <% end %> + <% if act.container_type == 'Course' %> + <% case act.org_act_type.to_s %> + <% when 'HomeworkCommon' %> + <%= render :partial => 'org_course_homework', :locals => {:activity => HomeworkCommon.find(act.org_act_id),:user_activity_id =>act.id,:course_activity => 0} %> + <% when 'News' %> + <%= render :partial => 'org_course_news', :locals => {:activity => News.find(act.org_act_id),:user_activity_id =>act.id} %> + <% when 'Message'%> + <%= render :partial => 'org_course_message', :locals => {:activity => Message.find(act.org_act_id),:user_activity_id =>act.id} %> + <% when 'Poll' %> + <%= render :partial => 'org_course_poll', :locals => {:activity => Poll.find(act.org_act_id), :user_activity_id => act.id} %> + <% when 'Course'%> + <%= render :partial => 'org_course_create', :locals => {:activity => Course.find(act.org_act_id), :user_activity_id => act.id} %> + <% end %> + <% end %> <% end %> <%#= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> diff --git a/app/views/organizations/_org_course_create.html.erb b/app/views/organizations/_org_course_create.html.erb new file mode 100644 index 000000000..97213283e --- /dev/null +++ b/app/views/organizations/_org_course_create.html.erb @@ -0,0 +1,36 @@ +
    +
    +
    + <%= link_to image_tag(url_to_avatar(activity.teacher), :width => "50", :height => "50"), user_path(activity.tea_id), :alt => "用户头像" %> +
    +
    +
    + <% if activity.try(:teacher).try(:realname) == ' ' %> + <%= link_to activity.try(:teacher), user_path(activity.tea_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:teacher).try(:realname), user_path(activity.tea_id), :class => "newsBlue mr15" %> + <% end %> + TO + <%= link_to activity.name.to_s+" | 课程", course_path(activity.id,:host=>Setting.host_course), :class => "newsBlue ml15" %> +
    +
    + <%= link_to activity.name, course_path(activity.id,:host=>Setting.host_course), :class => "postGrey" %> +
    +
    + 创建时间:<%= format_time(activity.created_at) %> +
    + +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/organizations/_org_course_homework.html.erb b/app/views/organizations/_org_course_homework.html.erb new file mode 100644 index 000000000..9699eff5f --- /dev/null +++ b/app/views/organizations/_org_course_homework.html.erb @@ -0,0 +1,187 @@ +<% is_teacher = User.current.allowed_to?(:as_teacher,activity.course) %> +
    +
    +
    + <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user_id), :alt => "用户头像" %> +
    +
    +
    + <% if activity.try(:user).try(:realname) == ' ' %> + <%= link_to activity.try(:user), user_path(activity.user_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:user).try(:realname), user_path(activity.user_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> + <% end %> TO + <%= link_to activity.course.name.to_s+" | 课程作业", homework_common_index_path(:course => activity.course.id, :host=> Setting.host_course), :class => "newsBlue ml15"%> +
    + + <% if activity.homework_detail_manual%> + <% if activity.homework_detail_manual.comment_status == 1%> + <% if activity.anonymous_comment == 0%> + 未开启匿评 + <% else %> + 匿评已禁用 + <% end %> + <% if Time.parse(activity.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")%> + 作品提交中 + <% elsif Time.parse(activity.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d") %> + 作品补交中 + <% end %> + <% elsif activity.homework_detail_manual.comment_status == 2%> + <% if activity.anonymous_comment == 0%> + 匿评中 + <% else %> + 匿评已禁用 + <% end %> + 教师评阅中 + <% elsif activity.homework_detail_manual.comment_status == 3%> + <% if activity.anonymous_comment == 0%> + 匿评已结束 + <% else %> + 匿评已禁用 + <% end %> + 教师评阅中 + <% end%> + <% end%> +
    +
    + <% is_teacher = User.current.allowed_to?(:as_teacher,activity.course) %> + <%= user_for_homework_common activity,is_teacher %> +
    + + <% if activity.homework_type == 2 && is_teacher%> +
    + <%= link_to "模拟答题", new_user_commit_homework_users_path(homework_id: activity.id, is_test: true), class: 'c_blue test-program-btn', title: '教师可以通过模拟答题设置作业的标准答案' %> +
    + <% end %> + <% if activity.homework_type == 2%> +
    + 语言: + <%= activity.language_name%> +
    + <% end %> + +
    截止时间:<%= activity.end_time.to_s %> 23:59
    +
    +
    +
    + <%= activity.description.html_safe %> +
    +
    +
    + + +
    +
    + <%= render :partial => 'student_work/work_attachments', :locals => {:attachments => activity.attachments} %> +
    +
    + <% if is_teacher%> + <% comment_status = activity.homework_detail_manual.comment_status %> +
    +
      +
    • +
        +
      • + <%= link_to l(:button_edit),edit_homework_common_path(activity,:is_in_course => -1,:course_activity=>course_activity), :class => "postOptionLink"%> +
      • +
      • + <%= link_to(l(:label_bid_respond_delete), homework_common_path(activity,:is_in_course => -1,:course_activity=>course_activity),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "postOptionLink") %> +
      • +
      • + <%= link_to("评分设置", score_rule_set_homework_common_path(activity,:user_activity_id => user_activity_id, :is_in_course => 0),:class => "postOptionLink", :remote => true) %> +
      • + <% if activity.anonymous_comment == 0 %> +
      • + <%= link_to("匿评设置", start_evaluation_set_homework_common_path(activity),:class => "postOptionLink", :remote => true) if activity.homework_detail_manual.comment_status == 1%> +
      • +
      • + <%= homework_anonymous_comment activity,-1,user_activity_id,course_activity %> +
      • + <% end %> + <% if activity.anonymous_comment == 0 && (comment_status == 0 || comment_status == 1)%> +
      • + <%= link_to("禁用匿评", alert_forbidden_anonymous_comment_homework_common_path(activity,:user_activity_id => user_activity_id,:course_activity=>course_activity),:class => "postOptionLink", :remote => true)%> +
      • + <% end %> +
      +
    • +
    +
    + <% end%> +
    +
    +
    + + <% count=activity.journals_for_messages.count %> +
    +
    +
    +
    + 回复(<%= count %>) +
    +
    + <%if count>3 %> + + <% end %> +
    + + <% replies_all_i = 0 %> + <% if count > 0 %> +
    +
      + <% activity.journals_for_messages.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
    • +
      + <%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %> +
      +
      +
      + <% if comment.try(:user).try(:realname) == ' ' %> + <%= link_to comment.try(:user), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:user).try(:realname), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> +
      +
      + <%= comment.notes.html_safe %>
      +
      +
      +
    • + <% end %> +
    +
    + <% end %> + +
    +
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
    +
    +
    + <%= form_for('new_form',:url => {:controller => 'words', :action => 'leave_homework_message', :id => activity.id},:method => "post", :remote => true) do |f|%> + <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %> + <%= hidden_field_tag 'course_activity',params[:course_activity],:value =>course_activity %> + +
    + +
    +

    + <% end%> +
    +
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/organizations/_org_course_message.html.erb b/app/views/organizations/_org_course_message.html.erb new file mode 100644 index 000000000..9ca8f5d10 --- /dev/null +++ b/app/views/organizations/_org_course_message.html.erb @@ -0,0 +1,140 @@ +
    +
    +
    + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id,:host=>Setting.host_user), :alt => "用户头像" %> +
    +
    +
    + <% if activity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id,:host=>Setting.host_user), :class => "newsBlue mr15" %> + <% end %> + TO + <%= link_to activity.course.name.to_s+" | 课程讨论区", course_boards_path(activity.course,:host=> Setting.host_course), :class => "newsBlue ml15 mr5"%> +
    + + <% if activity.sticky == 1%> + 置顶 + <% end%> + <% if activity.locked%> +        + <% end%> +
    +
    + 发帖时间:<%= format_time(activity.created_on) %> +
    +
    +
    + <% if activity.parent_id.nil? %> + <%= activity.content.to_s.html_safe%> + <% else %> + <%= activity.parent.content.to_s.html_safe%> + <% end %> +
    +
    +
    + + +
    + +
    +
    +
    + <% count=0 %> + <% if activity.parent %> + <% count=activity.parent.children.count%> + <% else %> + <% count=activity.children.count%> + <% end %> +
    +
    +
    +
    回复( + <%= count %> + )
    +
    <%#=format_date(activity.updated_on)%>
    + <%if count > 3 %> + + <% end %> +
    + + <% activity= activity.parent ? activity.parent : activity%> + <% replies_all_i = 0 %> + <% if count > 0 %> +
    +
      + <% activity.children.reorder("created_on desc").each do |reply|%> + + <% replies_all_i=replies_all_i+1 %> +
    • +
      + <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id,:host=>Setting.host_user), :alt => "用户头像" %> +
      +
      +
      + <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(reply.created_on) %> +
      +
      + <%= reply.content.html_safe %> +
      +
      +
      +
    • + <% end %> +
    +
    + <% end %> + + <% if !activity.locked? && authorize_for_course('messages', 'reply') %> +
    +
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
    +
    +
    + <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => 'true'},:method => "post", :remote => true) do |f|%> + + + +
    + +
    +

    + <% end%> +
    +
    +
    +
    +
    +
    + <% end %> +
    +
    diff --git a/app/views/organizations/_org_course_news.html.erb b/app/views/organizations/_org_course_news.html.erb new file mode 100644 index 000000000..475a982e5 --- /dev/null +++ b/app/views/organizations/_org_course_news.html.erb @@ -0,0 +1,106 @@ +
    +
    +
    + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id), :alt => "用户头像" %> +
    +
    +
    + <% if @ctivity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_path(activity.author_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id), :class => "newsBlue mr15" %> + <% end %> TO + <%= link_to activity.course.name.to_s+" | 课程通知", course_news_index_path(activity.course), :class => "newsBlue ml15" %> +
    + + <% if activity.sticky == 1%> + 置顶 + <% end%> +
    +
    + 发布时间:<%= format_time(activity.created_on) %> +
    +
    +
    + <%= activity.description.html_safe %> +
    +
    +
    + + +
    +
    +
    +
    + <% count=activity.comments.count %> +
    +
    +
    +
    + 回复(<%= count %>) +
    +
    <%#= format_date(activity.updated_on) %>
    + <%if count>3 %> + + <% end %> +
    + + <% replies_all_i = 0 %> + <% if count > 0 %> +
    +
      + <% activity.comments.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
    • +
      + <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_path(comment.author_id), :alt => "用户头像" %> +
      +
      +
      + <% if comment.try(:author).try(:realname) == ' ' %> + <%= link_to comment.try(:author), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:author).try(:realname), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> +
      +
      + <%= comment.comments.html_safe %>
      +
      +
      +
    • + <% end %> +
    +
    + <% end %> + +
    +
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
    +
    +
    + <%= form_for('new_form',:url => {:controller => 'comments', :action => 'create', :id => activity},:method => "post", :remote => true) do |f|%> + + +
    + +
    +

    + <% end%> +
    +
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/organizations/_org_course_poll.html.erb b/app/views/organizations/_org_course_poll.html.erb new file mode 100644 index 000000000..c363909d9 --- /dev/null +++ b/app/views/organizations/_org_course_poll.html.erb @@ -0,0 +1,56 @@ +<% has_commit = has_commit_poll?(activity.id ,User.current)%> +<% poll_name = activity.polls_name.empty? ? l(:label_poll_new) : activity.polls_name%> +<% if ( activity.polls_status==2) %> +
    +
    +
    + + <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user_id), :alt => "用户头像" %> +
    +
    +
    + <% if activity.try(:user).try(:realname) == ' ' %> + <%= link_to activity.try(:user), user_path(activity.user_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:user).try(:realname), user_path(activity.user_id), :class => "newsBlue mr15" %> + <% end %> + TO + <%= link_to Course.find(activity.polls_group_id).name.to_s+" | 问卷", poll_index_path(:polls_type => "Course", :polls_group_id => activity.polls_group_id), :class => "newsBlue ml15" %> + +
    +
    + <%#= link_to activity.polls_name.to_s/*+"(问卷名称)"*/, %> + <% if has_commit %> + <%= link_to poll_name, poll_result_poll_path(activity.id), :class => "postGrey"%> + <% else %> + <%= link_to poll_name, poll_path(activity.id), :class => "postGrey"%> + <% end %> +
    +
    + 发布时间:<%= format_time(activity.published_at) %> +
    +
    +
    + <%= activity.polls_description.html_safe %> +
    +
    +
    + + +
    + +
    +
    +
    +
    +<% end %> \ No newline at end of file diff --git a/app/views/organizations/more_org_courses.js.erb b/app/views/organizations/more_org_courses.js.erb new file mode 100644 index 000000000..02bfb1d70 --- /dev/null +++ b/app/views/organizations/more_org_courses.js.erb @@ -0,0 +1,2 @@ +$("#show_more_org_course").replaceWith("<%= escape_javascript( render :partial => 'layouts/org_courses', + :locals => {:courses => @org_courses,:org_id => @organization, :page => @page} )%>"); diff --git a/app/views/organizations/show.html.erb b/app/views/organizations/show.html.erb index e62a66913..acaf2879e 100644 --- a/app/views/organizations/show.html.erb +++ b/app/views/organizations/show.html.erb @@ -42,7 +42,7 @@ <% if !@organization.home_id.nil? and OrgDocumentComment.where("id = ?", @organization.home_id).count > 0 %> <% act = OrgActivity.where("org_act_type = 'OrgDocumentComment' and org_act_id =?", @organization.home_id).first %> diff --git a/config/routes.rb b/config/routes.rb index f2a08d35e..c68c8a1c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,6 +38,7 @@ RedmineApp::Application.routes.draw do put 'set_homepage' get 'members' get 'more_org_projects' + get 'more_org_courses' end collection do get 'check_uniq' diff --git a/public/javascripts/org.js b/public/javascripts/org.js index e26995931..1e1951006 100644 --- a/public/javascripts/org.js +++ b/public/javascripts/org.js @@ -42,4 +42,12 @@ function show_more_org_project(url){ } ); +} + +function show_more_org_course(url){ + $.get( + url, + {page: $("#org_course_page_num").val()}, + function (data){} + ); } \ No newline at end of file