Sha256: 312da6f6d7a075c3a49f5543cdc1e55bdc020b84b24e06fabc8ef00f93613ebb

Contents?: true

Size: 1.22 KB

Versions: 28

Compression:

Stored size: 1.22 KB

Contents

module Workarea
  module Admin
    class ReleaseCalendarViewModel < ApplicationViewModel

      def days
        @days ||= date_range.reduce({}) do |days, date|
          days.merge(date.strftime("%Y-%m-%d") => find_releases_for_date(date))
        end
      end

      def prev_week
        start_date - 1.week
      end

      def next_week
        start_date + 1.week
      end

      def weekdays
        date_range.slice(0, 7).map { |d| Date::ABBR_DAYNAMES[d.wday] }
      end

      def start_date
        options.fetch(:start_date, Time.zone.today).to_date
      end

      def unscheduled
        @unscheduled ||= Release.unscheduled.to_a
      end

      private

      def find_releases_for_date(date)
        releases_in_range
          .map { |r| ReleaseViewModel.new(r, options) }
          .select { |r| r.calendar_on == date }
          .sort_by(&:calendar_at)
      end

      def releases_in_range
        @releases ||= Release.published_within(date_range.first, date_range.last)
      end

      def date_range
        range_start = start_date.beginning_of_week(start_day = :sunday) - 1.week
        range_end = start_date.end_of_week(start_day = :sunday) + 2.weeks

        (range_start..range_end).to_a
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.26 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.25 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.23 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.22 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.21 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.20 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.19 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.18 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.17 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.16 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.15 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.14 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.13 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.12 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.11 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.10 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.9 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.8 app/view_models/workarea/admin/release_calendar_view_model.rb
workarea-admin-3.5.7 app/view_models/workarea/admin/release_calendar_view_model.rb