Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Component, OnInit, ViewChild} from '@angular/core';
- import {MatDialog} from "@angular/material/dialog";
- import {AddDialogComponent} from "../adddialog/add-dialog/add-dialog.component";
- import {DeleteDialogComponent} from "../delete-dialog/delete-dialog.component";
- import {PrintDialogComponent} from "../print-dialog/print-dialog.component";
- import {MatTableDataSource} from "@angular/material/table";
- import {DataSource, SelectionModel} from "@angular/cdk/collections";
- import {MatPaginator} from "@angular/material/paginator";
- import {EditPracownikComponent} from "../editDialog/edit-pracownik/edit-pracownik.component";
- import {HttpErrorResponse} from "@angular/common/http";
- import {HttpService} from "./http.service";
- import {Observable} from "rxjs";
- import {User} from "./http.model";
- import {PeriodicElement} from "../pojazdy/pojazdy.component";
- /*Komentarz*/
- /*export interface PeriodicElement {
- id: number;
- name: string;
- surname: string;
- status: string;
- section: string;
- email: string;
- mobileNumber: string;
- phoneNumber: string;
- position: string;
- }*/
- /*const ELEMENT_DATA: PeriodicElement[] = [
- {
- position: 1, name: 'Jan', surname: 'Kowalski', status: 'Zatrudniony', dzial: 'Spedycja', email:
- 'kowalskijan@wp.pl', phone: '070088070', homePhone: '341231234', stanowisko: 'Spedytor'
- },
- {
- position: 2, name: 'Marek', surname: 'Nowak', status: 'Zatrudniony', dzial: 'Dostawa', email:
- 'nowakmarek@wp.pl', phone: '123456789', homePhone: '344321245',stanowisko: 'Kierowca'
- },
- {
- position: 3, name: 'Kristof', surname: 'Fryllla', status: 'Niezatrudniony', dzial: 'Administracja', email:
- 'xxx@wp.pl', phone: '987654321', homePhone: '344355674', stanowisko: 'Szef wszystkich szefów'
- },
- {
- position: 4, name: 'Michjel', surname: 'Derr', status: 'Niezatrudniony', dzial: 'Pijawki', email:
- 'minionki@wp.pl', phone: '998997999', homePhone: '340988765', stanowisko: 'Profesjonelny leń'
- },
- ];*/
- /*Koniec komentarza */
- @Component({
- selector: 'app-pracownik',
- templateUrl: './pracownik.component.html',
- styleUrls: ['./pracownik.component.scss']
- })
- export class PracownikComponent implements OnInit{
- constructor(private dialog: MatDialog, public httpService: HttpService) {
- }
- openDialog() {
- let dialogRef = this.dialog.open(AddDialogComponent);
- dialogRef.afterClosed().subscribe();
- }
- openDialog1() {
- let dialogRef = this.dialog.open(DeleteDialogComponent);
- dialogRef.afterClosed().subscribe();
- }
- openDialog2() {
- let dialogRef = this.dialog.open(EditPracownikComponent);
- dialogRef.afterClosed().subscribe();
- }
- openDialog3() {
- let dialogRef = this.dialog.open(PrintDialogComponent);
- dialogRef.afterClosed().subscribe();
- }
- displayedColumns: string[] = ['select', 'id', 'name', 'surname', 'status', 'section', 'email', 'mobileNumber'
- , 'phoneNumber', 'position', 'edit', 'delete'];
- dataSource = new UserDataSource(this.httpService);
- //dataSource1 = new MatTableDataSource<User>();
- //dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA); <-- Wymaga MatTable Data Source by działały te funkcje Angular Material
- selection = new SelectionModel<UserDataSource>(true, []);
- @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
- ngOnInit() {
- this.dataSource.paginator = this.paginator;
- }
- isAllSelected() {
- const numSelected = this.selection.selected.length;
- const numRows = this.dataSource.data.length;
- return numSelected === numRows;
- }
- masterToggle() {
- this.isAllSelected() ?
- this.selection.clear() :
- this.dataSource.data.forEach(row => this.selection.select(row));
- }
- checkboxLabel(row?: UserDataSource): string {
- if (!row) {
- return `${this.isAllSelected() ? 'select' : 'deselect'} all`;
- }
- return `${this.selection.isSelected(row) ? 'deselect' : 'select'} row ${row.id + 1}`;
- }
- applyFilter(filterValue: string) {
- this.dataSource.filter = filterValue.trim().toLowerCase();
- }
- }
- export class UserDataSource extends DataSource<any> {
- id: number;
- constructor(public httpService: HttpService) {
- super();
- }
- connect(): Observable<User[]> {
- return this.httpService.getUser();
- }
- disconnect() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement