Skip to content

Commit

Permalink
refactor session_time method with partial (#3229)
Browse files Browse the repository at this point in the history
refactor session_time method with partial
  • Loading branch information
akuppa9 authored Jan 2, 2024
1 parent 20283d3 commit f97c901
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
33 changes: 14 additions & 19 deletions apps/dashboard/app/helpers/batch_connect/sessions_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def session_view(session)
concat content_tag(:div, cancel_or_delete(session), class: 'float-right')
concat host(session)
concat created(session)
concat session_time(session)
concat render_session_time(session)
concat id(session)
concat support_ticket(session) unless @user_configuration.support_ticket.empty?
concat display_choices(session)
Expand Down Expand Up @@ -89,28 +89,23 @@ def created(session)
def session_time(session)
time_limit = session.info.wallclock_limit
time_used = session.info.wallclock_time

content_tag(:p) do
if session.starting? || session.running?
if time_limit && time_used
concat content_tag(:strong, t('dashboard.batch_connect_sessions_stats_time_remaining'))
concat " "
concat distance_of_time_in_words(time_limit - time_used, 0, false, :only => [:minutes, :hours], :accumulate_on => :hours)
elsif time_used
concat content_tag(:strong, t('dashboard.batch_connect_sessions_stats_time_used'))
concat " "
concat distance_of_time_in_words(time_used, 0, false, :only => [:minutes, :hours], :accumulate_on => :hours)
end
else # not starting or running
if time_limit
concat content_tag(:strong, t('dashboard.batch_connect_sessions_stats_time_requested'))
concat " "
concat distance_of_time_in_words(time_limit, 0, false, :only => [:minutes, :hours], :accumulate_on => :hours)
end
if session.starting? || session.running?
if time_limit && time_used
[t('dashboard.batch_connect_sessions_stats_time_remaining'), distance_of_time_in_words(time_limit - time_used, 0, false, :only => [:minutes, :hours], :accumulate_on => :hours)]
elsif time_used
[t('dashboard.batch_connect_sessions_stats_time_used'), distance_of_time_in_words(time_used, 0, false, :only => [:minutes, :hours], :accumulate_on => :hours)]
end
else
if time_limit
[t('dashboard.batch_connect_sessions_stats_time_requested'), distance_of_time_in_words(time_limit, 0, false, :only => [:minutes, :hours], :accumulate_on => :hours)]
end
end
end

def render_session_time(session)
render(partial: 'batch_connect/sessions/card/session_time', locals: { session: session })
end

def host(session)
render(partial: 'batch_connect/sessions/card/host', locals: { session: session })
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<% label, value = session_time(session) %>
<p>
<strong><%= label %></strong> <%= value %>
</p>

0 comments on commit f97c901

Please sign in to comment.