Skip to content

Commit

Permalink
feat: add playlist filter to the videos page
Browse files Browse the repository at this point in the history
  • Loading branch information
danirod committed Jun 1, 2024
1 parent 0c94069 commit 7ff50aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion app/controllers/dashboard/videos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class VideosController < Dashboard::DashboardController

def index
@sorter = VideoSorter.new(query: params[:sort] || DEFAULT_SORT_CRITERIA)
@videos = @sorter.videos.page(params[:page])
@videos = @sorter.videos.where(filter_criteria).page(params[:page])
@playlists = Playlist.select(:id, :title).order(:topic_id, :created_at)
end

def show; end
Expand Down Expand Up @@ -75,5 +76,9 @@ def video_params
video_params[:tags] = video_params[:tags].split if video_params[:tags].present?
end
end

def filter_criteria
params.permit(:playlist_id).compact_blank
end
end
end
4 changes: 2 additions & 2 deletions app/views/dashboard/pending/show_notes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<%= f.submit 'Apply filters', type: :submit, name: nil, class: 'btn btn-primary btn-sm' %>
<%= link_to 'Reset', dashboard_pending_show_notes_path, class: 'btn btn-light btn-sm' %>
</p>
<% end %>
<% end %>

<table class="table">
<thead>
Expand All @@ -44,4 +44,4 @@
</tbody>
</table>

<%= paginate @videos %>
<%= paginate @videos %>
13 changes: 13 additions & 0 deletions app/views/dashboard/videos/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
<% content_for :toolbar do %>
<%= link_to t('.new_video'), [:new, :dashboard, :video], class: 'btn btn-success' %>
<% end %>
<%= form_with method: :get do |f| %>
<p>
<%= f.label :playlist_id, 'Playlist' %>
<%= f.select :playlist_id, @playlists.pluck(:title, :id), selected: params[:playlist_id], include_blank: '(ninguna)' %>
</p>
<p>
<%= hidden_field_tag :sort, params[:sort] %>
<%= f.submit 'Apply filters', type: :submit, name: nil, class: 'btn btn-primary btn-sm' %>
<%= link_to 'Reset', dashboard_videos_path, class: 'btn btn-light btn-sm' %>
</p>
<% end %>

<table class="table table-default table-hover align-middle">
<thead>
<tr>
Expand Down

0 comments on commit 7ff50aa

Please sign in to comment.