Closed everett1992 closed 10 years ago
You can drag and drop items in the queue to reorder them. The drag and drop code is pretty ugly, I need to disable drop targets that won't change the order of the queue.
I went with a weird SQL implementation, episodes are assigned an index between the indexi of the next and previous index. if two episodes have indexi that are within one integer of each other all indexi are recalculated. I'm not handling this on the client yet so heavy queue use without reloads can lead to unexpected behavior. Working on that next.
Currently the queue really is a queue, you can't reorder things without removing and readding them in the right order. It is this because it was easy and efficient to build server-side. Each episode in the queue is a
QueuedEpisode
object.To get the queue query for all of the users Queued Episodes in the order they were created. Adding and removing episodes is as easy as creating or deleting the queued episodes, and each action only needs to modify one queued episode.
Alternatives:
QueuedEpisodes
object which would have an ordered string of episode Id's. Rails wouldn't like this, I don't think activerecord would let us query forQueuedEpisodes.episodes
, but Ember.js would be just fine with it. Adding, removing, and changing the order of episodes in the queue would only need to make one database call.1
,2
, ... ,n
, but then reordering and deleting episodes would require each episode after the modified one to be updated (incrementing or decrementing each value). A novel thought I had was to store the index as a double. Then to move an episode the episode's index would be set halfway between the indexes of the two surrounding episodes. This would need two database reads, per modification. It could have confusing bugs if users add and delete a lot of episodes (floating point errors).QueuedEpisode
has anid
, and anepisode_id
. You could swap the order of two queued episodes by swapping theirQueuedEpisode
'sepisode_id
s. Inserting and deleting would be the same, swapping would take two database accesses (Four total i guess, one read and write for each swapped).I think swapping
episode_is
's is the best options. Does anyone have input?