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) {
|
mpdClient.controller('queue', function ($scope, $resource, api, serverEvents) {
|
||||||
var Queue = $resource('/api/queue')
|
$scope.queueSongs = api.getQueue().query()
|
||||||
|
|
||||||
$scope.queueSongs = Queue.query()
|
|
||||||
|
|
||||||
$scope.updateQueue = function(data) {
|
$scope.updateQueue = function(data) {
|
||||||
$scope.queueSongs = data
|
$scope.queueSongs = data
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
mpdClient.controller('transport', function ($scope, $http, serverEvents) {
|
mpdClient.controller('transport', function ($scope, $http, api, serverEvents) {
|
||||||
var Status = $http({ method: 'GET', url: '/api/status' })
|
|
||||||
|
|
||||||
$scope.status = {}
|
$scope.status = {}
|
||||||
|
|
||||||
Status.success(function (data, status, headers, config) {
|
api.getStatus().success(function (data, status, headers, config) {
|
||||||
$scope.updateStatus(data)
|
$scope.updateStatus(data)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -17,9 +15,7 @@ mpdClient.controller('transport', function ($scope, $http, serverEvents) {
|
|||||||
$scope.totalTime = data[1]
|
$scope.totalTime = data[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.sendCommand = function (command) {
|
$scope.sendCommand = api.sendCommand
|
||||||
$http({ method: 'PUT', url: '/api/control/' + command })
|
|
||||||
}
|
|
||||||
|
|
||||||
$scope.stopped = function () {
|
$scope.stopped = function () {
|
||||||
return $scope.status.state == 'stop'
|
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