Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. import {Component, OnInit} from '@angular/core';
  2. import {Account, AccountService} from "app/core";
  3. import {HttpErrorResponse, HttpHeaders, HttpResponse} from "@angular/common/http";
  4. import {ITicket} from "app/shared/model/ticket.model";
  5. import {TicketService} from "app/entities/ticket";
  6. import {JhiAlertService, JhiEventManager, JhiParseLinks} from "ng-jhipster";
  7. import {Subscription} from "rxjs";
  8.  
  9. @Component({
  10. selector: 'jhi-selfticket',
  11. templateUrl: './selfticket.component.html',
  12. styles: []
  13. })
  14. export class SelfticketComponent implements OnInit {
  15.  
  16. tickets: ITicket[];
  17.  
  18. account: Account;
  19. page: any;
  20. itemsPerPage: any;
  21. eventSubscriber: Subscription;
  22. predicate: any;
  23. reverse: any;
  24. links: any;
  25. totalItems: any;
  26.  
  27.  
  28. constructor(
  29. private accountService: AccountService,
  30. private ticketService: TicketService,
  31. private jhiAlertService: JhiAlertService,
  32. private eventManager: JhiEventManager,
  33. private parseLinks: JhiParseLinks
  34. ) {
  35. }
  36.  
  37. ngOnInit() {
  38. this.loadSelf();
  39. this.accountService.identity().then((account: Account) => {
  40. this.account = account;
  41. });
  42. this.registerChangeInTickets();
  43. }
  44.  
  45. loadSelf() {
  46. this.ticketService
  47. .querySelf({
  48. page: this.page - 1,
  49. size: this.itemsPerPage,
  50. sort: this.sort()
  51. })
  52. .subscribe(
  53. (res: HttpResponse<ITicket[]>) => this.paginateTickets(res.body, res.headers),
  54. (res: HttpErrorResponse) => this.onError(res.message)
  55. );
  56.  
  57. }
  58.  
  59. sort() {
  60. const result = [this.predicate + ',' + (this.reverse ? 'asc' : 'desc')];
  61. if (this.predicate !== 'id') {
  62. result.push('id');
  63. }
  64. return result;
  65. }
  66.  
  67. protected paginateTickets(data: ITicket[], headers: HttpHeaders) {
  68. this.links = this.parseLinks.parse(headers.get('link'));
  69. this.totalItems = parseInt(headers.get('X-Total-Count'), 10);
  70. this.tickets = data;
  71. }
  72.  
  73. protected onError(errorMessage: string) {
  74. this.jhiAlertService.error(errorMessage, null, null);
  75. }
  76.  
  77. registerChangeInTickets() {
  78. this.eventSubscriber = this.eventManager.subscribe('ticketListModification', response => this.loadSelf());
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement