Sha256: 8dd53c711c4b6ffe6700b26919bfc5f70fe18803450f5760683b7d739091356c
Contents?: true
Size: 1.78 KB
Versions: 14
Compression:
Stored size: 1.78 KB
Contents
# frozen_string_literal: true module PagesCore module Admin module NewsPageController extend ActiveSupport::Concern included do before_action :require_news_pages, only: [:news] before_action :find_news_pages, only: %i[news new_news] before_action :find_year_and_month, only: %i[news] end def news @archive_finder = archive_finder(@news_pages, @locale) unless @year redirect_to(news_admin_pages_path(@locale, (@archive_finder.latest_year || Time.zone.now.year))) return end @pages = @archive_finder.by_year_and_maybe_month(@year, @month) .paginate(per_page: 50, page: params[:page]) end def new_news new render action: :new end private def archive_finder(parents, locale) Page.where(parent_page_id: parents) .visible .order("published_at DESC") .in_locale(locale) .archive_finder end def find_news_pages @news_pages = Page.news_pages .in_locale(@locale) .reorder("parent_page_id ASC, position ASC") return if @news_pages.any? redirect_to(admin_pages_url(@locale)) end def find_year_and_month @year = params[:year]&.to_i @month = params[:month]&.to_i end # Redirect away if no news pages has been configured def require_news_pages return if Page.news_pages.any? redirect_to(admin_pages_url(@locale)) end def latest_year archive_finder.latest_year_and_month.first || Time.zone.now.year end end end end
Version data entries
14 entries across 14 versions & 1 rubygems