1
0
mirror of https://github.com/danbee/mpd-client synced 2025-03-04 08:39:09 +00:00

Add API service.

This commit is contained in:
Dan Barber 2014-03-21 11:13:34 +00:00
parent b247caa2bd
commit 2d317e7057
3 changed files with 23 additions and 11 deletions

View File

@ -1,7 +1,5 @@
mpdClient.controller('queue', function ($scope, $resource, serverEvents) {
var Queue = $resource('/api/queue')
$scope.queueSongs = Queue.query()
mpdClient.controller('queue', function ($scope, $resource, api, serverEvents) {
$scope.queueSongs = api.getQueue().query()
$scope.updateQueue = function(data) {
$scope.queueSongs = data

View File

@ -1,9 +1,7 @@
mpdClient.controller('transport', function ($scope, $http, serverEvents) {
var Status = $http({ method: 'GET', url: '/api/status' })
mpdClient.controller('transport', function ($scope, $http, api, serverEvents) {
$scope.status = {}
Status.success(function (data, status, headers, config) {
api.getStatus().success(function (data, status, headers, config) {
$scope.updateStatus(data)
})
@ -17,9 +15,7 @@ mpdClient.controller('transport', function ($scope, $http, serverEvents) {
$scope.totalTime = data[1]
}
$scope.sendCommand = function (command) {
$http({ method: 'PUT', url: '/api/control/' + command })
}
$scope.sendCommand = api.sendCommand
$scope.stopped = function () {
return $scope.status.state == 'stop'

View File

@ -0,0 +1,18 @@
mpdClient.factory('api', function ($rootScope, $http, $resource) {
var apiUrl = '/api'
return {
sendCommand: function (command) {
$http({ method: 'PUT', url: apiUrl + '/control/' + command })
},
getStatus: function () {
return $http({ method: 'GET', url: apiUrl + '/status' })
},
getQueue: function () {
return $resource(apiUrl + '/queue')
}
}
})