commit 9cc55d8d1b3100596c1d2ec9cc0bc35062eac74d
Author: Václav Jirák <jirakv95@gmail.com>
Date:   Thu May 30 21:22:55 2019 +0200

    Re #7534 'Profile settings' component connected to the API

diff --git a/webapp/src/app/header/header.component.ts b/webapp/src/app/header/header.component.ts
index 31ce273..8e6685f 100644
--- a/webapp/src/app/header/header.component.ts
+++ b/webapp/src/app/header/header.component.ts
@@ -3,6 +3,7 @@ import {MatDialog} from '@angular/material';
 import {LocalizationService} from '../localization/localization.service';
 import {UserService} from '../services/api/user.service';
 import {UserProfile} from '../models/user.model';
+import {ProfileSettingsComponent} from "../profile-settings/profile-settings.component";
 
 @Component({
   selector: 'app-header',
@@ -22,15 +23,24 @@ export class HeaderComponent {
   }
 
   onProfileClick(): void {
-    // TODO (až bude hotovej endpoint na post notifikace)
-    // this.dialog.open(ProfileSettingsComponent, {
-    //   data: {
-    //     notifyDate: this.notificationSettings,
-    //     notifyTime: {
-    //       hour: this.notificationSettings.getHours(),
-    //       minute: this.notificationSettings.getMinutes()
-    //     }
-    //   }
-    // });
+    this.userService.getLoggedUserProfile()
+      .subscribe((data: UserProfile) => {
+        this.profile = data;
+
+        this.dialog.open(ProfileSettingsComponent, {
+          data: {
+            notification: this.profile.notification
+          }
+        }).afterClosed().subscribe(dialogData => {
+          this.userService.putNotificationSettingsWithLanguage(
+            {
+              notification: dialogData.notification
+            },
+            this.localizationService.getCurrentLanguage()
+          ).subscribe(() => {
+            this.userService.getLoggedUserProfile().subscribe((profile: UserProfile) => this.profile = profile);
+          });
+        });
+      });
   }
 }
diff --git a/webapp/src/app/models/settings.model.ts b/webapp/src/app/models/settings.model.ts
index 220b591..1a6b806 100644
--- a/webapp/src/app/models/settings.model.ts
+++ b/webapp/src/app/models/settings.model.ts
@@ -12,3 +12,6 @@ export interface UserSettings {
   role: UserType;
 }
 
+export interface NotificationSettings {
+  notification: string;
+}
diff --git a/webapp/src/app/profile-settings/profile-settings.component.html b/webapp/src/app/profile-settings/profile-settings.component.html
index c61146f..a14810a 100644
--- a/webapp/src/app/profile-settings/profile-settings.component.html
+++ b/webapp/src/app/profile-settings/profile-settings.component.html
@@ -2,7 +2,7 @@
 
 <div mat-dialog-content>
   <span class="notification-label">Notifikace o vypršení dovolené: </span>
-  <app-datetime [(date)]="data.notifyDate" [(time)]="data.notifyTime" [minuteStep]="15"></app-datetime>
+  <app-datetime [(date)]="date" [(time)]="time" [minuteStep]="15"></app-datetime>
 </div>
 
 <div mat-dialog-actions align="end">
diff --git a/webapp/src/app/profile-settings/profile-settings.component.ts b/webapp/src/app/profile-settings/profile-settings.component.ts
index 76e21c7..a18170c 100644
--- a/webapp/src/app/profile-settings/profile-settings.component.ts
+++ b/webapp/src/app/profile-settings/profile-settings.component.ts
@@ -1,5 +1,7 @@
 import { Component, Inject } from '@angular/core';
 import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
+import {DateToolsService} from '../services/util/date-tools.service';
+import {DateFormatterService} from "../services/util/date-formatter.service";
 
 @Component({
   selector: 'app-profile-settings',
@@ -7,17 +9,30 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
   styleUrls: ['./profile-settings.component.sass']
 })
 export class ProfileSettingsComponent {
+  private date: Date;
+  private time: string;
+
   constructor(
+    private dateToolsService: DateToolsService,
+    private dateFormatterService: DateFormatterService,
     public dialogRef: MatDialogRef<ProfileSettingsComponent>,
     @Inject(MAT_DIALOG_DATA) public data: ProfileSettingsDialogData,
   ) {
+    const parsedDatetime = this.dateToolsService.toDateAndTime(this.data.notification);
+
+    this.date = parsedDatetime.date;
+    this.time = parsedDatetime.time;
   }
 
   onConfirmClick(): void {
     this.dialogRef.close({
       isConfirmed: true,
-      notifyDate: this.data.notifyDate,
-      notifyTime: this.data.notifyTime
+      notification: this.dateFormatterService.formatDatetime(
+        this.dateToolsService.toDate(
+          this.dateFormatterService.formatDate(this.date),
+          this.time
+        )
+      )
     });
   }
 
@@ -29,6 +44,5 @@ export class ProfileSettingsComponent {
 }
 
 export interface ProfileSettingsDialogData {
-  notifyDate: Date;
-  notifyTime: string;
+  notification: string; // yyyy/mm/dd hh:mm:ss
 }
diff --git a/webapp/src/app/services/api/user.service.ts b/webapp/src/app/services/api/user.service.ts
index 6bf8c7f..26b9586 100644
--- a/webapp/src/app/services/api/user.service.ts
+++ b/webapp/src/app/services/api/user.service.ts
@@ -5,7 +5,7 @@ import {Calendar, CalendarEdit, PostCalendar} from '../../models/calendar.model'
 import {BasicService} from './basic.service';
 import {catchError} from 'rxjs/operators';
 import {Languages, RequestStatus, RequestTypes} from '../../enums/common.enum';
-import {UserSettings} from '../../models/settings.model';
+import {NotificationSettings, UserSettings} from '../../models/settings.model';
 import {UserProfile} from '../../models/user.model';
 import {UserRequest} from '../../models/requests.model';
 import {MatSnackBar} from '@angular/material';
@@ -126,6 +126,10 @@ export class UserService extends BasicService { // dost podobny k usersService,
     return this.makePutUserSettingsApiCall(settings, language);
   }
 
+  putNotificationSettingsWithLanguage(settings: NotificationSettings, language: Languages) {
+    console.log(settings);
+    return this.makePutNotificationSettingsApiCall(settings, language);
+  }
   /**
    * Accept or deny user request
    * @param request request to accept or deny
@@ -237,6 +241,22 @@ export class UserService extends BasicService { // dost podobny k usersService,
       );
   }
 
+  /**
+   * Změna nastavení notifikace uživatele podle id
+   * PUT /user/settings?[lang=<CZ,EN>]
+   * @param settings notification setting to be set for given user
+   * @param language specified language
+   */
+  private makePutNotificationSettingsApiCall(settings: NotificationSettings, language: Languages) {
+    const httpParams: HttpParams = this.createParams({lang: language});
+    const options = {params: httpParams};
+
+    return this.http.put<NotificationSettings>(this._userUrl + 'settings', settings, options)
+      .pipe(
+        catchError(err => this.handleError(err))
+      );
+  }
+
   /**
    * Vytvoření nové dovolené nebo sick day
    * POST /user/calendar/create?[lang=<CZ,EN>]
diff --git a/webapp/src/app/services/util/date-tools.service.ts b/webapp/src/app/services/util/date-tools.service.ts
index a3ec568..03fc5a6 100644
--- a/webapp/src/app/services/util/date-tools.service.ts
+++ b/webapp/src/app/services/util/date-tools.service.ts
@@ -61,4 +61,22 @@ export class DateToolsService {
 
     return result;
   }
+
+  /**
+   * Creates {date: Date, time: string} object from string representation of datetime in format 'yyyy/mm/dd hh:mm:ss'
+   * @param datetime string representation of datetime in format 'yyyy/mm/dd hh:mm:ss'
+   */
+  toDateAndTime(datetime: string) {
+    const parsedDatetime = datetime.split(' ');
+    const parsedDate = parsedDatetime[0].split('/');
+    const parsedTime = parsedDatetime[1].split(':');
+
+    const date = new Date(Number(parsedDate[0]), Number(parsedDate[1]), Number(parsedDate[2]));
+    const time = parsedTime[0] + ':' + parsedTime[1];
+
+    return {
+      date,
+      time
+    };
+  }
 }
