Merge branch 'dev_hjq' of http://repository.trustie.net/xianbo/trustie2 into dev_hjq

This commit is contained in:
huang 2015-08-13 18:34:29 +08:00
commit 510613f9a4
13 changed files with 212 additions and 11 deletions

View File

@ -112,7 +112,19 @@ class IssuesController < ApplicationController
end
def show
# 当前用户查看指派给他的缺陷消息,则设置消息为已读
query = @issue.forge_messages
if User.current.id == @issue.assigned_to_id
query.update_all(:viewed => true)
end
# 缺陷状态更新
query_journals = @issue.journals
if User.current.id == @issue.author_id
query_journals.each do |query_journal|
query_journal.forge_messages.update_all(:viewed => true)
end
end
#
@journals = @issue.journals.includes(:user, :details).reorder("#{Journal.table_name}.id ASC").all
@journals.each_with_index {|j,i| j.indice = i+1}
@journals.reject!(&:private_notes?) unless User.current.allowed_to?(:view_private_notes, @issue.project)

View File

@ -0,0 +1,20 @@
class ForgeMessage < ActiveRecord::Base
# 公共表中活动类型,命名规则:TYPE_OF_{类名}_ACT
TYPE_OF_ISSUE_ACT = "Issue"
TYPE_OF_MESSAGE_ACT = "Message"
TYPE_OF_ATTACHMENT_ACT = "Attachment"
TYPE_OF_DOCUMENT_ACT = "Document"
TYPE_OF_JOURNAL_ACT = "Journal"
TYPE_OF_WIKI_ACT = "Wiki"
TYPE_OF_NEWS_ACT = "News"
attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed
belongs_to :forge_message ,:polymorphic => true
belongs_to :project
belongs_to :user
validates :user_id,presence: true
validates :project_id,presence: true
validates :forge_message_id,presence: true
validates :forge_message_type, presence: true
end

View File

@ -49,6 +49,8 @@ class Issue < ActiveRecord::Base
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
# end
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
# ForgeMessage虚拟关联(多态)
has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy
acts_as_nested_set :scope => 'root_id', :dependent => :destroy
@ -80,7 +82,7 @@ class Issue < ActiveRecord::Base
attr_reader :current_journal
# fq
after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity
after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message
after_update :be_user_score
after_destroy :down_user_score
# after_create :be_user_score
@ -138,6 +140,16 @@ class Issue < ActiveRecord::Base
:project_id => self.project_id)
end
# end
# 发布缺陷forge_messages中添加记录
def act_as_forge_message
# 指派给自己的缺陷不提示消息
unless self.author_id == self.assigned_to_id
self.forge_messages << ForgeMessage.new(:user_id => self.assigned_to_id,
:project_id => self.project_id,
:viewed => false)
end
end
# Returns a SQL conditions string used to find all issues visible by the specified user

View File

@ -29,6 +29,8 @@ class Journal < ActiveRecord::Base
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
# 被ForgeActivity虚拟关联
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
# 被ForgeMessage虚拟关联
has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy
# end
attr_accessor :indice
@ -48,7 +50,7 @@ class Journal < ActiveRecord::Base
before_create :split_private_notes
# fq
after_save :act_as_activity,:be_user_score,:act_as_forge_activity
after_save :act_as_activity,:be_user_score,:act_as_forge_activity, :act_as_forge_message
# end
#after_destroy :down_user_score
#before_save :be_user_score
@ -163,10 +165,17 @@ class Journal < ActiveRecord::Base
# Description 公共表中需要保存一份该记录
def act_as_forge_activity
self.forge_acts << ForgeActivity.new(:user_id => self.user_id,
:project_id => self.issue.project.id)
:project_id => self.issue.project.id)
end
# 缺陷状态更改,消息提醒
def act_as_forge_message
self.forge_messages << ForgeMessage.new(:user_id => self.issue.author_id,
:project_id => self.issue.project_id,
:viewed => false)
end
# 更新用户分数 -by zjc
def be_user_score
#新建了缺陷留言且留言不为空,不为空白

View File

@ -91,6 +91,8 @@ class Project < ActiveRecord::Base
has_many :tags, :through => :project_tags, :class_name => 'Tag'
has_many :project_tags, :class_name => 'ProjectTags'
# 关联虚拟表
has_many :forge_messages
belongs_to :organization

View File

@ -109,7 +109,6 @@ class User < Principal
has_many :contests, :foreign_key => 'author_id', :dependent => :destroy
has_many :softapplications, :foreign_key => 'user_id', :dependent => :destroy
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1"
has_many :journal_replies, :dependent => :destroy
has_many :activities, :dependent => :destroy
has_many :students_for_courses
@ -128,8 +127,14 @@ class User < Principal
has_many :messages, :foreign_key => 'author_id'
has_one :user_score, :dependent => :destroy
has_many :documents # 项目中关联的文档再次与人关联
# 关联虚拟表
has_many :forge_messages
# end
# 虚拟转换
has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1"
has_many :issue_assigns, :class_name => 'ForgeMessage', :conditions => 'viewed=0 and forge_message_type="Issue"'
has_many :status_updates, :class_name => 'ForgeMessage', :conditions => 'viewed=0 and forge_message_type="Journal"'
# 邮件邀请状态
# has_many :invite_lists
# end
@ -235,6 +240,24 @@ class User < Principal
# ======================================================================
# 查询用户未读过的记录
# 用户留言记录
def count_new_jour
count = self.new_jours.count
# count = self.journals_for_messages(:conditions => ["status=? and is_readed = ? " ,1, 0]).count
end
# 查询指派给我的缺陷记录
def count_new_issue_assign_to
self.issue_assigns
end
# 查询指派给我的缺陷记录
def issue_status_update
self.status_updates
end
# end
def extensions
self.user_extensions ||= UserExtensions.new
end
@ -258,7 +281,7 @@ class User < Principal
###添加留言 fq
def add_jour(user, notes, reference_user_id = 0, options = {})
if options.count == 0
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true)
self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true, :is_readed => false)
else
jfm = self.journals_for_messages.build(options)
jfm.save
@ -292,11 +315,6 @@ class User < Principal
end
## end
# 查询用户未读过的记录
def count_new_jour
count = self.journals_for_messages.where("status=?", 1).count
end
#added by nie
def count_new_journal_reply
count = self.journal_reply.count

View File

@ -37,6 +37,7 @@
{:controller=> 'users', :action => 'user_newfeedback', id: User.current.id, host: Setting.host_user},
{:class => 'my-message'} if User.current.logged?%>
</li>
</ul>
</div>
<% end -%>

View File

@ -53,6 +53,50 @@
</li>
</ul>
</li>
<!--消息提醒-->
<li id="current_message_li">
<%= link_to "#{l(:label_forge_message)}<span class='pic_triangle'></span>".html_safe %>
<ul id="message_sub_menu" style="right: 0px;display: none;left: 10px;">
<% if @show_course == 1 %>
<% user_course = get_user_course User.current%>
<% unless user_course.empty? %>
<li id="my_courses_message_li">
<%=link_to l(:label_course_message), {:controller => 'users', :action => 'user_courses', id: User.current.id},target:"_blank", :class => "parent" %>
<ul id="my_courses_message_ul">
<% user_course.reverse.each do |course| %>
<li title="<%=course.name%>">
<%= link_to course.name, {:controller => 'courses',:action => 'show',:id => course.id},target:"_blank" %>
</li>
<% end %>
</ul>
</li>
<% end %>
<% end %>
<% unless User.current.projects.empty? %>
<li id="my_projects_message_li">
<%= "#{l(:label_project_message)}"+"("+User.current.count_new_issue_assign_to.count.to_s+")" %>
<ul id="my_projects_message_ul" >
<% User.current.count_new_issue_assign_to.reverse.each do |issue_assign| %>
<li title="<%= issue_assign.forge_message %>">
<%= link_to issue_assign.forge_message, {:controller => 'issues', :action => 'show',id: issue_assign.forge_message_id, host: Setting.host_name }, target:"_blank" %>
</li>
<% end %>
<% User.current.issue_status_update.reverse.each do |issue_update| %>
<li title="<%= issue_update.forge_message %>">
<%= link_to issue_update.forge_message.issue, {:controller => 'issues', :action => 'show',id: issue_update.forge_message_id, host: Setting.host_name }, target:"_blank" %>
</li>
<% end %>
</ul>
</li>
<% end %>
<li>
<%=link_to "...", {:controller => 'my', :action=> 'account', host: Setting.host_user}%>
</li>
</ul>
</li>
<% end -%>
<%= header_render_menu :account_menu -%>
</ul>

View File

@ -67,6 +67,13 @@ zh:
label_project_mail_upload: 上传了资源
label_invite: 邀请
# 项目消息通知
label_forge_message: 消息
label_issue_message: 问题
label_course_message: 课程消息
label_project_message: 项目消息
label_issue_tracking: 问题跟踪
label_release_issue: 发布问题

View File

@ -0,0 +1,13 @@
class CreateForgeMessages < ActiveRecord::Migration
def change
create_table :forge_messages do |t|
t.integer :user_id
t.integer :project_id
t.integer :forge_message_id
t.string :forge_message_type
t.integer :viewed
t.timestamps
end
end
end

View File

@ -46,6 +46,54 @@ $(document).ready(function () {
addCourseSlipMenu();
});
//消息提醒
function MessageAddSlipMenu () {
var loggedas = $('#current_message_li a:first');
var sub_menu = $('#message_sub_menu');
loggedas.mouseenter(function() {
sub_menu.show();
$('#my_projects_message_ul').hide();
$('#my_courses_message_ul').hide();
});
sub_menu.mouseleave(function() {
sub_menu.hide();
$('#my_projects_message_ul').hide();
$('#my_courses_message_ul').hide();
});
}
function MessageAddProjectSlipMenu () {
var loggedas = $('#my_projects_message_li');
var project_sub_menu = $('#my_projects_message_ul');
var course_sub_menu = $('#my_courses_message_ul');
loggedas.mouseenter(function() {
course_sub_menu.hide();
project_sub_menu.show();
});
loggedas.mouseleave(function() {
project_sub_menu.hide();
course_sub_menu.hide();
});
}
function MessageAddCourseSlipMenu () {
var loggedas = $('#my_courses_message_li');
var project_sub_menu = $('#my_projects_message_ul');
var course_sub_menu = $('#my_courses_message_ul');
loggedas.mouseenter(function() {
project_sub_menu.hide();
course_sub_menu.show();
});
loggedas.mouseleave(function() {
course_sub_menu.hide();
project_sub_menu.hide();
});
}
$(document).ready(function () {
MessageAddSlipMenu();
MessageAddProjectSlipMenu ();
MessageAddCourseSlipMenu();
});
//将右侧的最小高度设置成左侧高度,美化界面
$(document).ready(function () {
$("#RSide").css("min-height",$("#LSide").height()-30);

View File

@ -0,0 +1,10 @@
FactoryGirl.define do
factory :forge_message do
user_id 1
project_id 1
forge_message_id 1
forge_message_type "MyString"
viewed 1
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe ForgeMessage, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end