TPI的问题反馈更新为“评论”,直接在TPI中显示评论tab

This commit is contained in:
cxt 2017-07-19 17:26:22 +08:00
parent 5cbd1695f0
commit b86b465a76
22 changed files with 277 additions and 51 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 discusses controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

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

View File

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

View File

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

View File

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

10
app/models/discuss.rb Normal file
View File

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

View File

@ -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}",

View File

@ -0,0 +1,15 @@
<% if PraiseTread.praised(discuss) %>
<a href='<%= praise_tread_praise_plus_path({:obj_id => discuss.id,
:obj_type => discuss.class
}) %>' data-remote="true" title="点赞" class="fr mt5">
<i class="fa fa-thumbs-up color_Purple_grey"></i>
<%= discuss.praise_tread_cache ? discuss.praise_tread_cache.praise_num : 0 %>
</a>
<% else %>
<a href='<%= praise_tread_praise_minus_path({:obj_id => discuss.id,
:obj_type => discuss.class
}) %>' data-remote="true" class="fr mt5" title="取消点赞" >
<i class="fa fa-thumbs-up color-light-green"></i>
<%= discuss.praise_tread_cache ? discuss.praise_tread_cache.praise_num : 0 %>
</a>
<% end %>

View File

@ -0,0 +1,3 @@
<% if @shixun %>
$.get('<%= shixun_discuss_shixun_path(@shixun) %>');
<% end %>

View File

@ -21,8 +21,8 @@
<li id="tab_nav_3">
<a href="javascript:void(0);" class="tab_type" style="font-size: 16px">参考答案</a>
</li>
<li id="tab_nav_4" onclick="HoverLi1(4);">
<a href="javascript:void(0);" class="tab_type" style="font-size: 16px">评论</a>
<li id="tab_nav_4">
<%= link_to '评论', shixun_discuss_shixun_path(@shixun), :class => "tab_type", :style => "font-size: 16px", :remote => true %>
</li>
<span class="btn-cir-big fr mt8 mr15" >经验值:<%= @game_challenge.score %></span>
</ul>
@ -37,7 +37,7 @@
</div>
</div>
</div>
<div id="tab_con_2" class="tab-info"style="display: none" >
<div id="tab_con_2" class="tab-info" style="display: none" >
<div class="fit -scroll">
<div class="-layout-v -fit">
<div class="-flex -scroll task-padding16 panel-box-sizing new_li read_only" unselectable="on" id="game_ready_knowledge">
@ -55,57 +55,15 @@
</div>
</div>
</div>
<div id="tab_con_4" class="tab-info"style="display: none">
<div class="fit -scroll">
<div class="-layout-v -fit">
<div class="-flex -scroll panel-box-sizing new_li task-padding10" id="game_comment_show">
<div id="comments_content">
<div class="comments_item_content comment_item_bottom clearfix mt5">
<img src="http://img2.imgtn.bdimg.com/it/u=1161837241,1939117256&fm=214&gp=0.jpg"/>
<div class="fr comment_item_one">
<p class="clearfix pl8">
<span class="fl color-grey">瑶瑶</span>
<span class="fr color-grey font-12 color_Purple_grey" style="padding-top: 2px;">2</span>
<i class="fa fa-thumbs-up mr3 fr mt5 color_Purple_grey"></i>
</p>
<p class="pl8">太棒了,学到了很多有用的知识点</p>
<p class="clearfix pl8"><span class="fl color-grey">2小时前</span><span class="fr font-12 color-light-green">回复</span></p>
<div class="comments_return comment_item_top">
<p class="clearfix comment_item_left_green return_item pl5">
<span class="fl color-grey">老师回复</span>
<span class="fr color-grey font-12 color_Purple_grey" style="padding-top: 2px;">2</span>
<i class="fa fa-thumbs-up mr3 fr mt5 color_Purple_grey"></i>
</p>
<p class="pl8">对你有帮助就好</p>
<p class="clearfix pl8"><span class="fl color-grey">1小时前</span><span class="fr font-12 color-light-green">删除</span></p>
</div>
</div>
</div>
<div class="comments_item_content comment_item_bottom clearfix mt5">
<img src="http://img2.imgtn.bdimg.com/it/u=1161837241,1939117256&fm=214&gp=0.jpg"/>
<div class="fr comment_item_one">
<p class="clearfix pl8">
<span class="fl color-grey">瑶瑶</span>
<span class="fr color-grey font-12 color_Purple_grey" style="padding-top: 2px;">2</span>
<i class="fa fa-thumbs-up mr3 fr mt5 color_Purple_grey"></i>
</p>
<p class="pl8">太棒了,学到了很多有用的知识点</p>
<p class="clearfix pl8"><span class="fl color-grey">2小时前</span><span class="fr font-12 color-light-green">回复</span></p>
</div>
</div>
</div>
<!--评论区域的分页-->
</div>
</div>
</div>
<div id="tab_con_4" class="tab-info" style="display: none">
<%#= render :partial => "games/shixun_comment_list" %>
</div>
</div>
</div>
<div class="-layout-h -center -padding-h-16 -horizontal -footer-left" >
<div class="-layout-h -center -padding-h-16 -horizontal -footer-left">
<ul class="-layout -task-ml80 pr">
<li class="comment-input"><textarea id="comment_news" placeholder="我想说点什么~" MultiLine = True ScrollBars = 2 type="text" ></textarea></li>
<li class="comment_position" style="right: 70px"><a class="course-bth-blue color_white">发送</a></li>
<%= render :partial => "games/shixun_comment_block" %>
<li class="comment_position" style="right: 70px"><a href="javascript:void(0);" onclick="send_dis_to_shixun()" class="course-bth-blue color_white">发送</a></li>
<li title="<%= @praise.nil? ? "点赞" : "取消点赞" %>" onclick="game_praise()" id="game_praise_tread" class="comment_position pt5" style="right: 40px">
<i class="fa fa-thumbs-up font-20 <%= @praise.nil? ? "" : "color-light-green" %>" alt="赞" ></i>
</li>
@ -239,4 +197,10 @@
}
});
}
function reply_to_dis(id, name){
$("#comment_news").attr("placeholder", "回复"+name+":");
$("#dis_reply_id").val(id);
$("#comment_news").focus();
}
</script>

View File

@ -0,0 +1,40 @@
<li class="comment-input" id="shixun_comment_block">
<%= form_for('', :url => {:controller => 'discusses', :action => 'create', :dis_id => @shixun.id, :dis_type => "Shixun"}, :method => "post", :remote => true, :html => {:id => 'new_comment_form'}) do |f| %>
<textarea id="comment_news" name="content" placeholder="我想说点什么~" MultiLine = True ScrollBars = 2 type="text" ></textarea>
<input type="hidden" id="dis_reply_id" name="reply_id" value="">
<% end %>
</li>
<script>
var click = true;
function send_dis_to_shixun(){
if($("#comment_news").val() == ""){
return
} else{
if(click){
click = false;
$("#new_comment_form").submit();
return
}
}
}
$(".comment-input").on("keydown", "input[name='content']", function(event){
var target, code, tag;
if (!event) {
event = window.event; //针对ie浏览器
code = event.keyCode;
}
else {
code = event.keyCode;
}
if(code == 13) {
send_dis_to_shixun();
return false;
}
});
$("#comment_news").on('blur', function(){
$("#comment_news").attr("placeholder", "我想说点什么~");
$("#dis_reply_id").val();
});
</script>

View File

@ -0,0 +1,62 @@
<div class="fit -scroll">
<div class="-layout-v -fit">
<div class="-flex -scroll panel-box-sizing new_li task-padding10" id="game_comment_show">
<div id="comments_content">
<% if @shixun.discusses.blank? %>
<%= render :partial => "welcome/no_data" %>
<% else %>
<% @discusses.each do |dis| %>
<div class="comments_item_content comment_item_bottom clearfix mt5">
<%= link_to image_tag(url_to_avatar(dis.user), :alt => "头像"), user_path(dis.user), :target => '_blank' %>
<div class="fr comment_item_one">
<p class="clearfix pl8">
<%= link_to dis.user.show_name, user_path(dis.user), :class => "fl link-color-grey" %>
<span class="fr color-grey font-12 color_Purple_grey" style="padding-top: 2px;" id="dis_praise_<%= dis.id %>">
<%= render :partial => "discusses/dis_praise", :locals => {:discuss => dis} %>
</span>
</p>
<p class="pl8"><%= dis.content %></p>
<p class="clearfix pl8">
<span class="fl color-grey"><%= time_from_now dis.created_at %></span>
<% if User.current.manager_of_shixun?(@shixun) && dis.children.count == 0 %>
<a href="javascript:void(0);" onclick="reply_to_dis('<%= dis.id %>', '<%= dis.user.show_name %>')" class="fr ml10 font-12 link-color-green">回复</a>
<% end %>
<% if (User.current.manager_of_shixun?(@shixun) || User.current == dis.user) && dis.children.count == 0 %>
<a href="javascript:void(0);" onclick="delete_confirm_box_2('<%= discuss_path(dis) %>', '确定要删除该条回复吗?')" class="fr font-12 link-color-green">删除</a>
<% end %>
</p>
<% dis.children.each do |child| %>
<div class="comments_return comment_item_top">
<p class="clearfix comment_item_left_green return_item pl5">
<span class="fl color-grey">老师回复</span>
<span class="fr color-grey font-12 color_Purple_grey" style="padding-top: 2px;" id="dis_praise_<%= child.id %>">
<%= render :partial => "discusses/dis_praise", :locals => {:discuss => child} %>
</span>
</p>
<p class="pl8"><%= child.content %></p>
<p class="clearfix pl8">
<span class="fl color-grey"><%= time_from_now child.created_at %></span>
<% if User.current.manager_of_shixun?(@shixun) || (User.current == dis.user && dis.children.count == 0) %>
<a href="javascript:void(0);" onclick="delete_confirm_box_2('<%= discuss_path(dis) %>', '确定要删除该条回复吗?')" class="fr font-12 link-color-green">删除</a>
<% end %>
</p>
</div>
<% end %>
</div>
</div>
<% end %>
<div style="text-align:center;" class="new_expand">
<div class="pages_user_show" style="width:auto; display:inline-block;margin: 18px 0;">
<ul id="homework_pository_ref_pages">
<%= pagination_links_full @discusses_pages, @discusses_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %>
</ul>
<div class="cl"></div>
</div>
</div>
<% end %>
</div>
<!--评论区域的分页-->
</div>
</div>
</div>

View File

@ -12,6 +12,10 @@
$('.reply_praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"reply"})%>');
<% end %>
<% end %>
<% elsif @obj_type == 'Discuss'%>
$('#dis_praise_<%= @obj.id %>').html('<%= j(
render :partial => "discusses/dis_praise",:locals => {:discuss => @obj}
)%>');
<% else %>
$('#praise_tread').html('<%= j(
render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:show_flag => false,:user_id => User.current.id,:horizontal=>@horizontal}

View File

@ -16,6 +16,10 @@
$('#praise_tread_<%= @obj.id %>').html('<%= j(
render :partial => "/memos/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal}
)%>');
<% elsif @obj_type == 'Discuss'%>
$('#dis_praise_<%= @obj.id %>').html('<%= j(
render :partial => "discusses/dis_praise",:locals => {:discuss => @obj}
)%>');
<% else %>
$('#praise_tread_<%= @obj.id %>').html('<%= j(
render :partial => "/praise_tread/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal}

View File

@ -0,0 +1,5 @@
$("#shixun_comment_block").replaceWith("<%= j(render :partial => "games/shixun_comment_block") %>");
$(".-tab-nav li").removeClass("tab_hover");
$('#tab_nav_4').addClass("tab_hover");
$(".tab-info").hide();
$('#tab_con_4').show().html("<%= j(render :partial => "games/shixun_comment_list") %>");

View File

@ -52,6 +52,16 @@ RedmineApp::Application.routes.draw do
end
end
resources :discusses do
member do
end
collection do
end
end
resources :shixuns do
member do
get 'game_webssh'
@ -80,6 +90,7 @@ RedmineApp::Application.routes.draw do
get 'operation'
get 'entry_edit'
match 'entry_update'
get 'shixun_discuss'
end
collection do
get 'shixun_courses'

View File

@ -0,0 +1,16 @@
class CreateDiscusses < ActiveRecord::Migration
def change
create_table :discusses do |t|
t.references :user
t.string :dis_type
t.integer :dis_id
t.text :content
t.integer :parent_id
t.integer :root_id
t.integer :praise_count
t.timestamps
end
add_index :discusses, :user_id
end
end

View File

@ -170,7 +170,8 @@ a.panel-table-title{display:block; max-width:240px;text-align:center;}
/* 个人主页翻页 */
.pages_user_show a:hover,.pages_user_show a.active{ background-color:#FF6610;; color:#fff;border: 1px solid #ff6610;}
.pages_user_show a{ display: inline-block;border:1px solid #d1d1d1; color:#888; float:left;text-align:center; padding:3px 10px; line-height:1.9; margin: 0 5px;}
.pages_user_show li{float: left;}
.pages_user_show li{float: left; list-style-type: none;}
.pages_user_show ul li{list-style-type: none !important;}
/* 小翻页 */
.pages_little_show a:hover,.pages_little_show a.active{ background-color:#FF6610;; color:#fff;border:1px solid #FF6610}
.pages_little_show a{ display: inline-block;border:1px solid #d1d1d1; color:#888; float:left;text-align:center; padding:3px 3px; line-height:1.9; margin: 0 2px; font-size: 12px;}

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe DiscussesController, :type => :controller do
end

View File

@ -0,0 +1,12 @@
FactoryGirl.define do
factory :discuss do
user nil
dis_type "MyString"
dis_id 1
content "MyText"
parent_id 1
root_id 1
praise_count 1
end
end

View File

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe Discuss, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end