This commit is contained in:
caishi 2019-10-29 11:21:41 +08:00
commit 644300ccaa
17 changed files with 201 additions and 114 deletions

View File

@ -40,6 +40,7 @@ gem 'ruby-ole'
gem 'rails_kindeditor',path:'lib/rails_kindeditor'
gem 'binding_of_caller'
gem 'chinese_pinyin'
gem 'jbuilder'
# gem 'sunspot_rails', '~> 1.3.3'
# gem 'sunspot_solr'
# gem 'sunspot'

View File

@ -2,10 +2,12 @@ class PrivateMessagesController < ApplicationController
before_filter :require_login
before_filter :set_user
before_filter :set_message, except: [:index]
before_filter :set_type_and_count
def index
#用户更新私信为全部已读
jours = current_user.private_messages
jours = PrivateMessage.without_deleted.where("user_id = ?", @user.id).order("created_at desc")
@limit = 20
@jours_count = jours.count
@jours_all_pages = Paginator.new @jours_count, @limit, params['page'] || 1
@ -19,7 +21,49 @@ class PrivateMessagesController < ApplicationController
end
def create
ActiveRecord::Base.transaction do
begin
user_id = params[:private_message][:receiver_id]
receiver_user = User.find_by_id(user_id)
if receiver_user.present?
content = params[:private_message][:content].strip.truncate(200)
sender_params = {
user_id: current_user.id,
target_id: user_id,
sender_id: current_user.id,
receiver_id: user_id,
content: content,
status: 0,
send_time: Time.now
}
receiver_params = {
user_id: user_id,
target_id: current_user.id,
sender_id: current_user.id,
receiver_id: user_id,
content: content,
status: 0,
send_time: Time.now
}
@sender_message = PrivateMessage.new(sender_params)
@receiver_message = PrivateMessage.new(receiver_params)
@sender_message.save!
@receiver_message.save!
respond_to do |format|
format.js
format.html{
redirect_to user_private_message_path(current_user,@sender_message.id)
}
end
else
redirect_to user_private_messages_path(current_user), notice: "用户不存在"
end
rescue Exception => e
Rails.logger.info("#######___________####{e}")
raise ActiveRecord::Rollback
end
end
end
def show
@ -28,12 +72,18 @@ class PrivateMessagesController < ApplicationController
render :layout=>'base_user_message'
end
def private_messages_detail
@user_message_details = @user.private_messages.where(target_id: params[:target_ids])
@contact_user = User.find_by_id(params[:target_ids])
render :layout=>'base_user_message'
end
def destroy
end
def get_recent_users
@recent_users = @user.recent_contacts.without_deleted.distinct.order("created_at desc").limit(10).includes(:user_extension)
end
def search_users
@ -52,5 +102,9 @@ class PrivateMessagesController < ApplicationController
@jour = JournalsForMessage.find_by_id(params[:id])
end
def set_type_and_count
@unred_all_messages = 0
@user_message_type = "2"
end
end

View File

@ -490,7 +490,7 @@ class UsersController < ApplicationController
# 说明: homework 发布作业message讨论区 news新闻 poll问卷works_reviewers作品评阅works_reply:作品回复,exercise:课程测验
# issue问题journal缺陷状态更新 forum公共贴吧: user_feedback: 用户留言; new_reply:新闻回复comment
def user_messages
@user_message_type = 1
@user_message_type = "1"
@msg_type = params[:type] || "all"
if !User.current.logged?
redirect_to signin_url

View File

@ -6,7 +6,8 @@ class PrivateMessage < ActiveRecord::Base
belongs_to :receiver, class_name: "User"
#status 0表示未读1表示已读2表示已删除
scope :without_deleted, -> { where.not(status: 2) }
scope :without_deleted, -> { where("status != 2") }
scope :only_unread, -> { where(status: 0) }
end

View File

@ -145,6 +145,8 @@ class User < Principal
#####fq
# 新版私信
has_many :private_messages, dependent: :destroy
has_many :recent_contacts, through: :private_messages, source: :target
has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy
has_many :journals_messages, :class_name => 'JournalsForMessage', :foreign_key => "user_id", :dependent => :destroy
# has_many :bids, :foreign_key => 'author_id', :dependent => :destroy
@ -351,6 +353,10 @@ class User < Principal
end
end
def get_user_contact_messages(user_id)
private_messages.where(user_id: user_id).size
end
#判断是否可以点击项目或issue
def user_can_see_project(target)
return false if target.blank?

View File

@ -6,12 +6,13 @@
<div class="ant-modal-content"><div class="ant-modal-header">
<div class="ant-modal-title" id="rcDialogTitle4">写私信</div>
</div>
<%= form_for [@user, PrivateMessage.new] do |m| %>
<div class="ant-modal-body">
<div>
<div class="mb20 pr">
<div class="myw100baifenbi">
<span class="ant-input-affix-wrapper">
<input class="ant-input" placeholder="发送给..." type="text" value="">
<%= m.text_field :receiver_id, class: "ant-input",placeholder: "发送给" %>
<span class="ant-input-suffix">
<img src="/images/search.png">
</span>
@ -26,39 +27,23 @@
<img alt="头像" class="radius fl mr10 myimgw48 myimgh48" src="/images/avatars/User/1?t=1569554901">
<span class="recently_name">实践教学</span>
</p>
<p class="clearfix recently_item">
<img alt="头像" class="radius fl mr10 myimgw48 myimgh48" src="/images/avatars/User/b">
<span class="recently_name">innov</span>
</p>
<p class="clearfix recently_item">
<img alt="头像" class="radius fl mr10 myimgw48 myimgh48" src="/images/avatars/User/15582?t=1566447907">
<span class="recently_name">胡莎莎</span>
</p>
<p class="clearfix recently_item">
<img alt="头像" class="radius fl mr10 myimgw48 myimgh48" src="/images/avatars/User/b">
<span class="recently_name">asdad</span>
</p>
<p class="clearfix recently_item">
<img alt="头像" class="radius fl mr10 myimgw48 myimgh48" src="/images/avatars/User/75650?t=1569488496">
<span class="recently_name">汪维</span>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="writeLetter_Info">
<textarea class="writeLetter_text greyInput" name="content" id="writeLetter_text" maxlength="200"></textarea>
<%= m.text_area :content, class: "writeLetter_text greyInput", id: "writeLetter_text", maxLenght: "200" %>
<span class="longchar">200</span>
</div>
</div>
<p style="height: 25px;"></p>
<p class="clearfix edu-txt-center">
<a class="pop_close task-btn mr30">取消</a>
<a class="task-btn task-btn-orange" id="submit_send_letter">确定</a>
<%= m.submit "确定",class: "task-btn task-btn-orange", data:{"disabled-with": "提交中..."} %>
</p>
</div>
<% end %>
</div>
<div tabindex="0" aria-hidden="true" style="width: 0px; height: 0px; overflow: hidden;">
@ -66,3 +51,4 @@
</div>
</div>
</div>

View File

@ -2,61 +2,61 @@
<div class="flex1">
<p class="clearfix pt30 pb30 t-center font-16 bor-bottom-greyE">
<%= link_to "<i class='iconfont icon-zuojiantou font-14 fl ml25 color-grey-9' data-tip-down='返回到列表'></i>".html_safe,user_private_messages_path(@user),remote: true %>
<%= @jour_messages.first.user.try(:show_name) %>与你的私信
<%= @contact_user.try(:show_name) %>与你的私信
</p>
<% @jour_messages.chunk { |c| format_date(c.created_at).to_date }.each do |day, jour| %>
<%= day %>
<%= jour.notes %>
<% end %>
<div class="letterBox">
<p class="mt30 t-center"><span class="letter-time">2019-10-19</span></p>
<div class="OtherSide clearfix" id="message_content_25148">
<a href="javascript:void(0)"><img alt="头像" class="mr10 radius fl" height="48" width="48" src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1820523987,3798556096&fm=26&gp=0.jpg" /></a>
<% if @user_message_details.size > 0 %>
<% @user_message_details.chunk { |c| format_date(c.created_at).to_date }.each do |day, jour| %>
<div class="letterBox" id="contact-messages-<%= current_user.try(:login) %>" >
<p class="mt30 t-center"><span class="letter-time"><%= day %></span></p>
<% jour.each do |j| %>
<% if j.sender_id == current_user.id %>
<div class="OtherSide clearfix" id="message_content_<%= j.id %>">
<%= link_to image_tag(url_to_avatar(j.sender), class: "r_list_img"), user_path(j.sender), :alt => "用户头像", class: "mr10 radius fl", target: "_blank" %>
<div class="fl pr OtherSide-info">
<span class="trangle"></span>
<div class="sms break_word markdown-body" id="Leftdialogue1">
<p><a href="http://www.baidu.com" title="wwwbaidu">wwwbaidu</a></p>
<ol>
<li>kdajlkd</li>
<li>dskdfjslakfj</li>
</ol>
<%= j.content %>
</div>
<div class="edu-txt-right mt5">
<a href="javascript:void(0)" class="color-grey-c">删除</a>
<%= link_to "删除", user_private_message_path(j.sender, j.id), remote: true, data: {confirm: "确认删除吗?"} %>
</div>
</div>
<span class="fl ml15 color-grey-c lineh-15 mt15">9:53</span>
<span class="fl ml15 color-grey-c lineh-15 mt15"><%= j.created_at.strftime("%H:%M") %></span>
</div>
<div class="ThisSide clearfix" id="message_content_25149">
<a href="javascript:void(0)"><img alt="头像" class="ml10 radius fr" height="48" width="48" src="https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1820523987,3798556096&fm=26&gp=0.jpg" /></a>
<div class="fr pr ThisSide-info">
<% else %>
<div class="ThisSide clearfix" id="message_content_<%= j.id %>">
<%= link_to image_tag(url_to_avatar(j.receiver), class: "r_list_img"), user_path(j.receiver), :alt => "用户头像", class: "mr10 radius fl", target: "_blank" %>
<div class="fl pr ThisSide-info">
<span class="trangle"></span>
<div class="sms break_word markdown-body" id="Leftdialogue1">
<p><a href="http://www.baidu.com" title="wwwbaidu">wwwbaidu</a></p>
<ol>
<li>kdajlkd</li>
<li>dskdfjslakfj</li>
</ol>
<%= j.content %>
</div>
<div class="edu-txt-left mt5">
<a href="javascript:void(0)" class="color-grey-c">删除</a>
<div class="edu-txt-right mt5">
<%= link_to "删除", user_private_message_path(j.receiver, j.id), remote: true, data: {confirm: "确认删除吗?"} %>
</div>
</div>
<span class="fr mr15 color-grey-c lineh-15 mt15">9:53</span>
<span class="fl ml15 color-grey-c lineh-15 mt15"><%= j.created_at.strftime("%H:%M") %></span>
</div>
<% end %>
<% end %>
</div>
<% end %>
<% else %>
<%= render partial: "projects/no_data" %>
<% end %>
<%= form_for [current_user, PrivateMessage.new], remote: true do |f| %>
<%= f.hidden_field :receiver_id,value: @contact_user.id, class: "ant-input",placeholder: "发送给" %>
<div class="repeatBox padding20">
<div>
<textarea></textarea>
<%= f.text_area :content, class: "writeLetter_text greyInput" %>
</div>
<p class="clearfix mt15">
<span class="fl ml5 color-orange f12 mt5">在问题反馈时,请同时发送问题发生页的网址链接,以便我们高效的为您服务</span>
<a href="javascript:void(0)" class="fr task-btn task-btn-orange">回复</a>
<%= f.submit "回复", class: "fr task-btn task-btn-orange", data: {"disabled-with": "回复中..."} %>
</p>
</div>
<% end %>
</div>
<div class="bor-left-greyE" style="width: 290px;">
<p class="pt30 pb30 pl30 edu-txt-left font-16 bor-bottom-greyE">私信列表</p>

View File

@ -0,0 +1,14 @@
<div class="OtherSide clearfix" id="message_content_<%= j.id %>">
<%= link_to image_tag(url_to_avatar(j.target), class: "r_list_img"), user_path(j.target), :alt => "用户头像", class: "mr10 radius fl", target: "_blank" %>
<div class="fl pr OtherSide-info">
<span class="trangle"></span>
<div class="sms break_word markdown-body" id="Leftdialogue1">
<%= j.content %>
</div>
<div class="edu-txt-right mt5">
<%= link_to "删除", user_private_message_path(j.target, j.id), remote: true, data: {confirm: "确认删除吗?"} %>
</div>
</div>
<span class="fl ml15 color-grey-c lineh-15 mt15"><%= j.created_at.strftime("%H:%M") %></span>
</div>

View File

@ -5,21 +5,19 @@
<div>
<% if @jours_count > 0 %>
<% @jours_alls.each do |jour| %>
<div class="private-item clearfix df">
<%= link_to image_tag(url_to_avatar(jour.user), class: "r_list_img"), user_path(jour.user), :alt => "用户头像", class: "fl mr10 private_message_a", target: "_blank" %>
<%= link_to user_private_message_path(current_user,jour.id), remote: true do%>
<div class="private-item clearfix df" onclick="get_message_link('<%= private_messages_detail_user_private_messages_path(current_user, target_ids: jour.target_id) %>')">
<%= link_to image_tag(url_to_avatar(jour.target), class: "r_list_img"), user_path(jour.target), :alt => "用户头像", class: "fl mr10 private_message_a", target: "_blank" %>
<div class="fl flex1">
<p>
<%= jour.user.try(:show_name) %>
<span>与你的私信</span>
<span class="color-grey-c mr20">[<%= (jour.m_reply_count.to_i + 1) %>条]</span>
<span class="color-grey-c">6天前</span>
<span class="mr20"><%= link_to jour.target.try(:show_name), user_path(jour.target) %></span>
<messpan>与你的私信</messpan>
<span class="color-grey-c mr20">[<%= (jour.target.get_user_contact_messages(jour.user_id) + 1) %>条]</span>
<span class="color-grey-c"><%= time_from_now(jour.updated_at) %></span>
</p>
<div class="color-grey-6 markdown-body mt10">
<%= jour.notes.html_safe %>
<%= jour.content.html_safe %>
</div>
</div>
<% end %>
</div>
<% end %>
<ul class="pages" style="width: auto;display: table;margin-left: auto;margin-right: auto; padding-top: 10px">

View File

@ -0,0 +1 @@
$("#contact-messages-<%= current_user.try(:login) %>").append("<%= j render partial: "private_messages/user_contact_content", locals: {j: @sender_message} %>")

View File

@ -0,0 +1,6 @@
json.array @recent_users.each.to_a do |a|
json.user_id a.id
json.user_login a.login
json.user_name a.try(:show_name)
json.image_url url_to_avatar(a)
end

View File

@ -1,3 +1,14 @@
<div id="user-messages-<%= current_user.try(:login) %>">
<%= render partial: "private_messages/user_new_feedbacks" %>
</div>
<script>
function get_message_link(path) {
console.log(path)
$.ajax({
type: 'GET',
url: path,
dataType: "script"
});
}
</script>

View File

@ -0,0 +1,5 @@
<div id="user-messages-<%= current_user.try(:login) %>">
<%= render partial: "private_messages/private_box" %>
</div>

View File

@ -15,14 +15,14 @@
</p>
</div>
<div class="l_InfoNav mb20">
<li class="clearfix active">
<%= link_to "消息", user_message_path(current_user), remote: true, class: "ml30 width100" %>
<li class="clearfix <%= @user_message_type == "1" ? "active" : "" %>">
<%= link_to "消息", user_message_path(current_user), class: "ml30 width100" %>
<span id="unread-message-count-<%= current_user.login %>">
<%= render partial: "users/messages_count" %>
</span>
</li>
<li class="clearfix">
<%= link_to "私信", user_private_messages_path(current_user), class: "ml30 width100", remote: true %>
<li class="clearfix <%= @user_message_type == "2" ? "active" : "" %>">
<%= link_to "私信", user_private_messages_path(current_user), class: "ml30 width100" %>
</li>
</div>

View File

@ -707,7 +707,11 @@ RedmineApp::Application.routes.draw do
#added by young
resources :users do
resources :private_messages
resources :private_messages do
collection do
get "private_messages_detail"
end
end
collection do
match "tag_saveEx" , :via => [:get, :post]
post "user_new_homework"

View File

@ -618,11 +618,11 @@ a.user_editinfo{border-top:1px solid #e5e5e5; height:30px; line-height:30px; tex
.OtherSide, .ThisSide {
margin-top: 30px;
}
a.task-btn-orange {
.task-btn-orange {
background: #4CACFF!important;
color: #fff!important;
}
a.task-btn {
.task-btn {
cursor: pointer;
display: inline-block;
border: none;