playlists_ctrl.js 1.3 KB

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