Skip to content

Commit

Permalink
fix track bulk upload
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Aug 30, 2024
1 parent 130cf8a commit 2c19503
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 80 deletions.
9 changes: 7 additions & 2 deletions app/controllers/tracks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def create
# @track = current_user.tracks.new(track_params)
@track_form.user = current_user
@track_form.private = track_bulk_params[:private]
@track_form.tracks_attributes = audios.map { |o| {audio: o} }
@track_form.tracks_attributes = audios.map { |o|
{
audio: o
}
}
@track_form.step = "info"
else
@track_form.tracks_attributes_objects = track_bulk_params[:tracks_attributes]
Expand Down Expand Up @@ -135,7 +139,8 @@ def track_bulk_params
:private,
:enable_label,
:step,
audio: [], tracks_attributes: [
audio: [],
tracks_attributes: [
:audio, :cover, :title, :description, :private, tags: []
]
)
Expand Down
8 changes: 6 additions & 2 deletions app/models/track_bulk_creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
class TrackBulkCreator
include ActiveModel::Model

attr_accessor :tracks_attributes, :step, :user, :make_playlist, :private
attr_accessor :tracks_attributes,
:step,
:user,
:make_playlist,
:private

validate :validate_tracks

Expand Down Expand Up @@ -36,7 +40,7 @@ def tracks
@tracks ||= tracks_attributes.map do |attributes|
blob = ActiveStorage::Blob.find_signed(attributes[:audio])
t = Track.new(attributes)
t.title = File.basename(blob.filename.to_s, File.extname(blob.filename.to_s))
t.title = File.basename(blob.filename.to_s, File.extname(blob.filename.to_s)) unless t.title.present?
t.user = user
t.private = private
t
Expand Down
30 changes: 3 additions & 27 deletions app/views/playlists/_playlist_item.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -149,33 +149,9 @@
</div>

<% if playlist.price %>
<!--<.live_component
module={RauversionWeb.PlaylistLive.BuyModalComponent}
id={"buy-modal-#{@playlist.id}"}
playlist={@playlist}
current_user={@current_user}
>-->
<button
class="my-2 underline text-sm dark:bg-green-700 dark:border-green-500 dark:hover:bg-green-800 border-black rounded-sm border px-3 mt-2"
>
<%= t("payments.buy_digital_album") %>
</button>

<span>
<span class="font-bold">
<%= number_to_currency(playlist.price, precision: 2) %>
</span>
<span class="text-gray-700 dark:text-gray-300">
USD
</span>
</span>

<% if playlist.name_your_price %>
<span class="text-gray-700 dark:text-gray-300">
<%= gettext("or more") %>
</span>
<% end %>
<!--</.live_component>-->
<%= render "shared/music_purchase",
resource: playlist,
variant: :mini %>
<% end %>
</div>
</div>
Expand Down
83 changes: 43 additions & 40 deletions app/views/playlists/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<div class="flex flex-col sm:flex-row mb-6">

<!--
<% if @track.present? %>
<div
data-audio-id="<%= @track.id %>"
Expand Down Expand Up @@ -120,9 +121,10 @@
</div>
</div>
<% end %>
-->

<div class="w-1/4 hidden sm:block">
<div class="group relative aspect-w-1 aspect-h-1 rounded-md- bg-gray-100 overflow-hidden">
<div class=" m-4 rounded-lg group relative aspect-w-1 aspect-h-1 rounded-md- bg-gray-100 overflow-hidden">
<%= image_tag @playlist.cover_url(:large),
class: "object-center object-cover group-hover:opacity-75"
%>
Expand All @@ -140,6 +142,46 @@
</div>
</div>
</div>

<div class="flex-grow">
<div class="mt-4 my-2 border dark:border-gray-800 shadow-xs mx-3 dark:bg-gray-900 rounded-md">
<div class="flex space-x-3">
<div class="flex-grow">
<div class="flex flex-col">
<div class="space-y-2">
<ul role="list" class="divide-y divide-subtle">

<% @playlist.ordered_tracks.each do |track| %>
<li>
<a
href="<%= player_path(id: track, t: true) %>"
data-track-id="<%= track.id %>"
data-track-detector-target="track"
class="block p-2 bg-muted hover:bg-default w-full text-left text-default">
<div class="flex items-center space-x-4">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M5.25 5.653c0-.856.917-1.398 1.667-.986l11.54 6.348a1.125 1.125 0 010 1.971l-11.54 6.347a1.125 1.125 0 01-1.667-.985V5.653z"></path>
</svg>
<div class="flex-1 min-w-0">
<p class="text-sm font-medium text-subtle truncate"></p>
<p> <%= track.title %> </p>
<p></p>
<p class="text-sm text-muted truncate">
<%= track.user.username %>
</p>
</div>
</div>
</a>
</li>
<% end %>

</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">
Expand Down Expand Up @@ -200,45 +242,6 @@
<div class="hidden sm:block p-4 w-1/4">
<%= image_tag @playlist.user.avatar_url(:small), class: "rounded-full object-center object-cover group-hover:opacity-75" %>
</div>
<div class="flex-grow">
<div class="my-2 border dark:border-gray-800 shadow-xs mx-3 dark:bg-gray-900 rounded-md">
<div class="flex space-x-3">
<div class="flex-grow">
<div class="flex flex-col">
<div class="space-y-2">
<ul role="list" class="divide-y divide-subtle">

<% @playlist.ordered_tracks.each do |track| %>
<li>
<a
href="<%= player_path(id: track, t: true) %>"
data-track-id="<%= track.id %>"
data-track-detector-target="track"
class="block p-2 bg-muted hover:bg-default w-full text-left text-default">
<div class="flex items-center space-x-4">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" d="M5.25 5.653c0-.856.917-1.398 1.667-.986l11.54 6.348a1.125 1.125 0 010 1.971l-11.54 6.347a1.125 1.125 0 01-1.667-.985V5.653z"></path>
</svg>
<div class="flex-1 min-w-0">
<p class="text-sm font-medium text-subtle truncate"></p>
<p> <%= track.title %> </p>
<p></p>
<p class="text-sm text-muted truncate">
<%= track.user.username %>
</p>
</div>
</div>
</a>
</li>
<% end %>

</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<div class="sm:text-xl text-sm container mx-auto px-4 my-4 flex flex-col space-y-4">
Expand Down
26 changes: 21 additions & 5 deletions app/views/shared/_music_purchase.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
<div id="xx-5">
<div class="text-xl space-x-2">
<%
classes = local_assigns[:variant] == :mini ?
{
border: "border",
text: "text-sm",
pad: "px-2 py-2",
m: "my-4"
}
:
{
border: "border-4",
text: "text-xl",
pad: "px-3 py-3"
}
%>

<div id="xx-5" class="<%= classes[:m]%>">
<div class="<%= classes[:text] %> space-x-2">
<% if resource.is_a?(Track) %>
<%= link_to new_track_track_purchase_path(resource),
"data-turbo-frame": "modal",
class: "underline dark:border-white hover:bg-white hover:text-black border-black rounded-sm border-4 px-3 py-3" do %>
class: "#{classes[:pad]} underline dark:border-white hover:bg-white hover:text-black border-black rounded-sm border-4" do %>
<%= t("tracks.buy_digital_music")%>
<% end %>
<% end %>
<% if resource.is_a?(Playlist) %>
<%= link_to new_playlist_playlist_purchase_path(resource),
"data-turbo-frame": "modal",
class: "underline dark:border-white hover:bg-white hover:text-black border-black rounded-sm border-4 px-3 py-3" do %>
class: "#{classes[:pad]} #{classes[:border]} underline dark:border-white hover:bg-white hover:text-black border-black rounded-sm" do %>
<%= t("tracks.buy_digital_music")%>
<span> <%= number_to_currency(resource.price) %> <span class="text-gray-700 dark:text-gray-300"> USD </span> </span>
<% end %>
Expand All @@ -23,7 +39,7 @@
</div>
</div>

<% if @supporters.any? %>
<% if @supporters && @supporters.any? %>
<div class="sm:text-xl text-sm container mx-auto my-4 flex flex-col space-y-4">
<h3 class="font-bold font-medium"><%= t("tracks.supporters") %></h3>
<div class="-space-x-4">
Expand Down
4 changes: 2 additions & 2 deletions app/views/sharer/new.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<div class="hidden visible py-1 px-0 mb-4 font-sans text-xs text-red-700 opacity-100">
<%= t("sharer.link_reset_error") %>
</div>
<div class="text-zinc-800">
<!--<div class="text-zinc-800">
<button
type="button"
class="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-brand-600 hover:bg-brand-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-brand-500"
Expand All @@ -92,7 +92,7 @@
<%= t("sharer.cancel") %>
</button>
</div>
</div>
</div>-->
<div class="hidden text-zinc-800">
<%= t("sharer.secret_link_reset_success") %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/tracks/create.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<%= render "basic_info_fields", form: ff %>
</div>
<% end %>
<div class="my-4">
<%= form.submit %>
<div class="my-4 mb-10">
<%= form.submit("Save") %>
</div>
</div>
<% end %>
Expand Down

0 comments on commit 2c19503

Please sign in to comment.