Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
djrandom-py
Commits
5f6cded0
Commit
5f6cded0
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
merge old chunks when searching
parent
a4f33312
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/djrandom/frontend/static/player.js
+47
-20
47 additions, 20 deletions
server/djrandom/frontend/static/player.js
with
47 additions
and
20 deletions
server/djrandom/frontend/static/player.js
+
47
−
20
View file @
5f6cded0
...
...
@@ -40,7 +40,7 @@ djr.Backend.prototype.getPlaylist = function(uuid, callback, ctx) {
type
:
'
GET
'
,
context
:
ctx
||
this
,
success
:
function
(
data
,
status
,
jqxhr
)
{
callback
(
new
djr
.
PlaylistChunk
(
data
.
songs
));
callback
(
new
djr
.
PlaylistChunk
(
data
.
songs
,
uuid
));
}
});
};
...
...
@@ -74,8 +74,9 @@ djr.Backend.prototype.nowPlaying = function(song) {
// A Playlist chunk (basically, an array of songs).
djr
.
PlaylistChunk
=
function
(
songs
)
{
djr
.
PlaylistChunk
=
function
(
songs
,
title
)
{
this
.
songs
=
songs
||
[];
this
.
title
=
title
;
};
djr
.
PlaylistChunk
.
prototype
.
hasSong
=
function
(
sha1
)
{
...
...
@@ -108,12 +109,8 @@ djr.Playlist.prototype.allSongs = function() {
return
songs
;
};
// Add a new chunk (only adds unique songs).
// Returns the chunk ID, or -1 if no songs were added.
djr
.
Playlist
.
prototype
.
addChunk
=
function
(
playlist_chunk
)
{
djr
.
debug
(
'
adding chunk to playlist
'
+
this
.
uuid
);
var
chunk_id
=
this
.
next_chunk_id
++
;
// Creates a new chunk with only unique songs.
djr
.
Playlist
.
prototype
.
createUniqueChunk
=
function
(
songs
,
title
)
{
var
songs
=
[],
i
;
for
(
i
=
0
;
i
<
playlist_chunk
.
songs
.
length
;
i
++
)
{
var
song
=
playlist_chunk
.
songs
[
i
];
...
...
@@ -121,16 +118,26 @@ djr.Playlist.prototype.addChunk = function(playlist_chunk) {
continue
;
}
songs
.
push
(
song
);
this
.
song_map
[
song
]
=
chunk_id
;
}
if
(
songs
.
length
==
0
)
{
return
-
1
;
if
(
songs
.
length
>
0
)
{
return
new
djr
.
PlaylistChunk
(
songs
,
title
);
}
else
{
this
.
chunk_map
[
chunk_id
]
=
new
djr
.
PlaylistChunk
(
songs
);
return
null
;
}
};
// Add a new chunk (only adds unique songs).
// Returns the chunk ID, or -1 if no songs were added.
djr
.
Playlist
.
prototype
.
addChunk
=
function
(
playlist_chunk
)
{
djr
.
debug
(
'
adding chunk to playlist
'
+
this
.
uuid
);
var
i
,
chunk_id
=
this
.
next_chunk_id
++
;
for
(
i
=
0
;
i
<
playlist_chunk
.
songs
.
length
;
i
++
)
{
var
song
=
playlist_chunk
.
songs
[
i
];
this
.
song_map
[
song
]
=
chunk_id
;
}
this
.
chunk_map
[
chunk_id
]
=
playlist_chunk
;
this
.
chunks
.
push
(
chunk_id
);
return
chunk_id
;
}
};
// Return the songs for a specific chunk.
...
...
@@ -150,9 +157,15 @@ djr.Playlist.prototype.removeChunk = function(chunk_id) {
// Return a new Playlist with all the current chunks merged.
djr
.
Playlist
.
prototype
.
merge
=
function
()
{
var
new_title_parts
=
[],
i
;
for
(
i
=
0
;
i
<
this
.
chunks
.
length
;
i
++
)
{
new_title_parts
.
push
(
this
.
chunk_map
[
this
.
chunks
[
i
]].
title
);
}
var
new_title
=
new_title_parts
.
join
(
'
+
'
);
var
new_playlist
=
new
djr
.
Playlist
();
new_playlist
.
uuid
=
this
.
uuid
;
new_playlist
.
addChunk
(
this
.
allSongs
());
new_playlist
.
addChunk
(
new
djr
.
PlaylistChunk
(
this
.
allSongs
(),
new_title
));
return
new_playlist
;
};
...
...
@@ -201,7 +214,7 @@ djr.Player = function(backend, selector) {
};
djr
.
Player
.
prototype
.
hideAllChunks
=
function
()
{
$
(
'
.chunk .inner
'
).
hide
();
$
(
'
.chunk .
chunk_
inner
'
).
hide
();
};
// Callback for removechunk click.
...
...
@@ -211,6 +224,10 @@ djr.Player.prototype.removeChunkCallback = function() {
$
(
this
).
remove
();
};
djr
.
Player
.
prototype
.
mergePlaylistChunks
=
function
()
{
this
.
playlist
=
this
.
playlist
.
merge
();
};
// Search!
djr
.
Player
.
prototype
.
search
=
function
(
query
)
{
var
player
=
this
;
...
...
@@ -225,12 +242,22 @@ djr.Player.prototype.search = function(query) {
return
;
}
var
chunk_id
=
player
.
playlist
.
addChunk
(
new
djr
.
PlaylistChunk
(
songs
));
if
(
chunk_id
<
0
)
{
// Create a chunk of unique new songs.
var
new_chunk
=
player
.
playlist
.
createUniqueChunk
(
songs
,
query
);
if
(
!
new_chunk
)
{
djr
.
debug
(
'
All the results are already in the playlist.
'
);
return
;
}
songs
=
player
.
playlist
.
getChunkSongs
(
chunk_id
);
songs
=
new_chunk
.
songs
;
// Ok, now, if we have more than 1 chunk in the playlist, we
// merge them.
if
(
player
.
playlist
.
chunks
.
length
>
1
)
{
player
.
mergePlaylistChunks
();
}
// Now add the new chunks with the search results.
var
chunk_id
=
player
.
playlist
.
addChunk
(
new_chunk
);
djr
.
debug
(
'
search: new chunk
'
+
chunk_id
+
'
,
'
+
songs
.
length
+
'
songs
'
);
player
.
backend
.
getHtmlForSongs
(
songs
,
function
(
songs_html
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment