commit 1d169f6d2cf60239134c2001a25e9f0eb33a7687
Author: Hung Hoang <hoanghun5@gmail.com>
Date:   Mon May 27 18:00:51 2019 +0200

    Re#7527 SnackBar opens if the error occurs

diff --git a/webapp/src/app/employees/employees-list.component.html b/webapp/src/app/employees/employees-list.component.html
index ed336a2..6b8f178 100644
--- a/webapp/src/app/employees/employees-list.component.html
+++ b/webapp/src/app/employees/employees-list.component.html
@@ -1,5 +1,6 @@
 <div class="employee-component">
-  <h3> <span class="align-baseline">Zaměstnanci</span>
+  <div>
+    <span class="align-baseline" style="font-size: x-large">Zaměstnanci</span>
 
     <button
       id="settings-button"
@@ -19,12 +20,12 @@
       (change)="uploadXlsxFile(fileInput.files); fileInput.value = null;"
     />
 
-    <label for="input-file" class="btn btn-primary align-baseline">Import</label>
-    <button class="btn btn-danger align-baseline" (click)="downloadPdf()">
+    <label for="input-file" class="btn btn-primary " style="margin-right: 5px">Import</label>
+    <label class="btn btn-danger" (click)="downloadPdf()">
       Export
-    </button>
+    </label>
 
-  </h3>
+  </div>
 
   <table class="table text-center table-hover">
     <thead class="thead-light">
diff --git a/webapp/src/app/employees/employees-list.component.sass b/webapp/src/app/employees/employees-list.component.sass
index 47705f3..7071a5d 100644
--- a/webapp/src/app/employees/employees-list.component.sass
+++ b/webapp/src/app/employees/employees-list.component.sass
@@ -28,10 +28,6 @@
 
 
 .input-file
-  width: 0.1px
-  height: 0.1px
-  opacity: 0
-  overflow: hidden
-  position: absolute
-  z-index: -1
+  display: none
+
 
diff --git a/webapp/src/app/employees/employees-list.component.ts b/webapp/src/app/employees/employees-list.component.ts
index bee6abc..cf69bbb 100644
--- a/webapp/src/app/employees/employees-list.component.ts
+++ b/webapp/src/app/employees/employees-list.component.ts
@@ -58,14 +58,15 @@ export class EmployeesListComponent implements OnInit {
     // https://stackoverflow.com/a/52687792/6204336
     this.fileService.getExportedPdf()
       .subscribe((data: any) => {
-        console.log(data);
-        const blob = new Blob([data], {type: 'application/pdf'});
-        const link = window.URL.createObjectURL(blob);
-        const linkElement = document.createElement('a');
-        linkElement.href = link;
-        linkElement.download = 'super.pdf';
-        linkElement.click();
-      });
+          console.log(data);
+          const blob = new Blob([data], {type: 'application/pdf'});
+          const link = window.URL.createObjectURL(blob);
+          const linkElement = document.createElement('a');
+          linkElement.href = link;
+          linkElement.download = 'dochazka.pdf';
+          linkElement.click();
+        },
+        error1 => this.showSnackBarError(error1, 'Export PDF souboru se nezdařil'));
   }
 
   /**
@@ -75,7 +76,9 @@ export class EmployeesListComponent implements OnInit {
    */
   uploadXlsxFile(files: FileList): void {
     this.fileService.uploadXlsFile(files)
-      .subscribe(() => this.snackBar.open('Import souboru se provedl', 'Zavřít', {duration: 5000}));
+      .subscribe(() => this.snackBar.open('Import souboru se provedl', 'Zavřít', {duration: 5000}),
+        error1 => this.showSnackBarError(error1, 'Import soubor se nezdařil')
+      );
   }
 
   /**
@@ -87,39 +90,42 @@ export class EmployeesListComponent implements OnInit {
   openEditUserDialog(user: User): void {
     this.userService.getUserProfile(user.id)
       .subscribe((userProfile: UserProfile) => {
-        const dialogRef = this.dialog.open(EditEmployeeDialogComponent, {
-          data: userProfile,
-        });
-
-        dialogRef.componentInstance.postUserSettings.subscribe((emittedData) => {
-          this.userService.putUserSettings(emittedData)
-            .subscribe(() => this.snackBar.open('Povedlo se', 'Zavrit', {duration: 5000}));
-        });
-      });
+          const dialogRef = this.dialog.open(EditEmployeeDialogComponent, {
+            data: userProfile,
+          });
+
+          dialogRef.componentInstance.postUserSettings.subscribe((emittedData) => {
+            this.userService.putUserSettings(emittedData)
+              .subscribe(() => this.snackBar.open('Povedlo se', 'Zavrit', {duration: 5000}));
+          });
+        },
+        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila')
+      );
   }
 
   openDefaultSettingsDialog(): void {
     this.settingsService.getDefaultSettingsWithLanguage(Languages.CZECH)
       .subscribe((settingsData: Settings) => {
-        const parsedDate = new Date(settingsData.notification);
+          const parsedDate = new Date(settingsData.notification);
 
-        const parsedSettings = {
-          notificationDate: new Date(parsedDate.getFullYear(), parsedDate.getMonth(), parsedDate.getDate()),
-          notificationTime: parsedDate.getHours() + ':' + parsedDate.getMinutes(),
-          sickdaysCount: settingsData.sickdayCount
-        };
+          const parsedSettings = {
+            notificationDate: new Date(parsedDate.getFullYear(), parsedDate.getMonth(), parsedDate.getDate()),
+            notificationTime: parsedDate.getHours() + ':' + parsedDate.getMinutes(),
+            sickdaysCount: settingsData.sickdayCount
+          };
 
-        this.dialog.open(DefaultSettingsDialogComponent, {
+          this.dialog.open(DefaultSettingsDialogComponent, {
             data: parsedSettings,
             width: '300px'
           })
-          .afterClosed().subscribe(data => {
+            .afterClosed().subscribe(data => {
             if (data && data.isConfirmed) {
               this.settingsService.postDefaultSettingsWithLanguage(this.toSettings(data), this.localizationService.getCurrentLanguage())
                 .subscribe((foo: any) => console.log(foo));
             }
           });
-      });
+        },
+        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila'));
   }
 
   private toSettings(data): Settings {
@@ -197,27 +203,18 @@ export class EmployeesListComponent implements OnInit {
     return dayInfo;
   }
 
+  private showSnackBarError(error1, message: string) {
+    console.log(error1);
+    this.snackBar.open(message, 'Zavřít', {duration: 5000});
+  }
+
   ngOnInit() {
     this.usersService.getAuthorizedUsers()
       .subscribe((data: UserBasicInformation[]) => {
-        this._employeesBasicInformation = data;
-        this.mapUsers();
-      });
-
-    // const calendar: PostCalendar = { date: '1999/10/10', from: '15:00', to: '17:00', type: VacationType.VACATION };
-    // this.userService.postCalendar(calendar)
-    //   .subscribe((data: any) => console.log(data));
-
-    // const settings: UserSettings = {
-    //   id: 1,
-    //   role: UserType.EMPLOYEE,
-    //   sickdayCount: 1,
-    //   vacationCount: 1,
-    // };
-    //
-    // this.userService.putUserSettings(settings)
-    //   .subscribe((data: any) => console.log(data));
-
+          this._employeesBasicInformation = data;
+          this.mapUsers();
+        },
+        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila'));
   }
 
 }
diff --git a/webapp/src/app/services/api/basic.service.ts b/webapp/src/app/services/api/basic.service.ts
index faea7dd..84308ea 100644
--- a/webapp/src/app/services/api/basic.service.ts
+++ b/webapp/src/app/services/api/basic.service.ts
@@ -2,6 +2,7 @@ import {Injectable} from '@angular/core';
 import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http';
 import {throwError} from 'rxjs';
 import {environment} from '../../../environments/environment';
+import {MatSnackBar} from '@angular/material';
 
 @Injectable({
   providedIn: 'root'
@@ -9,7 +10,7 @@ import {environment} from '../../../environments/environment';
 export class BasicService {
   protected baseUrl = environment.apiUrl;
 
-  constructor(protected http: HttpClient) { }
+  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) { }
 
   protected handleError(error: HttpErrorResponse) {
     if (error.error instanceof ErrorEvent) {
@@ -19,6 +20,8 @@ export class BasicService {
         `Backend returned code ${error.status}, ` +
         `body was: ${error.error}`);
     }
+
+    this.snackBar.open('Komunikace se serverem se nezdařila', 'Zavřít');
     return throwError(
       'Something bad happened; please try again later.');
   }
diff --git a/webapp/src/app/services/api/file.service.ts b/webapp/src/app/services/api/file.service.ts
index ba6a02b..540169c 100644
--- a/webapp/src/app/services/api/file.service.ts
+++ b/webapp/src/app/services/api/file.service.ts
@@ -3,14 +3,15 @@ import {HttpClient, HttpParams} from '@angular/common/http';
 import {BasicService} from './basic.service';
 import {catchError} from 'rxjs/operators';
 import {Languages} from '../../enums/common.enum';
+import {MatSnackBar} from '@angular/material';
 
 @Injectable({
   providedIn: 'root'
 })
 export class FileService extends BasicService {
 
-  constructor(protected http: HttpClient) {
-    super(http);
+  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) {
+    super(http, snackBar);
   }
 
   /**
@@ -75,7 +76,6 @@ export class FileService extends BasicService {
     if (fileCount > 0) {
 
       formData.append('file', file.item(0));
-      console.log('posilam data');
       return this.http.post(this.baseUrl + '/api/import/xls', formData, options);
     }
   }
diff --git a/webapp/src/app/services/api/settings.service.ts b/webapp/src/app/services/api/settings.service.ts
index 6fd56f2..e72fc8e 100644
--- a/webapp/src/app/services/api/settings.service.ts
+++ b/webapp/src/app/services/api/settings.service.ts
@@ -5,6 +5,7 @@ import { catchError } from 'rxjs/operators';
 import { BasicService } from './basic.service';
 import { Settings } from '../../models/settings.model';
 import {Languages} from '../../enums/common.enum';
+import {MatSnackBar} from '@angular/material';
 
 @Injectable({
   providedIn: 'root'
@@ -12,8 +13,8 @@ import {Languages} from '../../enums/common.enum';
 export class SettingsService extends BasicService {
   defaultSettingsUrl = this.baseUrl + '/api/settings';
 
-  constructor(protected http: HttpClient) {
-    super(http);
+  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) {
+    super(http, snackBar);
   }
 
   /**
diff --git a/webapp/src/app/services/api/user.service.ts b/webapp/src/app/services/api/user.service.ts
index ea4575f..5d37510 100644
--- a/webapp/src/app/services/api/user.service.ts
+++ b/webapp/src/app/services/api/user.service.ts
@@ -8,6 +8,7 @@ import {Languages, RequestStatus, RequestTypes} from '../../enums/common.enum';
 import {UserSettings} from '../../models/settings.model';
 import {UserProfile} from '../../models/user.model';
 import {UserRequest} from '../../models/requests.model';
+import {MatSnackBar} from '@angular/material';
 
 @Injectable({
   providedIn: 'root'
@@ -15,8 +16,8 @@ import {UserRequest} from '../../models/requests.model';
 export class UserService extends BasicService { // dost podobny k usersService, mozna zmenit v rest api
   private _userUrl = this.baseUrl + '/api/user/';
 
-  constructor(protected http: HttpClient) {
-    super(http);
+  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) {
+    super(http, snackBar);
   }
 
   /**
diff --git a/webapp/src/app/services/api/users.service.ts b/webapp/src/app/services/api/users.service.ts
index 94054af..239a9fa 100644
--- a/webapp/src/app/services/api/users.service.ts
+++ b/webapp/src/app/services/api/users.service.ts
@@ -7,6 +7,7 @@ import {AuthorizationRequest, VacationRequest} from '../../models/requests.model
 import {Languages, ProfileStatus} from '../../enums/common.enum';
 import {Observable} from 'rxjs';
 import {UserBasicInformation} from '../../models/user.model';
+import {MatSnackBar} from '@angular/material';
 
 @Injectable({
   providedIn: 'root'
@@ -14,8 +15,8 @@ import {UserBasicInformation} from '../../models/user.model';
 export class UsersService extends BasicService {
   private _usersUrl = this.baseUrl + '/api/users';
 
-  constructor(protected http: HttpClient) {
-    super(http);
+  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) {
+    super(http, snackBar);
   }
 
   /**
