commit 0256e69850c779f87ec72bbea94b9d7dfb25d446
Author: castic96 <zdenek.castoral.jr@gmail.com>
Date:   Sun Apr 12 22:48:02 2020 +0200

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

diff --git a/fe/fulltextsearch/src/app/components/pages/browse/table/table.component.html b/fe/fulltextsearch/src/app/components/pages/browse/table/table.component.html
index 48d9a1b..7f2b796 100644
--- a/fe/fulltextsearch/src/app/components/pages/browse/table/table.component.html
+++ b/fe/fulltextsearch/src/app/components/pages/browse/table/table.component.html
@@ -31,7 +31,7 @@
   <div class="row justify-content-center align-items-center">
 
     <mat-paginator #paginator
-                   [length]="dataSource?.data.length"
+                   [length]="dataSourceLength | async"
                    [pageIndex]="0"
                    [pageSize]="10"
                    [pageSizeOptions]="[5, 10, 25]">
diff --git a/fe/fulltextsearch/src/app/components/pages/browse/table/table.component.ts b/fe/fulltextsearch/src/app/components/pages/browse/table/table.component.ts
index 303741c..9f7774d 100644
--- a/fe/fulltextsearch/src/app/components/pages/browse/table/table.component.ts
+++ b/fe/fulltextsearch/src/app/components/pages/browse/table/table.component.ts
@@ -1,21 +1,24 @@
-import { AfterViewInit, Component, OnInit, ViewChild } from '@angular/core';
+import { Component, OnInit, ViewChild } from '@angular/core';
 import { MatPaginator } from '@angular/material/paginator';
 import { MatSort } from '@angular/material/sort';
 import { MatTable } from '@angular/material/table';
 import { TableDataSource } from './table-datasource';
 import { DocumentResponse } from '../../../../model/DocumentResponse';
 import {QueryService} from '../../../../services/query.service';
+import {Observable} from 'rxjs';
+import {map, tap} from 'rxjs/operators';
 
 @Component({
   selector: 'app-table-browse',
   templateUrl: './table.component.html',
   styleUrls: ['./table.component.css']
 })
-export class TableComponent implements AfterViewInit, OnInit {
+export class TableComponent implements OnInit {
   @ViewChild(MatPaginator) paginator: MatPaginator;
   @ViewChild(MatSort) sort: MatSort;
   @ViewChild(MatTable) table: MatTable<DocumentResponse>;
   dataSource: TableDataSource;
+  dataSourceLength: Observable<number>;
 
   /** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
   displayedColumns = ['id', 'documentName', 'originDate', 'uploadedDate'];
@@ -23,15 +26,15 @@ export class TableComponent implements AfterViewInit, OnInit {
   constructor( private queryService: QueryService ) { }
 
   ngOnInit() {
-    this.dataSource = new TableDataSource();
-    this.queryService.getDocuments().subscribe( documents => {
-      this.dataSource.data = documents;
-    });
-  }
-
-  ngAfterViewInit() {
-    this.dataSource.sort = this.sort;
-    this.dataSource.paginator = this.paginator;
-    this.table.dataSource = this.dataSource;
+    this.dataSourceLength = this.queryService.getDocuments().pipe(
+      tap(data => {
+        this.dataSource = new TableDataSource();
+        this.dataSource.data = data;
+        this.table.dataSource = data;
+        this.dataSource.sort = this.sort;
+        this.dataSource.paginator = this.paginator;
+      }),
+      map(data => data.length)
+    );
   }
 }
diff --git a/fe/fulltextsearch/src/app/components/pages/search/search-paginator/search-paginator.component.html b/fe/fulltextsearch/src/app/components/pages/search/search-paginator/search-paginator.component.html
index ba03516..22311a5 100644
--- a/fe/fulltextsearch/src/app/components/pages/search/search-paginator/search-paginator.component.html
+++ b/fe/fulltextsearch/src/app/components/pages/search/search-paginator/search-paginator.component.html
@@ -17,7 +17,9 @@
     <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
   </table>
 
-  <mat-paginator #paginator
+  <mat-paginator
+      #paginator
+      *ngIf="dataSource"
       [length]="dataSource?.data.length"
       [pageIndex]="0"
       [pageSize]="3"
diff --git a/fe/fulltextsearch/src/app/components/pages/search/search.component.html b/fe/fulltextsearch/src/app/components/pages/search/search.component.html
index c00b913..50bb7b7 100644
--- a/fe/fulltextsearch/src/app/components/pages/search/search.component.html
+++ b/fe/fulltextsearch/src/app/components/pages/search/search.component.html
@@ -13,7 +13,7 @@
       </p>
     </div>
     <div class="row"> <!--<img src=" sem dat obrazek v base64 " />-->
-        <app-search-paginator [inputData] = "data" style="width: 100%"></app-search-paginator>
+        <app-search-paginator [inputData] = "data" style="width: 100%" *ngIf="data"></app-search-paginator>
     </div>
   </div>
 </div>
diff --git a/fe/fulltextsearch/src/app/components/pages/search/search.component.ts b/fe/fulltextsearch/src/app/components/pages/search/search.component.ts
index 554d390..766bc9b 100644
--- a/fe/fulltextsearch/src/app/components/pages/search/search.component.ts
+++ b/fe/fulltextsearch/src/app/components/pages/search/search.component.ts
@@ -13,10 +13,6 @@ export class SearchComponent implements OnInit, OnDestroy {
   private queryServiceSubscription$: Subscription;
 
   constructor(private dataHolderService: DataHolderService) {
-    this.customSubscribe();
-  }
-
-  private customSubscribe(): void {
     this.queryServiceSubscription$ = this.dataHolderService.storage$.subscribe(data => {
       if (data != null) {
         this.data = data;
diff --git a/fe/fulltextsearch/src/app/components/shared-components/search-box/search-box.component.ts b/fe/fulltextsearch/src/app/components/shared-components/search-box/search-box.component.ts
index c67cd0d..c925630 100644
--- a/fe/fulltextsearch/src/app/components/shared-components/search-box/search-box.component.ts
+++ b/fe/fulltextsearch/src/app/components/shared-components/search-box/search-box.component.ts
@@ -33,6 +33,10 @@ export class SearchBoxComponent implements OnInit, OnDestroy {
   }
 
   ngOnDestroy(): void {
-    this.queryServiceSubscription$.unsubscribe();
+    console.log(this.queryServiceSubscription$);
+    if (this.queryServiceSubscription$ !== undefined) {
+      console.log('podminka');
+      this.queryServiceSubscription$.unsubscribe();
+    }
   }
 }
