mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Eslint: no-duplicate-imports rule (bump grafana-eslint-config) * Chore: Fix duplicate imports (#31041) * Rebased this branch into eslint-no-duplicate-imports * updated some changes * merged uncaught duplicate imports * fixes frontend test- I hope * fixes e2e test- I hope Co-authored-by: Uchechukwu Obasi <obasiuche62@gmail.com>
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { IScope } from 'angular';
|
|
import _ from 'lodash';
|
|
import { AppEvents } from '@grafana/data';
|
|
import { OrgRole, AppEventEmitter, CoreEvents } from 'app/types';
|
|
import { getBackendSrv } from '@grafana/runtime';
|
|
|
|
import coreModule from '../../core/core_module';
|
|
import config from '../../core/config';
|
|
import { NavModelSrv } from 'app/core/nav_model_srv';
|
|
import { promiseToDigest } from '../../core/utils/promiseToDigest';
|
|
|
|
export class PlaylistsCtrl {
|
|
playlists: any;
|
|
navModel: any;
|
|
canEditPlaylists: boolean;
|
|
|
|
/** @ngInject */
|
|
constructor(private $scope: IScope & AppEventEmitter, navModelSrv: NavModelSrv) {
|
|
this.navModel = navModelSrv.getNav('dashboards', 'playlists', 0);
|
|
this.canEditPlaylists = config.bootData.user.orgRole !== OrgRole.Viewer;
|
|
|
|
promiseToDigest($scope)(
|
|
getBackendSrv()
|
|
.get('/api/playlists')
|
|
.then((result: any) => {
|
|
this.playlists = result.map((item: any) => {
|
|
item.startUrl = `playlists/play/${item.id}`;
|
|
return item;
|
|
});
|
|
})
|
|
);
|
|
}
|
|
|
|
removePlaylistConfirmed(playlist: any) {
|
|
_.remove(this.playlists, { id: playlist.id });
|
|
|
|
promiseToDigest(this.$scope)(
|
|
getBackendSrv()
|
|
.delete('/api/playlists/' + playlist.id)
|
|
.then(
|
|
() => {
|
|
this.$scope.appEvent(AppEvents.alertSuccess, ['Playlist deleted']);
|
|
},
|
|
() => {
|
|
this.$scope.appEvent(AppEvents.alertError, ['Unable to delete playlist']);
|
|
this.playlists.push(playlist);
|
|
}
|
|
)
|
|
);
|
|
}
|
|
|
|
removePlaylist(playlist: any) {
|
|
this.$scope.appEvent(CoreEvents.showConfirmModal, {
|
|
title: 'Delete',
|
|
text: 'Are you sure you want to delete playlist ' + playlist.name + '?',
|
|
yesText: 'Delete',
|
|
icon: 'trash-alt',
|
|
onConfirm: () => {
|
|
this.removePlaylistConfirmed(playlist);
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
coreModule.controller('PlaylistsCtrl', PlaylistsCtrl);
|