playlists_ctrl.ts 1.1 KB

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