Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

141 řádky
5.4 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 {DocumentJsonldDocumentObjectRead, DocumentService, PartnerJsonld, 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 {NgIf} from "@angular/common";
  10. import {ModalComponent} from "@app/_components/modal/modal.component";
  11. import {NgbModal, NgbModalOptions} from "@ng-bootstrap/ng-bootstrap";
  12. import {NewDocumentComponent} from "@app/documents/new-document/new-document.component";
  13. import {TranslateModule} from "@ngx-translate/core";
  14. import {NewProductComponent} from "@app/products/new-product/new-product.component";
  15. import {ModalStatus} from "@app/_helpers/modal.states";
  16. @Component({
  17. selector: 'app-documents',
  18. templateUrl: './documents.component.html',
  19. styleUrl: './documents.component.scss',
  20. standalone: true,
  21. imports: [MatTableModule, MatSortModule, MatPaginatorModule, RouterLink, RouterLinkActive, NgIf, TranslateModule],
  22. })
  23. export class DocumentsComponent {
  24. @ViewChild(MatSort) sort;
  25. @ViewChild(MatPaginator) documentsPaginator: MatPaginator;
  26. protected displayedColumns: string[];
  27. protected documentsSub: Subscription;
  28. protected documents: Array<DocumentJsonldDocumentObjectRead>;
  29. protected documentsDataSource;
  30. protected documentsLength: number;
  31. protected documentsPageEvent: PageEvent;
  32. protected documentsPageSize: number;
  33. protected documentsPageIndex: number;
  34. protected modalOptions: NgbModalOptions = {
  35. centered: true
  36. };
  37. constructor(
  38. private router: Router,
  39. private modalService: NgbModal,
  40. private documentService: DocumentService
  41. ) {
  42. this.sort = new MatSort();
  43. this.displayedColumns = ['pos', 'name', 'type', 'date'];
  44. this.documentsSub = new Subscription();
  45. this.documents = [];
  46. this.documentsPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype);
  47. this.documentsDataSource = new MatTableDataSource<DocumentJsonldDocumentObjectRead>(this.documents);
  48. this.documentsLength = 0;
  49. this.documentsPageEvent = new PageEvent();
  50. this.documentsPageSize = 10;
  51. this.documentsPageIndex = 0;
  52. }
  53. ngOnInit() {
  54. this.getDocumentsData();
  55. }
  56. ngAfterViewInit() {
  57. this.documentsDataSource.sort = this.sort;
  58. this.documentsDataSource.paginator = this.documentsPaginator;
  59. }
  60. getDocumentsData() {
  61. this.documentsSub = this.documentService.documentsGetCollection(
  62. this.documentsPageIndex + 1,
  63. this.documentsPageSize
  64. ).subscribe(
  65. data => {
  66. this.documents = data["hydra:member"];
  67. this.documentsDataSource = new MatTableDataSource<DocumentJsonldDocumentObjectRead>(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: any) {
  107. // const partner: PartnerJsonld = element as PartnerJsonld;
  108. // console.log(partner.type);
  109. // console.log(ApiConverter.extractId(partner.id));
  110. // this.router.navigate(['/documents', ApiConverter.extractId(partner.id)]);
  111. }
  112. openModalNewDocument() {
  113. const modalRefDocument = this.modalService.open(NewDocumentComponent, this.modalOptions);
  114. // TODO: Warum muss ich einen leeren String übergeben, damit es funktioniert?
  115. let document: ProductJsonld = {} as ProductJsonld;
  116. document.name = "";
  117. modalRefDocument.componentInstance.document = document;
  118. modalRefDocument.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  119. if (modalStatus === ModalStatus.Submitted) {
  120. modalRefDocument.dismiss();
  121. this.getDocumentsData();
  122. }
  123. });
  124. }
  125. }