Advertisement
michussj07

pracownik.component.ts

Dec 13th, 2019
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. import {Component, OnInit, ViewChild} from '@angular/core';
  2. import {MatDialog} from "@angular/material/dialog";
  3. import {AddDialogComponent} from "../adddialog/add-dialog/add-dialog.component";
  4. import {DeleteDialogComponent} from "../delete-dialog/delete-dialog.component";
  5. import {PrintDialogComponent} from "../print-dialog/print-dialog.component";
  6. import {MatTableDataSource} from "@angular/material/table";
  7. import {DataSource, SelectionModel} from "@angular/cdk/collections";
  8. import {MatPaginator} from "@angular/material/paginator";
  9. import {EditPracownikComponent} from "../editDialog/edit-pracownik/edit-pracownik.component";
  10. import {HttpErrorResponse} from "@angular/common/http";
  11. import {HttpService} from "./http.service";
  12. import {Observable} from "rxjs";
  13. import {User} from "./http.model";
  14. import {PeriodicElement} from "../pojazdy/pojazdy.component";
  15.  
  16. /*Komentarz*/
  17. /*export interface PeriodicElement {
  18. id: number;
  19. name: string;
  20. surname: string;
  21. status: string;
  22. section: string;
  23. email: string;
  24. mobileNumber: string;
  25. phoneNumber: string;
  26. position: string;
  27. }*/
  28.  
  29.  
  30. /*const ELEMENT_DATA: PeriodicElement[] = [
  31. {
  32. position: 1, name: 'Jan', surname: 'Kowalski', status: 'Zatrudniony', dzial: 'Spedycja', email:
  33. 'kowalskijan@wp.pl', phone: '070088070', homePhone: '341231234', stanowisko: 'Spedytor'
  34. },
  35. {
  36. position: 2, name: 'Marek', surname: 'Nowak', status: 'Zatrudniony', dzial: 'Dostawa', email:
  37. 'nowakmarek@wp.pl', phone: '123456789', homePhone: '344321245',stanowisko: 'Kierowca'
  38. },
  39. {
  40. position: 3, name: 'Kristof', surname: 'Fryllla', status: 'Niezatrudniony', dzial: 'Administracja', email:
  41. 'xxx@wp.pl', phone: '987654321', homePhone: '344355674', stanowisko: 'Szef wszystkich szefów'
  42. },
  43. {
  44. position: 4, name: 'Michjel', surname: 'Derr', status: 'Niezatrudniony', dzial: 'Pijawki', email:
  45. 'minionki@wp.pl', phone: '998997999', homePhone: '340988765', stanowisko: 'Profesjonelny leń'
  46. },
  47.  
  48. ];*/
  49. /*Koniec komentarza */
  50.  
  51.  
  52. @Component({
  53. selector: 'app-pracownik',
  54. templateUrl: './pracownik.component.html',
  55. styleUrls: ['./pracownik.component.scss']
  56. })
  57. export class PracownikComponent implements OnInit{
  58.  
  59. constructor(private dialog: MatDialog, public httpService: HttpService) {
  60. }
  61.  
  62. openDialog() {
  63. let dialogRef = this.dialog.open(AddDialogComponent);
  64.  
  65. dialogRef.afterClosed().subscribe();
  66. }
  67.  
  68. openDialog1() {
  69. let dialogRef = this.dialog.open(DeleteDialogComponent);
  70.  
  71. dialogRef.afterClosed().subscribe();
  72. }
  73. openDialog2() {
  74. let dialogRef = this.dialog.open(EditPracownikComponent);
  75.  
  76. dialogRef.afterClosed().subscribe();
  77. }
  78. openDialog3() {
  79. let dialogRef = this.dialog.open(PrintDialogComponent);
  80.  
  81. dialogRef.afterClosed().subscribe();
  82. }
  83.  
  84. displayedColumns: string[] = ['select', 'id', 'name', 'surname', 'status', 'section', 'email', 'mobileNumber'
  85. , 'phoneNumber', 'position', 'edit', 'delete'];
  86. dataSource = new UserDataSource(this.httpService);
  87. //dataSource1 = new MatTableDataSource<User>();
  88. //dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA); <-- Wymaga MatTable Data Source by działały te funkcje Angular Material
  89. selection = new SelectionModel<UserDataSource>(true, []);
  90.  
  91.  
  92. @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
  93.  
  94. ngOnInit() {
  95. this.dataSource.paginator = this.paginator;
  96. }
  97.  
  98. isAllSelected() {
  99. const numSelected = this.selection.selected.length;
  100. const numRows = this.dataSource.data.length;
  101. return numSelected === numRows;
  102. }
  103.  
  104. masterToggle() {
  105. this.isAllSelected() ?
  106. this.selection.clear() :
  107. this.dataSource.data.forEach(row => this.selection.select(row));
  108. }
  109.  
  110.  
  111. checkboxLabel(row?: UserDataSource): string {
  112. if (!row) {
  113. return `${this.isAllSelected() ? 'select' : 'deselect'} all`;
  114. }
  115. return `${this.selection.isSelected(row) ? 'deselect' : 'select'} row ${row.id + 1}`;
  116. }
  117.  
  118. applyFilter(filterValue: string) {
  119. this.dataSource.filter = filterValue.trim().toLowerCase();
  120. }
  121.  
  122. }
  123.  
  124. export class UserDataSource extends DataSource<any> {
  125. id: number;
  126. constructor(public httpService: HttpService) {
  127. super();
  128. }
  129.  
  130. connect(): Observable<User[]> {
  131. return this.httpService.getUser();
  132. }
  133. disconnect() {
  134. }
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement