From ab868d7b65654746ae12ea2d848a8184b7a9eef6 Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 12 Nov 2015 16:52:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E9=80=9A=E7=9F=A5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=BD=AE=E9=A1=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/news_controller.rb | 4 ++-- app/models/news.rb | 2 +- app/views/news/_course_form.html.erb | 4 ++++ app/views/news/_course_news_list.html.erb | 3 +++ app/views/news/_course_show.html.erb | 3 +++ app/views/users/_course_news.html.erb | 6 +++++- db/migrate/20151112072948_add_news_sticky.rb | 9 +++++++++ db/schema.rb | 3 ++- public/stylesheets/courses.css | 2 +- public/stylesheets/new_user.css | 1 + 10 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20151112072948_add_news_sticky.rb diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index 5d83c1320..be2b44c06 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -74,10 +74,10 @@ class NewsController < ApplicationController @q = params[:subject] if params[:subject].nil? || params[:subject].blank? scope_order = scope.all(:include => [:author, :course], - :order => "#{News.table_name}.created_on DESC") + :order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC") else scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").all(:include => [:author, :course], - :order => "#{News.table_name}.created_on DESC") + :order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC") end # :offset => @offset, diff --git a/app/models/news.rb b/app/models/news.rb index a9e9d1d18..e9b8b5314 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -66,7 +66,7 @@ class News < ActiveRecord::Base scope :course_visible, lambda {|*args| includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_news, *args)) } - safe_attributes 'title', 'summary', 'description' + safe_attributes 'title', 'summary', 'description', 'sticky' def visible?(user=User.current) !user.nil? && user.allowed_to?(:view_news, project) diff --git a/app/views/news/_course_form.html.erb b/app/views/news/_course_form.html.erb index 0a5488714..a51b85870 100644 --- a/app/views/news/_course_form.html.erb +++ b/app/views/news/_course_form.html.erb @@ -4,6 +4,10 @@

+
  • + <%= f.check_box :sticky, :value => is_new ? 0 : @news.sticky %> + <%= label_tag 'news_sticky', l(:label_board_sticky) %> +
  • <% if is_new %> <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> diff --git a/app/views/news/_course_news_list.html.erb b/app/views/news/_course_news_list.html.erb index 74a70e33d..3db222f25 100644 --- a/app/views/news/_course_news_list.html.erb +++ b/app/views/news/_course_news_list.html.erb @@ -13,6 +13,9 @@ <%= l(:label_release_news) %>: <%= link_to h(news.title), news_path(news),:class => 'problem_tit fl fb c_dblue' %> + <% if news.sticky == 1%> + 置顶 + <% end%> <%=link_to "#{news.comments.all.count}".html_safe, news_path(news.id), :class => "pro_mes_w" %>
    diff --git a/app/views/news/_course_show.html.erb b/app/views/news/_course_show.html.erb index 2d8dae59d..34e6e943f 100644 --- a/app/views/news/_course_show.html.erb +++ b/app/views/news/_course_show.html.erb @@ -8,6 +8,9 @@

    <%=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) %> diff --git a/app/views/users/_course_news.html.erb b/app/views/users/_course_news.html.erb index f9087f057..475a982e5 100644 --- a/app/views/users/_course_news.html.erb +++ b/app/views/users/_course_news.html.erb @@ -12,9 +12,13 @@ <% end %> TO <%= link_to activity.course.name.to_s+" | 课程通知", course_news_index_path(activity.course), :class => "newsBlue ml15" %> -
    + + <% if activity.sticky == 1%> + 置顶 + <% end%> +
    发布时间:<%= format_time(activity.created_on) %>
    diff --git a/db/migrate/20151112072948_add_news_sticky.rb b/db/migrate/20151112072948_add_news_sticky.rb new file mode 100644 index 000000000..85001debe --- /dev/null +++ b/db/migrate/20151112072948_add_news_sticky.rb @@ -0,0 +1,9 @@ +class AddNewsSticky < ActiveRecord::Migration + def up + add_column :news, :sticky, :integer, :default => 0 + end + + def down + remove_column :news, :sticky + end +end diff --git a/db/schema.rb b/db/schema.rb index 7898b3f4d..419b30c3e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151109080256) do +ActiveRecord::Schema.define(:version => 20151112072948) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -953,6 +953,7 @@ ActiveRecord::Schema.define(:version => 20151109080256) do t.datetime "created_on" t.integer "comments_count", :default => 0, :null => false t.integer "course_id" + t.integer "sticky", :default => 0 end add_index "news", ["author_id"], :name => "index_news_on_author_id" diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index 0cb6e203f..05bba54f6 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -555,7 +555,6 @@ a:hover.st_add{ color:#ff8e15;} a.link_file{ background:url(../images/pic_file.png) 0 2px no-repeat; padding-left:20px; } a:hover.link_file{ background:url(../images/pic_file.png) 0 -25px no-repeat; color:#3ca5c6;} -.r_txt_tit{width:510px; overflow:hidden; white-space: nowrap; text-overflow:ellipsis;color:#15bccf; float:left; color:#09658c; font-size:14px;} blockquote {background: #e8e8e8;padding: 10px;margin-bottom: 5px;word-break: break-all;word-wrap: break-word;} .respond-form{display: none;margin: auto;clear: both;} @@ -987,6 +986,7 @@ a:hover.icon_remove{background:url(../images/course/icons.png) -20px -338px no-r .m_w505{max-width: 505px;} .m_w500{max-width: 500px;} .m_w530{max-width: 530px;} +.m_w600{max-width: 600px;} .ProResultTable{ color:#888888;} .T_C{ text-align:center;} .SearchIcon{background:url(../images/homepage_icon2.png) 676px -393px no-repeat; } diff --git a/public/stylesheets/new_user.css b/public/stylesheets/new_user.css index ea45fdbd0..490de9e08 100644 --- a/public/stylesheets/new_user.css +++ b/public/stylesheets/new_user.css @@ -1082,6 +1082,7 @@ a:hover.icon_remove{background:url(../images/course/icons.png) -20px -338px no-r .m_w460{max-width: 460px;} .m_w505{max-width: 505px;} .m_w530{max-width: 530px;} +.m_w600{max-width: 600px;} .ProResultTable{ color:#888888;} .T_C{ text-align:center;} .SearchIcon{background:url(../images/homepage_icon2.png) 676px -393px no-repeat; }