grafana/public/app/features/org/user_groups_ctrl.ts

69 lines
1.8 KiB
TypeScript
Raw Normal View History

2017-04-09 18:24:16 -05:00
///<reference path="../../headers/common.d.ts" />
import coreModule from 'app/core/core_module';
2017-06-17 17:16:33 -05:00
import {appEvents} from 'app/core/core';
2017-04-09 18:24:16 -05:00
export class UserGroupsCtrl {
2017-04-09 18:24:16 -05:00
userGroups: any;
pages = [];
perPage = 50;
page = 1;
totalPages: number;
showPaging = false;
query: any = '';
navModel: any;
2017-04-09 18:24:16 -05:00
/** @ngInject */
constructor(private $scope, private $http, private backendSrv, private $location, navModelSrv) {
2017-08-17 07:59:10 -05:00
this.navModel = navModelSrv.getNav('cfg', 'users');
2017-04-09 18:24:16 -05:00
this.get();
}
get() {
this.backendSrv.get(`/api/user-groups/search?perpage=${this.perPage}&page=${this.page}&query=${this.query}`)
.then((result) => {
this.userGroups = result.userGroups;
this.page = result.page;
this.perPage = result.perPage;
this.totalPages = Math.ceil(result.totalCount / result.perPage);
this.showPaging = this.totalPages > 1;
this.pages = [];
for (var i = 1; i < this.totalPages+1; i++) {
this.pages.push({ page: i, current: i === this.page});
}
});
}
navigateToPage(page) {
this.page = page.page;
this.get();
}
deleteUserGroup(userGroup) {
this.$scope.appEvent('confirm-modal', {
title: 'Delete',
text: 'Are you sure you want to delete User Group ' + userGroup.name + '?',
yesText: "Delete",
icon: "fa-warning",
onConfirm: () => {
this.deleteUserGroupConfirmed(userGroup);
}
});
}
deleteUserGroupConfirmed(userGroup) {
this.backendSrv.delete('/api/user-groups/' + userGroup.id)
.then(this.get.bind(this));
}
2017-04-19 08:35:35 -05:00
2017-05-22 03:33:17 -05:00
openUserGroupModal() {
2017-06-17 17:16:33 -05:00
appEvents.emit('show-modal', {
templateHtml: '<create-user-group-modal></create-user-group-modal>',
modalClass: 'modal--narrow'
2017-04-19 08:35:35 -05:00
});
}
2017-04-09 18:24:16 -05:00
}
coreModule.controller('UserGroupsCtrl', UserGroupsCtrl);