2017-12-20 05:33:33 -06:00
|
|
|
import _ from 'lodash';
|
|
|
|
import coreModule from '../../core/core_module';
|
2016-01-26 12:03:43 -06:00
|
|
|
|
|
|
|
export class PlaylistsCtrl {
|
|
|
|
playlists: any;
|
2017-06-02 07:00:42 -05:00
|
|
|
navModel: any;
|
2016-01-26 12:03:43 -06:00
|
|
|
|
|
|
|
/** @ngInject */
|
2017-09-21 09:40:18 -05:00
|
|
|
constructor(private $scope, private backendSrv, navModelSrv) {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.navModel = navModelSrv.getNav('dashboards', 'playlists', 0);
|
2017-06-02 07:00:42 -05:00
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
backendSrv.get('/api/playlists').then(result => {
|
2017-06-02 07:00:42 -05:00
|
|
|
this.playlists = result;
|
|
|
|
});
|
2016-01-26 12:03:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
removePlaylistConfirmed(playlist) {
|
|
|
|
_.remove(this.playlists, { id: playlist.id });
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
this.backendSrv.delete('/api/playlists/' + playlist.id).then(
|
2017-12-19 09:06:54 -06:00
|
|
|
() => {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.$scope.appEvent('alert-success', ['Playlist deleted', '']);
|
2017-12-19 09:06:54 -06:00
|
|
|
},
|
|
|
|
() => {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.$scope.appEvent('alert-error', ['Unable to delete playlist', '']);
|
2016-01-26 12:03:43 -06:00
|
|
|
this.playlists.push(playlist);
|
2017-12-19 09:06:54 -06:00
|
|
|
}
|
|
|
|
);
|
2016-01-28 17:11:59 -06:00
|
|
|
}
|
2016-01-26 12:03:43 -06:00
|
|
|
|
|
|
|
removePlaylist(playlist) {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.$scope.appEvent('confirm-modal', {
|
|
|
|
title: 'Delete',
|
|
|
|
text: 'Are you sure you want to delete playlist ' + playlist.name + '?',
|
|
|
|
yesText: 'Delete',
|
|
|
|
icon: 'fa-trash',
|
2016-01-26 12:03:43 -06:00
|
|
|
onConfirm: () => {
|
|
|
|
this.removePlaylistConfirmed(playlist);
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2016-01-26 12:03:43 -06:00
|
|
|
});
|
2016-01-28 17:11:59 -06:00
|
|
|
}
|
2016-01-26 12:03:43 -06:00
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.controller('PlaylistsCtrl', PlaylistsCtrl);
|