Skip to content

Commit

Permalink
Add admin-only empty playlist display
Browse files Browse the repository at this point in the history
  • Loading branch information
bgadoury committed Aug 31, 2016
1 parent 33b1f9f commit bb98825
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 2 deletions.
20 changes: 20 additions & 0 deletions app/assets/stylesheets/playlists.css.scss.erb
Expand Up @@ -591,3 +591,23 @@ span.private_item {
margin-top: 8px;
}
}

#empty-playlists td {
padding: 5px;
border: 1px black solid;
}

#empty-playlists {
width: 1050px;
.url {
width: 110px;
}
.user {
width: 110px;
}
.title {
width: 210px;
}
.description {
}
}
5 changes: 5 additions & 0 deletions app/controllers/playlists_controller.rb
Expand Up @@ -46,6 +46,11 @@ def index
common_index Playlist
end

def empty
sql = "select p.* from playlists p left join playlist_items pi ON p.id = pi.playlist_id where pi.id is null order by p.id desc"
@playlists = Playlist.find_by_sql(sql).paginate(:page => params[:page], :per_page => 75)
end

def show
return if redirect_bad_format

Expand Down
2 changes: 1 addition & 1 deletion app/models/ability.rb
Expand Up @@ -73,7 +73,7 @@ def initialize(user)

can :access, :rails_admin
can :dashboard, :all
can [:import, :submit_import], :playlists
can [:import, :submit_import, :empty], :playlists
can [:index, :show, :export, :export_as, :export_unique, :bulk_delete, :destroy, :view_in_app, :edit_in_app, :edit,
:update, :position_update, :update_notes, :delete_inherited_annotations, :save_readable_state],
:all
Expand Down
36 changes: 36 additions & 0 deletions app/views/playlists/empty.html.erb
@@ -0,0 +1,36 @@
<h1>Playlists with Zero Playlist Items - 1</h1>

<br>
<br>
<%= will_paginate @playlists, container: false, :previous_label => 'Previous', :next_label => 'Next' %>

<table id="empty-playlists">
<!-- playlist URL, playlist ID, title and description field. -->
<tr>
<th>ID</th><th>User</th><th>Title</th><th>Description</th><th></th><th></th>
</tr>

<% @playlists.each do |playlist| %>
<tr>
<td class="url">
<%= link_to playlist_path(playlist), playlist_path(playlist), target: '_blank' %>
</td>
<td class="user">
<%= link_to(
raw("#{user_path(playlist.user)}<br>#{playlist.user.email_address}"),
user_path(playlist.user),
target: '_blank'
)%>
</td>
<td class="title">
<%= playlist.name %>
</td>
<td class="description">
<%= playlist.description %>
</td>
</tr>
<% end %>
</table>

<%= will_paginate @playlists, container: false, :previous_label => 'Previous', :next_label => 'Next' %>

3 changes: 2 additions & 1 deletion config/initializers/rails_admin.rb
Expand Up @@ -150,7 +150,8 @@ class EditInApp < RailsAdmin::Config::Actions::Base

RailsAdmin.config do |config|
config.navigation_static_links = {
'Playlist Importer' => '/playlists/import'
'Playlist Importer' => '/playlists/import',
'Empty Playlists' => '/playlists/empty',
}
config.current_user_method do
current_user
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -87,6 +87,7 @@
get 'playlist_lookup'
get 'import'
post 'submit_import'
get 'empty'
end
end
resources :playlist_items do
Expand Down

0 comments on commit bb98825

Please sign in to comment.