No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

148 líneas
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. import {ApiConverter} from "@app/_helpers/api.converter";
  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, DatePipe],
  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<DocumentJsonld>;
  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. protected apiConverter: ApiConverter
  42. ) {
  43. this.sort = new MatSort();
  44. this.displayedColumns = ['pos', 'name', 'description', 'partnerName', 'productName', 'createdAt', 'createdByName', 'download', 'edit'];
  45. this.documentsSub = new Subscription();
  46. this.documents = [];
  47. this.documentsPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype);
  48. this.documentsDataSource = new MatTableDataSource<DocumentJsonld>(this.documents);
  49. this.documentsLength = 0;
  50. this.documentsPageEvent = new PageEvent();
  51. this.documentsPageSize = 10;
  52. this.documentsPageIndex = 0;
  53. }
  54. ngOnInit() {
  55. this.getDocumentsData();
  56. }
  57. ngAfterViewInit() {
  58. this.documentsDataSource.sort = this.sort;
  59. this.documentsDataSource.paginator = this.documentsPaginator;
  60. }
  61. getDocumentsData() {
  62. this.documentsSub = this.documentService.documentsGetCollection(
  63. this.documentsPageIndex + 1,
  64. this.documentsPageSize
  65. ).subscribe(
  66. data => {
  67. this.documents = data["hydra:member"];
  68. this.documentsDataSource = new MatTableDataSource<DocumentJsonld>(this.documents);
  69. this.documentsLength = Number(data["hydra:totalItems"]);
  70. this.documentsPaginator.length = this.documentsLength;
  71. }
  72. );
  73. }
  74. /** Announce the change in sort state for assistive technology. */
  75. onSortChange(sortState: Sort) {
  76. // Reset page index to first page
  77. this.documentsPageIndex = 0;
  78. let order: OrderFilter;
  79. if (sortState.direction === "") {
  80. order = OrderFilter.Undefined;
  81. } else {
  82. order = sortState.direction;
  83. }
  84. // this.nameOrderAsc = OrderFilter.Undefined;
  85. // this.cityOrderAsc = OrderFilter.Undefined;
  86. // this.websiteOrderAsc = OrderFilter.Undefined;
  87. // switch (sortState.active) {
  88. // case "name":
  89. // this.nameOrderAsc = order;
  90. // break;
  91. // case "address":
  92. // this.cityOrderAsc = order;
  93. // break;
  94. // case "website":
  95. // this.websiteOrderAsc = order;
  96. // break;
  97. // }
  98. this.getDocumentsData();
  99. }
  100. handlePageEvent(e: PageEvent) {
  101. this.documentsPageEvent = e;
  102. this.documentsLength = e.length;
  103. this.documentsPageIndex = e.pageIndex.valueOf();
  104. this.documentsPageSize = e.pageSize.valueOf();
  105. this.getDocumentsData();
  106. }
  107. navigateToDocumentFile(element: DocumentJsonld) {
  108. window.open(element.documentUrl?.toString(), '_blank');
  109. }
  110. openModalNewDocument() {
  111. const modalRefDocument = this.modalService.open(NewDocumentComponent, this.modalOptions);
  112. let document: DocumentJsonld = {} as DocumentJsonld;
  113. modalRefDocument.componentInstance.document = document;
  114. modalRefDocument.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  115. if (modalStatus === ModalStatus.Submitted) {
  116. modalRefDocument.dismiss();
  117. this.getDocumentsData();
  118. }
  119. });
  120. }
  121. openModalEditDocument(document: DocumentJsonld) {
  122. const modalRefDocument = this.modalService.open(NewDocumentComponent, this.modalOptions);
  123. modalRefDocument.componentInstance.document = document;
  124. modalRefDocument.componentInstance.submit.subscribe((modalStatus: ModalStatus) => {
  125. if (modalStatus === ModalStatus.Submitted) {
  126. modalRefDocument.dismiss();
  127. this.getDocumentsData();
  128. }
  129. });
  130. }
  131. }