Class: Xport::DownloadPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/xport/download_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(download, h) ⇒ DownloadPresenter

Returns a new instance of DownloadPresenter.



7
8
9
10
# File 'lib/xport/download_presenter.rb', line 7

def initialize(download, h)
  @download = download
  @h        = h
end

Instance Attribute Details

#hObject (readonly)

Returns the value of attribute h.



5
6
7
# File 'lib/xport/download_presenter.rb', line 5

def h
  @h
end

Instance Method Details

#progress_bar(job_id) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/xport/download_presenter.rb', line 12

def progress_bar(job_id)
  return unless job_id
  job = Resque::Plugins::Status::Hash.get(job_id)
  return unless job

  case job.status
  when Resque::Plugins::Status::STATUS_COMPLETED
    nil
  when Resque::Plugins::Status::STATUS_QUEUED
    progress_bar_pending
  else
    h.(:div, class: 'progress', data: { component: 'Future.ProgressBar' }) do
      h.(:div, class: 'progress-bar', style: "width: #{job.pct_complete}%") do
        "#{job.pct_complete}% #{job.message}"
      end
    end
  end
end

#progress_bar_pendingObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xport/download_presenter.rb', line 31

def progress_bar_pending
  message = I18n.translate(
    'helpers.progress_bar.please_wait_pending',
    count: Resque.info[:pending]
  )

  h.(:div, class: 'progress', data: { component: 'Future.ProgressBar' }) do
    h.(:div, class: 'progress-bar progress-bar-pending', style: 'width: 100%') do
      h.(:span, message)
    end
  end
end