diff --git a/TODO.todo b/TODO.todo index 29aa30cd0c..0c33e2caf7 100644 --- a/TODO.todo +++ b/TODO.todo @@ -4,7 +4,6 @@ neuro for 6.0.10: Editor: - Add the media back into the editor. – Change the permalink behavior, that one is definitely stupid. RLY. - - Add per state filter in post listing. - Fix pagination display Typogarden: diff --git a/app/controllers/admin/content_controller.rb b/app/controllers/admin/content_controller.rb index 3cf9ffdade..2dd86729c5 100644 --- a/app/controllers/admin/content_controller.rb +++ b/app/controllers/admin/content_controller.rb @@ -13,7 +13,8 @@ def auto_complete_for_article_keywords def index @search = params[:search] ? params[:search] : {} - @articles = Article.search_no_draft_paginate(@search, {:page => params[:page], :per_page => this_blog.admin_display_elements}) + + @articles = Article.search_with_pagination(@search, {:page => params[:page], :per_page => this_blog.admin_display_elements}) if request.xhr? render :partial => 'article_list', :locals => { :articles => @articles } diff --git a/app/helpers/admin/base_helper.rb b/app/helpers/admin/base_helper.rb index fe2c39ba40..dc9f4617e5 100644 --- a/app/helpers/admin/base_helper.rb +++ b/app/helpers/admin/base_helper.rb @@ -206,8 +206,11 @@ def link_to_published(item) end def published_or_not(item) - return "#{_("Published")}" if item.published - "#{_("Unpublished")}" + puts item.state + return "#{_("Published")}" if item.state.to_s.downcase == 'published' + return "#{_("Draft")}" if item.state.to_s.downcase == 'draft' + return "#{_("Withdrawn")}" if item.state.to_s.downcase == 'withdrawn' + return "#{_("Publication pending")}" if item.state.to_s.downcase == 'publicationpending' end def macro_help_popup(macro, text) diff --git a/app/models/article.rb b/app/models/article.rb index 228f8d2a4c..23b12a7a1e 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -56,6 +56,8 @@ def spam scope :without_parent, {:conditions => {:parent_id => nil}} scope :child_of, lambda { |article_id| {:conditions => {:parent_id => article_id}} } scope :published, lambda { { :conditions => { :published => true, :published_at => Time.at(0)..Time.now }, :order => 'published_at DESC' } } + scope :pending, lambda { { :conditions => ['state = ? and published_at > ?', 'publication_pending', Time.now], :order => 'published_at DESC' } } + scope :withdrawn, lambda { { :conditions => { :state => 'withdrawn' }, :order => 'published_at DESC' } } scope :published_at, lambda {|time_params| { :conditions => { :published => true, :published_at => Article.time_delta(*time_params) }, :order => 'published_at DESC' } } setting :password, :string, '' @@ -97,8 +99,12 @@ def last_draft(article_id) article end - def search_no_draft_paginate(search_hash, paginate_hash) - list_function = ["Article.no_draft"] + function_search_no_draft(search_hash) + def search_with_pagination(search_hash, paginate_hash) + + state = (search_hash[:state] and ["no_draft", "drafts", "published", "withdrawn", "pending"].include? search_hash[:state]) ? search_hash[:state] : 'no_draft' + + + list_function = ["Article.#{state}"] + function_search_no_draft(search_hash) if search_hash[:category] and search_hash[:category].to_i > 0 list_function << 'category(search_hash[:category])' diff --git a/app/views/admin/content/_drafts.html.erb b/app/views/admin/content/_drafts.html.erb deleted file mode 100644 index ee609caeb6..0000000000 --- a/app/views/admin/content/_drafts.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -
-

<%= _("Drafts")%>

-
- <% Article.drafts.all.each do |draft| %> - <%= link_to("#{draft.title},", :action => 'edit', :id => draft.id) %> - <% end %> -
-
diff --git a/app/views/admin/content/index.html.erb b/app/views/admin/content/index.html.erb index 4a9effa4c4..16178c6c1b 100644 --- a/app/views/admin/content/index.html.erb +++ b/app/views/admin/content/index.html.erb @@ -8,15 +8,24 @@ :complete => "Element.hide('spinner')" \ do %> -<%#= render 'drafts' unless Article.drafts.empty? %> - - + + + diff --git a/spec/controllers/admin/content_controller_spec.rb b/spec/controllers/admin/content_controller_spec.rb index 30eb030c83..a8ac1689c2 100644 --- a/spec/controllers/admin/content_controller_spec.rb +++ b/spec/controllers/admin/content_controller_spec.rb @@ -33,6 +33,53 @@ response.should be_success end + it 'should restrict to drafts' do + article = Factory(:article, :state => 'draft') + get :index, :search => {:state => 'drafts'} + assigns(:articles).should == [article] + response.should render_template('index') + response.should be_success + end + + it 'should restrict to publication pending articles' do + article = Factory(:article, :state => 'publication_pending', :published_at => '2020-01-01') + get :index, :search => {:state => 'pending'} + assigns(:articles).should == [article] + response.should render_template('index') + response.should be_success + end + + it 'should restrict to withdrawn articles' do + article = Factory(:article, :state => 'withdrawn', :published_at => '2010-01-01') + get :index, :search => {:state => 'withdrawn'} + assigns(:articles).should == [article] + response.should render_template('index') + response.should be_success + end + + it 'should restrict to withdrawn articles' do + article = Factory(:article, :state => 'withdrawn', :published_at => '2010-01-01') + get :index, :search => {:state => 'withdrawn'} + assigns(:articles).should == [article] + response.should render_template('index') + response.should be_success + end + + it 'should restrict to published articles' do + article = Factory(:article, :state => 'published', :published_at => '2010-01-01') + get :index, :search => {:state => 'published'} + response.should render_template('index') + response.should be_success + end + + it 'should fallback to default behavior' do + article = Factory(:article, :state => 'draft') + get :index, :search => {:state => '3vI1 1337 h4x0r'} + response.should render_template('index') + assigns(:articles).should_not == [article] + response.should be_success + end + end shared_examples_for 'autosave action' do
+ <%= submit_tag(_("Search"), {:class => 'btn'}) %> +
+ <%= collection_select_with_current('search', 'category', Category.all, "id", "name", @search[:category].to_i, true) %>