user_groups_ctrl.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ///<reference path="../../headers/common.d.ts" />
  2. import coreModule from 'app/core/core_module';
  3. export default class UserGroupsCtrl {
  4. userGroups: any;
  5. pages = [];
  6. perPage = 50;
  7. page = 1;
  8. totalPages: number;
  9. showPaging = false;
  10. query: any = '';
  11. /** @ngInject */
  12. constructor(private $scope, private $http, private backendSrv) {
  13. this.get();
  14. }
  15. get() {
  16. this.backendSrv.get(`/api/user-groups/search?perpage=${this.perPage}&page=${this.page}&query=${this.query}`)
  17. .then((result) => {
  18. this.userGroups = result.userGroups;
  19. this.page = result.page;
  20. this.perPage = result.perPage;
  21. this.totalPages = Math.ceil(result.totalCount / result.perPage);
  22. this.showPaging = this.totalPages > 1;
  23. this.pages = [];
  24. for (var i = 1; i < this.totalPages+1; i++) {
  25. this.pages.push({ page: i, current: i === this.page});
  26. }
  27. });
  28. }
  29. navigateToPage(page) {
  30. this.page = page.page;
  31. this.get();
  32. }
  33. deleteUserGroup(userGroup) {
  34. this.$scope.appEvent('confirm-modal', {
  35. title: 'Delete',
  36. text: 'Are you sure you want to delete User Group ' + userGroup.name + '?',
  37. yesText: "Delete",
  38. icon: "fa-warning",
  39. onConfirm: () => {
  40. this.deleteUserGroupConfirmed(userGroup);
  41. }
  42. });
  43. }
  44. deleteUserGroupConfirmed(userGroup) {
  45. this.backendSrv.delete('/api/user-groups/' + userGroup.id)
  46. .then(this.get.bind(this));
  47. }
  48. openUserGroupModal() {
  49. var modalScope = this.$scope.$new();
  50. this.$scope.appEvent('show-modal', {
  51. src: 'public/app/features/org/partials/add_user.html',
  52. modalClass: 'user-group-modal',
  53. scope: modalScope
  54. });
  55. }
  56. }
  57. coreModule.controller('UserGroupsCtrl', UserGroupsCtrl);