-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved time tracking for uploading files and ripping movies (#470)
- Loading branch information
Showing
21 changed files
with
721 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
<div> | ||
<div class="progress mb-2"> | ||
<div class="progress-bar progress-bar-striped <%= 'progress-bar-animated' if completed < 100 %> bg-<%= status %>" role="progressbar" aria-valuenow="<%= completed %>" aria-valuemin="0" aria-valuemax="100" style="width: <%= completed %>%"> | ||
<div class="row"> | ||
<div class="<%= show_percentage ? 'col-9' : 'col-12' %>"> | ||
<div class="progress mb-2"> | ||
<div class="progress-bar progress-bar-striped <%= 'progress-bar-animated' if completed < 100 %> bg-<%= status %>" role="progressbar" aria-valuenow="<%= completed %>" aria-valuemin="0" aria-valuemax="100" style="width: <%= completed %>%"> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div> | ||
<%= message.presence %> | ||
<% if show_percentage %> | ||
... | ||
<%= number_to_percentage completed, precision: 2 %> | ||
<% if eta.present? %> | ||
(<%= eta %>) | ||
<% end %> | ||
<div class="mb-2 col-3"> | ||
<%= number_to_percentage completed, precision: 2 %> | ||
</div> | ||
<% end %> | ||
</div> | ||
<div class="overflow-hidden"> | ||
<%= message.presence&.html_safe %> | ||
</div> | ||
<% if eta.present? %> | ||
<div>ETA: <%= eta %></div> | ||
<% end %> | ||
<% if progress.present? %> | ||
<div>Progress: <%= progress %></div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v5.4.1 | ||
v5.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'time' | ||
require_relative 'timer' | ||
require_relative 'progress' | ||
require_relative 'projector' | ||
require_relative 'projectors/smoothed_average' | ||
require_relative 'component/rate' | ||
require_relative 'component/time' | ||
require_relative 'component/percentage' | ||
|
||
module ProgressTracker | ||
class Base | ||
extend Forwardable | ||
|
||
def_delegators :progressable, | ||
:progress, | ||
:total | ||
def initialize(options = {}) | ||
options[:projector] ||= {} | ||
|
||
self.autostart = options.fetch(:autostart, true) | ||
self.autofinish = options.fetch(:autofinish, true) | ||
self.finished = false | ||
|
||
self.timer = Timer.new(options) | ||
self.projector = Projector | ||
.from_type(options[:projector][:type]) | ||
.new(options[:projector]) | ||
self.progressable = Progress.new(options) | ||
|
||
options = options.merge(progress: progressable, | ||
projector:, | ||
timer:) | ||
|
||
self.percentage_component = Components::Percentage.new(options) | ||
self.rate_component = Components::Rate.new(options) | ||
self.time_component = Components::Time.new(options) | ||
|
||
start at: options[:starting_at] if autostart | ||
end | ||
|
||
def start(options = {}) | ||
timer.start | ||
update_progress(:start, options) | ||
end | ||
|
||
def finish | ||
return if finished? | ||
|
||
output.with_refresh do | ||
self.finished = true | ||
progressable.finish | ||
timer.stop | ||
end | ||
end | ||
|
||
def pause | ||
output.with_refresh { timer.pause } unless paused? | ||
end | ||
|
||
def stop | ||
output.with_refresh { timer.stop } unless stopped? | ||
end | ||
|
||
def resume | ||
output.with_refresh { timer.resume } if stopped? | ||
end | ||
|
||
def reset | ||
output.with_refresh do | ||
self.finished = false | ||
progressable.reset | ||
projector.reset | ||
timer.reset | ||
end | ||
end | ||
|
||
def stopped? | ||
timer.stopped? || finished? | ||
end | ||
|
||
alias paused? stopped? | ||
|
||
def finished? | ||
finished || (autofinish && progressable.finished?) | ||
end | ||
|
||
def started? # rubocop:disable Rails/Delegate | ||
timer.started? | ||
end | ||
|
||
def decrement | ||
update_progress(:decrement) | ||
end | ||
|
||
def increment | ||
update_progress(:increment) | ||
end | ||
|
||
def progress=(new_progress) | ||
update_progress(:progress=, new_progress) | ||
end | ||
|
||
def total=(new_total) | ||
update_progress(:total=, new_total) | ||
end | ||
|
||
def inspect | ||
"#<ProgressBar:#{progress}/#{total || 'unknown'}>" | ||
end | ||
|
||
attr_accessor :percentage_component, | ||
:rate_component, | ||
:time_component | ||
|
||
protected | ||
|
||
attr_accessor :autofinish, | ||
:autostart, | ||
:finished, | ||
:progressable, | ||
:projector, | ||
:timer | ||
|
||
def update_progress(*) | ||
progressable.__send__(*) | ||
projector.__send__(*) | ||
timer.stop if finished? | ||
end | ||
end | ||
end |
Oops, something went wrong.