Sha256: ac5efc3529a738b978f76518ab281b0562eeadc1316e2e5428556e94e60adabe

Contents?: true

Size: 1.53 KB

Versions: 34

Compression:

Stored size: 1.53 KB

Contents

module Workarea
  module Admin
    class ReleaseEventViewModel < ApplicationViewModel
      include Workarea::Admin::Engine.routes.url_helpers

      def all_day_event?
        return false unless starts_and_ends?
        ends_at - starts_at > 1
      end

      def starts_and_ends?
        starts_at.present? && ends_at.present?
      end

      def description
        description = [
          I18n.t('workarea.admin.releases.feed.view_release',
            url: release_url(host: Workarea.config.host, id: id))
        ]

        if all_day_event?
          description << I18n.t('workarea.admin.releases.feed.starts_on',
            date: starts_at.strftime('%b %-d, %Y at %r'))
          description << I18n.t('workarea.admin.releases.feed.ends_on',
            date: ends_at.strftime('%b %-d, %Y at %r'))
        end

        unless ends_at.present?
          description << I18n.t('workarea.admin.releases.feed.no_undo_date')
        end

        description.join('\n')
      end

      def publish_time
        model.publish_at || model.published_at
      end

      def undo_time
        model.undo_at || model.undone_at
      end

      def starts_at
        return if publish_time.nil?
        time = publish_time.strftime('%Y %m %d %H %M %S').split(' ').map(&:to_i)
        DateTime.civil(*time, publish_time.strftime('%z'))
      end

      def ends_at
        return if undo_time.nil?
        time = undo_time.strftime('%Y %m %d %H %M %S').split(' ').map(&:to_i)
        DateTime.civil(*time, undo_time.strftime('%z'))
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-admin-3.4.45 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.44 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.43 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.42 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.41 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.40 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.39 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.38 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.37 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.36 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.35 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.34 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.33 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.32 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.31 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.30 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.29 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.28 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.27 app/view_models/workarea/admin/release_event_view_model.rb
workarea-admin-3.4.26 app/view_models/workarea/admin/release_event_view_model.rb