Pony.fm/resources/assets/scripts/app/services/artists.coffee

80 lines
3 KiB
CoffeeScript
Raw Normal View History

# Pony.fm - A community for pony fan music.
2018-04-21 06:25:36 +02:00
# Copyright (C) 2015 Feld0
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
module.exports = angular.module('ponyfm').factory('artists', [
2016-06-12 13:31:57 +02:00
'$rootScope', '$http'
($rootScope, $http) ->
2015-10-25 03:35:37 +01:00
artistPage = []
artists = {}
artistContent = {}
artistFavourites = {}
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()
$http.get('/api/web/artists/' + slug)
.success (albums) ->
artistsDef.resolve albums
.catch () ->
artistsDef.reject()
artists[slug] = artistsDef.promise()
fetchContent: (slug, force) ->
force = force || false
slug = 1 if !slug
return artistContent[slug] if !force && artistContent[slug]
artistsDef = new $.Deferred()
$http.get('/api/web/artists/' + slug + '/content')
.success (albums) ->
artistsDef.resolve albums
.catch () ->
artistsDef.reject()
artistContent[slug] = artistsDef.promise()
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()
create: (username) ->
$http.post('/api/web/artists', {username: username})
2015-10-25 03:35:37 +01:00
self
])