This commit is contained in:
Administrator 2013-08-22 16:42:13 +08:00
parent 36e0113f73
commit 83ff8a31c1
15 changed files with 253 additions and 9 deletions

View File

@ -18,7 +18,10 @@
class CommentObserver < ActiveRecord::Observer
def after_create(comment)
if comment.commented.is_a?(News) && Setting.notified_events.include?('news_comment_added')
##by senluo
thread3=Thread.new do
Mailer.news_comment_added(comment).deliver
end
end
end
end

View File

@ -17,6 +17,9 @@
class DocumentObserver < ActiveRecord::Observer
def after_create(document)
##by senluo
thread2=Thread.new do
Mailer.document_added(document).deliver if Setting.notified_events.include?('document_added')
end
end
end

View File

@ -16,7 +16,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class IssueObserver < ActiveRecord::Observer
def after_create(issue)
thread1=Thread.new do
Mailer.issue_add(issue).deliver if Setting.notified_events.include?('issue_added')
end
end
end

View File

@ -23,7 +23,10 @@ class JournalObserver < ActiveRecord::Observer
(Setting.notified_events.include?('issue_status_updated') && journal.new_status.present?) ||
(Setting.notified_events.include?('issue_priority_updated') && journal.new_value_for('priority_id').present?)
)
##by senluo
thread4=Thread.new do
Mailer.issue_edit(journal).deliver
end
end
end
end

View File

@ -294,7 +294,7 @@ class Mailer < ActionMailer::Base
set_language_if_valid(user.language)
@url = url_for(:controller => 'welcome')
mail :to => user.mail,
:subject => 'Redmine test'
:subject => 'forge test'
end
# Overrides default deliver! method to prevent from sending an email

View File

@ -17,6 +17,9 @@
class MessageObserver < ActiveRecord::Observer
def after_create(message)
##by senluo
thread5=Thread.new do
Mailer.message_posted(message).deliver if Setting.notified_events.include?('message_posted')
end
end
end

View File

@ -17,6 +17,9 @@
class NewsObserver < ActiveRecord::Observer
def after_create(news)
##by senluo
thread6=Thread.new do
Mailer.news_added(news).deliver if Setting.notified_events.include?('news_added')
end
end
end

View File

@ -0,0 +1,11 @@
class UserExtension < ActiveRecord::Base
attr_accessible :birthday, :brief_introduction, :fans_num, :finish_project_num, :follow_num, :gender, :good_num, :location, :occupation, :publish_requirement_num, :user_id, :work_experience, :zip_code
belongs_to :user
validate :validate_user
def validate_user
errors.add :user_id, :invalid if user.nil? || !user.active? || User.current != user_id
end
end

View File

@ -0,0 +1,47 @@
# fq
class WatchersOfProjects < ActiveRecord::Base
attr_accessible :project_id, :user_id
belongs_to :project
belongs_to :user
validate :validate_user
validate :validate_project
validates_uniqueness_of :user_id, :scope => :project_id
validates_presence_of :user_id, :project_id
def self.watch(user_id, project_id)
@new_watch = WatchersOfProjects.new
@new_watch.user_id = user_id
@new_watch.project_id = project_id
@new_watch.save
true
end
def self.watcher_count(project)
@project = project
@count = @project.watchers_of_projects.count
@count
end
def self.is_watched(user_id, project_id)
@is_watched = self.where("user_id = ? and project_id = ?", user_id, project_id).to_a.first
if @is_watched.nil?
false
else
true
end
end
def self.watch_cancle(user_id, project_id)
self.delete_all(["user_id = ? and project_id = ?", user_id, project_id])
true
end
def validate_user
errors.add :user_id, :invalid if user.nil? || !user.active?
end
def validate_project
errors.add :project_id, :invalid if project.nil?
end
end

View File

@ -0,0 +1,66 @@
# fq
class WatchersOfUser < ActiveRecord::Base
attr_accessible :user_id, :watcher_id
belongs_to :user
validates_uniqueness_of :watcher_id, :scope => :user_id
validate :validate_user
validate :validate_watcher
validates_presence_of :watcher_id, :user_id
def self.watch_user(watcher_id, user_id)
unless user_id == watcher_id
@watchers_of_user = WatchersOfUser.new
@watchers_of_user.watcher_id = watcher_id
@watchers_of_user.user_id = user_id
@watchers_of_user.save
true
else
false
end
end
def cancel_watching_user
self.class.cancel_watching_user(self.watcher_id, self.user_id)
end
def self.cancel_watching_user(watcher_id, user_id)
self.delete_all(["user_id = ? and watcher_id = ?", user_id, watcher_id])
true
end
def self.find_users(watcher_id)
@user = WatchersOfUser.find_by_sql("select * from users where id in (select user_id from #{WatchersOfUser.table_name} where watcher_id = #{watcher_id})")
@user
# @watch_table_for_user=WatchersOfUser.where(:watcher_id => watcher_id)
# @user = []
# @watch_table_for_user.each do |watch|
# @user.push(watch.user)
# end
# @user
end
def self.find_watchers(user_id)
@watcher = WatchersOfUser.find_by_sql("select * from users where id in (select watcher_id from #{WatchersOfUser.table_name} where user_id = #{user_id})")
@watcher
# user = User.find(user_id)
# @watch_table_for_watcher = user.watchers_of_users
# @watcher = []
# @watch_table_for_watcher.each do |watch|
# user_temp = User.find(watch.watcher_id)
# @watcher.push(user_temp)
# end
# @watcher
end
#验证user是否存在
def validate_user
errors.add :user_id, :invalid if user.nil? || !user.active?
end
#验证watcher是否存在
def validate_watcher
user = User.where("id = ?", watcher_id).to_a.first
errors.add :watcher_id, :invalid if user.nil? || !user.active?
end
end

View File

@ -17,12 +17,18 @@
class WikiContentObserver < ActiveRecord::Observer
def after_create(wiki_content)
##by senluo
thread7=Thread.new do
Mailer.wiki_content_added(wiki_content).deliver if Setting.notified_events.include?('wiki_content_added')
end
end
def after_update(wiki_content)
if wiki_content.text_changed?
##by senluo
thread8=Thread.new do
Mailer.wiki_content_updated(wiki_content).deliver if Setting.notified_events.include?('wiki_content_updated')
end
end
end
end

View File

@ -0,0 +1,41 @@
<div id="tags">
<%= tag('img', {:src => "/images/sidebar/tags.png"}, false, false) %>
<strong><label><%= l(:label_tag) %>:</label></strong>
<!-- 1代表是user类型 2代表是project类型 3代表是issue类型 -->
<!-- 3 代表的是issue 当是issue是 处理方式与前2个对象不同 -->
<% if object_flag == '3' %>
<%= toggle_link (image_tag "/images/sidebar/add.png"), 'put-tag-form-issue', {:focus => 'name-issue'} %>
<div id="tags_show_issue">
<%= render :partial => "layouts/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
</div>
<div id="put-tag-form-issue" style="display: none">
<%= form_for "tag_for_save",:remote=>true,:url=>tag_path,
:update => "tags_show",
:complete => '$("#put-tag-form-issue").hide();' do |f| %>
<%= f.text_field :name ,:id => "name-issue",:size=>"30" %>
<%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%>
<%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%>
<%= f.submit "add"%>
<%= link_to_function l(:button_cancel), '$("#put-tag-form-issue").hide();'%>
<% end %>
</div>
</div>
<% else %>
<%= toggle_link (image_tag "/images/sidebar/add.png"), 'put-tag-form', {:focus => 'name'} %>
<div id="tags_show">
<%= render :partial => "layouts/tag_name",:locals => {:obj => obj,:non_list_all => false ,:object_flag => object_flag} %>
</div>
<div id="put-tag-form" style="display: none">
<%= form_for "tag_for_save",:remote=>true,:url=>tag_path,
:update => "tags_show",
:complete => '$("#put-tag-form").hide();' do |f| %>
<%= f.text_field :name ,:id => "name",:size=>"28"%>
<%= f.text_field :object_id,:value=> obj.id,:style=>"display:none"%>
<%= f.text_field :object_flag,:value=> object_flag,:style=>"display:none"%>
<%= f.submit "add"%>
<%= link_to_function l(:button_cancel), '$("#put-tag-form").hide();'%>
<% end %>
</div>
</div>
<% end %>

View File

@ -0,0 +1,55 @@
<style type="text/css">
.click {
background: green
}
.unclick {
background: blue
}
#tag {
background-color: #dbe4ee;
border-radius: 5px 5px 5px 5px;
color: #3a587d !important;
padding: 0px 4px;
margin: 3px;
display: inline-block;
font-size: 11px;
text-decoration: none;
cursor: pointer;
}
</style>
<!-- 1代表是user类型 2代表是project类型 3代表是issue类型 4代表需求-->
<% @tags = obj.reload.tag_list %>
<% if non_list_all and (@tags.size > 0) %>
<!-- 这里是显示的非主页的tag 所以当tag数量较多时 不必全部显示 用“更多”代替 -->
<% if @tags.size > Setting.show_tags_length.to_i then %>
<% i = 0 %>
<% until i>Setting.show_tags_length.to_i do %>
<div id="tag" class="click unclick">
<%= link_to @tags[i], :controller => "tags",:action => "index",:q => @tags[i],:object_flag => object_flag,:obj_id => obj.id %>
</div>
<% i += 1%>
<% end %>
<%= link_to l(:label_more_tags),:action => "show",:id => obj.id %>
<% else %>
<% @tags.each do |tag| %>
<div id="tag" class="click unclick">
<%= link_to tag,:controller => "tags",:action => "index",:q=>tag,:object_flag => object_flag,:obj_id => obj.id
%>
</div>
<% end %>
<% end %>
<% else %>
<!-- 用来显示三大对象的主页中的tag 故是全部显示 -->
<% if @tags.size > 0 %>
<% @tags.each do |tag| %>
<div id="tag" class="click unclick">
<%= link_to tag,:controller => "tags",:action => "index",:q=>tag ,:object_flag => object_flag,:obj_id => obj.id %>
</div>
<% end %>
<% end %>
<% end %>

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB