Merge branch 'cxt_course' of https://git.trustie.net/jacknudt/trustieforge into cxt_course

This commit is contained in:
Tim 2016-05-19 17:24:11 +08:00
commit b0fba934ae
25 changed files with 94 additions and 44 deletions

View File

@ -6,7 +6,7 @@ unless RUBY_PLATFORM =~ /w32/
gem 'iconv'
end
#gem 'certified'
gem 'certified'
gem 'wechat',path: 'lib/wechat'
gem 'grack', path:'lib/grack'

View File

@ -33,10 +33,10 @@ module Mobile
shield_project_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Project'").map(&:shield_id)
shield_course_ids = ShieldActivity.select("shield_id").where("container_type='User' and container_id=#{user.id} and shield_type='Course'").map(&:shield_id)
page = params[:page] ? params[:page] : 0
user_project_ids = (user.projects.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (user.courses.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.map{|course| course.id}-shield_course_ids).join(",") + ")"
user_project_ids = (user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (user.projects.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (user.courses.map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','ProjectCreateInfo')"
project_types = "('Message','Issue','Project')"
principal_types = "JournalsForMessage"
watched_user_ids = User.watched_by(user.id).count == 0 ? " " : ("," + User.watched_by(user.id).map{|u| u.id.to_s }.join(','))
user_ids = "(" + user.id.to_s + watched_user_ids + ")"

View File

@ -14,7 +14,7 @@ module Mobile
else
case f
when :user_act
if ac.act_type == "ProjectCreateInfo"
if ac.act_type == "Project"
ac unless ac.nil?
else
ac.act unless ac.nil? || ac.act.nil?
@ -87,7 +87,7 @@ module Mobile
"项目缺陷"
when "Message"
"项目讨论区"
when "ProjectCreateInfo"
when "Project"
"项目"
end
end
@ -101,7 +101,7 @@ module Mobile
expose :container_type #课程/项目/博客/个人
expose :author, using: Mobile::Entities::User do |a, opt| #用户信息
if a.is_a? ::UserActivity
if a.act_type == "ProjectCreateInfo"
if a.act_type == "Project"
get_user(get_project(a.act_id).user_id)
elsif !a.act.nil?
if a.act_type == 'Issue' || a.act_type == 'News' || a.act_type == 'Message' || a.act_type == 'BlogComment'

View File

@ -20,15 +20,16 @@ class HomeworkCommonController < ApplicationController
@page = params[:page] ? params[:page].to_i + 1 : 0
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
if @is_teacher
@homeworks = @course.homework_commons.order("updated_at desc").limit(10).offset(@page * 10)
#@homeworks = @course.homework_commons.order("created_at desc").limit(10).offset(@page * 10)
@homework_commons = @course.homework_commons.order("created_at desc")
else
@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("updated_at desc").limit(10).offset(@page * 10)
#@homeworks = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc").limit(10).offset(@page * 10)
@homework_commons = @course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at desc")
end
@is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher))
@is_new = params[:is_new]
@homeworks = paginateHelper @homework_commons,10
#设置at已读
@homeworks.each do |homework|
homework.journals_for_messages.each do |j|
@ -291,9 +292,9 @@ class HomeworkCommonController < ApplicationController
def open_student_works
if @homework.is_open == 0
@homework.update_attribute(:is_open, 1)
@homework.update_column('is_open', 1)
else
@homework.update_attribute(:is_open, 0)
@homework.update_column('is_open', 0)
end
@user_activity_id = params[:user_activity_id]
@is_in_course = params[:is_in_course] if params[:is_in_course]
@ -440,7 +441,7 @@ class HomeworkCommonController < ApplicationController
puts time
s_time = time
if format_time(time) > format_time(h.updated_at)
h.update_attribute(:updated_at, s_time)
h.update_column('updated_at', s_time)
end
end
end

View File

@ -127,7 +127,7 @@ class OrganizationsController < ApplicationController
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(',')})) "+
"or (container_type ='Project' and org_act_type in ('Issue','Message','Project') 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'

View File

@ -814,7 +814,7 @@ class StudentWorkController < ApplicationController
stu_score = StudentWorksScore.find_by_sql("SELECT AVG(score) AS score FROM (SELECT * FROM (SELECT * FROM student_works_scores WHERE student_work_id = #{@work.id} AND reviewer_role = 3 ORDER BY created_at DESC) AS t GROUP BY user_id) AS a")
@work.student_score = stu_score.first.score.try(:round, 2).to_f
end
@homework.update_attributes(:updated_at => Time.now)
@homework.update_column('updated_at', Time.now)
update_course_activity(@homework.class,@homework.id)
update_user_activity(@homework.class,@homework.id)
update_org_activity(@homework.class,@homework.id)

View File

@ -589,7 +589,7 @@ class UsersController < ApplicationController
new_homework.homework_detail_programing.save if new_homework.homework_detail_programing
new_homework.homework_detail_group.save if new_homework.homework_detail_group
end
homework.update_attribute(:quotes, homework.quotes+1)
homework.update_column(:quotes, homework.quotes+1)
end
@homework = homework
respond_to do |format|
@ -862,7 +862,7 @@ class UsersController < ApplicationController
student_work.save
send_message_to_teacher(student_work)
homework.update_attributes(:updated_at => Time.now)
homework.update_column(:updated_at, Time.now)
update_course_activity(homework.class,homework.id)
update_user_activity(homework.class,homework.id)
update_org_activity(homework.class,homework.id)
@ -950,7 +950,7 @@ class UsersController < ApplicationController
homework_detail_group.save if homework_detail_group
if params[:quotes] && !params[:quotes].blank?
quotes_homework = HomeworkCommon.find params[:quotes].to_i
quotes_homework.update_attribute(:quotes, quotes_homework.quotes+1)
quotes_homework.update_column(:quotes, quotes_homework.quotes+1)
end
if params[:is_in_course] == "1"
redirect_to homework_common_index_path(:course => homework.course_id)
@ -1373,7 +1373,7 @@ class UsersController < ApplicationController
user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (@user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.where("is_delete = 0").map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course','JournalsForMessage')"
project_types = "('Message','Issue','ProjectCreateInfo')"
project_types = "('Message','Issue','Project')"
principal_types = "JournalsForMessage"
if params[:type].present?
case params[:type]

View File

@ -211,7 +211,7 @@ class WechatsController < ActionController::Base
user_project_ids = (@user.projects.visible.map{|project| project.id}-shield_project_ids).empty? ? "(-1)" : "(" + (@user.projects.visible.map{|project| project.id}-shield_project_ids).join(",") + ")"
user_course_ids = (@user.courses.visible.map{|course| course.id}-shield_course_ids).empty? ? "(-1)" : "(" + (@user.courses.visible.map{|course| course.id}-shield_course_ids).join(",") + ")"
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
project_types = "('Message','Issue','ProjectCreateInfo')"
project_types = "('Message','Issue','Project')"
principal_types = "JournalsForMessage"
blog_ids = "("+@user.blog.id.to_s+","+((User.watched_by(@user.id).count == 0 )? '0' :User.watched_by(@user.id).map{|u| u.blog.id}.join(','))+")"

View File

@ -3248,3 +3248,14 @@ def strip_html(text,len=0,endss="...")
end
return ss
end
def get_hw_index(hw,is_teacher)
if is_teacher
homeworks = hw.course.homework_commons.order("created_at asc")
else
homeworks = hw.course.homework_commons.where("publish_time <= '#{Date.today}'").order("created_at asc")
end
hw_ids = homeworks.map{|hw| hw.id} if !homeworks.empty?
index = hw_ids.index(hw.id)
return index
end

View File

@ -5,8 +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, :add_org_activity
after_create :add_course_lead
after_create :add_course_lead,:add_user_activity, :add_org_activity
before_destroy :destroy_user_activity, :destroy_org_activity
#在个人动态里面增加当前动态

View File

@ -20,7 +20,7 @@ class ForgeActivity < ActiveRecord::Base
validates :forge_act_id,presence: true
validates :forge_act_type, presence: true
has_many :user_acts, :class_name => 'UserAcivity',:as =>:act
after_save :add_user_activity, :add_org_activity
after_create :add_user_activity, :add_org_activity
before_destroy :destroy_user_activity, :destroy_org_activity
#在个人动态里面增加当前动态

View File

@ -29,8 +29,8 @@ class HomeworkCommon < ActiveRecord::Base
:description => :description,
:author => :author,
:url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}}
after_create :act_as_activity, :send_mail
after_update :update_activity
after_create :act_as_activity, :send_mail,:act_as_course_message
after_update :update_activity, :wechat_message
after_save :act_as_course_activity
after_destroy :delete_kindeditor_assets
@ -59,12 +59,12 @@ class HomeworkCommon < ActiveRecord::Base
else
self.course.members.each do |m|
# if m.user_id != self.user_id
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
#count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
#if count == 0
# ws = WechatService.new
# ws.homework_template(m.user_id, "homework", self.id, "#{l(:label_new_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59")
#end
#self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
if count == 0
ws = WechatService.new
ws.homework_template(m.user_id, "homework", self.id, "#{l(:label_new_homework_template)}", self.course.name, self.name.html_safe, self.end_time.to_s + " 23:59:59")
end
# end
end
end

View File

@ -164,7 +164,20 @@ class Issue < ActiveRecord::Base
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Project' and shield_id=#{self.project_id}").count
if m.user_id != self.author_id && count == 0
ws = WechatService.new
content = strip_html self.project.name + " 有新缺陷了:" + self.subject.html_safe, 200
str = " 有新缺陷了: "
case self.tracker_id
when 1
str = " 有新缺陷了: "
when 2
str = " 有新功能了: "
when 3
str = " 有新支持了: "
when 4
str = " 有新任务了: "
when 5
str = " 有新周报了: "
end
content = strip_html self.project.name + str + self.subject.html_safe, 200
ws.message_update_template m.user_id, "issues", self.id, "#{l(:label_new_issue_template)}", content, format_time(self.created_on)
end
end

View File

@ -274,7 +274,7 @@ class Message < ActiveRecord::Base
else # 回帖
parent_author_id = Message.find(self.parent_id).author_id
if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
#self.course_messages << CourseMessage.new(:user_id => parent_author_id, :course_id => self.board.course_id, :viewed => false)
self.course_messages << CourseMessage.new(:user_id => parent_author_id, :course_id => self.board.course_id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Course' and shield_id=#{self.board.course_id}").count
if count == 0
content = strip_html self.content.html_safe, 200
@ -297,7 +297,7 @@ class Message < ActiveRecord::Base
else # 回帖
parent_author_id = Message.find(self.parent_id).author_id
if parent_author_id != self.author_id # 只针对主贴回复,回复自己的帖子不发消息
#self.forge_messages << ForgeMessage.new(:user_id => parent_author_id, :project_id => self.board.project_id, :viewed => false)
self.forge_messages << ForgeMessage.new(:user_id => parent_author_id, :project_id => self.board.project_id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{parent_author_id} and shield_type='Project' and shield_id=#{self.board.project_id}").count
if count == 0
content = strip_html self.content.html_safe, 200

View File

@ -62,7 +62,7 @@ class News < ActiveRecord::Base
:author_key => :author_id
acts_as_watchable
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score
after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity, :add_author_as_watcher, :send_mail, :add_news_count, :act_as_student_score, :act_as_system_message
after_update :update_activity
after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities, :down_course_score
@ -169,7 +169,7 @@ class News < ActiveRecord::Base
if self.course
self.course.members.each do |m|
if m.user_id != self.author_id
self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
#self.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => self.course_id, :viewed => false)
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
if count == 0
ws = WechatService.new

View File

@ -73,6 +73,12 @@
<% end%>
<%= render :partial => 'users/user_homework_list', :locals => {:homework_commons => @homeworks,:page => 0,:is_in_course => 1,:course_id => @course.id} %>
<div style="width:210px; text-align:center; margin:0 auto;">
<ul class="wlist" style=" border:none; display:inline-block; float:none; margin-top:10px;">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%>
</ul>
<div class="cl"></div>
</div>
</div>
<div class="cl"></div>

View File

@ -56,7 +56,7 @@
<%= render :partial => 'organizations/org_project_issue', :locals => {:activity => Issue.find(act.org_act_id),:user_activity_id =>act.id} %>
<% when 'Message' %>
<%= render :partial => 'organizations/project_message', :locals => {:activity => Message.find(act.org_act_id),:user_activity_id =>act.id} %>
<% when 'ProjectCreateInfo'%>
<% when 'Project'%>
<%= render :partial => 'organizations/project_create', :locals => {:activity => act,:user_activity_id =>act.id} %>
<% end %>
<% end %>

View File

@ -6,7 +6,7 @@
<%= render :partial => 'organizations/org_project_issue', :locals => {:activity => act.forge_act,:user_activity_id =>act.id} %>
<% when 'Message' %>
<%= render :partial => 'organizations/project_message', :locals => {:activity => act.forge_act,:user_activity_id =>act.id} %>
<% when 'ProjectCreateInfo'%>
<% when 'Project'%>
<%= render :partial => 'organizations/project_create', :locals => {:activity => act,:user_activity_id =>act.id} %>
<% end %>
<% end %>

View File

@ -54,7 +54,7 @@
sd_create_editor_from_data(<%= user_activity.id %>, null, "100%", "<%= user_activity.class.to_s %>");
});
</script>
<% if user_activity.act_type == "ProjectCreateInfo" %>
<% if user_activity.act_type == "Project" %>
<%= render :partial => 'project_create', :locals => {:activity => user_activity,:user_activity_id =>user_activity.id} %>
<% else %>
<% act= user_activity.act %>
@ -94,7 +94,7 @@
<%# end %>
<% when 'Message' %>
<%= render :partial => 'project_message', :locals => {:activity => act,:user_activity_id =>user_activity.id,:is_course=>0,:is_board=>0} %>
<% when 'ProjectCreateInfo'%>
<% when 'Project'%>
<%# cache (act) do %>
<%= render :partial => 'project_create', :locals => {:activity => act,:user_activity_id =>user_activity.id} %>
<%# end %>

View File

@ -11,7 +11,12 @@
<%= link_to homework_common.course.name, course_path(homework_common.course_id), :class => "newsBlue ml15"%>
</div>
<span class="homepagePostTitle hidden fl m_w505">
<%= link_to homework_common.name,student_work_index_path(:homework => homework_common.id),:class => "postGrey"%>
<% if is_in_course == 1%>
<% index = get_hw_index(homework_common, is_teacher) %>
<%= link_to "<span class='fontBlue2'>作业#{index+1}</span>".html_safe+homework_common.name,student_work_index_path(:homework => homework_common.id),:class => "postGrey"%>
<% else %>
<%= link_to homework_common.name,student_work_index_path(:homework => homework_common.id),:class => "postGrey"%>
<% end %>
</span>
<% if homework_common.homework_detail_manual%>

View File

@ -31,7 +31,7 @@
<% if homework_commons.count == 10%>
<% if is_in_course == 1%>
<!-- 在课程内 -->
<%= link_to "点击展开更多",homework_common_index_path(:course => course_id,:page => page,:is_in_course => is_in_course),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%>
<%#= link_to "点击展开更多",homework_common_index_path(:course => course_id,:page => page,:is_in_course => is_in_course),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%>
<% else%>
<!-- 在个人主页 -->
<%= link_to "点击展开更多",student_homeworks_user_path(User.current.id,:page => page,:is_in_course => is_in_course),:id => "user_show_more_homework",:remote => "true",:class => "loadMore f_grey"%>

View File

@ -240,14 +240,18 @@
<li class="homepageNewsPubType fl">
<%= link_to ma.course_message.user.show_name,
user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<span class="<%= ma.viewed == 0 ? "homepageNewsTypeNotRead fl":"homepageNewsType fl" %>"><%= ma.apply_result == 1 ? '同意' : '拒绝'%>引用作业:</span>
<span class="<%= ma.viewed == 0 ? 'homepageNewsTypeNotRead fl':'homepageNewsType fl' %>"><%= ma.apply_result == 1 ? '同意' : '拒绝'%>引用作业:</span>
</li>
<li class="homepageNewsContent fl"><a href="javascript:void(0);" class="newsGrey">
<% link_str = ma.apply_result == 1 ?
'您申请引用作业"'+HomeworkCommon.find(ma.course_message_id).name+'"的申请已通过'
:
'您申请引用作业"'+HomeworkCommon.find(ma.course_message_id).name+'"的申请被拒绝' %>
<%= link_to link_str, student_work_index_path(:homework => ma.course_message.id), :title => link_str,:class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey "}", :target => '_blank' %>
<% if User.current.member_of_course?(ma.course_message.course) || User.current.admin? || ma.course_message.is_open == 1 %>
<%= link_to link_str, student_work_index_path(:homework => ma.course_message.id), :title => link_str,:class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey "}", :target => '_blank' %>
<% else %>
<span title='<%=link_str %>' style="color:#4b4b4b; cursor: default;" class="<%= ma.viewed == 0 ? 'newsBlack' : 'newsGrey'%>"><%=link_str %></span>
<% end %>
<!--:onmouseover => "message_titile_show($(this),event)",-->
<!--:onmouseout => "message_titile_hide($(this))" %>-->
</a>

View File

@ -0,0 +1,9 @@
class ChangeUserActivitiesData < ActiveRecord::Migration
def up
execute("update user_activities set act_type = 'Project' where act_type = 'ProjectCreateInfo'")
execute("update org_activities set org_act_type = 'Project' where org_act_type = 'ProjectCreateInfo'")
end
def down
end
end

View File

@ -11,7 +11,8 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20160511055221) do
ActiveRecord::Schema.define(:version => 20160519070718) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
t.string "act_type", :null => false

View File

@ -637,6 +637,7 @@ a.replyGrey1:hover {color:#4b4b4b;}
a.newsBlue {color:#269ac9;}
a.newsBlue:hover {color:#297fb8;}
a.newsBlack {color:#4b4b4b; font-size:13px; font-weight:bold}
span.newsBlack {color:#4b4b4b; font-size:13px; font-weight:bold}
a.menuGrey {color:#808080;}
a.menuGrey:hover {color:#fe7d68;}
.navSearchTypeBox {width:368px; height:35px; position:absolute; border:1px solid #e1e1e1; background-color:#ffffff; padding-left:10px; display:none; color:#3e3e3e; font-size:14px;}