Sha256: 01f51eb4a83e5470d94af17d60c6f5833f6813efdef1284ba8a8d3b6fd0b5db9

Contents?: true

Size: 1.92 KB

Versions: 39

Compression:

Stored size: 1.92 KB

Contents

module Katello
  class SyncStatusPresenter
    include ::ActionView::Helpers::DateHelper
    include ::Katello::TranslationHelper
    STATUS_VALUES = {
      :stopped => _("Syncing Complete."),
      :error => _("Sync Incomplete"),
      :never_synced => _("Never Synced"),
      :running => _("Running"),
      :canceled => _("Canceled"),
      :paused => _("Paused")
    }.with_indifferent_access

    def initialize(repo, task)
      @repo = repo
      @task = task
    end

    def sync_progress
      return {:state => nil} unless @repo
      return empty_task(@repo) unless @task
      {
        :id => @repo.id,
        :product_id => @repo.product.id,
        :progress => {:progress => @task.progress * 100},
        :sync_id => @task.id,
        :state => format_state(@task),
        :raw_state => raw_state(@task),
        :start_time => format_date(@task.started_at),
        :finish_time => format_date(@task.ended_at),
        :duration => format_duration(@task.ended_at, @task.started_at),
        :display_size => @task.humanized[:output],
        :size => @task.humanized[:output],
        :is_running => @task.pending && @task.state != 'paused',
        :error_details => @task.errors
      }
    end

    private

    def empty_task(repo)
      state = 'never_synced'
      {
        :id => repo.id,
        :product_id => repo.product.id,
        :progress => {},
        :state => format_state(OpenStruct.new(:state => state)),
        :raw_state => state
      }
    end

    def raw_state(task)
      return 'error' if task.result == 'error' || task.result == 'warning'
      task.state
    end

    def format_state(task)
      STATUS_VALUES[raw_state(task)] || task.state
    end

    def format_duration(finish, start)
      return if finish.nil? || start.nil?
      distance_of_time_in_words(finish, start)
    end

    def format_date(check_date)
      return if check_date.nil?
      relative_time_in_words(check_date)
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
katello-3.16.0.rc5 app/presenters/katello/sync_status_presenter.rb
katello-3.16.0.rc4.1 app/presenters/katello/sync_status_presenter.rb
katello-3.15.3.1 app/presenters/katello/sync_status_presenter.rb
katello-3.15.3 app/presenters/katello/sync_status_presenter.rb
katello-3.16.0.rc4 app/presenters/katello/sync_status_presenter.rb
katello-3.16.0.rc3.1 app/presenters/katello/sync_status_presenter.rb
katello-3.15.2 app/presenters/katello/sync_status_presenter.rb
katello-3.16.0.rc3 app/presenters/katello/sync_status_presenter.rb
katello-3.16.0.rc2.1 app/presenters/katello/sync_status_presenter.rb
katello-3.16.0.rc2 app/presenters/katello/sync_status_presenter.rb
katello-3.15.1.1 app/presenters/katello/sync_status_presenter.rb
katello-3.16.0.rc1.1 app/presenters/katello/sync_status_presenter.rb
katello-3.15.1 app/presenters/katello/sync_status_presenter.rb
katello-3.16.0.rc1 app/presenters/katello/sync_status_presenter.rb
katello-3.15.0.1 app/presenters/katello/sync_status_presenter.rb
katello-3.15.0 app/presenters/katello/sync_status_presenter.rb
katello-3.15.0.rc2 app/presenters/katello/sync_status_presenter.rb
katello-3.15.0.rc1.3 app/presenters/katello/sync_status_presenter.rb
katello-3.15.0.rc1.2 app/presenters/katello/sync_status_presenter.rb
katello-3.15.0.rc1.1 app/presenters/katello/sync_status_presenter.rb