user_groups_ctrl.ts 2.1 KB

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