2013-08-01 04:01:41 +02:00
|
|
|
angular.module('ponyfm').factory('artists', [
|
|
|
|
'$rootScope', '$http'
|
|
|
|
($rootScope, $http) ->
|
|
|
|
artistPage = []
|
|
|
|
artists = {}
|
2013-08-01 04:47:21 +02:00
|
|
|
artistContent = {}
|
2013-08-01 10:57:08 +02:00
|
|
|
artistFavourites = {}
|
2013-08-01 04:01:41 +02:00
|
|
|
|
|
|
|
self =
|
|
|
|
filters: {}
|
|
|
|
|
|
|
|
fetchList: (page, force) ->
|
|
|
|
force = force || false
|
|
|
|
page = 1 if !page
|
|
|
|
return artistPage[page] if !force && artistPage[page]
|
|
|
|
artistsDef = new $.Deferred()
|
|
|
|
$http.get('/api/web/artists?page=' + page).success (albums) ->
|
|
|
|
artistsDef.resolve albums
|
|
|
|
$rootScope.$broadcast 'artists-feteched', albums
|
|
|
|
|
|
|
|
artistPage[page] = artistsDef.promise()
|
|
|
|
|
|
|
|
fetch: (slug, force) ->
|
|
|
|
force = force || false
|
|
|
|
slug = 1 if !slug
|
|
|
|
return artists[slug] if !force && artists[slug]
|
|
|
|
artistsDef = new $.Deferred()
|
2013-09-01 23:54:33 +02:00
|
|
|
$http.get('/api/web/artists/' + slug)
|
|
|
|
.success (albums) ->
|
|
|
|
artistsDef.resolve albums
|
|
|
|
.catch () ->
|
|
|
|
artistsDef.reject()
|
2013-08-01 04:01:41 +02:00
|
|
|
|
|
|
|
artists[slug] = artistsDef.promise()
|
|
|
|
|
2013-08-01 04:47:21 +02:00
|
|
|
fetchContent: (slug, force) ->
|
|
|
|
force = force || false
|
|
|
|
slug = 1 if !slug
|
|
|
|
return artistContent[slug] if !force && artistContent[slug]
|
|
|
|
artistsDef = new $.Deferred()
|
2013-09-01 23:54:33 +02:00
|
|
|
$http.get('/api/web/artists/' + slug + '/content')
|
|
|
|
.success (albums) ->
|
|
|
|
artistsDef.resolve albums
|
|
|
|
.catch () ->
|
|
|
|
artistsDef.reject()
|
2013-08-01 04:47:21 +02:00
|
|
|
|
|
|
|
artistContent[slug] = artistsDef.promise()
|
|
|
|
|
2013-08-01 10:57:08 +02:00
|
|
|
fetchFavourites: (slug, force) ->
|
|
|
|
force = force || false
|
|
|
|
slug = 1 if !slug
|
|
|
|
return artistFavourites[slug] if !force && artistFavourites[slug]
|
|
|
|
artistsDef = new $.Deferred()
|
|
|
|
$http.get('/api/web/artists/' + slug + '/favourites').success (albums) ->
|
|
|
|
artistsDef.resolve albums
|
|
|
|
|
|
|
|
artistFavourites[slug] = artistsDef.promise()
|
|
|
|
|
2013-08-01 04:01:41 +02:00
|
|
|
self
|
|
|
|
])
|