diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index e974f26b4..9853b4dc1 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -103,6 +103,9 @@ class AttachmentsController < ApplicationController
direct_download_history
end
else
+ # 记录用户行为
+ record_user_actions(params[:id])
+ # 直接下载历史版本
direct_download_history
end
end
@@ -113,6 +116,14 @@ class AttachmentsController < ApplicationController
redirect_to "http://" + (Setting.host_name.to_s) +"/file_not_found.html"
end
+ def record_user_actions id
+ if params[:action] == "download_history"
+ UserActions.create(:action_id => id, :action_type => "AttachmentHistory", :user_id => User.current.id) unless id.nil?
+ elsif params[:action] == "download"
+ UserActions.create(:action_id => id, :action_type => "Attachment", :user_id => User.current.id) unless id.nil?
+ end
+ end
+
def download
# modify by nwb
# 下载添加权限设置
@@ -135,6 +146,8 @@ class AttachmentsController < ApplicationController
direct_download
end
else
+ # 记录用户行为
+ record_user_actions(params[:id])
direct_download
end
end
diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb
index b6ac99f11..7ae1b85f8 100644
--- a/app/controllers/files_controller.rb
+++ b/app/controllers/files_controller.rb
@@ -207,8 +207,7 @@ class FilesController < ApplicationController
sort = "created_on DESC"
end
if keywords != "%%"
- resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%").
- reorder(sort)
+ resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' AND filename LIKE :like ", like: "%#{keywords}%").reorder(sort)
else
resultSet = Attachment.where("attachments.container_type = 'Course' And attachments.container_id = '#{course.id}' "). reorder(sort)
end
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 33b6e8643..034595e5d 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -2533,6 +2533,8 @@ class UsersController < ApplicationController
render_403
return
end
+ @resource_id = params[:project_id].nil? ? (params[:course_id].nil? ? params[:subfield_file_id] : params[:course_id]) : params[:project_id]
+ @resource_type = params[:project_id].nil? ? (params[:course_id].nil? ? "SubfieldFile" : "Course") : "Project"
@user = User.find(params[:id])
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
@score = @b_sort == "desc" ? "asc" : "desc"
@@ -2561,6 +2563,8 @@ class UsersController < ApplicationController
end
def import_resources_search
+ @resource_id = params[:mul_id]
+ @resource_type = params[:mul_type]
@order, @b_sort = params[:order] || "created_on", params[:sort] || "asc"
@score = @b_sort == "desc" ? "asc" : "desc"
@user = User.current
@@ -2571,6 +2575,7 @@ class UsersController < ApplicationController
render_403
return
end
+ @resource_id = params[:mul_id]
if(params[:type].blank? || params[:type] == "1") # 我的资源
# 修正:我的资源库的话,那么应该是我上传的所有资源加上,我加入的课程、项目、组织的所有资源
user_course_ids = User.current.courses.map { |c| c.id}
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index d98de27f6..37c7deb4c 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -865,7 +865,7 @@ module CoursesHelper
# 学生按作业总分排序,取前8个
def hero_homework_score(course, score_sort_by)
sql_select = "SELECT members.*,(
- SELECT SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty))
+ SELECT SUM(IF(student_works.final_score is null,null,IF(student_works.final_score = 0, 0, student_works.final_score - student_works.absence_penalty - student_works.late_penalty)))
FROM student_works,homework_commons
WHERE student_works.homework_common_id = homework_commons.id
AND homework_commons.course_id = #{course.id}
diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb
index bdd34d80d..44b919121 100644
--- a/app/helpers/users_helper.rb
+++ b/app/helpers/users_helper.rb
@@ -62,7 +62,7 @@ module UsersHelper
when 'Course'
result = current_time_and_term_resource content
when 'Project'
- result = content.name + "(" + content.id.to_s + ")"
+ result = content.name
when 'Issue'
result = content.subject
when 'Message'
diff --git a/app/models/course_activity.rb b/app/models/course_activity.rb
index a02eb750c..96ec6e355 100644
--- a/app/models/course_activity.rb
+++ b/app/models/course_activity.rb
@@ -66,8 +66,8 @@ class CourseActivity < ActiveRecord::Base
# 发布新课导语
# 导语要放置在课程创建信息之后
- # 导语
def add_course_lead
+ # 避免空数据迁移报错问题
if self.course_act_type == "Course" and Message.where("id=12440").any?
lead_message = Message.find(12440)
name = lead_message.subject
@@ -75,7 +75,7 @@ class CourseActivity < ActiveRecord::Base
# message的status状态为0为正常,为1表示创建课程时发送的message
# author_id 默认为课程使者创建
message = Message.create(:subject => name, :content => content, :board_id => self.course.boards.first.id, :author_id => 1 , :sticky => true, :status => true )
- # 更新的目的是为了排序,因为该条动态的时间可能与课程创建的动态创建时间一直
+ # 更新的目的是为了排序,因为该条动态的时间可能与课程创建的动态创建时间一致
message.course_acts.first.update_attribute(:updated_at, message.course_acts.first.updated_at + 1) if message.course_acts.first
end
end
diff --git a/app/models/user_actions.rb b/app/models/user_actions.rb
new file mode 100644
index 000000000..de2388911
--- /dev/null
+++ b/app/models/user_actions.rb
@@ -0,0 +1,4 @@
+class UserActions < ActiveRecord::Base
+ attr_accessible :action_id, :action_type, :user_id
+ has_many :users
+end
diff --git a/app/views/files/_course_file.html.erb b/app/views/files/_course_file.html.erb
index b548092cf..2cf43f896 100644
--- a/app/views/files/_course_file.html.erb
+++ b/app/views/files/_course_file.html.erb
@@ -108,23 +108,15 @@
共有 <%= @all_attachments.count%> 个资源
-
- <% if @order == "asc" %>
- 按 <%= link_to "时间",params.merge(:sort=>"created_on:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> /
- <%= link_to "下载次数",params.merge(:sort=>"downloads:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %> /
- <%= link_to "引用次数",params.merge(:sort=>"quotes:desc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"quotes"} %> 排序
- <% else %>
- 按 <%= link_to "时间",params.merge(:sort=>"created_on:asc"),:class => "f_b c_grey" ,:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> /
- <%= link_to "下载次数",params.merge(:sort=>"downloads:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %> /
- <%= link_to "引用次数",params.merge(:sort=>"quotes:asc"),:class => "f_b c_grey",:remote => @is_remote %><%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"quotes"} %> 排序
- <% end %>
+
+ <%= render :partial => 'course_file_filter_order', :locals => {:remote => @is_remote, :sort => @sort, :order => @order} %>
- <%= render :partial => 'course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} %>
+ <%= render :partial => 'course_list',:locals => {course: @course,all_attachments: @all_attachments,sort:@sort,order:@order,curse_attachments:@obj_attachments} %>
<%# html_title(l(:label_attachment_plural)) -%>
\ No newline at end of file
diff --git a/app/views/files/_course_file_filter_order.html.erb b/app/views/files/_course_file_filter_order.html.erb
new file mode 100644
index 000000000..a740d9481
--- /dev/null
+++ b/app/views/files/_course_file_filter_order.html.erb
@@ -0,0 +1,15 @@
+<% if @order == "asc" %>
+ 按 <%= link_to "时间", search_tag_attachment_course_files_path(@course, :sort => "created_on:desc", :tag_name => @tag_name.nil? ? " " : @tag_name, :q => @q.nil? ? " " : @q), :class => "f_b c_grey", :remote => true %>
+ <%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> /
+ <%= link_to "下载次数", search_tag_attachment_course_files_path(@course, :sort => "downloads:desc", :tag_name => @tag_name.nil? ? " " : @tag_name, :q => @q.nil? ? " " : @q), :class => "f_b c_grey",:remote => true %>
+ <%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %> /
+ <%= link_to "引用次数", search_tag_attachment_course_files_path(@course, :sort => "quotes:desc", :tag_name => @tag_name.nil? ? " " : @tag_name, :q => @q.nil? ? " " : @q), :class => "f_b c_grey", :remote => true %>
+ <%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"quotes"} %> 排序
+<% else %>
+ 按 <%= link_to "时间", search_tag_attachment_course_files_path(@course, :sort => "created_on:asc", :tag_name => @tag_name.nil? ? ' ' : @tag_name, :q => @q.nil? ? ' ' : @q), :class => "f_b c_grey" , :remote => true %>
+ <%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %> /
+ <%= link_to "下载次数", search_tag_attachment_course_files_path(@course, :sort => "downloads:asc", :tag_name => @tag_name.nil? ? ' ' : @tag_name, :q => @q.nil? ? ' ' : @q), :class => "f_b c_grey", :remote => true %>
+ <%= render partial: 'files/arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %> /
+ <%= link_to "引用次数", search_tag_attachment_course_files_path(@course, :sort =>"quotes:asc", :tag_name => @tag_name.nil? ? ' ' : @tag_name, :q => @q.nil? ? ' ' : @q),:class => "f_b c_grey", :remote => true %>
+ <%= render partial:'files/arrow_show',locals: { sort: @sort,order:@order,current:"quotes"} %> 排序
+<% end %>
\ No newline at end of file
diff --git a/app/views/files/search_tag_attachment.js.erb b/app/views/files/search_tag_attachment.js.erb
index 31df68b6a..3003d8b98 100644
--- a/app/views/files/search_tag_attachment.js.erb
+++ b/app/views/files/search_tag_attachment.js.erb
@@ -1,5 +1,6 @@
<% if @course %>
$("#course_list").html("<%= escape_javascript(render :partial => 'course_list',:locals => {course: @course,all_attachments: @result,sort:@sort,order:@order,curse_attachments:@searched_attach})%>");
+ $("#course_filter_order").html("<%= escape_javascript(render :partial => 'course_file_filter_order', :locals => {course: @course,all_attachments: @result,sort:@sort,order:@order,curse_attachments:@searched_attach, tag_name: @tag_name, q: @q})%>");
$("#attachment_count").html("<%= @result.count%>")
<% else %>
$("#course_list").html("<%= escape_javascript(render :partial => 'project_list',:locals => {project:@project, all_attachments:@result_search_project, sort:@sort, order:@order, project_attachments:@searched_attach}) %>");
diff --git a/app/views/users/_course_message.html.erb b/app/views/users/_course_message.html.erb
index 7477eaabd..aed741ce5 100644
--- a/app/views/users/_course_message.html.erb
+++ b/app/views/users/_course_message.html.erb
@@ -41,14 +41,6 @@
<% content = activity.parent.content%>
<% end %>
<%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>content} %>
- <% if activity.status == 1 %>
- <%= activity.created_on.year %>
- 年
- <%= activity.created_on.month %>
- 月
- <%= activity.created_on.day %>
- 日
- <% end %>
diff --git a/app/views/users/_import_resource_info.html.erb b/app/views/users/_import_resource_info.html.erb
index 4ea56ad9f..0a9d92b5c 100644
--- a/app/views/users/_import_resource_info.html.erb
+++ b/app/views/users/_import_resource_info.html.erb
@@ -27,7 +27,7 @@
我的资源
<% end %>
- <%=render :partial=>'users/user_import_resource_search', :locals => {:type => @type, :search => ''} %>
+ <%=render :partial=>'users/user_import_resource_search', :locals => {:type => @type, :search => '', :mul_id => @resource_id, :mul_type => @resource_type} %>
diff --git a/app/views/users/_user_import_resource_list.html.erb b/app/views/users/_user_import_resource_list.html.erb
index af4f951e0..f48e6c8fb 100644
--- a/app/views/users/_user_import_resource_list.html.erb
+++ b/app/views/users/_user_import_resource_list.html.erb
@@ -1,6 +1,6 @@
<%= form_tag( url_for({:controller => 'users', :action => 'import_into_container',
- :mul_id => project_id.nil? ? (course_id.nil? ? subfield_file_id : course_id) : project_id,
- :mul_type => project_id.nil? ? (course_id.nil? ? "SubfieldFile" : "Course") : "Project"}),
+ :mul_id => @resource_id,
+ :mul_type => @resource_type}),
:method => 'post', :id => 'resource_import_container_form') do %>
<% @attachments.each do |attach| %>
diff --git a/app/views/users/_user_import_resource_search.html.erb b/app/views/users/_user_import_resource_search.html.erb
index b048675dd..fc86ec26e 100644
--- a/app/views/users/_user_import_resource_search.html.erb
+++ b/app/views/users/_user_import_resource_search.html.erb
@@ -9,7 +9,7 @@
}
lastSearchCondition = $(e.target).val().trim();
$.ajax({
- url: '<%= url_for(:controller => 'users', :action => 'import_resources_search', :id => User.current.id) %>'+'?name='+ e.target.value+'&type=<%=type %>',
+ url: '<%= url_for({:controller => 'users', :action => 'import_resources_search', :id => User.current.id}) %>'+'?name='+ e.target.value+'&type=<%=type %>'+'&mul_id=<%=@resource_id %>'+'&mul_type=<%=@resource_type %>',
type:'get'
});
}
diff --git a/app/views/users/import_resources.js.erb b/app/views/users/import_resources.js.erb
index 6244e8e64..b07f534e7 100644
--- a/app/views/users/import_resources.js.erb
+++ b/app/views/users/import_resources.js.erb
@@ -1,9 +1,9 @@
<% if params[:project_id] %>
-$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :project_id => params[:project_id]} ) %>');
+$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :project_id => params[:project_id], :mul_id => @resource_id, :mul_type => @resource_type}) %>');
<% elsif params[:course_id] %>
-$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :course_id => params[:course_id]} ) %>');
+$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :course_id => params[:course_id], :mul_id => @resource_id, :mul_type => @resource_type}) %>');
<% elsif params[:subfield_file_id] %>
-$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :subfield_file_id => params[:subfield_file_id]} ) %>');
+$('#ajax-modal').html('<%= escape_javascript( render :partial => 'users/import_resource_info', :locals => {:user => User.current, :type => @type, :subfield_file_id => params[:subfield_file_id], :mul_id => @resource_id, :mul_type => @resource_type}) %>');
<% end %>
showModal('ajax-modal', '615px');
$('#ajax-modal').siblings().remove();
diff --git a/app/views/users/import_resources_search.js.erb b/app/views/users/import_resources_search.js.erb
index ea527ab6b..928235f4c 100644
--- a/app/views/users/import_resources_search.js.erb
+++ b/app/views/users/import_resources_search.js.erb
@@ -1,3 +1,5 @@
$("#import_resource_info_list").html('<%= escape_javascript( render :partial => 'user_import_resource_list',
- :locals => {:user => @user, :type => @type, :project_id => params[:project_id], :subfield_file_id => params[:subfield_file_id], :course_id => params[:course_id]} ) %>');
+ :locals => {:user => @user, :type => @type,
+ :mul_id => @resource_id,
+ :mul_type => @resource_type}) %>');
$("#pages").html('<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>');
diff --git a/db/migrate/20160317090350_create_user_actions.rb b/db/migrate/20160317090350_create_user_actions.rb
new file mode 100644
index 000000000..d7893fcad
--- /dev/null
+++ b/db/migrate/20160317090350_create_user_actions.rb
@@ -0,0 +1,11 @@
+class CreateUserActions < ActiveRecord::Migration
+ def change
+ create_table :user_actions do |t|
+ t.integer :user_id
+ t.string :action_type
+ t.integer :action_id
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 33bf42b5b..2c55aad61 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20160316055201) do
+ActiveRecord::Schema.define(:version => 20160317090350) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@@ -1782,6 +1782,14 @@ ActiveRecord::Schema.define(:version => 20160316055201) do
t.integer "fields_bits", :default => 0
end
+ create_table "user_actions", :force => true do |t|
+ t.integer "user_id"
+ t.string "action_type"
+ t.integer "action_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "user_activities", :force => true do |t|
t.string "act_type"
t.integer "act_id"
diff --git a/public/javascripts/course.js b/public/javascripts/course.js
index 544c2bc33..b5255f786 100644
--- a/public/javascripts/course.js
+++ b/public/javascripts/course.js
@@ -247,11 +247,11 @@ function regexTopicDescription()
function submit_topic()
{
- if(regexTopicSubject() && regexTopicDescription())
- {
+// if(regexTopicSubject() && regexTopicDescription())
+// {
message_content_editor.sync();
$("#message-form").submit();
- }
+// }
}
function reset_topic(){
diff --git a/public/javascripts/organization.js b/public/javascripts/organization.js
index bb7d6c5bb..7c1f3578c 100644
--- a/public/javascripts/organization.js
+++ b/public/javascripts/organization.js
@@ -3,11 +3,11 @@
*/
function submit_topic()
{
- if(regexTopicSubject() && regexTopicDescription())
- {
+// if(regexTopicSubject() && regexTopicDescription())
+// {
message_content_editor.sync();
$("#message-form").submit();
- }
+// }
}
function regexTopicSubject() {
diff --git a/public/javascripts/project.js b/public/javascripts/project.js
index c08c81054..75f6bb84e 100644
--- a/public/javascripts/project.js
+++ b/public/javascripts/project.js
@@ -618,11 +618,11 @@ function regexTopicDescription()
}
function submit_topic_project()
{
- if(regexTopicSubject() && regexTopicDescription())
- {
+// if(regexTopicSubject() && regexTopicDescription())
+// {
message_content_editor.sync();
$("#message-form-project").submit();
- }
+// }
}
function reset_topic(){
diff --git a/spec/factories/user_actions.rb b/spec/factories/user_actions.rb
new file mode 100644
index 000000000..38dbed67e
--- /dev/null
+++ b/spec/factories/user_actions.rb
@@ -0,0 +1,8 @@
+FactoryGirl.define do
+ factory :user_action, :class => 'UserActions' do
+ user_id 1
+action_type "MyString"
+action_id 1
+ end
+
+end
diff --git a/spec/models/user_actions_spec.rb b/spec/models/user_actions_spec.rb
new file mode 100644
index 000000000..afe799fb9
--- /dev/null
+++ b/spec/models/user_actions_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe UserActions, :type => :model do
+ pending "add some examples to (or delete) #{__FILE__}"
+end