为竞赛通知添加评论

president
wanglinchun 11 years ago
parent 2e11d76652
commit d06488c10d

@ -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/

@ -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/

@ -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

@ -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

@ -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

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

@ -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

@ -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]

@ -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

@ -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

@ -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

@ -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

@ -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

File diff suppressed because it is too large Load Diff

@ -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

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

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

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