Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 5d32cbea

Přidáno uživatelem Václav Jirák před téměř 6 roky(ů)

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

Zobrazit rozdíly:

webapp/src/app/add-vacation-dialog/add-vacation-dialog.component.ts
3 3
import {VacationType} from '../enums/common.enum';
4 4
import {FormControl} from '@angular/forms';
5 5
import {DateFormatterService} from '../services/util/date-formatter.service';
6
import {TranslateService} from '@ngx-translate/core';
6 7

  
7 8
@Component({
8 9
  selector: 'app-add-days-off-dialog',
......
22 23
    public dialogRef: MatDialogRef<AddVacationDialogComponent>,
23 24
    @Inject(MAT_DIALOG_DATA) public data: AddVacationDialogData,
24 25
    private snackBar: MatSnackBar,
25
    private dateFormatterService: DateFormatterService
26
    private dateFormatterService: DateFormatterService,
27
    private translateService: TranslateService
26 28
  ) {
27 29
    if (this.data.fromTime == null) {
28 30
      this.data.fromTime = '08:00';
......
36 38

  
37 39
  onConfirmClick(): void {
38 40
    if (this.selectedVacationType == null) {
39
      this.snackBar.open('Nevybrán typ volna', 'Zavřít', { duration: 5000 });
41
      this.translateService.get('error.vacationTypeNotSelected').subscribe((res: string) => {
42
        this.snackBar.open(res, 'X', { duration: 5000 });
43
      });
40 44
    } else {
41 45
      let data;
42 46
      const formattedDate = this.dateFormatterService.formatDate(this.data.date);
webapp/src/app/add-vacation-dialog/add-vacation-dialog.module.ts
14 14
import {BrowserModule} from '@angular/platform-browser';
15 15
import {SharedModule} from '../shared/shared.module';
16 16
import {NgxMaterialTimepickerModule} from 'ngx-material-timepicker';
17
import {TranslateModule} from "@ngx-translate/core";
17
import {TranslateModule} from '@ngx-translate/core';
18 18

  
19 19

  
20 20
@NgModule({
webapp/src/app/employees/default-settings-dialog/default-settings-dialog.component.ts
1 1
import {Component, Inject} from '@angular/core';
2 2
import {MAT_DIALOG_DATA, MatDialogRef, MatSnackBar} from '@angular/material';
3
import {TranslateService} from '@ngx-translate/core';
3 4

  
4 5
@Component({
5 6
  selector: 'app-default-settings',
......
13 14
    public dialogRef: MatDialogRef<DefaultSettingsDialogComponent>,
14 15
    @Inject(MAT_DIALOG_DATA) public data: DefaultSettingsDialogData,
15 16
    private snackBar: MatSnackBar,
17
    private translateService: TranslateService
16 18
  ) {
17 19
  }
18 20

  
......
26 28
        }
27 29
      );
28 30
    } else {
29
      this.snackBar.open('Nevyplněny všechny potřebné položky');
31
      this.translateService.get('error.missingField').subscribe((res: string) => {
32
        this.snackBar.open(res, 'X', { duration: 5000 });
33
      });
30 34
    }
31 35
  }
32 36

  
webapp/src/app/employees/edit-employee-dialog/edit-employee-dialog.component.ts
3 3
import {UserType} from '../../enums/common.enum';
4 4
import {UserProfile} from '../../models/user.model';
5 5
import {UserSettings} from '../../models/settings.model';
6
import {TranslateService} from '@ngx-translate/core';
6 7

  
7 8

  
8 9
@Component({
......
21 22

  
22 23
  constructor(public dialogRef: MatDialogRef<EditEmployeeDialogComponent>,
23 24
              @Inject(MAT_DIALOG_DATA) public data: UserProfile,
24
              private snackBar: MatSnackBar) {
25
              private snackBar: MatSnackBar,
26
              private translateService: TranslateService
27
  ) {
25 28
    this._sickDaysCount = data.sickDayCount;
26 29
    this._addVacationHoursCount = 0;
27 30
    this._userType = data.role;
......
33 36

  
34 37
  onConfirmClick(): void {
35 38
    if (this._sickDaysCount == null || this._addVacationHoursCount == null || this._userType == null) {
36
      this.snackBar.open('Vyplňte prosím všechny údaje', 'Zavřít');
39
      this.translateService.get('error.missingField').subscribe((res: string) => {
40
        this.snackBar.open(res, 'X', { duration: 5000 });
41
      });
37 42
    } else {
38 43
      this.postUserSettings.emit({
39 44
        id: this._userId,
webapp/src/app/employees/employees-list.component.ts
14 14
import {FileService} from '../services/api/file.service';
15 15
import {ProfileService} from '../services/util/profile.service';
16 16
import {UserProfileDialogComponent} from './user-profile/user-profile-dialog.component';
17
import {TranslateService} from '@ngx-translate/core';
17 18

  
18 19
const daysOfWeek: string[] = [
19 20
  'dayShortName.mon',
......
48 49
    private fileService: FileService,
49 50
    private profileService: ProfileService,
50 51
    public dialog: MatDialog,
51
    private snackBar: MatSnackBar) {
52
    private snackBar: MatSnackBar,
53
    private translateService: TranslateService
54
  ) {
52 55
    this.generateDays();
53 56
    this.generateDates();
54 57
    this.editDates();
......
70 73
          linkElement.href = link;
71 74
          linkElement.download = 'dochazka.pdf';
72 75
          linkElement.click();
73
        },
74
        error1 => this.showSnackBarError(error1, 'Export PDF souboru se nezdařil'));
76
        });
75 77
  }
76 78

  
77 79
  /**
......
81 83
   */
82 84
  uploadXlsxFile(files: FileList): void {
83 85
    this.fileService.uploadXlsFile(files)
84
      .subscribe(() => this.snackBar.open('Import souboru se provedl', 'Zavřít', {duration: 5000}),
85
        error1 => this.showSnackBarError(error1, 'Import soubor se nezdařil')
86
      );
86
      .subscribe(() => {
87
        this.translateService.get('infoMessage.importSuccessful').subscribe((res: string) => {
88
          this.snackBar.open(res, 'X', { duration: 5000 });
89
        });
90
      });
87 91
  }
88 92

  
89 93
  openUserProfile(user: User): void {
......
110 114

  
111 115
          dialogRef.componentInstance.postUserSettings.subscribe((emittedData) => {
112 116
            this.userService.putUserSettings(emittedData)
113
              .subscribe(() => this.snackBar.open('Povedlo se', 'Zavrit', {duration: 5000}));
117
              .subscribe();
114 118
          });
115
        },
116
        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila')
119
        }
117 120
      );
118 121
  }
119 122

  
......
138 141
                .subscribe();
139 142
            }
140 143
          });
141
        },
142
        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila'));
144
        });
143 145
  }
144 146

  
145 147
  private toSettings(data): Settings {
......
217 219
    return dayInfo;
218 220
  }
219 221

  
220
  private showSnackBarError(error1, message: string) {
221
    console.log(error1);
222
    this.snackBar.open(message, 'Zavřít', {duration: 5000});
223
  }
224

  
225 222
  ngOnInit() {
226 223
    this.usersService.getAuthorizedUsers()
227 224
      .subscribe((data: UserBasicInformation[]) => {
228 225
          this._employeesBasicInformation = data;
229 226
          this.mapUsers();
230
        },
231
        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila'));
227
        });
232 228
  }
233 229

  
234 230
}
webapp/src/app/services/api/basic.service.ts
3 3
import {throwError} from 'rxjs';
4 4
import {environment} from '../../../environments/environment';
5 5
import {MatSnackBar} from '@angular/material';
6

  
6
import {TranslateService} from '@ngx-translate/core';
7 7
@Injectable({
8 8
  providedIn: 'root'
9 9
})
10 10
export class BasicService {
11 11
  protected baseUrl = environment.apiUrl;
12 12

  
13
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) { }
13
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) { }
14 14

  
15 15
  protected handleError(error: HttpErrorResponse) {
16
    if (error.error instanceof ErrorEvent) {
17
      console.error('An error occurred:', error.error.message);
16
    let errMsg;
17
    if (!error.error.error) {
18
      this.translateService.get('error.serverCommunication').subscribe((res: string) => {
19
        errMsg = res;
20
      });
18 21
    } else {
19
      console.error(
20
        `Backend returned code ${error.status}, ` +
21
        `body was: ${error.error}`);
22
      errMsg = error.error.message;
22 23
    }
23 24

  
24
    this.snackBar.open('Komunikace se serverem se nezdařila', 'Zavřít');
25
    return throwError(
26
      'Something bad happened; please try again later.');
25
    this.snackBar.open(errMsg, 'X');
26

  
27
    return throwError(errMsg);
27 28
  }
28 29

  
29 30
  /**
webapp/src/app/services/api/file.service.ts
4 4
import {catchError} from 'rxjs/operators';
5 5
import {Languages} from '../../enums/common.enum';
6 6
import {MatSnackBar} from '@angular/material';
7
import {TranslateService} from '@ngx-translate/core';
7 8

  
8 9
@Injectable({
9 10
  providedIn: 'root'
10 11
})
11 12
export class FileService extends BasicService {
12 13

  
13
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) {
14
    super(http, snackBar);
14
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
15
    super(http, snackBar, translateService);
15 16
  }
16 17

  
17 18
  /**
webapp/src/app/services/api/settings.service.ts
6 6
import { Settings } from '../../models/settings.model';
7 7
import {Languages} from '../../enums/common.enum';
8 8
import {MatSnackBar} from '@angular/material';
9
import {TranslateService} from '@ngx-translate/core';
9 10

  
10 11
@Injectable({
11 12
  providedIn: 'root'
......
13 14
export class SettingsService extends BasicService {
14 15
  defaultSettingsUrl = this.baseUrl + '/api/settings';
15 16

  
16
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) {
17
    super(http, snackBar);
17
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
18
    super(http, snackBar, translateService);
18 19
  }
19 20

  
20 21
  /**
webapp/src/app/services/api/user.service.ts
10 10
import {UserRequest} from '../../models/requests.model';
11 11
import {MatSnackBar} from '@angular/material';
12 12
import {DateFormatterService} from '../util/date-formatter.service';
13
import {TranslateService} from '@ngx-translate/core';
13 14

  
14 15
@Injectable({
15 16
  providedIn: 'root'
......
17 18
export class UserService extends BasicService { // dost podobny k usersService, mozna zmenit v rest api
18 19
  private _userUrl = this.baseUrl + '/api/user/';
19 20

  
20
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, private dateFormater: DateFormatterService) {
21
    super(http, snackBar);
21
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService, private dateFormater: DateFormatterService) {
22
    super(http, snackBar, translateService);
22 23
  }
23 24

  
24 25
  /**
webapp/src/app/services/api/users.service.ts
8 8
import {Observable} from 'rxjs';
9 9
import {UserBasicInformation} from '../../models/user.model';
10 10
import {MatSnackBar} from '@angular/material';
11
import {TranslateService} from '@ngx-translate/core';
11 12

  
12 13
@Injectable({
13 14
  providedIn: 'root'
......
15 16
export class UsersService extends BasicService {
16 17
  private _usersUrl = this.baseUrl + '/api/users';
17 18

  
18
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar) {
19
    super(http, snackBar);
19
  constructor(protected http: HttpClient, protected snackBar: MatSnackBar, protected translateService: TranslateService) {
20
    super(http, snackBar, translateService);
20 21
  }
21 22

  
22 23
  /**
webapp/src/assets/i18n/cs.json
63 63
    "confirm": "Potvrdit",
64 64
    "close": "Zavřít"
65 65
  },
66
  "infoMessage": {
67
    "importSuccessful": "Successfully imported"
68
  },
69
  "error": {
70
    "serverCommunication": "Komunikace se serverem se nezdařila",
71
    "vacationTypeNotSelected": "Nevybrán typ volna",
72
    "missingField": "Nevyplněny všechny údaje"
73
  },
66 74
  "ACCEPTED": "Schváleno",
67 75
  "AUTHORIZED": "Autorizováno",
68 76
  "PENDING": "Čekající",
webapp/src/assets/i18n/en.json
49 49
    "to": "To",
50 50
    "vacationType": "Type"
51 51
  },
52
  "dayShortName" : {
52
  "dayShortName": {
53 53
    "mon": "mon",
54 54
    "tue": "tue",
55 55
    "wed": "wed",
......
62 62
    "confirm": "Confirm",
63 63
    "close": "Close"
64 64
  },
65
  "infoMessage": {
66
    "importSuccessful": "Successfully imported"
67
  },
68
  "error": {
69
    "serverCommunication": "Communication with server failed",
70
    "vacationTypeNotSelected": "Vacation type not selected",
71
    "missingField": "Not everything is filled in"
72
  },
65 73
  "ACCEPTED": "Accepted",
66 74
  "AUTHORIZED": "Authorized",
67 75
  "PENDING": "Pending",

Také k dispozici: Unified diff