選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

173 行
6.2 KiB

  1. import {AfterViewInit, ChangeDetectorRef, Component, OnInit, ViewChild} from '@angular/core';
  2. import {environment} from "@environments/environment";
  3. import {CommentJsonld, ContactJsonld, ContactService, PartnerJsonld, PostJsonld, PostService} from "@app/core/api/v1";
  4. import {Subscription} from "rxjs";
  5. import {ActivatedRoute} from "@angular/router";
  6. import {MatPaginator, MatPaginatorIntl, PageEvent} from "@angular/material/paginator";
  7. import {MatTableDataSource} from "@angular/material/table";
  8. import {NewPostingComponent} from "@app/postings/new-posting/new-posting.component";
  9. import {ModalComponent} from "@app/_components/modal/modal.component";
  10. import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
  11. import {NewContactComponent} from "@app/contacts/new-contact/new-contact.component";
  12. import {ModalStatus} from "@app/_helpers/modal.states";
  13. import {User} from "@app/_models";
  14. import {AccountService} from "@app/_services";
  15. import {NewCommentComponent} from "@app/postings/new-comment/new-comment.component";
  16. @Component({
  17. selector: 'app-contacts-detail',
  18. templateUrl: './contacts-detail.component.html',
  19. styleUrl: './contacts-detail.component.scss'
  20. })
  21. export class ContactsDetailComponent implements OnInit, AfterViewInit {
  22. @ViewChild(MatPaginator) postsPaginator: MatPaginator;
  23. protected user: User | null;
  24. protected readonly environment = environment;
  25. protected contact: ContactJsonld;
  26. protected id: string;
  27. protected contactSub: Subscription;
  28. protected postsSub: Subscription;
  29. protected posts: Array<PostJsonld>;
  30. protected postsDataSource;
  31. protected postsLength: number;
  32. protected postsPageEvent: PageEvent;
  33. protected postsPageSize: number;
  34. protected postsPageIndex: number;
  35. constructor(
  36. private contactService: ContactService,
  37. private accountService: AccountService,
  38. private route: ActivatedRoute,
  39. private postService: PostService,
  40. private modalService: NgbModal
  41. ) {
  42. this.user = this.accountService.userValue;
  43. this.id = "";
  44. this.contact = {} as ContactJsonld;
  45. this.contactSub = new Subscription();
  46. this.postsSub = new Subscription();
  47. this.posts = [];
  48. this.postsPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype);
  49. this.postsDataSource = new MatTableDataSource<PostJsonld>(this.posts);
  50. this.postsLength = 0;
  51. this.postsPageEvent = new PageEvent();
  52. this.postsPageSize = 10;
  53. this.postsPageIndex = 0;
  54. }
  55. ngOnInit() {
  56. this.route.params.subscribe(params => {
  57. this.id = params['id'];
  58. });
  59. this.getContactData();
  60. this.getPostsData();
  61. console.log(this.contact.imageUrl);
  62. }
  63. ngAfterViewInit() {
  64. this.postsDataSource.paginator = this.postsPaginator;
  65. }
  66. getContactData() {
  67. // switch over this.dataType (customers, etc.)
  68. this.contactSub = this.contactService.contactsIdGet(
  69. this.id
  70. ).subscribe(
  71. data => {
  72. this.contact = data;
  73. console.log(this.contact);
  74. }
  75. );
  76. }
  77. getPostsData() {
  78. this.postsSub = this.postService.postsGetCollection(
  79. this.postsPageIndex + 1,
  80. this.postsPageSize,
  81. this.contact.partner + '',
  82. [],
  83. this.id
  84. ).subscribe(
  85. data => {
  86. this.posts = data["hydra:member"];
  87. this.postsLength = Number(data["hydra:totalItems"]);
  88. }
  89. );
  90. }
  91. postsHandlePageEvent(e: PageEvent) {
  92. this.postsPageEvent = e;
  93. this.postsLength = e.length;
  94. this.postsPageIndex = e.pageIndex.valueOf();
  95. this.postsPageSize = e.pageSize.valueOf();
  96. this.getPostsData();
  97. }
  98. openModalNewPosting() {
  99. const modalRefPosting = this.modalService.open(NewPostingComponent);
  100. let posting: PostJsonld = {} as PostJsonld;
  101. posting.contact = this.contact.id ?? null;
  102. posting.partner = this.contact.partner ?? null;
  103. modalRefPosting.componentInstance.posting = posting;
  104. modalRefPosting.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  105. if (modalStatus === ModalStatus.Submitted) {
  106. modalRefPosting.dismiss();
  107. this.getPostsData();
  108. }
  109. });
  110. }
  111. openModalNewComment(post: PostJsonld) {
  112. const modalRefComment = this.modalService.open(NewCommentComponent);
  113. let comment: CommentJsonld = {} as CommentJsonld;
  114. comment.post = post.id ?? null;
  115. modalRefComment.componentInstance.comment = comment;
  116. modalRefComment.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  117. if (modalStatus === ModalStatus.Submitted) {
  118. modalRefComment.dismiss();
  119. this.getPostsData();
  120. }
  121. });
  122. }
  123. openModalEditPosting(post: PostJsonld) {
  124. const modalRefPostingEdit = this.modalService.open(NewPostingComponent);
  125. modalRefPostingEdit.componentInstance.posting = post;
  126. modalRefPostingEdit.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  127. if (modalStatus === ModalStatus.Submitted) {
  128. modalRefPostingEdit.dismiss();
  129. this.getPostsData();
  130. }
  131. });
  132. }
  133. openModalEditComment(comment: CommentJsonld) {
  134. console.log(comment);
  135. const modalRefComment = this.modalService.open(NewCommentComponent);
  136. modalRefComment.componentInstance.comment = comment;
  137. modalRefComment.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  138. if (modalStatus === ModalStatus.Submitted) {
  139. modalRefComment.dismiss();
  140. this.getPostsData();
  141. }
  142. });
  143. }
  144. openModalEditContact() {
  145. const modalRef = this.modalService.open(NewContactComponent);
  146. modalRef.componentInstance.contact = this.contact;
  147. modalRef.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  148. if (modalStatus === ModalStatus.Submitted) {
  149. modalRef.dismiss();
  150. this.getContactData();
  151. }
  152. });
  153. }
  154. }