playlists_ctrl.js 1.2 KB

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