words jourformessage design ing...

This commit is contained in:
yanxd 2013-12-25 09:17:15 +08:00
parent c8bdbdce66
commit ff317e48e9
5 changed files with 73 additions and 133 deletions

View File

@ -40,40 +40,11 @@ class WordsController < ApplicationController
end
def create_reply
if params[:new_form][:user_message].size>0
unless params[:user_id].nil?
if params[:reference_content]
message = params[:new_form][:user_message] + "\n" + params[:reference_content]
else
message = params[:new_form][:user_message]
end
refer_user_id = params[:new_form][:reference_user_id].to_i
# @user.add_jour(User.current, message, params[:object_id])
@user.add_reply(params[:object_id], @user.current, message)
unless refer_user_id == 0 || refer_user_id == User.current.id
User.find(refer_user_id).add_jour(User.current, message, refer_user_id)
end
@user.count_new_jour
# if a_message.size > 5
# @message = a_message[-5, 5]
# else
# @message = a_message
# end
# @message_count = a_message.count
end
end
@jours = @user.journals_for_messages.reverse
@limit = 10
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
find_user
@params = params
respond_to do |format|
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
format.html {render 'test/index'}
format.js
#format.api { render_api_ok }
end
end

View File

@ -1,13 +1,31 @@
# fq
# 数据库字段中带有m前缀和is_readed是二次开发添加之前的字段基本复用
# 注意reply_id 是提到人的id不是留言id, Base中叫做ator
class JournalsForMessage < ActiveRecord::Base
attr_accessible :jour_id, :jour_type, :notes, :reply_id, :status, :user_id
attr_accessor :indice
validates :notes, presence: true
include Redmine::SafeAttributes
safe_attributes "jour_type", # 留言所属类型
"jour_id", # 留言所属类型的id
"notes", # 留言内容
"reply_id", # 留言被回复留言者的用户id(用户a回复了用户b这是b的id用以查询谁给b留言了)
"status", # 留言是否被查看(弃用)
"user_id", # 留言者的id
"m_parent_id", # 留言信息的父留言id
"is_readed", # 留言是否已读
"m_reply_count", # 留言的回复数量
"m_reply_id" # 回复某留言的留言id(a留言回复了b留言这是b留言的id)
acts_as_tree :foreign_key => 'm_parent_id', :counter_cache => :m_reply_count, :order => "#{JournalsForMessage.table_name}.created_on ASC"
belongs_to :jour, :polymorphic => true
belongs_to :user
belongs_to :ator, :class_name => "User", :foreign_key => 'reply_id'
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :reply_for_journals, :dependent => :destroy
validates :notes, presence: true
after_create :act_as_activity #huang
after_create :reset_counters!
after_destroy :reset_counters!
def self.delete_message(message_id)
self.delete_all "id = #{message_id}"
@ -30,4 +48,12 @@ class JournalsForMessage < ActiveRecord::Base
end
end
end
def reset_counters!
self.class.reset_counters!(id)
end
def self.reset_counters! journals_for_messages_id
jfm_id = journals_for_messages_id.to_i
update_all("m_reply_count = (SELECT COUNT(*) FROM #{JournalsForMssages.table_name} WHERE m_parent_id = #{jfm_id} )", ["id = ?", jfm_id])
end
end

View File

@ -6,7 +6,7 @@ class Memo < ActiveRecord::Base
validates_presence_of :author_id, :forum_id, :subject
validates :content, presence: true
validates_length_of :subject, maximum: 50
validates_length_of :content, maximum: 3072
validates_length_of :content#, maximum: 3072
validate :cannot_reply_to_locked_topic, :on => :create
acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC"

View File

@ -1,3 +1,3 @@
<h3>test</h3>
<%= debug @params %>

View File

@ -13,14 +13,6 @@
ActiveRecord::Schema.define(:version => 20131224021723) do
create_table "a_user_watchers", :force => true do |t|
t.string "name"
t.text "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "member_id"
end
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
t.string "act_type", :null => false
@ -302,9 +294,9 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
add_index "issue_categories", ["project_id"], :name => "issue_categories_project_id"
create_table "issue_relations", :force => true do |t|
t.integer "issue_from_id", :null => false
t.integer "issue_to_id", :null => false
t.string "relation_type", :null => false
t.integer "issue_from_id", :null => false
t.integer "issue_to_id", :null => false
t.string "relation_type", :default => "", :null => false
t.integer "delay"
end
@ -472,22 +464,6 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
add_index "messages", ["last_reply_id"], :name => "index_messages_on_last_reply_id"
add_index "messages", ["parent_id"], :name => "messages_parent_id"
create_table "messages_for_bids", :force => true do |t|
t.string "message"
t.integer "user_id"
t.integer "bid_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "messages_for_users", :force => true do |t|
t.integer "messager_id"
t.integer "user_id"
t.string "message"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "news", :force => true do |t|
t.integer "project_id"
t.string "title", :limit => 60, :default => "", :null => false
@ -517,23 +493,6 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
t.string "salt", :null => false
end
create_table "permissions", :force => true do |t|
t.string "controller", :limit => 30, :default => "", :null => false
t.string "action", :limit => 30, :default => "", :null => false
t.string "description", :limit => 60, :default => "", :null => false
t.boolean "is_public", :default => false, :null => false
t.integer "sort", :default => 0, :null => false
t.boolean "mail_option", :default => false, :null => false
t.boolean "mail_enabled", :default => false, :null => false
end
create_table "permissions_roles", :id => false, :force => true do |t|
t.integer "permission_id", :default => 0, :null => false
t.integer "role_id", :default => 0, :null => false
end
add_index "permissions_roles", ["role_id"], :name => "permissions_roles_role_id"
create_table "praise_tread_caches", :force => true do |t|
t.integer "object_id", :null => false
t.string "object_type"
@ -564,22 +523,11 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
t.integer "watchers_count"
t.integer "project_id"
t.integer "project_type"
t.integer "gitlab_group_id", :limit => 8
t.float "grade", :default => 0.0
t.integer "course_ac_para", :default => 0
t.float "grade", :default => 0.0
t.integer "course_ac_para", :default => 0
end
add_index "project_statuses", ["changesets_count"], :name => "index_project_statuses_on_changesets_count"
add_index "project_statuses", ["watchers_count"], :name => "index_project_statuses_on_watchers_count"
create_table "project_tags", :force => true do |t|
t.integer "project_id"
t.integer "tag_id"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
end
add_index "project_statuses", ["grade"], :name => "index_project_statuses_on_grade"
create_table "projects", :force => true do |t|
t.string "name", :default => "", :null => false
@ -624,28 +572,18 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
add_index "queries", ["project_id"], :name => "index_queries_on_project_id"
add_index "queries", ["user_id"], :name => "index_queries_on_user_id"
create_table "reply_for_journals", :force => true do |t|
t.integer "jour_id"
t.integer "user_id"
t.text "notes"
t.integer "status"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "repositories", :force => true do |t|
t.integer "project_id", :default => 0, :null => false
t.string "url", :default => "", :null => false
t.string "login", :limit => 60, :default => ""
t.string "password", :default => ""
t.string "root_url", :default => ""
t.integer "project_id", :default => 0, :null => false
t.string "url", :default => "", :null => false
t.string "login", :limit => 60, :default => ""
t.string "password", :default => ""
t.string "root_url", :default => ""
t.string "type"
t.string "path_encoding", :limit => 64
t.string "log_encoding", :limit => 64
t.string "path_encoding", :limit => 64
t.string "log_encoding", :limit => 64
t.text "extra_info"
t.string "identifier"
t.boolean "is_default", :default => false
t.string "git_project_id"
t.boolean "is_default", :default => false
end
add_index "repositories", ["project_id"], :name => "index_repositories_on_project_id"
@ -659,6 +597,26 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
t.string "issues_visibility", :limit => 30, :default => "default", :null => false
end
create_table "seems_rateable_cached_ratings", :force => true do |t|
t.integer "cacheable_id", :limit => 8
t.string "cacheable_type"
t.float "avg", :null => false
t.integer "cnt", :null => false
t.string "dimension"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "seems_rateable_rates", :force => true do |t|
t.integer "rater_id", :limit => 8
t.integer "rateable_id"
t.string "rateable_type"
t.float "stars", :null => false
t.string "dimension"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "settings", :force => true do |t|
t.string "name", :default => "", :null => false
t.text "value"
@ -669,9 +627,9 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
create_table "shares", :force => true do |t|
t.date "created_on"
t.string "title"
t.string "share_type"
t.string "url"
t.string "title"
t.integer "share_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "project_id"
@ -679,12 +637,6 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
t.string "description"
end
create_table "students", :force => true do |t|
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "students_for_courses", :force => true do |t|
t.integer "student_id"
t.integer "course_id"
@ -743,7 +695,7 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
create_table "tokens", :force => true do |t|
t.integer "user_id", :default => 0, :null => false
t.string "action", :limit => 30, :default => "", :null => false
t.string "value", :limit => 40
t.string "value", :limit => 40, :default => "", :null => false
t.datetime "created_on", :null => false
end
@ -769,13 +721,12 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
t.integer "zip_code"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "identity"
t.string "technical_title"
t.integer "identity"
t.string "student_id"
t.string "teacher_realname"
t.string "student_realname"
t.string "location_city"
t.string "git_token"
end
create_table "user_grades", :force => true do |t|
@ -812,14 +763,6 @@ ActiveRecord::Schema.define(:version => 20131224021723) do
add_index "user_statuses", ["grade"], :name => "index_user_statuses_on_grade"
add_index "user_statuses", ["watchers_count"], :name => "index_user_statuses_on_watchers_count"
create_table "user_tags", :force => true do |t|
t.integer "user_id"
t.integer "tag_id"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "login", :default => "", :null => false
t.string "hashed_password", :limit => 40, :default => "", :null => false