Show play and add-to-playlist buttons in instant search results

for now this only works from inside the media app
This commit is contained in:
Robin Appelman 2011-07-31 00:50:04 +02:00
parent 0503c3499e
commit e6821e9d7c
6 changed files with 77 additions and 18 deletions

View file

@ -14,4 +14,5 @@ li button.right.prettybutton{font-size:1em;}
#collection{display:none}/*hide the collection initially*/
#collection li{padding-right:10px;}
img.remove{float:right;};
img.remove{float:right;}
#searchresults input.play, #searchresults input.add{float:right; height:16px; width:16px;}

View file

@ -109,18 +109,8 @@ Collection={
},
registerPlay:function(){
var item=PlayList.items[PlayList.current];
for(var i=0;i<Collection.artists.length;i++){
var artist=Collection.artists[i];
for(var j=0;j<artist.albums.length;j++){
var album=artist.albums[j]
for(var w=0;w<album.songs.length;w++){
var song=album.songs[w];
if(song.song_name==item.name && song.artist_name==item.artist && song.album_name==item.album){
song.song_playcount++;
}
}
}
}
var song=Collection.findSong(item.artist,item.album,item.name);
song.song_playcount++;
},
addButtons:function(parent){
parent.children('button.add').click(function(){
@ -133,6 +123,42 @@ Collection={
PlayList.add($(this).parent().data(type));
PlayList.play(oldSize);
});
},
find:function(artistName,albumName,songName){
if(songName){
return Collection.findSong(artistName,albumName,songName);
}else if(albumName){
return Collection.findAlbum(artistName,albumName);
}else{
return Collection.findArtist(artistName);
}
},
findArtist:function(name){
for(var i=0;i<Collection.artists.length;i++){
if(Collection.artists[i].artist_name==name){
return Collection.artists[i];
}
}
},
findAlbum:function(artistName,albumName){
var artist=Collection.findArtist(artistName);
if(artist){
for(var i=0;i<artist.albums.length;i++){
if(artist.albums[i].album_name==albumName){
return artist.albums[i];
}
}
}
},
findSong:function(artistName,albumName,songName){
var album=Collection.findAlbum(artistName,albumName);
if(album){
for(var i=0;i<album.songs.length;i++){
if(album.songs[i].song_name==songName){
return album.songs[i];
}
}
}
}
}

View file

@ -16,6 +16,31 @@ $(document).ready(function(){
if(tab=='collection'){
$('#plugins a[href="#collection"]').trigger('click');
}
OC.search.customResults.Music=function(row,item){
var parts=item.link.substr(item.link.indexOf('#')+1).split('&');
var data={};
for(var i=0;i<parts.length;i++){
var itemParts=parts[i].split('=');
data[itemParts[0]]=decodeURIComponent(itemParts[1]).replace(/\+/g,' ');
}
var media=Collection.find(data.artist,data.album,data.song);
var button=$('<input type="button" class="play"></input>');
button.css('background-image','url('+OC.imagePath('core','actions/play')+')')
button.click(function(){
var oldSize=PlayList.items.length;
PlayList.add(media);
PlayList.play(oldSize);
PlayList.render();
});
row.find('div.name').append(button);
var button=$('<input type="button" class="add"></input>');
button.css('background-image','url('+OC.imagePath('core','actions/play-add')+')')
button.click(function(){
PlayList.add(media);
PlayList.render();
});
row.find('div.name').append(button);
}
});

View file

@ -93,15 +93,15 @@ class OC_MediaSearchProvider extends OC_Search_Provider{
$results[]=new OC_Search_Result($artist['artist_name'],'',OC_Helper::linkTo( 'apps/media', 'index.php#artist='.urlencode($artist['artist_name']) ),'Music');
}
foreach($albums as $album){
$artist=urlencode(OC_MEDIA_COLLECTION::getArtistName($album['album_artist']));
$results[]=new OC_Search_Result($album['album_name'],'',OC_Helper::linkTo( 'apps/media', 'index.php#artist='.$artist.'&album='.urlencode($album['album_name']) ),'Music');
$artist=OC_MEDIA_COLLECTION::getArtistName($album['album_artist']);
$results[]=new OC_Search_Result($album['album_name'],'by '.$artist,OC_Helper::linkTo( 'apps/media', 'index.php#artist='.urlencode($artist).'&album='.urlencode($album['album_name']) ),'Music');
}
foreach($songs as $song){
$minutes=floor($song['song_length']/60);
$secconds=$song['song_length']%60;
$artist=urlencode(OC_MEDIA_COLLECTION::getArtistName($song['song_artist']));
$album=urlencode(OC_MEDIA_COLLECTION::getalbumName($song['song_album']));
$results[]=new OC_Search_Result($song['song_name'],"$minutes:$secconds",OC_Helper::linkTo( 'apps/media', 'index.php#artist='.$artist.'&album='.$album.'&song='.urlencode($song['song_name']) ),'Music');
$artist=OC_MEDIA_COLLECTION::getArtistName($song['song_artist']);
$album=OC_MEDIA_COLLECTION::getalbumName($song['song_album']);
$results[]=new OC_Search_Result($song['song_name'],"by $artist, in $album $minutes:$secconds",OC_Helper::linkTo( 'apps/media', 'index.php#artist='.urlencode($artist).'&album='.urlencode($album).'&song='.urlencode($song['song_name']) ),'Music');
}
return $results;
}

View file

@ -77,6 +77,7 @@ OC={
}
}
}
OC.search.customResults={};
OC.addStyle.loaded=[];
OC.addScript.loaded=[];

View file

@ -43,6 +43,9 @@ OC.search.showResults=function(results){
row.find('td.result a').attr('href',type[0].link);
row.find('td.result div.name').text(type[0].name);
row.find('td.result div.text').text(type[0].text);
if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here
OC.search.customResults[name](row,type[0]);
}
$('#searchresults tbody').append(row);
for(var i=1;i<type.length;i++){
var row=$('#searchresults tr.template').clone();
@ -51,6 +54,9 @@ OC.search.showResults=function(results){
row.find('td.result a').attr('href',type[i].link);
row.find('td.result div.name').text(type[i].name);
row.find('td.result div.text').text(type[i].text);
if(OC.search.customResults[name]){//give plugins the ability to customize the entries in here
OC.search.customResults[name](row,type[i]);
}
$('#searchresults tbody').append(row);
}
}