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

52 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import _ from 'lodash';
import coreModule from '../../core/core_module';
import { BackendSrv } from '@grafana/runtime';
import { NavModelSrv } from 'app/core/nav_model_srv';
import { CoreEvents } from 'app/types';
import { AppEvents } from '@grafana/data';
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: any, private backendSrv: BackendSrv, navModelSrv: NavModelSrv) {
2017-12-20 05:33:33 -06:00
this.navModel = navModelSrv.getNav('dashboards', 'playlists', 0);
backendSrv.get('/api/playlists').then((result: any) => {
this.playlists = result.map((item: any) => {
item.startUrl = `playlists/play/${item.id}`;
return item;
});
});
2016-01-26 12:03:43 -06:00
}
removePlaylistConfirmed(playlist: any) {
2016-01-26 12:03:43 -06:00
_.remove(this.playlists, { id: playlist.id });
2017-12-20 05:33:33 -06:00
this.backendSrv.delete('/api/playlists/' + playlist.id).then(
() => {
this.$scope.appEvent(AppEvents.alertSuccess, ['Playlist deleted']);
},
() => {
this.$scope.appEvent(AppEvents.alertError, ['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: any) {
this.$scope.appEvent(CoreEvents.showConfirmModal, {
2017-12-20 05:33:33 -06:00
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);