diff --git a/app/assets/javascripts/discusses.js.coffee b/app/assets/javascripts/discusses.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/discusses.js.coffee @@ -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/ diff --git a/app/assets/stylesheets/discusses.css.scss b/app/assets/stylesheets/discusses.css.scss new file mode 100644 index 000000000..3b4264c09 --- /dev/null +++ b/app/assets/stylesheets/discusses.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the discusses controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb new file mode 100644 index 000000000..ba3c12665 --- /dev/null +++ b/app/controllers/discusses_controller.rb @@ -0,0 +1,48 @@ +class DiscussesController < ApplicationController + include ApplicationHelper + before_filter :find_dis_object, :except => [:destroy] + before_filter :find_discuss, :only => [:destroy] + + def create + if @model + if params[:reply_id].blank? + @model.discusses << Discuss.new(:content => params[:content], :user_id => User.current.id, :praise_count => 0) + else + @model.discusses << Discuss.new(:content => params[:content], :user_id => User.current.id, :parent_id => params[:reply_id], :root_id => params[:reply_id], :praise_count => 0) + end + if params[:dis_type] == "Shixun" + redirect_to shixun_discuss_shixun_path(@model) + end + end + end + + def destroy + if @discuss + if @discuss.dis_type == "Shixun" + @shixun = @discuss.dis + end + @discuss.destroy + end + end + + private + + def find_discuss + @discuss = Discuss.find params[:id] + rescue ActiveRecord::RecordNotFound + render_404 + end + + def find_dis_object + unless params[:dis_id] && params[:dis_type] + render_404 + else + case params[:dis_type] + when 'Shixun' + @model = Shixun.find params[:dis_id] + end + end + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index a661892f8..680352e0a 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -149,6 +149,8 @@ class PraiseTreadController < ApplicationController @obj = Work.find_by_id(id) when 'Challenge' || 'ChallengeTread' @obj = Challenge.find_by_id(id) + when 'Discuss' + @obj = Discuss.find_by_id(id) else @obj = nil end diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 37a3de9a0..d54eddc55 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -484,6 +484,16 @@ class ShixunsController < ApplicationController end end + def shixun_discuss + @discusses = @shixun.discusses.where(:parent_id => nil).reorder("created_at desc") + @discusses_count = @discusses.count + @limit = 10 + @is_remote = true + @discusses_pages = Paginator.new @discusses_count, @limit, params['page'] || 1 + @offset ||= @discusses_pages.offset + @discusses = paginateHelper @discusses, @limit + end + def destroy unless User.current.admin? render_403 diff --git a/app/helpers/discusses_helper.rb b/app/helpers/discusses_helper.rb new file mode 100644 index 000000000..544945763 --- /dev/null +++ b/app/helpers/discusses_helper.rb @@ -0,0 +1,2 @@ +module DiscussesHelper +end diff --git a/app/models/discuss.rb b/app/models/discuss.rb new file mode 100644 index 000000000..dbf0f99ec --- /dev/null +++ b/app/models/discuss.rb @@ -0,0 +1,10 @@ +class Discuss < ActiveRecord::Base + belongs_to :user + attr_accessible :user_id, :content, :dis_id, :dis_type, :parent_id, :praise_count, :root_id + + has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_one :praise_tread_cache, as: :object, dependent: :destroy + acts_as_tree :foreign_key => 'parent_id' + belongs_to :dis, :polymorphic => true + validates_presence_of :dis, :user, :content +end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index e218ebb39..28232c9e6 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -22,6 +22,7 @@ class Shixun < ActiveRecord::Base belongs_to :major_course has_many :shixun_major_courses, :dependent => :destroy has_and_belongs_to_many :homework_commons + has_many :discusses, :as => :dis, :dependent => :destroy # 获取特定格式的实训测试用例 # params = {:challengeStage => "#{@challenge.position}", :challengeType => "#{@challenge.evaluation_way.to_i}", diff --git a/app/views/discusses/_dis_praise.html.erb b/app/views/discusses/_dis_praise.html.erb new file mode 100644 index 000000000..28b95f001 --- /dev/null +++ b/app/views/discusses/_dis_praise.html.erb @@ -0,0 +1,15 @@ +<% if PraiseTread.praised(discuss) %> + + + <%= discuss.praise_tread_cache ? discuss.praise_tread_cache.praise_num : 0 %> + +<% else %> + + + <%= discuss.praise_tread_cache ? discuss.praise_tread_cache.praise_num : 0 %> + +<% end %> \ No newline at end of file diff --git a/app/views/discusses/destroy.js.erb b/app/views/discusses/destroy.js.erb new file mode 100644 index 000000000..971d4cc8d --- /dev/null +++ b/app/views/discusses/destroy.js.erb @@ -0,0 +1,3 @@ +<% if @shixun %> +$.get('<%= shixun_discuss_shixun_path(@shixun) %>'); +<% end %> \ No newline at end of file diff --git a/app/views/games/_game_show.html.erb b/app/views/games/_game_show.html.erb index dbb98f2bc..09463a5d4 100644 --- a/app/views/games/_game_show.html.erb +++ b/app/views/games/_game_show.html.erb @@ -21,8 +21,8 @@
- 瑶瑶 - 2 - -
-太棒了,学到了很多有用的知识点
-2小时前回复
- -- 老师回复 - 2 - -
-对你有帮助就好
-1小时前删除
-- 瑶瑶 - 2 - -
-太棒了,学到了很多有用的知识点
-2小时前回复
-