2017-12-20 05:33:33 -06:00
|
|
|
import _ from 'lodash';
|
|
|
|
import coreModule from '../../core/core_module';
|
2019-07-18 01:03:04 -05:00
|
|
|
import { BackendSrv } from '@grafana/runtime';
|
|
|
|
import { NavModelSrv } from 'app/core/nav_model_srv';
|
2019-10-14 03:27:47 -05:00
|
|
|
import { CoreEvents } from 'app/types';
|
|
|
|
import { AppEvents } from '@grafana/data';
|
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 */
|
2019-07-18 01:03:04 -05:00
|
|
|
constructor(private $scope: any, private backendSrv: BackendSrv, navModelSrv: NavModelSrv) {
|
2017-12-20 05:33:33 -06:00
|
|
|
this.navModel = navModelSrv.getNav('dashboards', 'playlists', 0);
|
2017-06-02 07:00:42 -05:00
|
|
|
|
2019-07-18 01:03:04 -05:00
|
|
|
backendSrv.get('/api/playlists').then((result: any) => {
|
|
|
|
this.playlists = result.map((item: any) => {
|
2018-08-30 04:52:31 -05:00
|
|
|
item.startUrl = `playlists/play/${item.id}`;
|
|
|
|
return item;
|
|
|
|
});
|
2017-06-02 07:00:42 -05:00
|
|
|
});
|
2016-01-26 12:03:43 -06:00
|
|
|
}
|
|
|
|
|
2019-07-18 01:03:04 -05: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(
|
2017-12-19 09:06:54 -06:00
|
|
|
() => {
|
2019-10-14 03:27:47 -05:00
|
|
|
this.$scope.appEvent(AppEvents.alertSuccess, ['Playlist deleted']);
|
2017-12-19 09:06:54 -06:00
|
|
|
},
|
|
|
|
() => {
|
2019-10-14 03:27:47 -05:00
|
|
|
this.$scope.appEvent(AppEvents.alertError, ['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
|
|
|
|
2019-07-18 01:03:04 -05:00
|
|
|
removePlaylist(playlist: any) {
|
2019-10-14 03:27:47 -05:00
|
|
|
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-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);
|