commit 5d32cbea026f6cb550f4ae52d144be71cd267992
Author: Václav Jirák <jirakv95@gmail.com>
Date:   Thu Jun 6 16:42:44 2019 +0200

    Error and information messages modified - correct error messages from backend are displayed and information messages are translated

diff --git a/webapp/src/app/add-vacation-dialog/add-vacation-dialog.component.ts b/webapp/src/app/add-vacation-dialog/add-vacation-dialog.component.ts
index 7d3267c..86279de 100644
--- a/webapp/src/app/add-vacation-dialog/add-vacation-dialog.component.ts
+++ b/webapp/src/app/add-vacation-dialog/add-vacation-dialog.component.ts
@@ -3,6 +3,7 @@ import {MAT_DIALOG_DATA, MatDialogRef, MatSnackBar} from '@angular/material';
 import {VacationType} from '../enums/common.enum';
 import {FormControl} from '@angular/forms';
 import {DateFormatterService} from '../services/util/date-formatter.service';
+import {TranslateService} from '@ngx-translate/core';
 
 @Component({
   selector: 'app-add-days-off-dialog',
@@ -22,7 +23,8 @@ export class AddVacationDialogComponent {
     public dialogRef: MatDialogRef<AddVacationDialogComponent>,
     @Inject(MAT_DIALOG_DATA) public data: AddVacationDialogData,
     private snackBar: MatSnackBar,
-    private dateFormatterService: DateFormatterService
+    private dateFormatterService: DateFormatterService,
+    private translateService: TranslateService
   ) {
     if (this.data.fromTime == null) {
       this.data.fromTime = '08:00';
@@ -36,7 +38,9 @@ export class AddVacationDialogComponent {
 
   onConfirmClick(): void {
     if (this.selectedVacationType == null) {
-      this.snackBar.open('Nevybrán typ volna', 'Zavřít', { duration: 5000 });
+      this.translateService.get('error.vacationTypeNotSelected').subscribe((res: string) => {
+        this.snackBar.open(res, 'X', { duration: 5000 });
+      });
     } else {
       let data;
       const formattedDate = this.dateFormatterService.formatDate(this.data.date);
diff --git a/webapp/src/app/add-vacation-dialog/add-vacation-dialog.module.ts b/webapp/src/app/add-vacation-dialog/add-vacation-dialog.module.ts
index 9d40c99..53a3e24 100644
--- a/webapp/src/app/add-vacation-dialog/add-vacation-dialog.module.ts
+++ b/webapp/src/app/add-vacation-dialog/add-vacation-dialog.module.ts
@@ -14,7 +14,7 @@ import {FormsModule, ReactiveFormsModule} from '@angular/forms';
 import {BrowserModule} from '@angular/platform-browser';
 import {SharedModule} from '../shared/shared.module';
 import {NgxMaterialTimepickerModule} from 'ngx-material-timepicker';
-import {TranslateModule} from "@ngx-translate/core";
+import {TranslateModule} from '@ngx-translate/core';
 
 
 @NgModule({
diff --git a/webapp/src/app/employees/default-settings-dialog/default-settings-dialog.component.ts b/webapp/src/app/employees/default-settings-dialog/default-settings-dialog.component.ts
index a1676f4..196d45c 100644
--- a/webapp/src/app/employees/default-settings-dialog/default-settings-dialog.component.ts
+++ b/webapp/src/app/employees/default-settings-dialog/default-settings-dialog.component.ts
@@ -1,5 +1,6 @@
 import {Component, Inject} from '@angular/core';
 import {MAT_DIALOG_DATA, MatDialogRef, MatSnackBar} from '@angular/material';
+import {TranslateService} from '@ngx-translate/core';
 
 @Component({
   selector: 'app-default-settings',
@@ -13,6 +14,7 @@ export class DefaultSettingsDialogComponent {
     public dialogRef: MatDialogRef<DefaultSettingsDialogComponent>,
     @Inject(MAT_DIALOG_DATA) public data: DefaultSettingsDialogData,
     private snackBar: MatSnackBar,
+    private translateService: TranslateService
   ) {
   }
 
@@ -26,7 +28,9 @@ export class DefaultSettingsDialogComponent {
         }
       );
     } else {
-      this.snackBar.open('Nevyplněny všechny potřebné položky');
+      this.translateService.get('error.missingField').subscribe((res: string) => {
+        this.snackBar.open(res, 'X', { duration: 5000 });
+      });
     }
   }
 
diff --git a/webapp/src/app/employees/edit-employee-dialog/edit-employee-dialog.component.ts b/webapp/src/app/employees/edit-employee-dialog/edit-employee-dialog.component.ts
index bc6729b..3ebb517 100644
--- a/webapp/src/app/employees/edit-employee-dialog/edit-employee-dialog.component.ts
+++ b/webapp/src/app/employees/edit-employee-dialog/edit-employee-dialog.component.ts
@@ -3,6 +3,7 @@ import {MAT_DIALOG_DATA, MatDialogRef, MatSnackBar} from '@angular/material';
 import {UserType} from '../../enums/common.enum';
 import {UserProfile} from '../../models/user.model';
 import {UserSettings} from '../../models/settings.model';
+import {TranslateService} from '@ngx-translate/core';
 
 
 @Component({
@@ -21,7 +22,9 @@ export class EditEmployeeDialogComponent implements OnInit {
 
   constructor(public dialogRef: MatDialogRef<EditEmployeeDialogComponent>,
               @Inject(MAT_DIALOG_DATA) public data: UserProfile,
-              private snackBar: MatSnackBar) {
+              private snackBar: MatSnackBar,
+              private translateService: TranslateService
+  ) {
     this._sickDaysCount = data.sickDayCount;
     this._addVacationHoursCount = 0;
     this._userType = data.role;
@@ -33,7 +36,9 @@ export class EditEmployeeDialogComponent implements OnInit {
 
   onConfirmClick(): void {
     if (this._sickDaysCount == null || this._addVacationHoursCount == null || this._userType == null) {
-      this.snackBar.open('Vyplňte prosím všechny údaje', 'Zavřít');
+      this.translateService.get('error.missingField').subscribe((res: string) => {
+        this.snackBar.open(res, 'X', { duration: 5000 });
+      });
     } else {
       this.postUserSettings.emit({
         id: this._userId,
diff --git a/webapp/src/app/employees/employees-list.component.ts b/webapp/src/app/employees/employees-list.component.ts
index 9cf04b0..6239f53 100644
--- a/webapp/src/app/employees/employees-list.component.ts
+++ b/webapp/src/app/employees/employees-list.component.ts
@@ -14,6 +14,7 @@ import {DateFormatterService} from '../services/util/date-formatter.service';
 import {FileService} from '../services/api/file.service';
 import {ProfileService} from '../services/util/profile.service';
 import {UserProfileDialogComponent} from './user-profile/user-profile-dialog.component';
+import {TranslateService} from '@ngx-translate/core';
 
 const daysOfWeek: string[] = [
   'dayShortName.mon',
@@ -48,7 +49,9 @@ export class EmployeesListComponent implements OnInit {
     private fileService: FileService,
     private profileService: ProfileService,
     public dialog: MatDialog,
-    private snackBar: MatSnackBar) {
+    private snackBar: MatSnackBar,
+    private translateService: TranslateService
+  ) {
     this.generateDays();
     this.generateDates();
     this.editDates();
@@ -70,8 +73,7 @@ export class EmployeesListComponent implements OnInit {
           linkElement.href = link;
           linkElement.download = 'dochazka.pdf';
           linkElement.click();
-        },
-        error1 => this.showSnackBarError(error1, 'Export PDF souboru se nezdařil'));
+        });
   }
 
   /**
@@ -81,9 +83,11 @@ 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}),
-        error1 => this.showSnackBarError(error1, 'Import soubor se nezdařil')
-      );
+      .subscribe(() => {
+        this.translateService.get('infoMessage.importSuccessful').subscribe((res: string) => {
+          this.snackBar.open(res, 'X', { duration: 5000 });
+        });
+      });
   }
 
   openUserProfile(user: User): void {
@@ -110,10 +114,9 @@ export class EmployeesListComponent implements OnInit {
 
           dialogRef.componentInstance.postUserSettings.subscribe((emittedData) => {
             this.userService.putUserSettings(emittedData)
-              .subscribe(() => this.snackBar.open('Povedlo se', 'Zavrit', {duration: 5000}));
+              .subscribe();
           });
-        },
-        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila')
+        }
       );
   }
 
@@ -138,8 +141,7 @@ export class EmployeesListComponent implements OnInit {
                 .subscribe();
             }
           });
-        },
-        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila'));
+        });
   }
 
   private toSettings(data): Settings {
@@ -217,18 +219,12 @@ 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();
-        },
-        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 84308ea..e1fe2f3 100644
--- a/webapp/src/app/services/api/basic.service.ts
+++ b/webapp/src/app/services/api/basic.service.ts
@@ -3,27 +3,28 @@ import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http';
 import {throwError} from 'rxjs';
 import {environment} from '../../../environments/environment';
 import {MatSnackBar} from '@angular/material';
-
+import {TranslateService} from '@ngx-translate/core';
 @Injectable({
   providedIn: 'root'
 })
 export class BasicService {
   protected baseUrl = environment.apiUrl;
 
-  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) { }
+  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) { }
 
   protected handleError(error: HttpErrorResponse) {
-    if (error.error instanceof ErrorEvent) {
-      console.error('An error occurred:', error.error.message);
+    let errMsg;
+    if (!error.error.error) {
+      this.translateService.get('error.serverCommunication').subscribe((res: string) => {
+        errMsg = res;
+      });
     } else {
-      console.error(
-        `Backend returned code ${error.status}, ` +
-        `body was: ${error.error}`);
+      errMsg = error.error.message;
     }
 
-    this.snackBar.open('Komunikace se serverem se nezdařila', 'Zavřít');
-    return throwError(
-      'Something bad happened; please try again later.');
+    this.snackBar.open(errMsg, 'X');
+
+    return throwError(errMsg);
   }
 
   /**
diff --git a/webapp/src/app/services/api/file.service.ts b/webapp/src/app/services/api/file.service.ts
index 540169c..7bb45cb 100644
--- a/webapp/src/app/services/api/file.service.ts
+++ b/webapp/src/app/services/api/file.service.ts
@@ -4,14 +4,15 @@ import {BasicService} from './basic.service';
 import {catchError} from 'rxjs/operators';
 import {Languages} from '../../enums/common.enum';
 import {MatSnackBar} from '@angular/material';
+import {TranslateService} from '@ngx-translate/core';
 
 @Injectable({
   providedIn: 'root'
 })
 export class FileService extends BasicService {
 
-  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) {
-    super(http, snackBar);
+  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
+    super(http, snackBar, translateService);
   }
 
   /**
diff --git a/webapp/src/app/services/api/settings.service.ts b/webapp/src/app/services/api/settings.service.ts
index e72fc8e..a2c6479 100644
--- a/webapp/src/app/services/api/settings.service.ts
+++ b/webapp/src/app/services/api/settings.service.ts
@@ -6,6 +6,7 @@ import { BasicService } from './basic.service';
 import { Settings } from '../../models/settings.model';
 import {Languages} from '../../enums/common.enum';
 import {MatSnackBar} from '@angular/material';
+import {TranslateService} from '@ngx-translate/core';
 
 @Injectable({
   providedIn: 'root'
@@ -13,8 +14,8 @@ import {MatSnackBar} from '@angular/material';
 export class SettingsService extends BasicService {
   defaultSettingsUrl = this.baseUrl + '/api/settings';
 
-  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) {
-    super(http, snackBar);
+  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
+    super(http, snackBar, translateService);
   }
 
   /**
diff --git a/webapp/src/app/services/api/user.service.ts b/webapp/src/app/services/api/user.service.ts
index a8991a9..ca8b0eb 100644
--- a/webapp/src/app/services/api/user.service.ts
+++ b/webapp/src/app/services/api/user.service.ts
@@ -10,6 +10,7 @@ import {UserProfile} from '../../models/user.model';
 import {UserRequest} from '../../models/requests.model';
 import {MatSnackBar} from '@angular/material';
 import {DateFormatterService} from '../util/date-formatter.service';
+import {TranslateService} from '@ngx-translate/core';
 
 @Injectable({
   providedIn: 'root'
@@ -17,8 +18,8 @@ import {DateFormatterService} from '../util/date-formatter.service';
 export class UserService extends BasicService { // dost podobny k usersService, mozna zmenit v rest api
   private _userUrl = this.baseUrl + '/api/user/';
 
-  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, private dateFormater: DateFormatterService) {
-    super(http, snackBar);
+  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService, private dateFormater: DateFormatterService) {
+    super(http, snackBar, translateService);
   }
 
   /**
diff --git a/webapp/src/app/services/api/users.service.ts b/webapp/src/app/services/api/users.service.ts
index e87151f..7b8c08a 100644
--- a/webapp/src/app/services/api/users.service.ts
+++ b/webapp/src/app/services/api/users.service.ts
@@ -8,6 +8,7 @@ import {Languages, ProfileStatus} from '../../enums/common.enum';
 import {Observable} from 'rxjs';
 import {UserBasicInformation} from '../../models/user.model';
 import {MatSnackBar} from '@angular/material';
+import {TranslateService} from '@ngx-translate/core';
 
 @Injectable({
   providedIn: 'root'
@@ -15,8 +16,8 @@ import {MatSnackBar} from '@angular/material';
 export class UsersService extends BasicService {
   private _usersUrl = this.baseUrl + '/api/users';
 
-  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) {
-    super(http, snackBar);
+  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
+    super(http, snackBar, translateService);
   }
 
   /**
diff --git a/webapp/src/assets/i18n/cs.json b/webapp/src/assets/i18n/cs.json
index c08f42f..e16d04f 100644
--- a/webapp/src/assets/i18n/cs.json
+++ b/webapp/src/assets/i18n/cs.json
@@ -63,6 +63,14 @@
     "confirm": "Potvrdit",
     "close": "Zavřít"
   },
+  "infoMessage": {
+    "importSuccessful": "Successfully imported"
+  },
+  "error": {
+    "serverCommunication": "Komunikace se serverem se nezdařila",
+    "vacationTypeNotSelected": "Nevybrán typ volna",
+    "missingField": "Nevyplněny všechny údaje"
+  },
   "ACCEPTED": "Schváleno",
   "AUTHORIZED": "Autorizováno",
   "PENDING": "Čekající",
diff --git a/webapp/src/assets/i18n/en.json b/webapp/src/assets/i18n/en.json
index edce39d..002f951 100644
--- a/webapp/src/assets/i18n/en.json
+++ b/webapp/src/assets/i18n/en.json
@@ -49,7 +49,7 @@
     "to": "To",
     "vacationType": "Type"
   },
-  "dayShortName" : {
+  "dayShortName": {
     "mon": "mon",
     "tue": "tue",
     "wed": "wed",
@@ -62,6 +62,14 @@
     "confirm": "Confirm",
     "close": "Close"
   },
+  "infoMessage": {
+    "importSuccessful": "Successfully imported"
+  },
+  "error": {
+    "serverCommunication": "Communication with server failed",
+    "vacationTypeNotSelected": "Vacation type not selected",
+    "missingField": "Not everything is filled in"
+  },
   "ACCEPTED": "Accepted",
   "AUTHORIZED": "Authorized",
   "PENDING": "Pending",
