socialforge/app/controllers/homepages_controller.rb

64 lines
2.1 KiB
Ruby

class HomepagesController < ApplicationController
before_filter :find_user
def index
if User.current.logged? && User.current == @user
@b_sort = params[:sort] || 1
@b_sort = @b_sort.to_i == 1 ? 2 : 1
sort_type = @b_sort == 1 ? "asc" : "desc"
if @user.base_homepage.nil?
@articles = @user.homepage.article_homepages.reorder("updated_at #{sort_type}")
else
@articles = @user.homepage.article_homepages.where("id != #{@user.base_homepage.id}").reorder("updated_at #{sort_type}").all
@articles.insert(0, @user.base_homepage) unless @user.base_homepage.nil?
end
@limit = 20
@is_remote = true
@atta_count = @articles.count
@atta_pages = Paginator.new @atta_count, @limit, params['page'] || 1
@offset ||= @atta_pages.offset
@articles = paginateHelper @articles,@limit
respond_to do |format|
format.js
format.html {render :layout=>'new_base_user'}
end
else
render_403
end
end
def show
end
def set_homepage
@homepage = Homepage.find(params[:id])
@homepage.update_attribute(:article_id, params[:article_id])
if @user.base_homepage.nil?
@articles = @user.homepage.article_homepages.reorder("updated_at desc")
else
@articles = @user.homepage.article_homepages.where("id != #{@user.base_homepage.id}").reorder("updated_at desc").all
@articles.insert(0, @user.base_homepage) unless @user.base_homepage.nil?
end
redirect_to user_homepages_path(:user_id => @user.id)
end
def cancel_homepage
@homepage = Homepage.find(params[:id])
@homepage.update_attribute(:article_id, nil)
if @user.base_homepage.nil?
@articles = @user.homepage.article_homepages.reorder("updated_at desc")
else
@articles = @user.homepage.article_homepages.where("id != #{@user.base_homepage.id}").reorder("updated_at desc").all
@articles.insert(0, @user.base_homepage) unless @user.base_homepage.nil?
end
redirect_to user_homepages_path(:user_id => @user.id)
end
private
def find_user
@user = User.find(params[:user_id])
end
end