2.1博客增加“设为主页”的功能

This commit is contained in:
ouyangxuhua 2016-01-07 15:09:09 +08:00
parent 80668d6a47
commit e90a237a8a
8 changed files with 111 additions and 2 deletions

View File

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

View File

@ -25,6 +25,14 @@
:class => 'postOptionLink'
) if User.current && User.current.id == activity.author.id %>
</li>
<li>
<%= 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 %>
</li>
</ul>
</li>
</ul>

View File

@ -42,6 +42,12 @@
<%= @user.name%>的博客
</div>
</div>
<% 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| %>

View File

@ -0,0 +1,50 @@
<div class="resources mt10" id="user_activity_<%= user_activity_id%>" >
<div class="homepagePostBrief" onmouseover="$('#message_setting_<%=activity.id%>').show();" onmouseout="$('#message_setting_<%= activity.id%>').hide();">
<div class="homepagePostDes">
<% if activity.author.id == User.current.id%>
<div class="homepagePostSetting" id="message_setting_<%= activity.id%>" style="display: none">
<ul>
<li class="homepagePostSettingIcon">
<ul class="homepagePostSettiongText">
<li>
<%= link_to(
l(:button_edit),
{:controller => 'blog_comments',:action => 'edit',:user_id=>activity.author_id,:blog_id=>activity.blog_id, :id => activity.id},
:class => 'postOptionLink'
) if User.current && User.current.id == activity.author.id %>
</li>
<li>
<%= link_to(
l(:button_delete),
{:controller => 'blog_comments',:action => 'destroy',:user_id=>activity.author_id,:blog_id=>activity.blog_id, :id => activity.id},
:method => :delete,
:data => {:confirm => l(:text_are_you_sure)},
:class => 'postOptionLink'
) if User.current && User.current.id == activity.author.id %>
</li>
<li>
<%= link_to(
l(:button_cancel_homepage),
{:controller => 'blogs',:action => 'cancel_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 %>
</li>
</ul>
</li>
</ul>
</div>
<%end%>
<div class="cl"></div>
<div class="homepagePostTitle hidden m_w530 fl">
<%= link_to activity.title.to_s.html_safe, user_blog_blog_comment_path(:user_id=>activity.author_id,
:blog_id=>activity.blog.id,:id=>activity), :class=> "postGrey", :style => 'text-align:center;' %>
</div>
<div class="homepagePostIntro break_word upload_img list_style maxh360 lh18 table_maxWidth" >
<%= activity.content.to_s.html_safe %>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
</div>
</div>

View File

@ -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: 修改

View File

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

View File

@ -0,0 +1,5 @@
class AddHomepageIdToBlogs < ActiveRecord::Migration
def change
add_column :blogs, :homepage_id, :integer
end
end

View File

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