Sha256: a64956db9dcb30580d151f46d9216c65c5f198865abfad7d4c2a0a9646451cd0

Contents?: true

Size: 1.32 KB

Versions: 7

Compression:

Stored size: 1.32 KB

Contents

module Workarea
  module Admin
    class TimelineViewModel < ApplicationViewModel
      def upcoming_changesets
        @upcoming_changesets ||= ChangesetViewModel.wrap(
          model_changesets + content_changesets
        )
      end

      def activity
        @activity ||= ActivityViewModel.new(nil, id: model.id)
      end

      def activity_by_day
        @days ||= activity.entries.reduce({}) do |memo, entry|
          day = entry.created_at.to_date
          memo[day] ||= []
          memo[day] << entry
          memo
        end
      end

      def today_has_activity
        activity_by_day[Time.zone.today].present?
      end

      def empty?
        upcoming_changesets.empty? && activity.entries.empty?
      end

      def subject
        @subject ||= ApplicationController.wrap_in_view_model(model, options)
      end

      private

      def model_changesets
        Release::Changeset
          .by_document_path(model)
          .any_in(release_id: upcoming_releases.map(&:id))
      end

      def content_changesets
        return [] unless model.is_a?(Contentable)

        Workarea::Content.for(model)
          .changesets
          .any_in(release_id: upcoming_releases.map(&:id))
          .to_a
      end

      def upcoming_releases
        @upcoming_releases ||= Release.upcoming.to_a
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
workarea-admin-3.4.18 app/view_models/workarea/admin/timeline_view_model.rb
workarea-admin-3.4.17 app/view_models/workarea/admin/timeline_view_model.rb
workarea-admin-3.4.16 app/view_models/workarea/admin/timeline_view_model.rb
workarea-admin-3.4.15 app/view_models/workarea/admin/timeline_view_model.rb
workarea-admin-3.4.14 app/view_models/workarea/admin/timeline_view_model.rb
workarea-admin-3.4.13 app/view_models/workarea/admin/timeline_view_model.rb
workarea-admin-3.4.12 app/view_models/workarea/admin/timeline_view_model.rb