From b86b465a76fcaf8bc66990d31d2b0a566fcbf595 Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 19 Jul 2017 17:26:22 +0800 Subject: [PATCH] =?UTF-8?q?TPI=E7=9A=84=E9=97=AE=E9=A2=98=E5=8F=8D?= =?UTF-8?q?=E9=A6=88=E6=9B=B4=E6=96=B0=E4=B8=BA=E2=80=9C=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E2=80=9D=EF=BC=8C=E7=9B=B4=E6=8E=A5=E5=9C=A8TPI=E4=B8=AD?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E8=AF=84=E8=AE=BAtab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/discusses.js.coffee | 3 + app/assets/stylesheets/discusses.css.scss | 3 + app/controllers/discusses_controller.rb | 48 ++++++++++++++ app/controllers/praise_tread_controller.rb | 2 + app/controllers/shixuns_controller.rb | 10 +++ app/helpers/discusses_helper.rb | 2 + app/models/discuss.rb | 10 +++ app/models/shixun.rb | 1 + app/views/discusses/_dis_praise.html.erb | 15 +++++ app/views/discusses/destroy.js.erb | 3 + app/views/games/_game_show.html.erb | 64 ++++--------------- .../games/_shixun_comment_block.html.erb | 40 ++++++++++++ app/views/games/_shixun_comment_list.html.erb | 62 ++++++++++++++++++ app/views/praise_tread/praise_minus.js.erb | 4 ++ app/views/praise_tread/praise_plus.js.erb | 4 ++ app/views/shixuns/shixun_discuss.js.erb | 5 ++ config/routes.rb | 11 ++++ db/migrate/20170718080353_create_discusses.rb | 16 +++++ public/stylesheets/css/edu-public.css | 3 +- spec/controllers/discusses_controller_spec.rb | 5 ++ spec/factories/discusses.rb | 12 ++++ spec/models/discuss_spec.rb | 5 ++ 22 files changed, 277 insertions(+), 51 deletions(-) create mode 100644 app/assets/javascripts/discusses.js.coffee create mode 100644 app/assets/stylesheets/discusses.css.scss create mode 100644 app/controllers/discusses_controller.rb create mode 100644 app/helpers/discusses_helper.rb create mode 100644 app/models/discuss.rb create mode 100644 app/views/discusses/_dis_praise.html.erb create mode 100644 app/views/discusses/destroy.js.erb create mode 100644 app/views/games/_shixun_comment_block.html.erb create mode 100644 app/views/games/_shixun_comment_list.html.erb create mode 100644 app/views/shixuns/shixun_discuss.js.erb create mode 100644 db/migrate/20170718080353_create_discusses.rb create mode 100644 spec/controllers/discusses_controller_spec.rb create mode 100644 spec/factories/discusses.rb create mode 100644 spec/models/discuss_spec.rb 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 @@
  • 参考答案
  • -
  • - 评论 +
  • + <%= link_to '评论', shixun_discuss_shixun_path(@shixun), :class => "tab_type", :style => "font-size: 16px", :remote => true %>
  • 经验值:<%= @game_challenge.score %> @@ -37,7 +37,7 @@ -