Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Component, OnInit} from '@angular/core';
- import {Account, AccountService} from "app/core";
- import {HttpErrorResponse, HttpHeaders, HttpResponse} from "@angular/common/http";
- import {ITicket} from "app/shared/model/ticket.model";
- import {TicketService} from "app/entities/ticket";
- import {JhiAlertService, JhiEventManager, JhiParseLinks} from "ng-jhipster";
- import {Subscription} from "rxjs";
- @Component({
- selector: 'jhi-selfticket',
- templateUrl: './selfticket.component.html',
- styles: []
- })
- export class SelfticketComponent implements OnInit {
- tickets: ITicket[];
- account: Account;
- page: any;
- itemsPerPage: any;
- eventSubscriber: Subscription;
- predicate: any;
- reverse: any;
- links: any;
- totalItems: any;
- constructor(
- private accountService: AccountService,
- private ticketService: TicketService,
- private jhiAlertService: JhiAlertService,
- private eventManager: JhiEventManager,
- private parseLinks: JhiParseLinks
- ) {
- }
- ngOnInit() {
- this.loadSelf();
- this.accountService.identity().then((account: Account) => {
- this.account = account;
- });
- this.registerChangeInTickets();
- }
- loadSelf() {
- this.ticketService
- .querySelf({
- page: this.page - 1,
- size: this.itemsPerPage,
- sort: this.sort()
- })
- .subscribe(
- (res: HttpResponse<ITicket[]>) => this.paginateTickets(res.body, res.headers),
- (res: HttpErrorResponse) => this.onError(res.message)
- );
- }
- sort() {
- const result = [this.predicate + ',' + (this.reverse ? 'asc' : 'desc')];
- if (this.predicate !== 'id') {
- result.push('id');
- }
- return result;
- }
- protected paginateTickets(data: ITicket[], headers: HttpHeaders) {
- this.links = this.parseLinks.parse(headers.get('link'));
- this.totalItems = parseInt(headers.get('X-Total-Count'), 10);
- this.tickets = data;
- }
- protected onError(errorMessage: string) {
- this.jhiAlertService.error(errorMessage, null, null);
- }
- registerChangeInTickets() {
- this.eventSubscriber = this.eventManager.subscribe('ticketListModification', response => this.loadSelf());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement