grafana/public/app/features/playlist/playlists_ctrl.ts

45 lines
1.1 KiB
TypeScript
Raw Normal View History

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;
navModel: any;
2016-01-26 12:03:43 -06:00
/** @ngInject */
constructor(private $scope, private backendSrv, navModelSrv) {
2017-12-20 05:33:33 -06:00
this.navModel = navModelSrv.getNav('dashboards', 'playlists', 0);
2017-12-20 05:33:33 -06:00
backendSrv.get('/api/playlists').then(result => {
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-20 05:33:33 -06:00
this.$scope.appEvent('alert-success', ['Playlist deleted', '']);
},
() => {
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);
}
);
}
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-26 12:03:43 -06:00
}
2017-12-20 05:33:33 -06:00
coreModule.controller('PlaylistsCtrl', PlaylistsCtrl);