Skip to content

Commit

Permalink
articles preview
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Oct 17, 2023
1 parent 04a5b94 commit ee92e92
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
5 changes: 5 additions & 0 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def show
)
end

def preview
@post = Post.find_signed(params[:id])
render "show"
end

def create
@article = current_user.posts.create(body: params[:post][:body])
redirect_to edit_article_path(@article), status: :see_other
Expand Down
1 change: 0 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def albums
.page(params[:page]).per(5)
@as = :playlist
@section = "playlists/playlist_item"
binding.pry
render "show"
end

Expand Down
25 changes: 10 additions & 15 deletions app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,14 @@ def self.all
"Eurodance",
"Italo Disco",
"Hi-NRG",
"Europop"
]
},
{
"genre": "Electronic Dance Music",
"subgenres": [
"House",
"Techno",
"Drum and Bass",
"Dubstep",
"Ambient",
"Trance",
"Footwork",
"Europop",
"House",
"Techno",
"Drum and Bass",
"Dubstep",
"Ambient",
"Trance",
"Footwork"
]
},
{
Expand Down Expand Up @@ -256,8 +251,8 @@ def self.all
]
},
{
"genre": "Latin Electronica",
"subgenres": [
"genre" => "Latin Electronica",
"subgenres" => [
"Latin House",
"Reggaeton",
"Moombahton",
Expand Down
11 changes: 9 additions & 2 deletions app/models/playlist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,16 @@ def album?
end

def self.list_playlists_by_user_with_track(track_id, user_id)
Playlist.select("playlists.*, COUNT(track_playlists.track_id) as track_count")
#Playlist.select("playlists.*, COUNT(track_playlists.track_id) as track_count")
# .left_outer_joins(:track_playlists)
# .where(user_id: user_id, track_playlists: {track_id: [nil, track_id]})
# .group("playlists.id")


Playlist
.select("playlists.*, SUM(CASE WHEN track_playlists.track_id = #{track_id} THEN 1 ELSE 0 END) as track_count")
.left_outer_joins(:track_playlists)
.where(user_id: user_id, track_playlists: {track_id: [nil, track_id]})
.where(user_id: user_id)
.group("playlists.id")
end

Expand Down
4 changes: 4 additions & 0 deletions app/views/articles/mine.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@
</td>
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 dark:text-gray-200 dark:bg-gray-900 divide-x space-x-2">
<%= link_to t('Edit'), edit_article_path(post), class: 'text-brand-600 hover:text-brand-900' %>
<%= link_to t('Preview'), preview_article_path(post.signed_id), class: 'text-brand-600 hover:text-brand-900 pl-2' %>
<% if post.slug %>
<%= link_to t('articles.view'), article_path(post.slug), class: 'text-brand-600 hover:text-brand-900 pl-2' %>
<% end %>


</td>
</tr>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions app/views/track_playlists/_track_item.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<div id="track-item-<%= track.id %>-<%= playlist.id %>"
data-track-detector-target="track"
data-track-id="<%= track.id %>">
Expand Down
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
end

resources :articles do
member do
get :preview
end
collection do
get :mine
end
Expand Down

0 comments on commit ee92e92

Please sign in to comment.