docbrown/app/controllers/internal/articles_controller.rb
Ben Halpern 2771a2e866
Add Algolia to comments, modify button styles, add comments tab to reading list area (#32)
* Add Algolia to search and add Only My Posts filter

* Actually fix Algolia index possible issue

* Fix search issue

* Make minor adjustments to sponsorship sidebar

* Make submission rules headsup html allowed and remove devise trackable

* Remove devise_trackable from application_controller

* Adjust login CTA for /new

* Adjust string in test to reflect changes

* Quick fix for internal navigatioon draft caching issue

* Add ID to internal/articles

* Fix auth with Twitter in two places

* Added comments to algolia and modified design

* Update sidebar styles and make other small adjustments

* Clean up tag styling and other small improvements

* Finalize design adjustments

* Add indexing condition for comments

* Fix Algolia typo

* Fix Algolia indexing on comment
2018-03-04 22:25:08 -05:00

104 lines
3 KiB
Ruby

class Internal::ArticlesController < Internal::ApplicationController
layout "internal"
def index
case params[:state]
when "by-featured-number"
@articles = Article.
where(published: true).
includes(:user).
order("featured_number DESC").
page(params[:page]).
limited_columns_internal_select.
per(50)
when "unfeatured-by-published"
@articles = Article.
where(featured: false, published: true).
includes(:user).
order("published_at DESC").
page(params[:page]).
limited_columns_internal_select.
per(50)
when "rss"
@articles = Article.
where(published_from_feed: true).
includes(:user).
order("created_at DESC").
page(params[:page]).
limited_columns_internal_select.
per(50)
when "rss-recent"
@articles = Article.
where(published_from_feed: true).
includes(:user).
order("published_at DESC").
page(params[:page]).
limited_columns_internal_select.
per(50)
when "spam"
@articles = Article.
where(published: true).
where("spaminess_rating > ?", 10).
includes(:user).
order("published_at DESC").
page(params[:page]).
limited_columns_internal_select.
per(50)
when /top\-/
@articles = Article.
where("published_at > ?", params[:state].split("-")[1].to_i.months.ago).
includes(:user).
order("positive_reactions_count DESC").
page(params[:page]).
limited_columns_internal_select.
per(50)
else #MIX
@articles = Article.
where(published: true).
order("published_at DESC").
page(params[:page]).
limited_columns_internal_select.
per(50)
@featured_articles = Article.
where(published: true).
or(Article.where(published_from_feed: true)).
where(featured: true).
where("featured_number > ?", Time.now.to_i).
includes(:user).
limited_columns_internal_select.
order("featured_number DESC")
end
end
def show
@article = Article.find(params[:id])
end
def update
article = Article.find(params[:id])
article.featured = article_params[:featured].to_s == "true"
article.approved = article_params[:approved].to_s == "true"
article.live_now = article_params[:live_now].to_s == "true"
article.update!(article_params)
if article.live_now
Article.where.not(id: article.id).where(live_now: true).update_all(live_now: false)
end
CacheBuster.new.bust "/live_articles"
# raise
render body: nil
# redirect_to "/internal/articles"
end
private
def article_params
params.require(:article).permit(:featured,
:social_image,
:approved,
:live_now,
:main_image_background_hex_color,
:featured_number)
end
end