Revize 9cc55d8d
Přidáno uživatelem Václav Jirák před téměř 6 roky(ů)
webapp/src/app/header/header.component.ts | ||
---|---|---|
3 | 3 |
import {LocalizationService} from '../localization/localization.service'; |
4 | 4 |
import {UserService} from '../services/api/user.service'; |
5 | 5 |
import {UserProfile} from '../models/user.model'; |
6 |
import {ProfileSettingsComponent} from "../profile-settings/profile-settings.component"; |
|
6 | 7 |
|
7 | 8 |
@Component({ |
8 | 9 |
selector: 'app-header', |
... | ... | |
22 | 23 |
} |
23 | 24 |
|
24 | 25 |
onProfileClick(): void { |
25 |
// TODO (až bude hotovej endpoint na post notifikace) |
|
26 |
// this.dialog.open(ProfileSettingsComponent, { |
|
27 |
// data: { |
|
28 |
// notifyDate: this.notificationSettings, |
|
29 |
// notifyTime: { |
|
30 |
// hour: this.notificationSettings.getHours(), |
|
31 |
// minute: this.notificationSettings.getMinutes() |
|
32 |
// } |
|
33 |
// } |
|
34 |
// }); |
|
26 |
this.userService.getLoggedUserProfile() |
|
27 |
.subscribe((data: UserProfile) => { |
|
28 |
this.profile = data; |
|
29 |
|
|
30 |
this.dialog.open(ProfileSettingsComponent, { |
|
31 |
data: { |
|
32 |
notification: this.profile.notification |
|
33 |
} |
|
34 |
}).afterClosed().subscribe(dialogData => { |
|
35 |
this.userService.putNotificationSettingsWithLanguage( |
|
36 |
{ |
|
37 |
notification: dialogData.notification |
|
38 |
}, |
|
39 |
this.localizationService.getCurrentLanguage() |
|
40 |
).subscribe(() => { |
|
41 |
this.userService.getLoggedUserProfile().subscribe((profile: UserProfile) => this.profile = profile); |
|
42 |
}); |
|
43 |
}); |
|
44 |
}); |
|
35 | 45 |
} |
36 | 46 |
} |
webapp/src/app/models/settings.model.ts | ||
---|---|---|
12 | 12 |
role: UserType; |
13 | 13 |
} |
14 | 14 |
|
15 |
export interface NotificationSettings { |
|
16 |
notification: string; |
|
17 |
} |
webapp/src/app/profile-settings/profile-settings.component.html | ||
---|---|---|
2 | 2 |
|
3 | 3 |
<div mat-dialog-content> |
4 | 4 |
<span class="notification-label">Notifikace o vypršení dovolené: </span> |
5 |
<app-datetime [(date)]="data.notifyDate" [(time)]="data.notifyTime" [minuteStep]="15"></app-datetime>
|
|
5 |
<app-datetime [(date)]="date" [(time)]="time" [minuteStep]="15"></app-datetime>
|
|
6 | 6 |
</div> |
7 | 7 |
|
8 | 8 |
<div mat-dialog-actions align="end"> |
webapp/src/app/profile-settings/profile-settings.component.ts | ||
---|---|---|
1 | 1 |
import { Component, Inject } from '@angular/core'; |
2 | 2 |
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material'; |
3 |
import {DateToolsService} from '../services/util/date-tools.service'; |
|
4 |
import {DateFormatterService} from "../services/util/date-formatter.service"; |
|
3 | 5 |
|
4 | 6 |
@Component({ |
5 | 7 |
selector: 'app-profile-settings', |
... | ... | |
7 | 9 |
styleUrls: ['./profile-settings.component.sass'] |
8 | 10 |
}) |
9 | 11 |
export class ProfileSettingsComponent { |
12 |
private date: Date; |
|
13 |
private time: string; |
|
14 |
|
|
10 | 15 |
constructor( |
16 |
private dateToolsService: DateToolsService, |
|
17 |
private dateFormatterService: DateFormatterService, |
|
11 | 18 |
public dialogRef: MatDialogRef<ProfileSettingsComponent>, |
12 | 19 |
@Inject(MAT_DIALOG_DATA) public data: ProfileSettingsDialogData, |
13 | 20 |
) { |
21 |
const parsedDatetime = this.dateToolsService.toDateAndTime(this.data.notification); |
|
22 |
|
|
23 |
this.date = parsedDatetime.date; |
|
24 |
this.time = parsedDatetime.time; |
|
14 | 25 |
} |
15 | 26 |
|
16 | 27 |
onConfirmClick(): void { |
17 | 28 |
this.dialogRef.close({ |
18 | 29 |
isConfirmed: true, |
19 |
notifyDate: this.data.notifyDate, |
|
20 |
notifyTime: this.data.notifyTime |
|
30 |
notification: this.dateFormatterService.formatDatetime( |
|
31 |
this.dateToolsService.toDate( |
|
32 |
this.dateFormatterService.formatDate(this.date), |
|
33 |
this.time |
|
34 |
) |
|
35 |
) |
|
21 | 36 |
}); |
22 | 37 |
} |
23 | 38 |
|
... | ... | |
29 | 44 |
} |
30 | 45 |
|
31 | 46 |
export interface ProfileSettingsDialogData { |
32 |
notifyDate: Date; |
|
33 |
notifyTime: string; |
|
47 |
notification: string; // yyyy/mm/dd hh:mm:ss |
|
34 | 48 |
} |
webapp/src/app/services/api/user.service.ts | ||
---|---|---|
5 | 5 |
import {BasicService} from './basic.service'; |
6 | 6 |
import {catchError} from 'rxjs/operators'; |
7 | 7 |
import {Languages, RequestStatus, RequestTypes} from '../../enums/common.enum'; |
8 |
import {UserSettings} from '../../models/settings.model'; |
|
8 |
import {NotificationSettings, UserSettings} from '../../models/settings.model';
|
|
9 | 9 |
import {UserProfile} from '../../models/user.model'; |
10 | 10 |
import {UserRequest} from '../../models/requests.model'; |
11 | 11 |
import {MatSnackBar} from '@angular/material'; |
... | ... | |
126 | 126 |
return this.makePutUserSettingsApiCall(settings, language); |
127 | 127 |
} |
128 | 128 |
|
129 |
putNotificationSettingsWithLanguage(settings: NotificationSettings, language: Languages) { |
|
130 |
console.log(settings); |
|
131 |
return this.makePutNotificationSettingsApiCall(settings, language); |
|
132 |
} |
|
129 | 133 |
/** |
130 | 134 |
* Accept or deny user request |
131 | 135 |
* @param request request to accept or deny |
... | ... | |
237 | 241 |
); |
238 | 242 |
} |
239 | 243 |
|
244 |
/** |
|
245 |
* Změna nastavení notifikace uživatele podle id |
|
246 |
* PUT /user/settings?[lang=<CZ,EN>] |
|
247 |
* @param settings notification setting to be set for given user |
|
248 |
* @param language specified language |
|
249 |
*/ |
|
250 |
private makePutNotificationSettingsApiCall(settings: NotificationSettings, language: Languages) { |
|
251 |
const httpParams: HttpParams = this.createParams({lang: language}); |
|
252 |
const options = {params: httpParams}; |
|
253 |
|
|
254 |
return this.http.put<NotificationSettings>(this._userUrl + 'settings', settings, options) |
|
255 |
.pipe( |
|
256 |
catchError(err => this.handleError(err)) |
|
257 |
); |
|
258 |
} |
|
259 |
|
|
240 | 260 |
/** |
241 | 261 |
* Vytvoření nové dovolené nebo sick day |
242 | 262 |
* POST /user/calendar/create?[lang=<CZ,EN>] |
webapp/src/app/services/util/date-tools.service.ts | ||
---|---|---|
61 | 61 |
|
62 | 62 |
return result; |
63 | 63 |
} |
64 |
|
|
65 |
/** |
|
66 |
* Creates {date: Date, time: string} object from string representation of datetime in format 'yyyy/mm/dd hh:mm:ss' |
|
67 |
* @param datetime string representation of datetime in format 'yyyy/mm/dd hh:mm:ss' |
|
68 |
*/ |
|
69 |
toDateAndTime(datetime: string) { |
|
70 |
const parsedDatetime = datetime.split(' '); |
|
71 |
const parsedDate = parsedDatetime[0].split('/'); |
|
72 |
const parsedTime = parsedDatetime[1].split(':'); |
|
73 |
|
|
74 |
const date = new Date(Number(parsedDate[0]), Number(parsedDate[1]), Number(parsedDate[2])); |
|
75 |
const time = parsedTime[0] + ':' + parsedTime[1]; |
|
76 |
|
|
77 |
return { |
|
78 |
date, |
|
79 |
time |
|
80 |
}; |
|
81 |
} |
|
64 | 82 |
} |
Také k dispozici: Unified diff
Re #7534 'Profile settings' component connected to the API