2020-01-21 09:08:07 +00:00
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
2019-05-13 09:38:19 +02:00
|
|
|
import { NavModelSrv } from 'app/core/core';
|
2019-10-14 09:27:47 +01:00
|
|
|
import { Scope, CoreEvents, AppEventEmitter } from 'app/types';
|
2020-01-21 09:08:07 +00:00
|
|
|
import { promiseToDigest } from 'app/core/utils/promiseToDigest';
|
2019-05-13 09:38:19 +02:00
|
|
|
|
2018-09-07 17:55:38 +02:00
|
|
|
export default class AdminListOrgsCtrl {
|
2017-11-23 17:05:08 +01:00
|
|
|
/** @ngInject */
|
2020-01-21 09:08:07 +00:00
|
|
|
constructor($scope: Scope & AppEventEmitter, navModelSrv: NavModelSrv) {
|
|
|
|
|
$scope.init = async () => {
|
2019-06-05 15:18:31 +02:00
|
|
|
$scope.navModel = navModelSrv.getNav('admin', 'global-orgs', 0);
|
2020-01-21 09:08:07 +00:00
|
|
|
await $scope.getOrgs();
|
2015-08-11 15:20:50 +02:00
|
|
|
};
|
|
|
|
|
|
2020-01-21 09:08:07 +00:00
|
|
|
$scope.getOrgs = async () => {
|
|
|
|
|
const orgs = await promiseToDigest($scope)(getBackendSrv().get('/api/orgs'));
|
|
|
|
|
$scope.orgs = orgs;
|
2015-08-11 15:20:50 +02:00
|
|
|
};
|
|
|
|
|
|
2019-05-13 09:38:19 +02:00
|
|
|
$scope.deleteOrg = (org: any) => {
|
2019-10-14 09:27:47 +01:00
|
|
|
$scope.appEvent(CoreEvents.showConfirmModal, {
|
2017-12-20 12:33:33 +01:00
|
|
|
title: 'Delete',
|
2019-10-14 09:27:47 +01:00
|
|
|
text: `Do you want to delete organization ${org.name}?`,
|
2017-12-20 12:33:33 +01:00
|
|
|
text2: 'All dashboards for this organization will be removed!',
|
|
|
|
|
icon: 'fa-trash',
|
|
|
|
|
yesText: 'Delete',
|
2020-01-21 09:08:07 +00:00
|
|
|
onConfirm: async () => {
|
|
|
|
|
await getBackendSrv().delete('/api/orgs/' + org.id);
|
|
|
|
|
await $scope.getOrgs();
|
2017-12-20 12:33:33 +01:00
|
|
|
},
|
2015-08-11 15:20:50 +02:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.init();
|
2017-11-23 17:05:08 +01:00
|
|
|
}
|
|
|
|
|
}
|