Sha256: 1a9f3cdfd1d96001955db7e836954a6885b6d568e6733bc56cf384ba982c4683

Contents?: true

Size: 881 Bytes

Versions: 14

Compression:

Stored size: 881 Bytes

Contents

# frozen_string_literal: true

module Admin
  module CalendarsHelper
    def calendar_pages(locale)
      Page.where(
        id: Page.with_dates.visible.pluck(:parent_page_id).uniq.compact
      ).in_locale(locale)
    end

    def calendar_page_options(locale)
      options_for_select(
        calendar_pages(locale).map do |p|
          [page_name(p, include_parents: true).gsub("»", "ยป"), p.id]
        end
      )
    end

    def calendar_years_with_count
      calendar_counts.each_with_object({}) do |entry, obj|
        obj[entry[:year]] ||= 0
        obj[entry[:year]] += entry[:count]
      end
    end

    def calendar_months_count(year)
      calendar_counts.filter { |e| e[:year] == year }
                     .map { |e| [e[:month], e[:count]] }
    end

    private

    def calendar_counts
      @calendar_counts ||= Page.count_by_month
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
pages_core-3.15.5 app/helpers/admin/calendars_helper.rb
pages_core-3.15.4 app/helpers/admin/calendars_helper.rb
pages_core-3.15.3 app/helpers/admin/calendars_helper.rb
pages_core-3.15.2 app/helpers/admin/calendars_helper.rb
pages_core-3.15.1 app/helpers/admin/calendars_helper.rb
pages_core-3.14.0 app/helpers/admin/calendars_helper.rb
pages_core-3.13.0 app/helpers/admin/calendars_helper.rb
pages_core-3.12.7 app/helpers/admin/calendars_helper.rb
pages_core-3.12.6 app/helpers/admin/calendars_helper.rb
pages_core-3.12.5 app/helpers/admin/calendars_helper.rb
pages_core-3.12.4 app/helpers/admin/calendars_helper.rb
pages_core-3.12.3 app/helpers/admin/calendars_helper.rb
pages_core-3.12.2 app/helpers/admin/calendars_helper.rb
pages_core-3.12.1 app/helpers/admin/calendars_helper.rb