From f26f71c07ae7610839de26777dca467137b7775d Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 24 Dec 2015 09:57:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E9=80=9A=E7=9F=A5=E6=94=B9?= =?UTF-8?q?=E6=88=90=E5=8A=A8=E6=80=81=E7=9A=84=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/comments_controller.rb | 5 +- app/controllers/news_controller.rb | 39 +++- app/views/news/_course_news.html.erb | 72 +++--- app/views/news/_course_news_detail.html.erb | 56 +++++ app/views/news/_course_news_new.html.erb | 60 +++++ app/views/news/_course_show.html.erb | 237 +++++++++++++------- app/views/news/edit.html.erb | 23 +- app/views/news/index.js.erb | 6 +- config/routes.rb | 1 + 9 files changed, 365 insertions(+), 134 deletions(-) create mode 100644 app/views/news/_course_news_detail.html.erb create mode 100644 app/views/news/_course_news_new.html.erb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 8a64918ae..359029517 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -27,7 +27,8 @@ class CommentsController < ApplicationController raise Unauthorized unless @news.commentable? @comment = Comment.new - @project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment] + #@project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment] + @comment.comments = params[:comment][:comments] @comment.author = User.current if @news.comments << @comment if params[:asset_id] @@ -48,7 +49,7 @@ class CommentsController < ApplicationController # end # end # # ������ض�̬�ļ�¼add end - flash[:notice] = l(:label_comment_added) + #flash[:notice] = l(:label_comment_added) course_activity = CourseActivity.where("course_act_type='News' and course_act_id =#{@news.id}").first if course_activity course_activity.updated_at = Time.now diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index be2b44c06..d3ac71b99 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -69,20 +69,25 @@ class NewsController < ApplicationController elsif @course if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course))) scope = @course ? @course.news.course_visible : News.course_visible + news_arr = scope.map{|news| news.id} + + @page = params[:page] ? params[:page].to_i + 1 : 0 + news_page = @page *10 @news_count = scope.count + @is_new = params[:is_new] @q = params[:subject] if params[:subject].nil? || params[:subject].blank? - scope_order = scope.all(:include => [:author, :course], - :order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC") + scope_order = scope.reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all() + #all(:include => [:author, :course], + #:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page) else - scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").all(:include => [:author, :course], - :order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC") + scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").reorder("#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC").limit(10).offset(news_page).includes(:author,:course).all() + #.all(:include => [:author, :course],:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC") end - # :offset => @offset, - # :limit => @limit) - @newss = paginateHelper scope_order,10 + @newss = scope_order + #@newss = paginateHelper scope_order,10 respond_to do |format| format.html { @news = News.new @@ -130,6 +135,7 @@ class NewsController < ApplicationController result = cs.show_course_news params,User.current @news = result[:news] @comments = result[:comments] + @comment = Comment.new #@comments = @news.comments #@comments.reverse! if User.current.wants_comments_in_reverse_order? #modify by nwb @@ -147,7 +153,22 @@ class NewsController < ApplicationController @news = News.new(:project => @project, :author => User.current) elsif @course @news = News.new(:course => @course, :author => User.current) - render :layout => 'base_courses' + #render :layout => 'base_courses' + @news.safe_attributes = params[:news] + @news.save_attachments(params[:attachments]) + if @news.save + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,@news.id,OwnerTypeHelper::NEWS + end + render_attachment_warning_if_needed(@news) + #flash[:notice] = l(:notice_successful_create) + redirect_to course_news_index_url(@course) + else + redirect_to course_news_index_url(@course) + #layout_file = 'base_courses' + #render :action => 'new', :layout => layout_file + end end end @@ -210,7 +231,7 @@ class NewsController < ApplicationController @news.save_attachments(params[:attachments]) if @news.save render_attachment_warning_if_needed(@news) - flash[:notice] = l(:notice_successful_update) + #flash[:notice] = l(:notice_successful_update) redirect_to news_url(@news) else #flash[:error] = l(:notice_successful_update) diff --git a/app/views/news/_course_news.html.erb b/app/views/news/_course_news.html.erb index e2c50fe24..245ee4104 100644 --- a/app/views/news/_course_news.html.erb +++ b/app/views/news/_course_news.html.erb @@ -1,42 +1,34 @@ -<% - btn_tips = l(:label_news_notice) - label_tips = l(:label_course_news) -%> - -
-

<%= label_tips %>

-
-
-
-

- <%= l(:label_total_news) %> - <%= @news_count %> - <%= l(:label_course_news_count) %> -

- <% if @course && User.current.allowed_to?(:manage_news, @course) %> - <%= link_to(btn_tips,new_course_news_path(@course),:class => 'problem_new_btn fl c_dorange')%> -
- - <% end %> +
+
+
+ 课程通知 +
- -
-
- -
- <%= render :partial => 'course_news_list', :locals=>{ :newss=>@newss,:obj_pages=>@obj_pages, :obj_count=>@obj_count} %> -
-<% content_for :header_tags do %> - <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %> - <%= stylesheet_link_tag 'scm' %> -<% end %> -<% html_title(l(:label_course_news)) -%> + <% if @course && User.current.allowed_to?(:manage_news, @course) %> + <%= labelled_form_for @news, :url =>{:controller=>'news',:action => 'new', :course_id => @course.id}, + :html => {:nhname=>'form',:multipart => true, :id => 'news-form'} do |f| %> + <%= render :partial => 'course_news_new', :locals => {:f => f, :news => @news, :edit_mode => false, :course => @course} %> + <% end %> + <% end %> + <%= render :partial=> 'course_news_detail',:locals =>{:newss => @newss, :page => 0} %> +
\ No newline at end of file diff --git a/app/views/news/_course_news_detail.html.erb b/app/views/news/_course_news_detail.html.erb new file mode 100644 index 000000000..954f7dbf1 --- /dev/null +++ b/app/views/news/_course_news_detail.html.erb @@ -0,0 +1,56 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: false, prettify: false) %> + <%= javascript_include_tag "init_activity_KindEditor" %> +<% end %> + + +<% if newss%> + <% newss.each do |news| %> + + <% if news %> + <%= render :partial => 'users/course_news', :locals => {:activity => news, :user_activity_id => news.id} %> + <% end %> + <% end %> + + <% if newss.count == 10 %> + <%= link_to "点击展开更多",news_index_path(:course_id => @course.id ,:page => page),:id => "show_more_course_news",:remote => "true",:class => "loadMore mt10 f_grey"%> + <% end %> +<% end%> + diff --git a/app/views/news/_course_news_new.html.erb b/app/views/news/_course_news_new.html.erb new file mode 100644 index 000000000..158f57459 --- /dev/null +++ b/app/views/news/_course_news_new.html.erb @@ -0,0 +1,60 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: true, prettify: false) %> +<% end %> + +
+
+
+
+ +

+
+ +
+
+
\ No newline at end of file diff --git a/app/views/news/_course_show.html.erb b/app/views/news/_course_show.html.erb index a976dbe1e..914b1a6a1 100644 --- a/app/views/news/_course_show.html.erb +++ b/app/views/news/_course_show.html.erb @@ -2,85 +2,172 @@ <%= import_ke(enable_at: false, prettify: false, init_activity: false) %> <% end %> -
-

<%= l(:label_course_news) %>

-
-
- <%= link_to image_tag(url_to_avatar(@news.author),:width => 42,:height => 42), user_path(@news.author), :class => "problem_pic fl" %> -
-

- <%=h @news.title %> -

- <% if @news.sticky == 1%> - 置顶 - <% end%> - <%= link_to(l(:button_edit), - edit_news_path(@news), - :class => 'talk_edit fr') if User.current.allowed_to?(:manage_news, @course) %> - <%= delete_link(news_path(@news),:class => 'talk_edit fr') if User.current.allowed_to?(:manage_news, @course) %> -
-
- <%= @news.description.html_safe %> -
- <%= l(:label_create_time) %> : <%= format_time(@news.created_on) %> + + + +
+
+
+ <%= link_to image_tag(url_to_avatar(@news.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@news.author) %>
- <%= link_to_attachments_course @news %> - +
+ <% if User.current.allowed_to?(:manage_news, @course)%> + + <%end%> + +
+ +
+ <% if @news.try(:author).try(:realname) == ' ' %> + <%= link_to @news.try(:author), user_path(@news.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> + <% else %> + <%= link_to @news.try(:author).try(:realname), user_path(@news.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> + <% end %> +
+
<%= format_time( @news.created_on)%>
+
+
+ <%= @news.description.html_safe%> +
+
+
+ <%= link_to_attachments_course @news, :author => false %> +
+
+
-
+
+ <% unless @comments.empty? %> +
+
回复(<%=@comments.count %>)
+
+
+
+ <% @comments.each_with_index do |reply,i| %> + +
+
+ <%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %> +
+
+
+ <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% end %> +
+
+ <%= reply.comments.html_safe%> +
+
+ <%= format_time(reply.created_on) %> + +
+

+
+
+
+ <% end %> +
- <% if @news.commentable? %> -
-

<%= l(:label_comment_add) %>

- <%= form_tag({:controller => 'comments', :action => 'create', :id => @news}, :id => "add_comment_form") do %> -
- <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> - <%= kindeditor_tag :comment, '',:height=>'100',:editor_id =>'comment_editor', :placeholder=>"最多250个字"%> -
-

-

- - <%= l(:label_cancel_with_space) %> - - - <%= l(:label_comment_with_space) %> - -

- <% end %> -
- <% end %> -
- <% comments = @comments.reverse %> - <% comments.each do |comment| %> - <% next if comment.new_record? %> -
-
<%= link_to image_tag(url_to_avatar(comment.author),:width => 42,:height => 42), user_path(comment.author), :class => "problem_pic fl"%>
-
-
- <%= link_to_user_header(comment.author,false,:class => 'c_blue fb fl mb10 ') if comment.respond_to?(:author) %> - - <%= format_time(comment.created_on) %> - + <% end %> +
+ <% if @news.commentable? %> +
+ +
+
+ <%= form_for @comment, :url=>{:controller => 'comments', :action => 'create', :id => @news}, :html => {:multipart => true, :id => 'add_comment_form'} do |f| %> +
+ <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> + <%= f.kindeditor :comments, :editor_id => 'comment_editor', + :owner_id => @comment.nil? ? 0: @comment.id, + :owner_type => OwnerTypeHelper::COMMENT, + :width => '99%', + :height => 100, + :minHeight=>100, + :input_html => { :id => 'comment_content', + :class => 'talk_text fl', + :maxlength => 5000 }%> +
+

+

+ + <%= l(:label_cancel_with_space) %> + + + <%= l(:label_comment_with_space) %> + +

+ <% end %>
-

<%= comment.comments.html_safe %>

-
-
- <%= link_to_if_authorized_course image_tag('delete.png'), {:controller => 'comments', :action => 'destroy', :id => @news, :comment_id => comment}, - :data => {:confirm => l(:text_are_you_sure)}, :method => :delete, :title => l(:button_delete) %>
-
-
-
- <% end if @comments.any? %> - - - - - <% content_for :header_tags do %> - <%= stylesheet_link_tag 'scm' %> - <% end %> - - -<% html_title @news.title -%> \ No newline at end of file + <% end %> +
+
diff --git a/app/views/news/edit.html.erb b/app/views/news/edit.html.erb index c2ba15588..b043b06f8 100644 --- a/app/views/news/edit.html.erb +++ b/app/views/news/edit.html.erb @@ -1,14 +1,23 @@ <%= content_for(:header_tags) do %> <%= import_ke(enable_at: false, prettify: false, init_activity: false) %> <% end %> - -
-

<%= l(:label_course_news) %>

-
-
+ +
+
+
+ 编辑通知 +
+
<%= labelled_form_for :news, @news, :url => news_path(@news), :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> - <%= render :partial => 'course_form', :locals => { :f => f, :is_new => false } %> + <%#= labelled_form_for :news, :url =>{:controller=>'news',:action => 'new', :course_id => @course.id}, + :html => {:nhname=>'form',:multipart => true, :id => 'news-form'} do |f| %> + <%= render :partial => 'course_news_new', :locals => {:f => f, :news => @news, :edit_mode => true, :course => @course} %> <% end %> -
diff --git a/app/views/news/index.js.erb b/app/views/news/index.js.erb index 04671917b..302c0cf9d 100644 --- a/app/views/news/index.js.erb +++ b/app/views/news/index.js.erb @@ -1 +1,5 @@ -$("#news_list").html("<%= escape_javascript(render :partial => 'course_news_list', :locals=>{ :newss=>@newss,:obj_pages=>@obj_pages, :obj_count=>@obj_count})%>"); \ No newline at end of file +<% if @project %> + $("#news_list").html("<%= escape_javascript(render :partial => 'course_news_list', :locals=>{ :newss=>@newss,:obj_pages=>@obj_pages, :obj_count=>@obj_count})%>"); +<% else %> + $("#show_more_course_news").replaceWith("<%= escape_javascript( render :partial => 'course_news_detail', :locals =>{:newss => @newss, :page => @page} )%>"); +<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 4121639c0..289c602db 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -438,6 +438,7 @@ RedmineApp::Application.routes.draw do post '/courses/:id/course_activity', :to => 'courses#show', :as => 'course_activity' get '/boards/:id/boards_topic', :to =>'boards#show', :as => 'boards_topic' + match 'courses/:course_id/news/new', :to => 'news#new', :via => [:get, :post], :as => 'new_course_news' #added by young resources :users do