Add paging to Recordings Table (GRN2-26) (#512)

* Add translations for the validation messages

* Add translations for next/prev button

* Add paging to recordings

* sync

* Fix line endings
This commit is contained in:
shawn-higgins1
2019-05-14 09:01:41 -04:00
committed by Jesus Federico
parent d8f6c3f872
commit 23abdb52ee
18 changed files with 725 additions and 129 deletions

View File

@ -19,8 +19,14 @@
module APIConcern
extend ActiveSupport::Concern
# Format recordings to match their current use in the app
def format_recordings(api_res)
# Format, filter, and sort recordings to match their current use in the app
def format_recordings(api_res, search_params, ret_search_params)
search = search_params[:search] || ""
order_col = search_params[:column] && search_params[:direction] != "none" ? search_params[:column] : "end_time"
order_dir = search_params[:column] && search_params[:direction] != "none" ? search_params[:direction] : "asc"
search = search.downcase
api_res[:recordings].each do |r|
next if r.key?(:error)
# Format playbacks in a more pleasant way.
@ -34,6 +40,57 @@ module APIConcern
r.delete(:playback)
end
api_res[:recordings].sort_by { |rec| rec[:endTime] }.reverse
recs = filter_recordings(api_res, search)
recs = sort_recordings(recs, order_col, order_dir)
if ret_search_params
[search, order_col, order_dir, recs]
else
recs
end
end
def filter_recordings(api_res, search)
api_res[:recordings].select do |r|
(!r[:metadata].nil? && ((!r[:metadata][:name].nil? &&
r[:metadata][:name].downcase.include?(search)) ||
(r[:metadata][:"gl-listed"] == "true" && search == "public") ||
(r[:metadata][:"gl-listed"] == "false" && search == "unlisted"))) ||
((r[:metadata].nil? || r[:metadata][:name].nil?) &&
r[:name].downcase.include?(search)) ||
r[:participants].include?(search) ||
!r[:playbacks].select { |p| p[:type].downcase.include?(search) }.empty?
end
end
def sort_recordings(recs, order_col, order_dir)
recs = case order_col
when "end_time"
recs.sort_by { |r| r[:endTime] }
when "name"
recs.sort_by do |r|
if !r[:metadata].nil? && !r[:metadata][:name].nil?
r[:metadata][:name].downcase
else
r[:name].downcase
end
end
when "length"
recs.sort_by { |r| r[:playbacks].reject { |p| p[:type] == "statistics" }.first[:length] }
when "users"
recs.sort_by { |r| r[:participants] }
when "visibility"
recs.sort_by { |r| r[:metadata][:"gl-listed"] }
when "formats"
recs.sort_by { |r| r[:playbacks].first[:type].downcase }
else
recs.sort_by { |r| r[:endTime] }
end
if order_dir == 'asc'
recs
else
recs.reverse
end
end
end

View File

@ -121,15 +121,16 @@ class Room < ApplicationRecord
end
# Fetches all recordings for a room.
def recordings
def recordings(search_params = {}, ret_search_params = false)
res = bbb.get_recordings(meetingID: bbb_id)
format_recordings(res)
format_recordings(res, search_params, ret_search_params)
end
# Fetches a rooms public recordings.
def public_recordings
recordings.select { |r| r[:metadata][:"gl-listed"] == "true" }
def public_recordings(search_params = {}, ret_search_params = false)
search, order_col, order_dir, recs = recordings(search_params, ret_search_params)
[search, order_col, order_dir, recs.select { |r| r[:metadata][:"gl-listed"] == "true" }]
end
def update_recording(record_id, meta)

View File

@ -121,7 +121,7 @@ class User < ApplicationRecord
order("#{column} #{direction}")
end
def all_recordings
def all_recordings(search_params = {}, ret_search_params = false)
pag_num = Rails.configuration.pagination_number
pag_loops = rooms.length / pag_num - 1
@ -142,7 +142,7 @@ class User < ApplicationRecord
full_res = bbb.get_recordings(meetingID: last_pag_room.pluck(:bbb_id))
res[:recordings].push(*full_res[:recordings])
format_recordings(res)
format_recordings(res, search_params, ret_search_params)
end
# Activates an account and initialize a users main room