Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 0256e698

Přidáno uživatelem castic96 před asi 4 roky(ů)

Re #7802: Implementace vykreslování search page s výsledky
- oprava chyb při subscribe
- oprava chyb v asynchronní komunikaci

Zobrazit rozdíly:

fe/fulltextsearch/src/app/components/pages/browse/table/table.component.ts
1
import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
1
import { Component, OnInit, ViewChild } from '@angular/core';
2 2
import { MatPaginator } from '@angular/material/paginator';
3 3
import { MatSort } from '@angular/material/sort';
4 4
import { MatTable } from '@angular/material/table';
5 5
import { TableDataSource } from './table-datasource';
6 6
import { DocumentResponse } from '../../../../model/DocumentResponse';
7 7
import {QueryService} from '../../../../services/query.service';
8
import {Observable} from 'rxjs';
9
import {map, tap} from 'rxjs/operators';
8 10

  
9 11
@Component({
10 12
  selector: 'app-table-browse',
11 13
  templateUrl: './table.component.html',
12 14
  styleUrls: ['./table.component.css']
13 15
})
14
export class TableComponent implements AfterViewInit, OnInit {
16
export class TableComponent implements OnInit {
15 17
  @ViewChild(MatPaginator) paginator: MatPaginator;
16 18
  @ViewChild(MatSort) sort: MatSort;
17 19
  @ViewChild(MatTable) table: MatTable<DocumentResponse>;
18 20
  dataSource: TableDataSource;
21
  dataSourceLength: Observable<number>;
19 22

  
20 23
  /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
21 24
  displayedColumns = ['id', 'documentName', 'originDate', 'uploadedDate'];
......
23 26
  constructor( private queryService: QueryService ) { }
24 27

  
25 28
  ngOnInit() {
26
    this.dataSource = new TableDataSource();
27
    this.queryService.getDocuments().subscribe( documents => {
28
      this.dataSource.data = documents;
29
    });
30
  }
31

  
32
  ngAfterViewInit() {
33
    this.dataSource.sort = this.sort;
34
    this.dataSource.paginator = this.paginator;
35
    this.table.dataSource = this.dataSource;
29
    this.dataSourceLength = this.queryService.getDocuments().pipe(
30
      tap(data => {
31
        this.dataSource = new TableDataSource();
32
        this.dataSource.data = data;
33
        this.table.dataSource = data;
34
        this.dataSource.sort = this.sort;
35
        this.dataSource.paginator = this.paginator;
36
      }),
37
      map(data => data.length)
38
    );
36 39
  }
37 40
}

Také k dispozici: Unified diff