playlists_ctrl.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.map(item => {
  11. item.startUrl = `playlists/play/${item.id}`;
  12. return item;
  13. });
  14. });
  15. }
  16. removePlaylistConfirmed(playlist) {
  17. _.remove(this.playlists, { id: playlist.id });
  18. this.backendSrv.delete('/api/playlists/' + playlist.id).then(
  19. () => {
  20. this.$scope.appEvent('alert-success', ['Playlist deleted', '']);
  21. },
  22. () => {
  23. this.$scope.appEvent('alert-error', ['Unable to delete playlist', '']);
  24. this.playlists.push(playlist);
  25. }
  26. );
  27. }
  28. removePlaylist(playlist) {
  29. this.$scope.appEvent('confirm-modal', {
  30. title: 'Delete',
  31. text: 'Are you sure you want to delete playlist ' + playlist.name + '?',
  32. yesText: 'Delete',
  33. icon: 'fa-trash',
  34. onConfirm: () => {
  35. this.removePlaylistConfirmed(playlist);
  36. },
  37. });
  38. }
  39. }
  40. coreModule.controller('PlaylistsCtrl', PlaylistsCtrl);