AdminListUsersCtrl.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { BackendSrv } from 'app/core/services/backend_srv';
  2. import { NavModelSrv } from 'app/core/core';
  3. export default class AdminListUsersCtrl {
  4. users: any;
  5. pages: any[] = [];
  6. perPage = 50;
  7. page = 1;
  8. totalPages: number;
  9. showPaging = false;
  10. query: any;
  11. navModel: any;
  12. /** @ngInject */
  13. constructor(private $scope: any, private backendSrv: BackendSrv, navModelSrv: NavModelSrv) {
  14. this.navModel = navModelSrv.getNav('admin', 'global-users');
  15. this.query = '';
  16. this.getUsers();
  17. }
  18. getUsers() {
  19. this.backendSrv
  20. .get(`/api/users/search?perpage=${this.perPage}&page=${this.page}&query=${this.query}`)
  21. .then((result: any) => {
  22. this.users = result.users;
  23. this.page = result.page;
  24. this.perPage = result.perPage;
  25. this.totalPages = Math.ceil(result.totalCount / result.perPage);
  26. this.showPaging = this.totalPages > 1;
  27. this.pages = [];
  28. for (let i = 1; i < this.totalPages + 1; i++) {
  29. this.pages.push({ page: i, current: i === this.page });
  30. }
  31. });
  32. }
  33. navigateToPage(page: any) {
  34. this.page = page.page;
  35. this.getUsers();
  36. }
  37. deleteUser(user: any) {
  38. this.$scope.appEvent('confirm-modal', {
  39. title: 'Delete',
  40. text: 'Do you want to delete ' + user.login + '?',
  41. icon: 'fa-trash',
  42. yesText: 'Delete',
  43. onConfirm: () => {
  44. this.backendSrv.delete('/api/admin/users/' + user.id).then(() => {
  45. this.getUsers();
  46. });
  47. },
  48. });
  49. }
  50. }