user-profile.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 { IUserProfile } from 'app/shared/model/user-profile.model';
  6. import { Principal } from 'app/core';
  7. import { UserProfileService } from './user-profile.service';
  8. @Component({
  9. selector: 'jhi-user-profile',
  10. templateUrl: './user-profile.component.html'
  11. })
  12. export class UserProfileComponent implements OnInit, OnDestroy {
  13. userProfiles: IUserProfile[];
  14. currentAccount: any;
  15. eventSubscriber: Subscription;
  16. constructor(
  17. private userProfileService: UserProfileService,
  18. private jhiAlertService: JhiAlertService,
  19. private eventManager: JhiEventManager,
  20. private principal: Principal
  21. ) {}
  22. loadAll() {
  23. this.userProfileService.query().subscribe(
  24. (res: HttpResponse<IUserProfile[]>) => {
  25. this.userProfiles = 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.registerChangeInUserProfiles();
  36. }
  37. ngOnDestroy() {
  38. this.eventManager.destroy(this.eventSubscriber);
  39. }
  40. trackId(index: number, item: IUserProfile) {
  41. return item.id;
  42. }
  43. registerChangeInUserProfiles() {
  44. this.eventSubscriber = this.eventManager.subscribe('userProfileListModification', response => this.loadAll());
  45. }
  46. private onError(errorMessage: string) {
  47. this.jhiAlertService.error(errorMessage, null, null);
  48. }
  49. }