admin_list_users_ctrl.ts 1.2 KB

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