From e90a237a8afa083cc078fde92f9aabf7b711dcca Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Thu, 7 Jan 2016 15:09:09 +0800 Subject: [PATCH] =?UTF-8?q?2.1=E5=8D=9A=E5=AE=A2=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E2=80=9C=E8=AE=BE=E4=B8=BA=E4=B8=BB=E9=A1=B5=E2=80=9D=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/blogs_controller.rb | 14 +++++- app/views/blogs/_article.html.erb | 8 +++ app/views/blogs/_article_list.html.erb | 6 +++ app/views/blogs/_homepage.html.erb | 50 +++++++++++++++++++ config/locales/zh.yml | 2 + config/routes.rb | 2 + ...20160107050736_add_homepage_id_to_blogs.rb | 5 ++ db/schema.rb | 26 +++++++++- 8 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 app/views/blogs/_homepage.html.erb create mode 100644 db/migrate/20160107050736_add_homepage_id_to_blogs.rb diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 07bf60464..0202224ed 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -1,5 +1,5 @@ class BlogsController < ApplicationController - before_filter :find_blog,:except => [:index,:create,:new] + before_filter :find_blog,:except => [:index,:create,:new,:set_homepage, :cancel_homepage] before_filter :find_user def index @articls = @user.blog.articles @@ -26,6 +26,18 @@ class BlogsController < ApplicationController def edit end + + def set_homepage + @blog = Blog.find(params[:id]) + @blog.update_attribute(:homepage_id, params[:article_id]) + redirect_to user_blogs_path(params[:user_id]) + end + + def cancel_homepage + @blog = Blog.find(params[:id]) + @blog.update_attribute(:homepage_id, nil) + redirect_to user_blogs_path(params[:user_id]) + end private def find_blog if params[:blog_id] diff --git a/app/views/blogs/_article.html.erb b/app/views/blogs/_article.html.erb index 99c743a96..cd701d804 100644 --- a/app/views/blogs/_article.html.erb +++ b/app/views/blogs/_article.html.erb @@ -25,6 +25,14 @@ :class => 'postOptionLink' ) if User.current && User.current.id == activity.author.id %> +
  • + <%= link_to( + l(:button_set_homepage), + {:controller => 'blogs',:action => 'set_homepage',:user_id=>activity.author_id,:id=>activity.blog_id, :article_id => activity.id}, + :method => :post, + :class => 'postOptionLink' + ) if User.current && User.current.id == activity.blog.author_id %> +
  • diff --git a/app/views/blogs/_article_list.html.erb b/app/views/blogs/_article_list.html.erb index 62f1391b0..6c206c75d 100644 --- a/app/views/blogs/_article_list.html.erb +++ b/app/views/blogs/_article_list.html.erb @@ -42,6 +42,12 @@ <%= @user.name%>的博客 + + <% if blog.homepage_id and BlogComment.where("id=?", blog.homepage_id).count > 0 %> + <% homepage = BlogComment.find(blog.homepage_id) %> + <%= render :partial => 'blogs/homepage', :locals => {:activity => homepage, :user_activity_id => homepage.id} %> + <% end %> + <% if User.current.logged? && User.current.id == @user.id %> <%= labelled_form_for @article, :url =>{:controller=>'blog_comments',:action => 'create',:user_id=>user.id , :blog_id => blog.id}, :html => {:nhname=>'form',:multipart => true, :id => 'message-form'} do |f| %> diff --git a/app/views/blogs/_homepage.html.erb b/app/views/blogs/_homepage.html.erb new file mode 100644 index 000000000..a4059fc33 --- /dev/null +++ b/app/views/blogs/_homepage.html.erb @@ -0,0 +1,50 @@ +
    +
    +
    + <% if activity.author.id == User.current.id%> + + <%end%> +
    + +
    + <%= activity.content.to_s.html_safe %> +
    +
    +
    +
    +
    +
    diff --git a/config/locales/zh.yml b/config/locales/zh.yml index e4a23373d..f68a75e0e 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -901,6 +901,8 @@ zh: button_test: 测试 button_edit: 编辑 button_delete: 删除 + button_set_homepage: 设为首页 + button_cancel_homepage: 取消首页 button_edit_associated_wikipage: "编辑相关wiki页面: %{page_title}" button_add: 新增 button_change: 修改 diff --git a/config/routes.rb b/config/routes.rb index 37eda17e9..42af87dfc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -554,6 +554,8 @@ RedmineApp::Application.routes.draw do #消息 match 'users/:id/user_messages', :to => 'users#user_messages', :via => :get, :as => "user_message" match 'users/:id/user_system_messages', :to => 'users#user_system_messages', :via => :get, :as => "user_system_messages" + match 'set_homepage', :to => 'blogs#set_homepage', :via => :post + match 'cancel_homepage', :to => 'blogs#cancel_homepage', :via => :post #match 'users/:id/user_messages/:homework', :to => 'users#user_messages_homework', :via => :get, :as => "user_message_homewrok" diff --git a/db/migrate/20160107050736_add_homepage_id_to_blogs.rb b/db/migrate/20160107050736_add_homepage_id_to_blogs.rb new file mode 100644 index 000000000..1a3c919ab --- /dev/null +++ b/db/migrate/20160107050736_add_homepage_id_to_blogs.rb @@ -0,0 +1,5 @@ +class AddHomepageIdToBlogs < ActiveRecord::Migration + def change + add_column :blogs, :homepage_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index c9f50170c..76adfc71c 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 => 20160106065255) do +ActiveRecord::Schema.define(:version => 20160107050736) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -80,6 +80,27 @@ ActiveRecord::Schema.define(:version => 20160106065255) do add_index "at_messages", ["user_id"], :name => "index_at_messages_on_user_id" + create_table "attachment_histories", :force => true do |t| + t.integer "container_id" + t.string "container_type" + t.string "filename", :default => "" + t.string "disk_filename", :default => "" + t.integer "filesize", :default => 0 + t.string "content_type", :default => "" + t.string "digest", :limit => 40, :default => "" + t.integer "downloads", :default => 0 + t.integer "author_id" + t.datetime "created_on" + t.string "description" + t.string "disk_directory" + t.integer "attachtype" + t.integer "is_public" + t.integer "copy_from" + t.integer "quotes" + t.integer "version" + t.integer "attachment_id" + end + create_table "attachments", :force => true do |t| t.integer "container_id" t.string "container_type", :limit => 30 @@ -186,6 +207,7 @@ ActiveRecord::Schema.define(:version => 20160106065255) do t.integer "author_id" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.integer "homepage_id" end create_table "boards", :force => true do |t| @@ -475,6 +497,8 @@ ActiveRecord::Schema.define(:version => 20160106065255) do t.integer "outline", :default => 0 t.integer "publish_resource", :default => 0 t.integer "is_delete", :default => 0 + t.integer "end_time" + t.string "end_term" end create_table "custom_fields", :force => true do |t|