diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb
index 16d516f82..f462a64e7 100644
--- a/app/controllers/my_controller.rb
+++ b/app/controllers/my_controller.rb
@@ -118,7 +118,7 @@ class MyController < ApplicationController
@user.safe_attributes = params[:user]
@user.pref.attributes = params[:pref]
@user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
- @user.login = params[:login]
+ #@user.login = params[:login]
unless @user.user_extensions.nil?
if @user.user_extensions.identity == 2
@user.firstname = params[:enterprise_name]
diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb
index 815a44839..1508fc871 100644
--- a/app/controllers/welcome_controller.rb
+++ b/app/controllers/welcome_controller.rb
@@ -161,7 +161,7 @@ class WelcomeController < ApplicationController
query: @name,
type:"most_fields",
operator: "or",
- fields: ['login', 'firstname','lastname','name','description^0.5','filename']
+ fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5']
}
},
highlight: {
@@ -173,10 +173,12 @@ class WelcomeController < ApplicationController
lastname: {},
name:{},
description:{},
- filename:{}
+ filename:{},
+ subject:{},
+ content:{}
}
}
- },[User,Course,Attachment,Project] ).page(params[:page] || 1).per(20).results
+ },[User,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results
when 'user'
@users = User.search(@name).page(params[:page] || 1).per(20)
when 'project'
@@ -185,6 +187,8 @@ class WelcomeController < ApplicationController
@courses = Course.search(@name).page(params[:page] || 1).per(20).results
when 'attachment'
@attachments = Attachment.search(@name).page(params[:page] || 1).per(20).results
+ when 'memo'
+ @memos = Memo.search(@name).page(params[:page] || 1).per(20).results
else
@alls = Elasticsearch::Model.search({
query: {
@@ -192,7 +196,7 @@ class WelcomeController < ApplicationController
query: @name,
type:"most_fields",
operator: "or",
- fields: ['login', 'firstname','lastname','name','description^0.5','filename']
+ fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5']
}
},
highlight: {
@@ -204,10 +208,12 @@ class WelcomeController < ApplicationController
lastname: {},
name:{},
description:{},
- filename:{}
+ filename:{},
+ subject:{},
+ content:{}
}
}
- },[User,Course,Attachment,Project] ).page(params[:page] || 1).per(20).results
+ },[User,Course,Attachment,Project,Memo] ).page(params[:page] || 1).per(20).results
end
@@ -216,13 +222,14 @@ class WelcomeController < ApplicationController
@course_count = Course.search(@name).results.total
@attach_count = Attachment.search(@name).results.total
@project_count = Project.search(@name).results.total
+ @memo_count = Memo.search(@name).results.total
@total_count = Elasticsearch::Model.search({
query: {
multi_match: {
query: @name,
type:"most_fields",
operator: "or",
- fields: ['login', 'firstname','lastname','name','description^0.5','filename']
+ fields: ['login', 'firstname','lastname','name','description^0.5','filename','subject','content^0.5']
}
},
highlight: {
@@ -234,10 +241,12 @@ class WelcomeController < ApplicationController
lastname: {},
name:{},
description:{},
- filename:{}
+ filename:{},
+ subject:{},
+ content:{}
}
}
- },[User,Course,Attachment,Project] ).results.total
+ },[User,Course,Attachment,Project,Memo] ).results.total
# search_type = params[:search_type].to_sym unless search_condition.blank?
# search_by = params[:search_by]
#
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 999cefdaa..8d4a1a524 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -46,7 +46,7 @@ class Attachment < ActiveRecord::Base
settings index: { number_of_shards: 5 } do
mappings dynamic: 'false' do
indexes :filename, analyzer: 'smartcn',index_options: 'offsets'
- indexes :downloads, analyzer: 'smartcn',index_options: 'offsets'
+ indexes :downloads, index:"not_analyzed",index_options: 'offsets'
end
end
diff --git a/app/models/course.rb b/app/models/course.rb
index 1c1bedb3b..d7ca1387c 100644
--- a/app/models/course.rb
+++ b/app/models/course.rb
@@ -16,7 +16,7 @@ class Course < ActiveRecord::Base
mappings dynamic: 'false' do
indexes :name, analyzer: 'smartcn',index_options: 'offsets'
indexes :description, analyzer: 'smartcn',index_options: 'offsets'
- indexes :updated_at, analyzer: 'smartcn',index_options: 'offsets',type:"date"
+ indexes :updated_at, index:"not_analyzed",type:"date"
end
end
diff --git a/app/models/memo.rb b/app/models/memo.rb
index 7c4fbdcf1..2ead1cbb6 100644
--- a/app/models/memo.rb
+++ b/app/models/memo.rb
@@ -1,7 +1,9 @@
+require 'elasticsearch/model'
class Memo < ActiveRecord::Base
include Redmine::SafeAttributes
include UserScoreHelper
include ApplicationHelper
+ include Elasticsearch::Model
belongs_to :forum
has_many_kindeditor_assets :assets, :dependent => :destroy
belongs_to :author, :class_name => "User", :foreign_key => 'author_id'
@@ -12,6 +14,18 @@ class Memo < ActiveRecord::Base
validates_length_of :content, maximum: 30000
validate :cannot_reply_to_locked_topic, :on => :create
+
+ #elasticsearch kaminari init
+ Kaminari::Hooks.init
+ Elasticsearch::Model::Response::Response.__send__ :include, Elasticsearch::Model::Response::Pagination::Kaminari
+ settings index: { number_of_shards: 5 } do
+ mappings dynamic: 'false' do
+ indexes :subject, analyzer: 'smartcn',index_options: 'offsets'
+ indexes :content, analyzer: 'smartcn',index_options: 'offsets'
+ indexes :updated_at,index:"not_analyzed" ,type:'date'
+ end
+ end
+
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC"
acts_as_attachable
has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj
@@ -47,9 +61,9 @@ class Memo < ActiveRecord::Base
"parent_id",
"replies_count"
- after_create :add_author_as_watcher, :reset_counters!, :send_mail, :send_message
- # after_update :update_memos_forum
- after_destroy :reset_counters!,:delete_kindeditor_assets#,:down_user_score -- 公共区发帖暂不计入得分
+ after_create :add_author_as_watcher, :reset_counters!, :send_mail, :send_message,:create_memo_ealasticsearch_index
+ after_update :update_memo_ealasticsearch_index
+ after_destroy :reset_counters!,:delete_kindeditor_assets,:delete_memo_ealasticsearch_index#,:down_user_score -- 公共区发帖暂不计入得分,
# after_create :send_notification
# after_save :plusParentAndForum
# after_destroy :minusParentAndForum
@@ -57,6 +71,36 @@ class Memo < ActiveRecord::Base
# scope :visible, lambda { |*args|
# includes(:forum => ).where()
# }
+ scope :indexable,lambda {
+ where('parent_id is null')
+ }
+
+ def self.search(query)
+ __elasticsearch__.search(
+ {
+ query: {
+ multi_match: {
+ query: query,
+ type:"most_fields",
+ operator: "or",
+ fields: ['subject','content^0.5']
+ }
+ },
+ sort: {
+ _score:{order: "desc" },
+ updated_at:{order: "desc" }
+ },
+ highlight: {
+ pre_tags: [''],
+ post_tags: [''],
+ fields: {
+ subject: {},
+ content: {}
+ }
+ }
+ }
+ )
+ end
def send_mail
Mailer.run.forum_message_added(self) if Setting.notified_events.include?('forum_message_added')
@@ -203,6 +247,22 @@ class Memo < ActiveRecord::Base
# Author lizanle
# Description 从硬盘上删除资源
def delete_kindeditor_assets
- delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MEMO
+ delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MEMO
+ end
+
+ def create_memo_ealasticsearch_index
+ if self.parent_id.nil?
+ self.__elasticsearch__.index_document
+ end
+ end
+ def update_memo_ealasticsearch_index
+ if self.parent_id.nil?
+ self.__elasticsearch__.update_document
+ end
+ end
+ def delete_memo_ealasticsearch_index
+ if self.parent_id.nil?
+ self.__elasticsearch__.delete_document
+ end
end
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 44b9a7912..cd4036810 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -39,7 +39,7 @@ class Project < ActiveRecord::Base
mappings dynamic: 'false' do
indexes :name, analyzer: 'smartcn',index_options: 'offsets'
indexes :description, analyzer: 'smartcn',index_options: 'offsets'
- indexes :updated_on, analyzer: 'smartcn',index_options: 'offsets', type:'date'
+ indexes :updated_on, index:"not_analyzed", type:'date'
end
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 1c5d1b0c8..8e2c096de 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -35,7 +35,7 @@ class User < Principal
indexes :login, analyzer: 'smartcn',index_options: 'offsets'
indexes :firstname, analyzer: 'smartcn',index_options: 'offsets'
indexes :lastname, analyzer: 'smartcn',index_options: 'offsets'
- indexes :last_login_on, analyzer: 'smartcn',index_options: 'offsets',type: 'date'
+ indexes :last_login_on, index:"not_analyzed",type: 'date'
end
end
diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb
index be178607f..fa9171496 100644
--- a/app/views/my/account.html.erb
+++ b/app/views/my/account.html.erb
@@ -30,7 +30,7 @@
- - <%= f.text_field :login,:no_label=>true, :required => true, :nh_required=>"1", :name => "login",:class=>"w210"%>
+ - <%= f.text_field :login,:no_label=>true, :required => true, :nh_required=>"1",:disabled=>'disabled', :name => "login",:class=>"w210"%>
- <%= f.text_field :mail,:no_label=>true, :required => true,:nh_required=>"1",:class=>"w210"%>
-
diff --git a/app/views/news/_project_form.html.erb b/app/views/news/_project_form.html.erb
index 269420bfe..81012e749 100644
--- a/app/views/news/_project_form.html.erb
+++ b/app/views/news/_project_form.html.erb
@@ -1,18 +1,19 @@
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg' %>
-
-
-
+
+
+
-
<% if is_new %>
<%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %>
- <%= f.kindeditor :description,:width=>'91%',:editor_id=>'project_news_description_editor' %>
+ <%= f.kindeditor :description,:width=>'90%',:editor_id=>'project_news_description_editor' %>
<% else %>
- <%= f.kindeditor :description,:width=>'91%', :editor_id=>'project_news_description_editor', :owner_id => @news.id, :owner_type => OwnerTypeHelper::NEWS %>
+ <%= f.kindeditor :description,:width=>'90%', :editor_id=>'project_news_description_editor', :owner_id => @news.id, :owner_type => OwnerTypeHelper::NEWS %>
<% end %>
diff --git a/app/views/users/_user_message_course.html.erb b/app/views/users/_user_message_course.html.erb
index 640f98b1f..1ca8f5e1a 100644
--- a/app/views/users/_user_message_course.html.erb
+++ b/app/views/users/_user_message_course.html.erb
@@ -45,12 +45,12 @@
-
<% if !User.current.allowed_to?(:as_teacher, ma.course_message.course) && cur_user_works_for_homework(ma.course_message).nil? %>
- <%= link_to "作业题目:" + ma.course_message.name, new_student_work_path(:homework => ma.course_message.id),
+ <%= link_to "作业标题:" + ma.course_message.name, new_student_work_path(:homework => ma.course_message.id),
:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
:onmouseover =>"message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))" %>
<% else %>
- <%= link_to "作业题目:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id),
+ <%= link_to "作业标题:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id),
:class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
:onmouseover => "message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))" %>
@@ -103,7 +103,7 @@
user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher", :title => "#{ma.course_message.user.lastname + ma.course_message.user.firstname}老师" %>
">发布的作业:
-
- <%= link_to "作业题目:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id),
+ <%= link_to "作业标题:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id),
:class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
:onmouseover => "message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))" %>
@@ -142,7 +142,7 @@
">启动了作业匿评:
-
- <%= link_to "作业题目:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
+ <%= link_to "作业标题:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
:onmouseover => "message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))" %>
@@ -173,19 +173,25 @@
<%=link_to ma.course_message.user.lastname + ma.course_message.user.firstname + "老师",
user_path(ma.course_message.user), :class => "newsBlue homepageNewsPublisher" %>">关闭了作业匿评:
-
- <%= link_to "作业题目:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
+ <%= link_to "作业标题:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
:onmouseover =>"message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))"%>
<%= User.current.lastname + User.current.firstname %><%= User.current.allowed_to?(:as_teacher,ma.course_message.course) ? '老师':'同学'%>您好!
- <%= User.current.eql?(ma.course_message.user)?"您":(ma.course_message.user.lastname + ma.course_message.user.firstname+"老师") %>关闭了匿评,作业详情如下:
+ 该作业已经被关闭了匿评。作业信息如下:
- 课程名称:<%= ma.course_message.course.name %>(<%= ma.course_message.course.time.to_s + '年'+ ma.course_message.course.term %>)
- 作业标题:<%= ma.course_message.name %>
+
+
注:缺省情况下,系统将在作业提交截止日期后14天自动关闭匿评。
+
+ <% if User.current.allowed_to?(:as_teacher,ma.course_message.course)%>
+
祝您的教学活动高效、顺利、愉快!
+ <% end %>
- <%= time_tag(ma.created_at).html_safe %>
@@ -202,7 +208,7 @@
">启动作业匿评失败
- <%= link_to "作业题目:" + ma.course_message.name, student_work_index_path(:homework => ma.course_message.id), :class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
+ <%= link_to truncate(ma.course_message.name,:length=>25)+'(失败原因:提交作品的人数低于2人)', student_work_index_path(:homework => ma.course_message.id), :class => "#{ma.viewed == 0 ? "c_red" : "newsGrey "}",
:onmouseover => "message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))" %>
@@ -213,7 +219,6 @@
- - 失败原因:提交作品的人数低于2人
- 课程名称:<%= ma.course_message.course.name %>(<%= ma.course_message.course.time.to_s + '年' + ma.course_message.course.term %>)
- 作业标题:<%= ma.course_message.name %>
- 提交截止:<%= ma.course_message.end_time%> 23:59
@@ -385,7 +390,7 @@
">发布的作业:
-
- <%= link_to "作业题目:" + ma.course_message.homework_common.name, student_work_index_path(:homework => ma.course_message.homework_common_id),
+ <%= link_to "作业标题:" + ma.course_message.homework_common.name, student_work_index_path(:homework => ma.course_message.homework_common_id),
:class => "#{ma.viewed==0 ? "newsBlack" : "newsGrey"}",
:onmouseover => "message_titile_show($(this),event)",
:onmouseout => "message_titile_hide($(this))" %>
diff --git a/app/views/users/search_user_course.js.erb b/app/views/users/search_user_course.js.erb
index 60ddd6d9c..2a0c98cad 100644
--- a/app/views/users/search_user_course.js.erb
+++ b/app/views/users/search_user_course.js.erb
@@ -15,4 +15,6 @@ $('#ajax-modal').siblings().remove();
$('#ajax-modal').before("");
$('#ajax-modal').parent().css("top","").css("left","");
$('#ajax-modal').parent().addClass("popbox").addClass("resourceUploadPopup");
-$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
\ No newline at end of file
+$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
+var val = $("#search_course_input").val();
+$("#search_course_input").val("").focus().val(val);
diff --git a/app/views/users/search_user_project.js.erb b/app/views/users/search_user_project.js.erb
index 26a0f265c..f38d9edc8 100644
--- a/app/views/users/search_user_project.js.erb
+++ b/app/views/users/search_user_project.js.erb
@@ -12,3 +12,6 @@ $('#ajax-modal').before("') {
res_name = line.children().eq(1).children().attr('title');
res_link = line.children().eq(1).html();
- line.children().eq(1).html('<%= form_tag(url_for(:controller => 'users',:action => 'rename_resource',:method => 'post',:remote=>true,:id=>@user.id),:id=>"res_name_form" ) do%>' +
+ line.children().eq(1).html(
' '+
- '<% end %>');
+ '"/> ');
$("#res_name").focus();
$("html,body").animate({scrollTop:$("#res_name").offset().top},1000)
}else{
@@ -382,6 +381,8 @@
return str.slice(0, i + 1);
}
+
+
//恢复编辑状态到链接状态
//如果当前是编辑状态,任何的不在输入框里的单击右键事件都需要将编辑状态变回链接状态
//如果是编辑状态,且做了修改,那么久要进行修改,并且将修改值经过处理替换到页面显示
@@ -395,22 +396,22 @@
if( name && name != res_name.trim()){
if(confirm('确定修改为 '+name)){
- $.post(
- '<%=rename_resource_user_path(@user) %>',
- "res_name="+$('#res_name').val()+"&res_id="+$("#res_id").val(),
- function (data){
- if(data != 'fail'){//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变
+ $.ajax({
+ url: '<%=rename_resource_user_path(@user) %>'+ "?res_name="+$('#res_name').val() + "&res_id=" + $("#res_id").val(),
+ type:'get',
+ success:function (data)
+ {
+ if (data != 'fail') {//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变
last_line.children().eq(1).html(res_link);
- last_line.children().eq(1).children().attr('title',name);
- last_line.children().eq(1).children().attr('href',data);
- last_line.children().eq(1).children().html(name.length > 17? name.substring(0,17)+'...' : name);
- }else{
+ last_line.children().eq(1).children().attr('title', name);
+ last_line.children().eq(1).children().attr('href', data);
+ last_line.children().eq(1).children().html(name.length > 17 ? name.substring(0, 17) + '...' : name);
+ } else {
last_line.children().eq(1).html(res_link);
res_link = null; //如果修改失败,恢复之后将res_link置空
}
- },
- 'text'
- );
+ }
+ } );
}else{
last_line.children().eq(1).html(res_link);
res_link = null; //如果没有做修改,恢复之后将res_link置空
diff --git a/app/views/welcome/_search_all_results.html.erb b/app/views/welcome/_search_all_results.html.erb
index 014c6b487..34ef9a8eb 100644
--- a/app/views/welcome/_search_all_results.html.erb
+++ b/app/views/welcome/_search_all_results.html.erb
@@ -72,6 +72,22 @@
+ <% when 'memo'%>
+
<%end %>
<% end %>
+
+
+
diff --git a/app/views/welcome/search.js.erb b/app/views/welcome/search.js.erb
index c53c5d219..5cb446896 100644
--- a/app/views/welcome/search.js.erb
+++ b/app/views/welcome/search.js.erb
@@ -9,5 +9,7 @@ $("#searchContent_3").html('<%= escape_javascript(render :partial => 'search_cou
$("#searchContent_5").html('<%= escape_javascript(render :partial => 'search_project_results',:locals => {:projects=>@projects})%>');
<% when 'attachment'%>
$("#searchContent_4").html('<%= escape_javascript(render :partial => 'search_attachment_results',:locals => {:attachments=>@attachments})%>');
+<% when 'memo'%>
+$("#searchContent_6").html('<%= escape_javascript(render :partial => 'search_memo_results',:locals => {:memos=>@memos})%>');
<%else%>
<%end %>
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index db63fe3ee..0ef113d18 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -489,7 +489,7 @@ RedmineApp::Application.routes.draw do
post "add_exist_file_to_course"
post "add_exist_file_to_project"
get 'resource_preview'
- post 'rename_resource'
+ get 'rename_resource'
get 'search_user_project'
get 'user_resource_type'
get 'user_ref_resource_search'
diff --git a/lib/tasks/elasticsearch_batch_op.rake b/lib/tasks/elasticsearch_batch_op.rake
index fb2c638bc..91c2ddff9 100644
--- a/lib/tasks/elasticsearch_batch_op.rake
+++ b/lib/tasks/elasticsearch_batch_op.rake
@@ -28,4 +28,11 @@ namespace :importer do
ENV['BATCH']='1000'
Rake::Task["elasticsearch:import:model"].invoke
end
+ task :importmemo do
+ ENV['CLASS']='Memo'
+ ENV['SCOPE']='indexable'
+ ENV['FORCE']='y'
+ ENV['BATCH']='1000'
+ Rake::Task["elasticsearch:import:model"].invoke
+ end
end
\ No newline at end of file