Skip to content

Commit

Permalink
Refactor some timeline code. Fixes #16 :O
Browse files Browse the repository at this point in the history
  • Loading branch information
glacials committed May 9, 2015
1 parent cc8c558 commit 4d8179d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/time.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$ ->
$(".time").each (i, el) ->
if $.trim(el.innerHTML) is "0"
if parseFloat(el.innerHTML) is 0
el.innerHTML = "-"
else
el.innerHTML = numeral(Math.floor(el.innerHTML)).format("00:00:00")
8 changes: 8 additions & 0 deletions app/helpers/runs_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module RunsHelper

TIMELINE_COLORS = [:blue, :purple, :green, :red, :orange, :yellow]

def difference(run_a, run_b)
(run_a.time - run_b.time).tap do |difference|
if difference > 0
Expand Down Expand Up @@ -46,6 +49,11 @@ def table_locals(table_type, options = {})
end
end

def next_timeline_color
@next_index = ((@next_index || -1) + 1) % TIMELINE_COLORS.length
TIMELINE_COLORS[@next_index]
end

private

def sorting_info
Expand Down
3 changes: 1 addition & 2 deletions app/views/runs/_timeline.slim
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
- scale_to ||= run.time
- cache [:timeline, :v3, {run: run, scale_to: scale_to}] do
- colors = [:blue, :purple, :green, :red, :orange, :yellow]
.timeline
- run.reduced_splits.each_with_index do |split, index|
.pure-u.split id="#{run.id}-split-#{index}" class=(colors[index % colors.length]) style='width: 0;'
.pure-u.split id="#{run.id}-split-#{index}" class=next_timeline_color style='width: 0;'
.title = split.name
.time = split.duration
- if run.time < scale_to
Expand Down
9 changes: 5 additions & 4 deletions app/views/runs/show.slim
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
li
a href=edit_run_path(@run) edit

= render partial: 'timeline', locals: {run: @run}
- if @run.splits.all? { |split| !split.skipped? } && @run.has_golds?
= render partial: 'gold_timeline', locals: {run: @run}
= render partial: 'timeline_inspector', locals: {run: @run}
- if @run.time > 0
= render partial: 'timeline', locals: {run: @run}
- if @run.splits.all? { |split| !split.skipped? } && @run.has_golds?
= render partial: 'gold_timeline', locals: {run: @run}
= render partial: 'timeline_inspector', locals: {run: @run}

article
- cache [:splits, :v1, @run] do
Expand Down

0 comments on commit 4d8179d

Please sign in to comment.