为竞赛通知添加评论

This commit is contained in:
wanglinchun 2014-06-05 10:28:36 +08:00
parent 2e11d76652
commit d06488c10d
18 changed files with 189 additions and 224 deletions

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the notificationcomments controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -18,8 +18,7 @@
class CommentsController < ApplicationController
default_search_scope :news
model_object News
before_filter :find_model_object
before_filter :find_model_object_contest
before_filter :find_model_object
before_filter :find_project_from_association
before_filter :authorize
@ -51,12 +50,6 @@ class CommentsController < ApplicationController
@comment = nil
@news
end
def find_model_object_contest
super
@contestnotifications = @object
@comment = nil
@contestnotifications
end
end

View File

@ -5,7 +5,7 @@ class ContestnotificationsController < ApplicationController
default_search_scope :contestnotifications
# model_object Contestnotifications
# before_filter :find_model_object_contest, :except => [:new, :create, :index]
# before_filter :find_contest_from_association, :except => [:new, :create, :index]
before_filter :find_contest_from_association, :except => [:new, :create, :index]
# before_filter :find_contest_by_contest_id, :only => [:new, :create]
before_filter :find_contest
before_filter :find_author
@ -71,8 +71,8 @@ class ContestnotificationsController < ApplicationController
# format.html # show.html.erb
# format.json { render json: @contestnotification }
# end
@comments = @contestnotifications.comments
@comments.reverse! if User.current.wants_comments_in_reverse_order?
@notificationcomments = @contestnotifications.notificationcomments
@notificationcomments.reverse! if User.current.wants_notificationcomments_in_reverse_order?
render :layout => 'base_newcontest'
end

View File

@ -0,0 +1,35 @@
class NotificationcommentsController < ApplicationController
default_search_scope :contestnotifications
model_object Contestnotifications
before_filter :find_model_object
before_filter :find_contest_from_association
before_filter :authorize
def create
raise Unauthorized unless @contestnotifications.commentable?
@notificaioncomment = Notificaioncomment.new
@notificaioncomment.safe_attributes = params[:notificaioncomment]
@notificaioncomment.author = User.current
if @contestnotifications.notificaioncomments << @notificaioncomment
flash[:notice] = l(:label_comment_added)
end
redirect_to contest_contestnotification_path(@contestnotifications)
end
def destroy
@contestnotifications.notificaioncomments.find(params[:notificaioncomment_id]).destroy
redirect_to contest_contestnotification_path(@contestnotifications)
end
private
def find_model_object
super
@contestnotifications = @object
@notificaioncomment = nil
@contestnotifications
end
end

View File

@ -0,0 +1,2 @@
module NotificationcommentsHelper
end

View File

@ -0,0 +1,11 @@
class Notificationcomments < ActiveRecord::Base
attr_accessible :author_id, :notificationcommented_id, :notificationcommented_type, :notificationcomments
include Redmine::SafeAttributes
belongs_to :notificationcommented, :polymorphic => true, :counter_cache => true
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
validates_presence_of :notificationcommented, :author, :comments
safe_attributes 'notificationcomments'
end

View File

@ -111,6 +111,7 @@ class User < Principal
has_many :news, :foreign_key => 'author_id'
has_many :contestnotification, :foreign_key => 'author_id'
has_many :comments, :foreign_key => 'author_id'
has_many :notificationcomments, :foreign_key => 'author_id'
has_many :wiki_contents, :foreign_key => 'author_id'
has_many :journals
has_many :messages, :foreign_key => 'author_id'
@ -460,6 +461,9 @@ class User < Principal
self.pref[:comments_sorting] == 'desc'
end
def wants_notificationcomments_in_reverse_order?
self.pref[:notificationcomments_sorting] == 'desc'
end
# Return user's RSS key (a 40 chars long string), used to access feeds
def rss_key
if rss_token.nil?
@ -804,6 +808,7 @@ class User < Principal
substitute = User.anonymous
Attachment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
Comment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
Notificationcomment.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
Issue.update_all ['author_id = ?', substitute.id], ['author_id = ?', id]
Issue.update_all 'assigned_to_id = NULL', ['assigned_to_id = ?', id]
Journal.update_all ['user_id = ?', substitute.id], ['user_id = ?', id]

View File

@ -54,6 +54,9 @@ class UserPreference < ActiveRecord::Base
def comments_sorting; self[:comments_sorting] end
def comments_sorting=(order); self[:comments_sorting]=order end
def notificationcomments_sorting; self[:notificationcomments_sorting] end
def notificationcomments_sorting=(order); self[:notificationcomments_sorting]=order end
def warn_on_leaving_unsaved; self[:warn_on_leaving_unsaved] || '1'; end
def warn_on_leaving_unsaved=(value); self[:warn_on_leaving_unsaved]=value; end
end

View File

@ -71,8 +71,8 @@ RedmineApp::Application.routes.draw do
end
#resources :contestnotifications, :only => [:index, :show, :edit, :update, :destroy]
match '/contestnotifications/:id/comments', :to => 'comments#create', :via => :post
match '/contestnotifications/:id/comments/:comment_id', :to => 'comments#destroy', :via => :delete
match '/contestnotifications/:id/notificationcomments', :to => 'notificationcomments#create', :via => :post
match '/contestnotifications/:id/notificationcomments/:notificationcomment_id', :to => 'notificationcomments#destroy', :via => :delete
match '/contestnotifications/preview', :controller => 'previews', :action => 'contestnotifications', :as => 'preview_contestnotifications', :via => [:get, :post, :put]
## new added by linchun #新竞赛相关
resources :contests, only: [:index] do

View File

@ -4,7 +4,7 @@ class CreateRelativeMemos < ActiveRecord::Migration
t.integer :osp_id, :null => true
t.integer :parent_id, null: true
t.string :subject, null: false
t.mediumtext :content, null: false
t.text :content, null: false
t.integer :author_id
t.integer :replies_count, default: 0
t.integer :last_reply_id

View File

@ -6,7 +6,7 @@ class CreateContestnotifications < ActiveRecord::Migration
t.string :summary
t.string :description
t.integer :author_id
t.integer :comments_count
t.integer :notificationcomments_count
t.timestamps
end

View File

@ -0,0 +1,12 @@
class CreateNotificationcomments < ActiveRecord::Migration
def change
create_table :notificationcomments do |t|
t.string :notificationcommented_type
t.integer :notificationcommented_id
t.integer :author_id
t.text :notificationcomments
t.timestamps
end
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140530010015) do
ActiveRecord::Schema.define(:version => 20140605003915) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -50,12 +50,18 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.datetime "created_on"
t.string "description"
t.string "disk_directory"
t.integer "attachtype", :default => 1
end
add_index "attachments", ["author_id"], :name => "index_attachments_on_author_id"
add_index "attachments", ["container_id", "container_type"], :name => "index_attachments_on_container_id_and_container_type"
add_index "attachments", ["created_on"], :name => "index_attachments_on_created_on"
create_table "attachmentstypes", :force => true do |t|
t.integer "typeId", :null => false
t.string "typeName", :limit => 50
end
create_table "auth_sources", :force => true do |t|
t.string "type", :limit => 30, :default => "", :null => false
t.string "name", :limit => 60, :default => "", :null => false
@ -76,20 +82,6 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
add_index "auth_sources", ["id", "type"], :name => "index_auth_sources_on_id_and_type"
create_table "bak_mentioned", :primary_key => "Id", :force => true do |t|
t.string "this_real_name", :limit => 1000
t.integer "is_mentioned_in"
t.string "context", :limit => 2000
end
add_index "bak_mentioned", ["this_real_name", "is_mentioned_in"], :name => "name_mention", :length => {"this_real_name"=>900, "is_mentioned_in"=>nil}
add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name"
add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name_2"
add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name_3", :length => {"this_real_name"=>900}
add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name_4"
add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name_5"
add_index "bak_mentioned", ["this_real_name"], :name => "this_real_name_6"
create_table "biding_projects", :force => true do |t|
t.integer "project_id"
t.integer "bid_id"
@ -129,9 +121,12 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
add_index "boards", ["last_message_id"], :name => "index_boards_on_last_message_id"
add_index "boards", ["project_id"], :name => "boards_project_id"
create_table "categories", :primary_key => "Id", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "proj_categories"
create_table "bug_to_osps", :force => true do |t|
t.integer "osp_id"
t.integer "relative_memo_id"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "changes", :force => true do |t|
@ -216,9 +211,9 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.string "summary"
t.string "description"
t.integer "author_id"
t.integer "comments_count"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "notificationcomments_count"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "contests", :force => true do |t|
@ -309,14 +304,6 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
add_index "documents", ["created_on"], :name => "index_documents_on_created_on"
add_index "documents", ["project_id"], :name => "documents_project_id"
create_table "eco_projects", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.integer "eco_proj_id"
t.datetime "date_collected"
end
add_index "eco_projects", ["proj_id"], :name => "proj_id"
create_table "enabled_modules", :force => true do |t|
t.integer "project_id"
t.string "name", :null => false
@ -338,137 +325,6 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
add_index "enumerations", ["id", "type"], :name => "index_enumerations_on_id_and_type"
add_index "enumerations", ["project_id"], :name => "index_enumerations_on_project_id"
create_table "events", :primary_key => "event_id", :force => true do |t|
t.string "job_name"
t.datetime "event_time"
t.string "event_type", :limit => 20
end
create_table "fm_article", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "article_title", :limit => 16777215
t.text "article_link", :limit => 16777215
t.text "article_time", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_article", ["proj_id"], :name => "proj_id"
create_table "fm_bugtracker_link", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "description", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_bugtracker_link", ["proj_id"], :name => "proj_id"
create_table "fm_datametric_link", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "description", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_datametric_link", ["proj_id"], :name => "proj_id"
create_table "fm_dependency_link", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "description", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_dependency_link", ["proj_id"], :name => "proj_id"
create_table "fm_download_link", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "download_link", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_download_link", ["proj_id"], :name => "proj_id"
create_table "fm_heartbeat", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.float "popularity_score", :limit => 12
t.float "vitality_score", :limit => 12
t.integer "subscription"
t.integer "voting_score"
t.integer "voting_count"
t.datetime "date_collected"
end
add_index "fm_heartbeat", ["proj_id"], :name => "proj_id"
create_table "fm_license", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "description", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_license", ["proj_id"], :name => "proj_id"
create_table "fm_mailinglist_link", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "description", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_mailinglist_link", ["proj_id"], :name => "proj_id"
create_table "fm_operating_system", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "description", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_operating_system", ["proj_id"], :name => "proj_id"
create_table "fm_programming_language", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "description", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_programming_language", ["proj_id"], :name => "proj_id"
create_table "fm_project_spotlight", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "description", :limit => 16777215
t.text "project_name", :limit => 16777215
t.text "project_spotlight_link", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_project_spotlight", ["proj_id"], :name => "proj_id"
create_table "fm_release", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "description", :limit => 16777215
t.text "release_version", :limit => 16777215
t.text "release_time", :limit => 16777215
t.text "release_tag", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_release", ["proj_id"], :name => "proj_id"
create_table "fm_submit", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "submitter", :limit => 16777215
t.text "submitter_link", :limit => 16777215
t.text "submit_time", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_submit", ["proj_id"], :name => "proj_id"
create_table "fm_summary", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.text "description", :limit => 16777215
t.datetime "date_collected"
end
add_index "fm_summary", ["proj_id"], :name => "proj_id"
create_table "forums", :force => true do |t|
t.string "name", :null => false
t.string "description", :default => ""
@ -490,9 +346,12 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
create_table "homework_attaches", :force => true do |t|
t.integer "bid_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "reward"
t.string "name"
t.string "description"
t.integer "state"
end
create_table "homework_for_courses", :force => true do |t|
@ -500,6 +359,13 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.integer "bid_id"
end
create_table "homework_users", :force => true do |t|
t.string "homework_attach_id"
t.string "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "issue_categories", :force => true do |t|
t.integer "project_id", :default => 0, :null => false
t.string "name", :limit => 30, :default => "", :null => false
@ -709,14 +575,15 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.datetime "updated_at", :null => false
end
create_table "ohloh_tagged", :force => true do |t|
t.integer "proj_id", :default => 0, :null => false
t.string "description", :limit => 100, :null => false
t.datetime "date_collected"
create_table "notificationcomments", :force => true do |t|
t.string "notificationcommented_type"
t.integer "notificationcommented_id"
t.integer "author_id"
t.text "notificationcomments"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "ohloh_tagged", ["proj_id"], :name => "proj_id"
create_table "open_id_authentication_associations", :force => true do |t|
t.integer "issued"
t.integer "lifetime"
@ -740,7 +607,7 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.integer "users_count", :default => 0
t.date "last_commit_time"
t.string "url"
t.datetime "date_collected"
t.date "date_collected"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
@ -781,6 +648,14 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
add_index "project_statuses", ["grade"], :name => "index_project_statuses_on_grade"
create_table "projecting_softapplictions", :force => true do |t|
t.integer "user_id"
t.integer "softapplication_id"
t.integer "project_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "projects", :force => true do |t|
t.string "name", :default => "", :null => false
t.text "description"
@ -796,6 +671,8 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.boolean "inherit_members", :default => false, :null => false
t.integer "project_type"
t.boolean "hidden_repo", :default => false, :null => false
t.integer "attachmenttype", :default => 1
t.integer "user_id"
end
add_index "projects", ["lft"], :name => "index_projects_on_lft"
@ -824,8 +701,15 @@ ActiveRecord::Schema.define(:version => 20140530010015) 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 "relative_memo_to_open_source_projects", :force => true do |t|
t.integer "osp_id"
t.integer "relative_memo_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "relative_memos", :force => true do |t|
t.integer "osp_id", :null => false
t.integer "osp_id"
t.integer "parent_id"
t.string "subject", :null => false
t.text "content", :null => false
@ -840,6 +724,10 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.integer "viewed_count_crawl", :default => 0
t.integer "viewed_count_local", :default => 0
t.string "url"
t.string "username"
t.string "userhomeurl"
t.date "date_collected"
t.string "topic_resource"
end
create_table "repositories", :force => true do |t|
@ -872,6 +760,7 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.string "province"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "logo_link"
end
create_table "seems_rateable_cached_ratings", :force => true do |t|
@ -907,11 +796,10 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.string "url"
t.string "title"
t.integer "share_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "project_id"
t.integer "user_id"
t.string "description"
end
create_table "softapplications", :force => true do |t|
@ -927,6 +815,9 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.integer "softapplication_id"
t.integer "is_public"
t.string "application_developers"
t.string "deposit_project_url"
t.string "deposit_project"
t.integer "project_id"
end
create_table "students_for_courses", :force => true do |t|
@ -936,14 +827,6 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.datetime "updated_at", :null => false
end
create_table "t_project_to_os_projects", :force => true do |t|
t.integer "crawl_proj_id"
t.string "crawl_proj_web"
t.integer "trustie_osp_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "taggings", :force => true do |t|
t.integer "tag_id"
t.integer "taggable_id"
@ -1002,22 +885,6 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
add_index "tokens", ["user_id"], :name => "index_tokens_on_user_id"
add_index "tokens", ["value"], :name => "tokens_value", :unique => true
create_table "tprojects", :force => true do |t|
t.string "name", :limit => 1000, :default => "0"
t.text "description", :limit => 16777215
t.string "commit_count", :limit => 100, :default => "0"
t.string "code_line", :limit => 100
t.string "last_commit_time", :limit => 100
t.string "url", :limit => 1000
t.datetime "date_collected"
t.string "created_at", :limit => 100
t.string "updated_at", :limit => 100
t.integer "proj_id", :null => false
t.string "user_count", :limit => 100
end
add_index "tprojects", ["proj_id"], :name => "proj_id"
create_table "trackers", :force => true do |t|
t.string "name", :limit => 30, :default => "", :null => false
t.boolean "is_in_chlog", :default => false, :null => false
@ -1037,8 +904,8 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
t.integer "zip_code"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "technical_title"
t.integer "identity"
t.string "technical_title"
t.string "student_id"
t.string "teacher_realname"
t.string "student_realname"
@ -1058,6 +925,11 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
add_index "user_grades", ["project_id"], :name => "index_user_grades_on_project_id"
add_index "user_grades", ["user_id"], :name => "index_user_grades_on_user_id"
create_table "user_levels", :force => true do |t|
t.integer "user_id"
t.integer "level"
end
create_table "user_preferences", :force => true do |t|
t.integer "user_id", :default => 0, :null => false
t.text "others"
@ -1068,16 +940,11 @@ ActiveRecord::Schema.define(:version => 20140530010015) do
add_index "user_preferences", ["user_id"], :name => "index_user_preferences_on_user_id"
create_table "user_scores", :force => true do |t|
t.integer "user_id", :null => false
t.integer "collaboration"
t.integer "influence"
t.integer "skill"
t.integer "active"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "level"
t.integer "file"
t.integer "issue"
t.integer "user_id"
t.integer "collaboration"
t.integer "influence"
t.integer "skill"
t.integer "activity"
end
create_table "user_statuses", :force => true do |t|

13
test/fixtures/notificationcomments.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
notificationcommented_type: MyString
notificationcommented_id: 1
author_id: 1
notificationcomments: MyText
two:
notificationcommented_type: MyString
notificationcommented_id: 1
author_id: 1
notificationcomments: MyText

View File

@ -0,0 +1,7 @@
require 'test_helper'
class NotificationcommentsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,4 @@
require 'test_helper'
class NotificationcommentsHelperTest < ActionView::TestCase
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class NotificationcommentsTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end