playlists_ctrl.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. define([
  2. 'angular',
  3. 'lodash'
  4. ],
  5. function (angular, _) {
  6. 'use strict';
  7. var module = angular.module('grafana.controllers');
  8. module.controller('PlaylistsCtrl', function($scope, $location, backendSrv) {
  9. backendSrv.get('/api/playlists')
  10. .then(function(result) {
  11. $scope.playlists = result;
  12. });
  13. $scope.removePlaylist = function(playlist) {
  14. var modalScope = $scope.$new(true);
  15. modalScope.playlist = playlist;
  16. modalScope.removePlaylist = function() {
  17. modalScope.dismiss();
  18. _.remove($scope.playlists, {id: playlist.id});
  19. backendSrv.delete('/api/playlists/' + playlist.id)
  20. .then(function() {
  21. $scope.appEvent('alert-success', ['Playlist deleted', '']);
  22. }, function() {
  23. $scope.appEvent('alert-error', ['Unable to delete playlist', '']);
  24. $scope.playlists.push(playlist);
  25. });
  26. };
  27. $scope.appEvent('show-modal', {
  28. src: './app/features/playlist/partials/playlist-remove.html',
  29. scope: modalScope
  30. });
  31. };
  32. $scope.createPlaylist = function() {
  33. $location.path('/playlists/create');
  34. };
  35. });
  36. });