Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1d169f6d

Přidáno uživatelem Hung Hoang před téměř 6 roky(ů)

Re#7527 SnackBar opens if the error occurs

Zobrazit rozdíly:

webapp/src/app/employees/employees-list.component.html
1 1
<div class="employee-component">
2
  <h3> <span class="align-baseline">Zaměstnanci</span>
2
  <div>
3
    <span class="align-baseline" style="font-size: x-large">Zaměstnanci</span>
3 4

  
4 5
    <button
5 6
      id="settings-button"
......
19 20
      (change)="uploadXlsxFile(fileInput.files); fileInput.value = null;"
20 21
    />
21 22

  
22
    <label for="input-file" class="btn btn-primary align-baseline">Import</label>
23
    <button class="btn btn-danger align-baseline" (click)="downloadPdf()">
23
    <label for="input-file" class="btn btn-primary " style="margin-right: 5px">Import</label>
24
    <label class="btn btn-danger" (click)="downloadPdf()">
24 25
      Export
25
    </button>
26
    </label>
26 27

  
27
  </h3>
28
  </div>
28 29

  
29 30
  <table class="table text-center table-hover">
30 31
    <thead class="thead-light">
webapp/src/app/employees/employees-list.component.sass
28 28

  
29 29

  
30 30
.input-file
31
  width: 0.1px
32
  height: 0.1px
33
  opacity: 0
34
  overflow: hidden
35
  position: absolute
36
  z-index: -1
31
  display: none
32

  
37 33

  
webapp/src/app/employees/employees-list.component.ts
58 58
    // https://stackoverflow.com/a/52687792/6204336
59 59
    this.fileService.getExportedPdf()
60 60
      .subscribe((data: any) => {
61
        console.log(data);
62
        const blob = new Blob([data], {type: 'application/pdf'});
63
        const link = window.URL.createObjectURL(blob);
64
        const linkElement = document.createElement('a');
65
        linkElement.href = link;
66
        linkElement.download = 'super.pdf';
67
        linkElement.click();
68
      });
61
          console.log(data);
62
          const blob = new Blob([data], {type: 'application/pdf'});
63
          const link = window.URL.createObjectURL(blob);
64
          const linkElement = document.createElement('a');
65
          linkElement.href = link;
66
          linkElement.download = 'dochazka.pdf';
67
          linkElement.click();
68
        },
69
        error1 => this.showSnackBarError(error1, 'Export PDF souboru se nezdařil'));
69 70
  }
70 71

  
71 72
  /**
......
75 76
   */
76 77
  uploadXlsxFile(files: FileList): void {
77 78
    this.fileService.uploadXlsFile(files)
78
      .subscribe(() => this.snackBar.open('Import souboru se provedl', 'Zavřít', {duration: 5000}));
79
      .subscribe(() => this.snackBar.open('Import souboru se provedl', 'Zavřít', {duration: 5000}),
80
        error1 => this.showSnackBarError(error1, 'Import soubor se nezdařil')
81
      );
79 82
  }
80 83

  
81 84
  /**
......
87 90
  openEditUserDialog(user: User): void {
88 91
    this.userService.getUserProfile(user.id)
89 92
      .subscribe((userProfile: UserProfile) => {
90
        const dialogRef = this.dialog.open(EditEmployeeDialogComponent, {
91
          data: userProfile,
92
        });
93

  
94
        dialogRef.componentInstance.postUserSettings.subscribe((emittedData) => {
95
          this.userService.putUserSettings(emittedData)
96
            .subscribe(() => this.snackBar.open('Povedlo se', 'Zavrit', {duration: 5000}));
97
        });
98
      });
93
          const dialogRef = this.dialog.open(EditEmployeeDialogComponent, {
94
            data: userProfile,
95
          });
96

  
97
          dialogRef.componentInstance.postUserSettings.subscribe((emittedData) => {
98
            this.userService.putUserSettings(emittedData)
99
              .subscribe(() => this.snackBar.open('Povedlo se', 'Zavrit', {duration: 5000}));
100
          });
101
        },
102
        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila')
103
      );
99 104
  }
100 105

  
101 106
  openDefaultSettingsDialog(): void {
102 107
    this.settingsService.getDefaultSettingsWithLanguage(Languages.CZECH)
103 108
      .subscribe((settingsData: Settings) => {
104
        const parsedDate = new Date(settingsData.notification);
109
          const parsedDate = new Date(settingsData.notification);
105 110

  
106
        const parsedSettings = {
107
          notificationDate: new Date(parsedDate.getFullYear(), parsedDate.getMonth(), parsedDate.getDate()),
108
          notificationTime: parsedDate.getHours() + ':' + parsedDate.getMinutes(),
109
          sickdaysCount: settingsData.sickdayCount
110
        };
111
          const parsedSettings = {
112
            notificationDate: new Date(parsedDate.getFullYear(), parsedDate.getMonth(), parsedDate.getDate()),
113
            notificationTime: parsedDate.getHours() + ':' + parsedDate.getMinutes(),
114
            sickdaysCount: settingsData.sickdayCount
115
          };
111 116

  
112
        this.dialog.open(DefaultSettingsDialogComponent, {
117
          this.dialog.open(DefaultSettingsDialogComponent, {
113 118
            data: parsedSettings,
114 119
            width: '300px'
115 120
          })
116
          .afterClosed().subscribe(data => {
121
            .afterClosed().subscribe(data => {
117 122
            if (data && data.isConfirmed) {
118 123
              this.settingsService.postDefaultSettingsWithLanguage(this.toSettings(data), this.localizationService.getCurrentLanguage())
119 124
                .subscribe((foo: any) => console.log(foo));
120 125
            }
121 126
          });
122
      });
127
        },
128
        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila'));
123 129
  }
124 130

  
125 131
  private toSettings(data): Settings {
......
197 203
    return dayInfo;
198 204
  }
199 205

  
206
  private showSnackBarError(error1, message: string) {
207
    console.log(error1);
208
    this.snackBar.open(message, 'Zavřít', {duration: 5000});
209
  }
210

  
200 211
  ngOnInit() {
201 212
    this.usersService.getAuthorizedUsers()
202 213
      .subscribe((data: UserBasicInformation[]) => {
203
        this._employeesBasicInformation = data;
204
        this.mapUsers();
205
      });
206

  
207
    // const calendar: PostCalendar = { date: '1999/10/10', from: '15:00', to: '17:00', type: VacationType.VACATION };
208
    // this.userService.postCalendar(calendar)
209
    //   .subscribe((data: any) => console.log(data));
210

  
211
    // const settings: UserSettings = {
212
    //   id: 1,
213
    //   role: UserType.EMPLOYEE,
214
    //   sickdayCount: 1,
215
    //   vacationCount: 1,
216
    // };
217
    //
218
    // this.userService.putUserSettings(settings)
219
    //   .subscribe((data: any) => console.log(data));
220

  
214
          this._employeesBasicInformation = data;
215
          this.mapUsers();
216
        },
217
        error1 => this.showSnackBarError(error1, 'Komunikace se serverem se nezdařila'));
221 218
  }
222 219

  
223 220
}
webapp/src/app/services/api/basic.service.ts
2 2
import {HttpClient, HttpErrorResponse, HttpParams} from '@angular/common/http';
3 3
import {throwError} from 'rxjs';
4 4
import {environment} from '../../../environments/environment';
5
import {MatSnackBar} from '@angular/material';
5 6

  
6 7
@Injectable({
7 8
  providedIn: 'root'
......
9 10
export class BasicService {
10 11
  protected baseUrl = environment.apiUrl;
11 12

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

  
14 15
  protected handleError(error: HttpErrorResponse) {
15 16
    if (error.error instanceof ErrorEvent) {
......
19 20
        `Backend returned code ${error.status}, ` +
20 21
        `body was: ${error.error}`);
21 22
    }
23

  
24
    this.snackBar.open('Komunikace se serverem se nezdařila', 'Zavřít');
22 25
    return throwError(
23 26
      'Something bad happened; please try again later.');
24 27
  }
webapp/src/app/services/api/file.service.ts
3 3
import {BasicService} from './basic.service';
4 4
import {catchError} from 'rxjs/operators';
5 5
import {Languages} from '../../enums/common.enum';
6
import {MatSnackBar} from '@angular/material';
6 7

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

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

  
16 17
  /**
......
75 76
    if (fileCount > 0) {
76 77

  
77 78
      formData.append('file', file.item(0));
78
      console.log('posilam data');
79 79
      return this.http.post(this.baseUrl + '/api/import/xls', formData, options);
80 80
    }
81 81
  }
webapp/src/app/services/api/settings.service.ts
5 5
import { BasicService } from './basic.service';
6 6
import { Settings } from '../../models/settings.model';
7 7
import {Languages} from '../../enums/common.enum';
8
import {MatSnackBar} from '@angular/material';
8 9

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

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

  
19 20
  /**
webapp/src/app/services/api/user.service.ts
8 8
import {UserSettings} from '../../models/settings.model';
9 9
import {UserProfile} from '../../models/user.model';
10 10
import {UserRequest} from '../../models/requests.model';
11
import {MatSnackBar} from '@angular/material';
11 12

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

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

  
22 23
  /**
webapp/src/app/services/api/users.service.ts
7 7
import {Languages, ProfileStatus} from '../../enums/common.enum';
8 8
import {Observable} from 'rxjs';
9 9
import {UserBasicInformation} from '../../models/user.model';
10
import {MatSnackBar} from '@angular/material';
10 11

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

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

  
21 22
  /**

Také k dispozici: Unified diff