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:
parent
b247caa2bd
commit
2d317e7057
@ -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
|
||||
|
||||
@ -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'
|
||||
|
||||
18
assets/js/services/api.service.js
Normal file
18
assets/js/services/api.service.js
Normal 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')
|
||||
}
|
||||
}
|
||||
})
|
||||
Loading…
Reference in New Issue
Block a user