teams_ctrl.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import coreModule from 'app/core/core_module';
  2. import appEvents from 'app/core/app_events';
  3. export class TeamsCtrl {
  4. teams: any;
  5. pages = [];
  6. perPage = 50;
  7. page = 1;
  8. totalPages: number;
  9. showPaging = false;
  10. query: any = '';
  11. navModel: any;
  12. /** @ngInject */
  13. constructor(private backendSrv, navModelSrv) {
  14. this.navModel = navModelSrv.getNav('cfg', 'teams', 0);
  15. this.get();
  16. }
  17. get() {
  18. this.backendSrv
  19. .get(`/api/teams/search?perpage=${this.perPage}&page=${this.page}&query=${this.query}`)
  20. .then(result => {
  21. this.teams = result.teams;
  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. deleteTeam(team) {
  37. appEvents.emit('confirm-modal', {
  38. title: 'Delete',
  39. text: 'Are you sure you want to delete Team ' + team.name + '?',
  40. yesText: 'Delete',
  41. icon: 'fa-warning',
  42. onConfirm: () => {
  43. this.deleteTeamConfirmed(team);
  44. },
  45. });
  46. }
  47. deleteTeamConfirmed(team) {
  48. this.backendSrv.delete('/api/teams/' + team.id).then(this.get.bind(this));
  49. }
  50. openTeamModal() {
  51. appEvents.emit('show-modal', {
  52. templateHtml: '<create-team-modal></create-team-modal>',
  53. modalClass: 'modal--narrow',
  54. });
  55. }
  56. }
  57. coreModule.controller('TeamsCtrl', TeamsCtrl);