Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

148 строки
5.6 KiB

  1. import {ChangeDetectorRef, Component, ViewChild} from '@angular/core';
  2. import {MatSort, MatSortModule, Sort} from "@angular/material/sort";
  3. import {MatPaginator, MatPaginatorIntl, MatPaginatorModule, PageEvent} from "@angular/material/paginator";
  4. import {Subscription} from "rxjs";
  5. import {DocumentJsonld, DocumentService, ProductJsonld} from "@app/core/api/v1";
  6. import {Router, RouterLink, RouterLinkActive} from "@angular/router";
  7. import {MatTableDataSource, MatTableModule} from "@angular/material/table";
  8. import {OrderFilter} from "@app/_models/orderFilter";
  9. import {DatePipe, NgIf} from "@angular/common";
  10. import {NgbModal, NgbModalOptions} from "@ng-bootstrap/ng-bootstrap";
  11. import {NewDocumentComponent} from "@app/documents/new-document/new-document.component";
  12. import {TranslateModule} from "@ngx-translate/core";
  13. import {ModalStatus} from "@app/_helpers/modal.states";
  14. import {NewCommentComponent} from "@app/postings/new-comment/new-comment.component";
  15. @Component({
  16. selector: 'app-documents',
  17. templateUrl: './documents.component.html',
  18. styleUrl: './documents.component.scss',
  19. standalone: true,
  20. imports: [MatTableModule, MatSortModule, MatPaginatorModule, RouterLink, RouterLinkActive, NgIf, TranslateModule, DatePipe],
  21. })
  22. export class DocumentsComponent {
  23. @ViewChild(MatSort) sort;
  24. @ViewChild(MatPaginator) documentsPaginator: MatPaginator;
  25. protected displayedColumns: string[];
  26. protected documentsSub: Subscription;
  27. protected documents: Array<DocumentJsonld>;
  28. protected documentsDataSource;
  29. protected documentsLength: number;
  30. protected documentsPageEvent: PageEvent;
  31. protected documentsPageSize: number;
  32. protected documentsPageIndex: number;
  33. protected modalOptions: NgbModalOptions = {
  34. centered: true
  35. };
  36. constructor(
  37. private router: Router,
  38. private modalService: NgbModal,
  39. private documentService: DocumentService
  40. ) {
  41. this.sort = new MatSort();
  42. this.displayedColumns = ['pos', 'name', 'description', 'download', 'partnerName', 'productName', 'createdAt', 'createdByName', 'edit'];
  43. this.documentsSub = new Subscription();
  44. this.documents = [];
  45. this.documentsPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype);
  46. this.documentsDataSource = new MatTableDataSource<DocumentJsonld>(this.documents);
  47. this.documentsLength = 0;
  48. this.documentsPageEvent = new PageEvent();
  49. this.documentsPageSize = 10;
  50. this.documentsPageIndex = 0;
  51. }
  52. ngOnInit() {
  53. this.getDocumentsData();
  54. }
  55. ngAfterViewInit() {
  56. this.documentsDataSource.sort = this.sort;
  57. this.documentsDataSource.paginator = this.documentsPaginator;
  58. }
  59. getDocumentsData() {
  60. this.documentsSub = this.documentService.documentsGetCollection(
  61. this.documentsPageIndex + 1,
  62. this.documentsPageSize
  63. ).subscribe(
  64. data => {
  65. this.documents = data["hydra:member"];
  66. //console.log(this.documents);
  67. this.documentsDataSource = new MatTableDataSource<DocumentJsonld>(this.documents);
  68. this.documentsLength = Number(data["hydra:totalItems"]);
  69. this.documentsPaginator.length = this.documentsLength;
  70. }
  71. );
  72. }
  73. /** Announce the change in sort state for assistive technology. */
  74. onSortChange(sortState: Sort) {
  75. // Reset page index to first page
  76. this.documentsPageIndex = 0;
  77. let order: OrderFilter;
  78. if (sortState.direction === "") {
  79. order = OrderFilter.Undefined;
  80. } else {
  81. order = sortState.direction;
  82. }
  83. // this.nameOrderAsc = OrderFilter.Undefined;
  84. // this.cityOrderAsc = OrderFilter.Undefined;
  85. // this.websiteOrderAsc = OrderFilter.Undefined;
  86. // switch (sortState.active) {
  87. // case "name":
  88. // this.nameOrderAsc = order;
  89. // break;
  90. // case "address":
  91. // this.cityOrderAsc = order;
  92. // break;
  93. // case "website":
  94. // this.websiteOrderAsc = order;
  95. // break;
  96. // }
  97. this.getDocumentsData();
  98. }
  99. handlePageEvent(e: PageEvent) {
  100. this.documentsPageEvent = e;
  101. this.documentsLength = e.length;
  102. this.documentsPageIndex = e.pageIndex.valueOf();
  103. this.documentsPageSize = e.pageSize.valueOf();
  104. this.getDocumentsData();
  105. }
  106. navigateToDocumentFile(element: DocumentJsonld) {
  107. window.open(element.documentUrl?.toString(), '_blank');
  108. }
  109. openModalNewDocument() {
  110. const modalRefDocument = this.modalService.open(NewDocumentComponent, this.modalOptions);
  111. let document: DocumentJsonld = {} as DocumentJsonld;
  112. modalRefDocument.componentInstance.document = document;
  113. modalRefDocument.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  114. if (modalStatus === ModalStatus.Submitted) {
  115. modalRefDocument.dismiss();
  116. this.getDocumentsData();
  117. }
  118. });
  119. }
  120. openModalEditDocument(document: DocumentJsonld) {
  121. const modalRefDocument = this.modalService.open(NewDocumentComponent, this.modalOptions);
  122. modalRefDocument.componentInstance.document = document;
  123. // console.log(document);
  124. modalRefDocument.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  125. if (modalStatus === ModalStatus.Submitted) {
  126. modalRefDocument.dismiss();
  127. this.getDocumentsData();
  128. }
  129. });
  130. }
  131. }