From 3fa8937b95a4d90000ad1be9c588424052136455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=A3is=20Ozols?= Date: Wed, 27 Jul 2011 13:46:24 +0300 Subject: Rails 3.1 - wip. --- .../admin/blog/categories_controller.rb | 11 --- app/controllers/admin/blog/comments_controller.rb | 40 -------- app/controllers/admin/blog/posts_controller.rb | 97 ------------------- app/controllers/admin/blog/settings_controller.rb | 53 ---------- app/controllers/blog/categories_controller.rb | 13 --- app/controllers/blog/posts_controller.rb | 105 -------------------- app/controllers/blog_controller.rb | 16 --- .../refinery/admin/blog/categories_controller.rb | 13 +++ .../refinery/admin/blog/comments_controller.rb | 42 ++++++++ .../refinery/admin/blog/posts_controller.rb | 99 +++++++++++++++++++ .../refinery/admin/blog/settings_controller.rb | 55 +++++++++++ .../refinery/blog/categories_controller.rb | 15 +++ app/controllers/refinery/blog/posts_controller.rb | 107 +++++++++++++++++++++ app/controllers/refinery/blog_controller.rb | 18 ++++ 14 files changed, 349 insertions(+), 335 deletions(-) delete mode 100644 app/controllers/admin/blog/categories_controller.rb delete mode 100644 app/controllers/admin/blog/comments_controller.rb delete mode 100644 app/controllers/admin/blog/posts_controller.rb delete mode 100644 app/controllers/admin/blog/settings_controller.rb delete mode 100644 app/controllers/blog/categories_controller.rb delete mode 100644 app/controllers/blog/posts_controller.rb delete mode 100644 app/controllers/blog_controller.rb create mode 100644 app/controllers/refinery/admin/blog/categories_controller.rb create mode 100644 app/controllers/refinery/admin/blog/comments_controller.rb create mode 100644 app/controllers/refinery/admin/blog/posts_controller.rb create mode 100644 app/controllers/refinery/admin/blog/settings_controller.rb create mode 100644 app/controllers/refinery/blog/categories_controller.rb create mode 100644 app/controllers/refinery/blog/posts_controller.rb create mode 100644 app/controllers/refinery/blog_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/admin/blog/categories_controller.rb b/app/controllers/admin/blog/categories_controller.rb deleted file mode 100644 index 6933c44..0000000 --- a/app/controllers/admin/blog/categories_controller.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Admin - module Blog - class CategoriesController < Admin::BaseController - - crudify :blog_category, - :title_attribute => :title, - :order => 'title ASC' - - end - end -end diff --git a/app/controllers/admin/blog/comments_controller.rb b/app/controllers/admin/blog/comments_controller.rb deleted file mode 100644 index 1868206..0000000 --- a/app/controllers/admin/blog/comments_controller.rb +++ /dev/null @@ -1,40 +0,0 @@ -module Admin - module Blog - class CommentsController < Admin::BaseController - - crudify :blog_comment, - :title_attribute => :name, - :order => 'published_at DESC' - - def index - @blog_comments = BlogComment.unmoderated - render :action => 'index' - end - - def approved - unless params[:id].present? - @blog_comments = BlogComment.approved - render :action => 'index' - else - @blog_comment = BlogComment.find(params[:id]) - @blog_comment.approve! - flash[:notice] = t('approved', :scope => 'admin.blog.comments', :author => @blog_comment.name) - redirect_to :action => params[:return_to] || 'index' - end - end - - def rejected - unless params[:id].present? - @blog_comments = BlogComment.rejected - render :action => 'index' - else - @blog_comment = BlogComment.find(params[:id]) - @blog_comment.reject! - flash[:notice] = t('rejected', :scope => 'admin.blog.comments', :author => @blog_comment.name) - redirect_to :action => params[:return_to] || 'index' - end - end - - end - end -end \ No newline at end of file diff --git a/app/controllers/admin/blog/posts_controller.rb b/app/controllers/admin/blog/posts_controller.rb deleted file mode 100644 index c8dfc13..0000000 --- a/app/controllers/admin/blog/posts_controller.rb +++ /dev/null @@ -1,97 +0,0 @@ -module Admin - module Blog - class PostsController < Admin::BaseController - - - crudify :blog_post, - :title_attribute => :title, - :order => 'published_at DESC' - - def uncategorized - @blog_posts = BlogPost.uncategorized.paginate({ - :page => params[:page], - :per_page => BlogPost.per_page - }) - end - - def tags - op = case ActiveRecord::Base.connection.adapter_name.downcase - when 'postgresql' - '~*' - else - 'LIKE' - end - wildcard = case ActiveRecord::Base.connection.adapter_name.downcase - when 'postgresql' - '.*' - else - '%' - end - @tags = BlogPost.tag_counts_on(:tags).where( - ["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"] - ).map { |tag| {:id => tag.id, :value => tag.name}} - render :json => @tags.flatten - end - - def create - # if the position field exists, set this object as last object, given the conditions of this class. - if BlogPost.column_names.include?("position") - params[:blog_post].merge!({ - :position => ((BlogPost.maximum(:position, :conditions => "")||-1) + 1) - }) - end - - if BlogPost.column_names.include?("user_id") - params[:blog_post].merge!({ - :user_id => current_user.id - }) - end - - if (@blog_post = BlogPost.create(params[:blog_post])).valid? - (request.xhr? ? flash.now : flash).notice = t( - 'refinery.crudify.created', - :what => "'#{@blog_post.title}'" - ) - - unless from_dialog? - unless params[:continue_editing] =~ /true|on|1/ - redirect_back_or_default(admin_blog_posts_url) - else - unless request.xhr? - redirect_to :back - else - render :partial => "/shared/message" - end - end - else - render :text => "" - end - else - unless request.xhr? - render :action => 'new' - else - render :partial => "/shared/admin/error_messages", - :locals => { - :object => @blog_post, - :include_object_name => true - } - end - end - end - - before_filter :find_all_categories, - :only => [:new, :edit, :create, :update] - - before_filter :check_category_ids, :only => :update - - protected - def find_all_categories - @blog_categories = BlogCategory.find(:all) - end - - def check_category_ids - params[:blog_post][:category_ids] ||= [] - end - end - end -end \ No newline at end of file diff --git a/app/controllers/admin/blog/settings_controller.rb b/app/controllers/admin/blog/settings_controller.rb deleted file mode 100644 index 5f2b3be..0000000 --- a/app/controllers/admin/blog/settings_controller.rb +++ /dev/null @@ -1,53 +0,0 @@ -module Admin - module Blog - class SettingsController < Admin::BaseController - - def notification_recipients - @recipients = BlogComment::Notification.recipients - - if request.post? - BlogComment::Notification.recipients = params[:recipients] - flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients', - :recipients => BlogComment::Notification.recipients) - unless request.xhr? or from_dialog? - redirect_back_or_default(admin_blog_posts_path) - else - render :text => "", - :layout => false - end - end - end - - def moderation - enabled = BlogComment::Moderation.toggle! - unless request.xhr? - redirect_back_or_default(admin_blog_posts_path) - else - render :json => {:enabled => enabled}, - :layout => false - end - end - - def comments - enabled = BlogComment.toggle! - unless request.xhr? - redirect_back_or_default(admin_blog_posts_path) - else - render :json => {:enabled => enabled}, - :layout => false - end - end - - def teasers - enabled = BlogPost.teaser_enabled_toggle! - unless request.xhr? - redirect_back_or_default(admin_blog_posts_path) - else - render :json => {:enabled => enabled}, - :layout => false - end - end - - end - end -end \ No newline at end of file diff --git a/app/controllers/blog/categories_controller.rb b/app/controllers/blog/categories_controller.rb deleted file mode 100644 index efda778..0000000 --- a/app/controllers/blog/categories_controller.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Blog - class CategoriesController < BlogController - - def show - @category = BlogCategory.find(params[:id]) - @blog_posts = @category.posts.live.includes(:comments, :categories).paginate({ - :page => params[:page], - :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10) - }) - end - - end -end \ No newline at end of file diff --git a/app/controllers/blog/posts_controller.rb b/app/controllers/blog/posts_controller.rb deleted file mode 100644 index edac5ab..0000000 --- a/app/controllers/blog/posts_controller.rb +++ /dev/null @@ -1,105 +0,0 @@ -module Blog - class PostsController < BlogController - - before_filter :find_all_blog_posts, :except => [:archive] - before_filter :find_blog_post, :only => [:show, :comment, :update_nav] - before_filter :find_tags - - respond_to :html, :js, :rss - - def index - # Rss feeders are greedy. Let's give them every blog post instead of paginating. - (@blog_posts = BlogPost.live.includes(:comments, :categories).all) if request.format.rss? - respond_with (@blog_posts) do |format| - format.html - format.rss - end - end - - def show - @blog_comment = BlogComment.new - - respond_with (@blog_post) do |format| - format.html { present(@blog_post) } - format.js { render :partial => 'post', :layout => false } - end - end - - def comment - if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid? - if BlogComment::Moderation.enabled? or @blog_comment.ham? - begin - Blog::CommentMailer.notification(@blog_comment, request).deliver - rescue - logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n" - end - end - - if BlogComment::Moderation.enabled? - flash[:notice] = t('thank_you_moderated', :scope => 'blog.posts.comments') - redirect_to blog_post_url(params[:id]) - else - flash[:notice] = t('thank_you', :scope => 'blog.posts.comments') - redirect_to blog_post_url(params[:id], - :anchor => "comment-#{@blog_comment.to_param}") - end - else - render :action => 'show' - end - end - - def archive - if params[:month].present? - date = "#{params[:month]}/#{params[:year]}" - @archive_date = Time.parse(date) - @date_title = @archive_date.strftime('%B %Y') - @blog_posts = BlogPost.live.by_archive(@archive_date).paginate({ - :page => params[:page], - :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10) - }) - else - date = "01/#{params[:year]}" - @archive_date = Time.parse(date) - @date_title = @archive_date.strftime('%Y') - @blog_posts = BlogPost.live.by_year(@archive_date).paginate({ - :page => params[:page], - :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10) - }) - end - respond_with (@blog_posts) - end - - def tagged - @tag = ActsAsTaggableOn::Tag.find(params[:tag_id]) - @tag_name = @tag.name - @blog_posts = BlogPost.tagged_with(@tag_name).paginate({ - :page => params[:page], - :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10) - }) - end - - protected - - def find_blog_post - unless (@blog_post = BlogPost.find(params[:id])).try(:live?) - if refinery_user? and current_user.authorized_plugins.include?("refinerycms_blog") - @blog_post = BlogPost.find(params[:id]) - else - error_404 - end - end - end - - def find_all_blog_posts - @blog_posts = BlogPost.live.includes(:comments, :categories).paginate({ - :page => params[:page], - :per_page => RefinerySetting.find_or_set(:blog_posts_per_page, 10) - }) - end - - def find_tags - @tags = BlogPost.tag_counts_on(:tags) - end - - end -end \ No newline at end of file diff --git a/app/controllers/blog_controller.rb b/app/controllers/blog_controller.rb deleted file mode 100644 index f51d5bb..0000000 --- a/app/controllers/blog_controller.rb +++ /dev/null @@ -1,16 +0,0 @@ -class BlogController < ApplicationController - - helper :blog_posts - before_filter :find_page, :find_all_blog_categories - -protected - - def find_page - @page = Page.find_by_link_url("/blog") - end - - def find_all_blog_categories - @blog_categories = BlogCategory.all - end - -end diff --git a/app/controllers/refinery/admin/blog/categories_controller.rb b/app/controllers/refinery/admin/blog/categories_controller.rb new file mode 100644 index 0000000..7196e8f --- /dev/null +++ b/app/controllers/refinery/admin/blog/categories_controller.rb @@ -0,0 +1,13 @@ +module Refinery + module Admin + module Blog + class CategoriesController < ::Admin::BaseController + + crudify :'refinery/blog_category', + :title_attribute => :title, + :order => 'title ASC' + + end + end + end +end diff --git a/app/controllers/refinery/admin/blog/comments_controller.rb b/app/controllers/refinery/admin/blog/comments_controller.rb new file mode 100644 index 0000000..9f78caa --- /dev/null +++ b/app/controllers/refinery/admin/blog/comments_controller.rb @@ -0,0 +1,42 @@ +module Refinery + module Admin + module Blog + class CommentsController < ::Admin::BaseController + + crudify :'refinery/blog_comment', + :title_attribute => :name, + :order => 'published_at DESC' + + def index + @blog_comments = Refinery::BlogComment.unmoderated + render :action => 'index' + end + + def approved + unless params[:id].present? + @blog_comments = Refinery::BlogComment.approved + render :action => 'index' + else + @blog_comment = Refinery::BlogComment.find(params[:id]) + @blog_comment.approve! + flash[:notice] = t('approved', :scope => 'admin.blog.comments', :author => @blog_comment.name) + redirect_to :action => params[:return_to] || 'index' + end + end + + def rejected + unless params[:id].present? + @blog_comments = Refinery::BlogComment.rejected + render :action => 'index' + else + @blog_comment = Refinery::BlogComment.find(params[:id]) + @blog_comment.reject! + flash[:notice] = t('rejected', :scope => 'admin.blog.comments', :author => @blog_comment.name) + redirect_to :action => params[:return_to] || 'index' + end + end + + end + end + end +end diff --git a/app/controllers/refinery/admin/blog/posts_controller.rb b/app/controllers/refinery/admin/blog/posts_controller.rb new file mode 100644 index 0000000..a934a15 --- /dev/null +++ b/app/controllers/refinery/admin/blog/posts_controller.rb @@ -0,0 +1,99 @@ +module Refinery + module Admin + module Blog + class PostsController < ::Admin::BaseController + + + crudify :'refinery/blog_post', + :title_attribute => :title, + :order => 'published_at DESC' + + def uncategorized + @blog_posts = Refinery::BlogPost.uncategorized.paginate({ + :page => params[:page], + :per_page => Refinery::BlogPost.per_page + }) + end + + def tags + op = case ActiveRecord::Base.connection.adapter_name.downcase + when 'postgresql' + '~*' + else + 'LIKE' + end + wildcard = case ActiveRecord::Base.connection.adapter_name.downcase + when 'postgresql' + '.*' + else + '%' + end + @tags = Refinery::BlogPost.tag_counts_on(:tags).where( + ["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"] + ).map { |tag| {:id => tag.id, :value => tag.name}} + render :json => @tags.flatten + end + + def create + # if the position field exists, set this object as last object, given the conditions of this class. + if Refinery::BlogPost.column_names.include?("position") + params[:blog_post].merge!({ + :position => ((Refinery::BlogPost.maximum(:position, :conditions => "")||-1) + 1) + }) + end + + if Refinery::BlogPost.column_names.include?("user_id") + params[:blog_post].merge!({ + :user_id => current_user.id + }) + end + + if (@blog_post = Refinery::BlogPost.create(params[:blog_post])).valid? + (request.xhr? ? flash.now : flash).notice = t( + 'refinery.crudify.created', + :what => "'#{@blog_post.title}'" + ) + + unless from_dialog? + unless params[:continue_editing] =~ /true|on|1/ + redirect_back_or_default(admin_blog_posts_url) + else + unless request.xhr? + redirect_to :back + else + render :partial => "/shared/message" + end + end + else + render :text => "" + end + else + unless request.xhr? + render :action => 'new' + else + render :partial => "/shared/admin/error_messages", + :locals => { + :object => @blog_post, + :include_object_name => true + } + end + end + end + + before_filter :find_all_categories, + :only => [:new, :edit, :create, :update] + + before_filter :check_category_ids, :only => :update + + protected + def find_all_categories + @blog_categories = Refinery::BlogCategory.find(:all) + end + + def check_category_ids + params[:blog_post][:category_ids] ||= [] + end + end + end + end +end diff --git a/app/controllers/refinery/admin/blog/settings_controller.rb b/app/controllers/refinery/admin/blog/settings_controller.rb new file mode 100644 index 0000000..469a1dc --- /dev/null +++ b/app/controllers/refinery/admin/blog/settings_controller.rb @@ -0,0 +1,55 @@ +module Refinery + module Admin + module Blog + class SettingsController < ::Admin::BaseController + + def notification_recipients + @recipients = Refinery::BlogComment::Notification.recipients + + if request.post? + Refinery::BlogComment::Notification.recipients = params[:recipients] + flash[:notice] = t('updated', :scope => 'admin.blog.settings.notification_recipients', + :recipients => Refinery::BlogComment::Notification.recipients) + unless request.xhr? or from_dialog? + redirect_back_or_default(admin_blog_posts_path) + else + render :text => "", + :layout => false + end + end + end + + def moderation + enabled = Refinery::BlogComment::Moderation.toggle! + unless request.xhr? + redirect_back_or_default(admin_blog_posts_path) + else + render :json => {:enabled => enabled}, + :layout => false + end + end + + def comments + enabled = Refinery::BlogComment.toggle! + unless request.xhr? + redirect_back_or_default(admin_blog_posts_path) + else + render :json => {:enabled => enabled}, + :layout => false + end + end + + def teasers + enabled = Refinery::BlogPost.teaser_enabled_toggle! + unless request.xhr? + redirect_back_or_default(admin_blog_posts_path) + else + render :json => {:enabled => enabled}, + :layout => false + end + end + + end + end + end +end diff --git a/app/controllers/refinery/blog/categories_controller.rb b/app/controllers/refinery/blog/categories_controller.rb new file mode 100644 index 0000000..2c8c4c5 --- /dev/null +++ b/app/controllers/refinery/blog/categories_controller.rb @@ -0,0 +1,15 @@ +module Refinery + module Blog + class CategoriesController < BlogController + + def show + @category = Refinery::BlogCategory.find(params[:id]) + @blog_posts = @category.posts.live.includes(:comments, :categories).paginate({ + :page => params[:page], + :per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10) + }) + end + + end + end +end diff --git a/app/controllers/refinery/blog/posts_controller.rb b/app/controllers/refinery/blog/posts_controller.rb new file mode 100644 index 0000000..bdf53f0 --- /dev/null +++ b/app/controllers/refinery/blog/posts_controller.rb @@ -0,0 +1,107 @@ +module Refinery + module Blog + class PostsController < BlogController + + before_filter :find_all_blog_posts, :except => [:archive] + before_filter :find_blog_post, :only => [:show, :comment, :update_nav] + before_filter :find_tags + + respond_to :html, :js, :rss + + def index + # Rss feeders are greedy. Let's give them every blog post instead of paginating. + (@blog_posts = Refinery::BlogPost.live.includes(:comments, :categories).all) if request.format.rss? + respond_with (@blog_posts) do |format| + format.html + format.rss + end + end + + def show + @blog_comment = Refinery::BlogComment.new + + respond_with (@blog_post) do |format| + format.html { present(@blog_post) } + format.js { render :partial => 'post', :layout => false } + end + end + + def comment + if (@blog_comment = @blog_post.comments.create(params[:blog_comment])).valid? + if Refinery::BlogComment::Moderation.enabled? or @blog_comment.ham? + begin + Refinery::Blog::CommentMailer.notification(@blog_comment, request).deliver + rescue + logger.warn "There was an error delivering a blog comment notification.\n#{$!}\n" + end + end + + if Refinery::BlogComment::Moderation.enabled? + flash[:notice] = t('thank_you_moderated', :scope => 'blog.posts.comments') + redirect_to blog_post_url(params[:id]) + else + flash[:notice] = t('thank_you', :scope => 'blog.posts.comments') + redirect_to blog_post_url(params[:id], + :anchor => "comment-#{@blog_comment.to_param}") + end + else + render :action => 'show' + end + end + + def archive + if params[:month].present? + date = "#{params[:month]}/#{params[:year]}" + @archive_date = Time.parse(date) + @date_title = @archive_date.strftime('%B %Y') + @blog_posts = BlogPost.live.by_archive(@archive_date).paginate({ + :page => params[:page], + :per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10) + }) + else + date = "01/#{params[:year]}" + @archive_date = Time.parse(date) + @date_title = @archive_date.strftime('%Y') + @blog_posts = Refinery::live.by_year(@archive_date).paginate({ + :page => params[:page], + :per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10) + }) + end + respond_with (@blog_posts) + end + + def tagged + @tag = ActsAsTaggableOn::Tag.find(params[:tag_id]) + @tag_name = @tag.name + @blog_posts = Refinery::BlogPost.tagged_with(@tag_name).paginate({ + :page => params[:page], + :per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10) + }) + end + + protected + + def find_blog_post + unless (@blog_post = Refinery::BlogPost.find(params[:id])).try(:live?) + if refinery_user? and current_user.authorized_plugins.include?("refinerycms_blog") + @blog_post = Refinery::BlogPost.find(params[:id]) + else + error_404 + end + end + end + + def find_all_blog_posts + @blog_posts = Refinery::BlogPost.live.includes(:comments, :categories).paginate({ + :page => params[:page], + :per_page => Refinery::Setting.find_or_set(:blog_posts_per_page, 10) + }) + end + + def find_tags + @tags = Refinery::BlogPost.tag_counts_on(:tags) + end + + end + end +end diff --git a/app/controllers/refinery/blog_controller.rb b/app/controllers/refinery/blog_controller.rb new file mode 100644 index 0000000..6bec0a5 --- /dev/null +++ b/app/controllers/refinery/blog_controller.rb @@ -0,0 +1,18 @@ +module Refinery + class BlogController < ::ApplicationController + + helper :blog_posts + before_filter :find_page, :find_all_blog_categories + + protected + + def find_page + @page = Refinery::Page.find_by_link_url("/blog") + end + + def find_all_blog_categories + @blog_categories = Refinery::BlogCategory.all + end + + end +end -- cgit v1.2.3