playlistsCtrl.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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(
  9. playlists,
  10. $scope,
  11. $location,
  12. backendSrv
  13. ) {
  14. $scope.playlists = playlists;
  15. $scope.playlistUrl = function(playlist) {
  16. return '/playlists/play/' + playlist.id;
  17. };
  18. $scope.removePlaylist = function(playlist) {
  19. var modalScope = $scope.$new(true);
  20. modalScope.playlist = playlist;
  21. modalScope.removePlaylist = function() {
  22. modalScope.dismiss();
  23. _.remove(playlists, {id: playlist.id});
  24. backendSrv.delete('/api/playlists/' + playlist.id)
  25. .then(function() {
  26. $scope.appEvent('alert-success', ['Playlist deleted', '']);
  27. }, function() {
  28. $scope.appEvent('alert-error', ['Unable to delete playlist', '']);
  29. playlists.push(playlist);
  30. });
  31. };
  32. $scope.appEvent('show-modal', {
  33. src: './app/features/playlist/partials/playlist-remove.html',
  34. scope: modalScope
  35. });
  36. };
  37. $scope.createPlaylist = function() {
  38. $location.path('/playlists/create');
  39. };
  40. });
  41. });