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