playlists_ctrl.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import _ from 'lodash';
  2. import coreModule from '../../core/core_module';
  3. import { BackendSrv } from '@grafana/runtime';
  4. import { NavModelSrv } from 'app/core/nav_model_srv';
  5. export class PlaylistsCtrl {
  6. playlists: any;
  7. navModel: any;
  8. /** @ngInject */
  9. constructor(private $scope: any, private backendSrv: BackendSrv, navModelSrv: NavModelSrv) {
  10. this.navModel = navModelSrv.getNav('dashboards', 'playlists', 0);
  11. backendSrv.get('/api/playlists').then((result: any) => {
  12. this.playlists = result.map((item: any) => {
  13. item.startUrl = `playlists/play/${item.id}`;
  14. return item;
  15. });
  16. });
  17. }
  18. removePlaylistConfirmed(playlist: any) {
  19. _.remove(this.playlists, { id: playlist.id });
  20. this.backendSrv.delete('/api/playlists/' + playlist.id).then(
  21. () => {
  22. this.$scope.appEvent('alert-success', ['Playlist deleted', '']);
  23. },
  24. () => {
  25. this.$scope.appEvent('alert-error', ['Unable to delete playlist', '']);
  26. this.playlists.push(playlist);
  27. }
  28. );
  29. }
  30. removePlaylist(playlist: any) {
  31. this.$scope.appEvent('confirm-modal', {
  32. title: 'Delete',
  33. text: 'Are you sure you want to delete playlist ' + playlist.name + '?',
  34. yesText: 'Delete',
  35. icon: 'fa-trash',
  36. onConfirm: () => {
  37. this.removePlaylistConfirmed(playlist);
  38. },
  39. });
  40. }
  41. }
  42. coreModule.controller('PlaylistsCtrl', PlaylistsCtrl);