From b7aa5406ea2d9fcc39c8fe70ba6ce5e9489c6c52 Mon Sep 17 00:00:00 2001 From: etiennevvv <59622352+etiennevvv@users.noreply.github.com> Date: Mon, 24 Feb 2020 12:58:28 -0500 Subject: [PATCH] GRN2-273: Fixed bug where incorrect recording length returned when "Notes" format was included (#961) * GRN2-273: Fixed bug where incorrect recording length returned * GRN2-273: Changing iteration variable name in recording_length method --- app/helpers/recordings_helper.rb | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/app/helpers/recordings_helper.rb b/app/helpers/recordings_helper.rb index 06296457..2cc2dc82 100644 --- a/app/helpers/recordings_helper.rb +++ b/app/helpers/recordings_helper.rb @@ -24,18 +24,13 @@ module RecordingsHelper # Helper for converting BigBlueButton dates into a nice length string. def recording_length(playbacks) - # Stats format currently doesn't support length. - valid_playbacks = playbacks.reject { |p| p[:type] == "statistics" } - return "0 min" if valid_playbacks.empty? - - len = valid_playbacks.first[:length] - if len > 60 - "#{(len / 60).to_i} h #{len % 60} min" - elsif len.zero? - "< 1 min" - else - "#{len} min" + # Looping through playbacks array and returning first non-zero length value + playbacks.each do |playback| + length = playback[:length] + return recording_length_string(length) unless length.zero? end + # Return '< 1 min' if length values are zero + "< 1 min" end # Prevents single images from erroring when not passed as an array. @@ -51,4 +46,15 @@ module RecordingsHelper def recording_thumbnails? Rails.configuration.recording_thumbnails end + + private + + # Returns length of the recording as a string + def recording_length_string(len) + if len > 60 + "#{(len / 60).to_i} h #{len % 60} min" + else + "#{len} min" + end + end end