admin_list_users_ctrl.ts 1.2 KB

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