privacy.component.ts 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Component, OnInit, OnDestroy } from '@angular/core';
  2. import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
  3. import { Subscription } from 'rxjs';
  4. import { JhiEventManager, JhiAlertService } from 'ng-jhipster';
  5. import { IPrivacy } from 'app/shared/model/privacy.model';
  6. import { Principal } from 'app/core';
  7. import { PrivacyService } from './privacy.service';
  8. @Component({
  9. selector: 'jhi-privacy',
  10. templateUrl: './privacy.component.html'
  11. })
  12. export class PrivacyComponent implements OnInit, OnDestroy {
  13. privacies: IPrivacy[];
  14. currentAccount: any;
  15. eventSubscriber: Subscription;
  16. constructor(
  17. private privacyService: PrivacyService,
  18. private jhiAlertService: JhiAlertService,
  19. private eventManager: JhiEventManager,
  20. private principal: Principal
  21. ) {}
  22. loadAll() {
  23. this.privacyService.query().subscribe(
  24. (res: HttpResponse<IPrivacy[]>) => {
  25. this.privacies = res.body;
  26. },
  27. (res: HttpErrorResponse) => this.onError(res.message)
  28. );
  29. }
  30. ngOnInit() {
  31. this.loadAll();
  32. this.principal.identity().then(account => {
  33. this.currentAccount = account;
  34. });
  35. this.registerChangeInPrivacies();
  36. }
  37. ngOnDestroy() {
  38. this.eventManager.destroy(this.eventSubscriber);
  39. }
  40. trackId(index: number, item: IPrivacy) {
  41. return item.id;
  42. }
  43. registerChangeInPrivacies() {
  44. this.eventSubscriber = this.eventManager.subscribe('privacyListModification', response => this.loadAll());
  45. }
  46. private onError(errorMessage: string) {
  47. this.jhiAlertService.error(errorMessage, null, null);
  48. }
  49. }