From 7cb3c12351d12c89e167ec518fab12fd92c44f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Sun, 3 Oct 2021 12:10:54 +0200 Subject: [PATCH] Comments and docs --- .../datepicker/datepicker.component.ts | 21 +++++++++++++++++++ .../event-detail/event-detail.component.ts | 11 +++++++++- .../app/components/event/event.component.ts | 6 ++++++ .../src/app/components/week/week.component.ts | 4 ++++ Frontend/src/app/mocks/mock.service.ts | 3 +++ .../landingpage/landingpage.component.ts | 13 ++++++++++++ Frontend/src/app/services/api/api.service.ts | 11 ++++++++++ .../app/services/utils/utilities.service.ts | 20 ++++++++++++++++++ 8 files changed, 88 insertions(+), 1 deletion(-) diff --git a/Frontend/src/app/components/datepicker/datepicker.component.ts b/Frontend/src/app/components/datepicker/datepicker.component.ts index 0913b61..fbfa7dc 100644 --- a/Frontend/src/app/components/datepicker/datepicker.component.ts +++ b/Frontend/src/app/components/datepicker/datepicker.component.ts @@ -170,6 +170,9 @@ export class DatepickerComponent implements OnInit { return new Date(year, month, 0).getDate(); } + /** + * Switches the currently selected date to the next week + */ switchToNextWeek() { let currentDate = new Date(parseInt(this.selectedYear), parseInt(this.selectedMonth)-1, parseInt(this.selectedDay)); let newDate = currentDate; @@ -180,6 +183,9 @@ export class DatepickerComponent implements OnInit { this.handleDateChange(); } + /** + * Switches the currently selected date to the previous week + */ switchToPreviousWeek() { let currentDate = new Date(parseInt(this.selectedYear), parseInt(this.selectedMonth)-1, parseInt(this.selectedDay)); let newDate = currentDate; @@ -190,6 +196,9 @@ export class DatepickerComponent implements OnInit { this.handleDateChange(); } + /** + * Switches the currently selected date to today + */ switchToToday() { let currentDate = new Date(); this.selectedYear = currentDate.getFullYear().toString(); @@ -198,6 +207,9 @@ export class DatepickerComponent implements OnInit { this.handleDateChange(); } + /** + * Switches whether to show deleted events in the overview + */ switchShowDeletedEvents() { if(this.internalShowDeletedEvents) { this.internalShowDeletedEvents = false; @@ -214,6 +226,9 @@ export class DatepickerComponent implements OnInit { this.saveDetailsToLocalStorage(); } + /** + * Saves preferences like the selected week to the local storage + */ saveDetailsToLocalStorage() { localStorage.setItem('has_saved_details', 'true'); localStorage.setItem('selected_year', this.selectedYear); @@ -222,6 +237,9 @@ export class DatepickerComponent implements OnInit { localStorage.setItem('show_deleted', this.internalShowDeletedEvents.toString()); } + /** + * Gets saved preferences from the local storage if there are any + */ getDetailsFromLocalStorage() { if((localStorage.getItem('has_saved_details') ?? 'false') === 'true') { this.selectedYear = localStorage.getItem('selected_year')!; @@ -233,6 +251,9 @@ export class DatepickerComponent implements OnInit { } } + /** + * Checks if the "show deleted events" button has the correct style + */ checkShowDeletedEventsBtn() { if(this.internalShowDeletedEvents) { this.switchDeletedBtnClass = 'show'; diff --git a/Frontend/src/app/components/event-detail/event-detail.component.ts b/Frontend/src/app/components/event-detail/event-detail.component.ts index 296a26c..d7d70fc 100644 --- a/Frontend/src/app/components/event-detail/event-detail.component.ts +++ b/Frontend/src/app/components/event-detail/event-detail.component.ts @@ -42,6 +42,9 @@ export class EventDetailComponent implements OnInit { }); } + /** + * Checks which details have changed in the changes and formats them properly to be displayed in the component + */ generateChangeDetails() { let changes = this.event.changes; @@ -118,12 +121,18 @@ export class EventDetailComponent implements OnInit { } } + /** + * Closes the current tab so the user gets back to the event overview + */ closeTab(): void { window.close(); } + /** + * Returns the formatted date for the given date + * @param date The date as a string to format + */ getDateTime(date: string): string { - console.log(date); return this.utilities.getDateTimeFromString(date); } } diff --git a/Frontend/src/app/components/event/event.component.ts b/Frontend/src/app/components/event/event.component.ts index cb119ea..2be1f62 100644 --- a/Frontend/src/app/components/event/event.component.ts +++ b/Frontend/src/app/components/event/event.component.ts @@ -42,10 +42,16 @@ export class EventComponent implements OnInit { } } + /** + * Opens a new tab with the event details + */ openEventDetails() { this.router.navigate([]).then(result => { window.open('/eventDetails/'+this.event.event_uid, '_blank'); }); } + /** + * Formats the starting time of the event + */ getTime(): string { return this.utilities.getTimeFromString(this.latestFullChange.new_start.toString()); } diff --git a/Frontend/src/app/components/week/week.component.ts b/Frontend/src/app/components/week/week.component.ts index 766d8bb..255e88c 100644 --- a/Frontend/src/app/components/week/week.component.ts +++ b/Frontend/src/app/components/week/week.component.ts @@ -22,6 +22,10 @@ export class WeekComponent implements OnInit { this.splitEventsIntoDays(); } + /** + * Splits the given events into their days so we have a list of events for every day of the week + * to pass into the day components + */ splitEventsIntoDays() { // Pre-fill list with 7 empty days this.eventsPerDay = []; diff --git a/Frontend/src/app/mocks/mock.service.ts b/Frontend/src/app/mocks/mock.service.ts index c8ea37e..7a63c87 100644 --- a/Frontend/src/app/mocks/mock.service.ts +++ b/Frontend/src/app/mocks/mock.service.ts @@ -1,5 +1,8 @@ import {Observable} from 'rxjs'; +/** + * Mock class for unit testing + */ export abstract class AbstractMockObservableService { protected _observable: Observable | undefined; protected _fakeContent: any; diff --git a/Frontend/src/app/pages/landingpage/landingpage.component.ts b/Frontend/src/app/pages/landingpage/landingpage.component.ts index 11f602a..08c9d5f 100644 --- a/Frontend/src/app/pages/landingpage/landingpage.component.ts +++ b/Frontend/src/app/pages/landingpage/landingpage.component.ts @@ -22,6 +22,9 @@ export class LandingpageComponent implements OnInit { ngOnInit(): void { } + /** + * Fetches the events for the currently selected date from the API + */ getEvents() { this.apiService.getEvents(this.selectedDate).subscribe(events => { this.events = events; @@ -29,11 +32,21 @@ export class LandingpageComponent implements OnInit { }); } + /** + * Called when the selected date is changed in the datepicker component. + * Fetches the events for the new date + * @param newDate The new date to get the events for + */ dateChangedFromPicker(newDate: string) { this.selectedDate = newDate; this.getEvents(); } + /** + * Called when the state of "show deleted events" is changed in the datepicker component. + * Passes the new value to the underlying components + * @param newShowDeleted The new state of "show deleted events" + */ showDeletedChangedFromPicker(newShowDeleted: boolean) { this.showDeletedEvents = newShowDeleted; } diff --git a/Frontend/src/app/services/api/api.service.ts b/Frontend/src/app/services/api/api.service.ts index e950469..be033ac 100644 --- a/Frontend/src/app/services/api/api.service.ts +++ b/Frontend/src/app/services/api/api.service.ts @@ -23,6 +23,12 @@ export class ApiService { /____/ */ + /** + * Gets all events and their corresponding changes for the given week. + * Best to supply only dates which are a monday, although other days are possible as well + * @param week The week to fetch the events for + * @return Observable A list of events + */ getEvents(week: string): Observable { try { let params = new HttpParams(); @@ -34,6 +40,11 @@ export class ApiService { return new Observable(); } + /** + * Gets the event details for the specified event + * @param id The UID of the event as saved in SQL + * @return Observable The single event + */ getEventById(id: string): Observable { try { return this.http.get((this.apiUrl + '/' + id)); diff --git a/Frontend/src/app/services/utils/utilities.service.ts b/Frontend/src/app/services/utils/utilities.service.ts index 09268a2..8ca7db6 100644 --- a/Frontend/src/app/services/utils/utilities.service.ts +++ b/Frontend/src/app/services/utils/utilities.service.ts @@ -8,15 +8,30 @@ export class UtilitiesService { constructor() { } + /** + * Get the formatted time for the given date + * @param date The date to format the time for + * @return string the formatted time in the format HH:MM (24h format) + */ getTimeFromDate(date: Date): string { return date.getHours().toString().padStart(2, '0') + ':' + date.getMinutes().toString().padStart(2, '0'); } + /** + * Get the formatted time for the given date + * @param dateString The date as a string to format the time for + * @return string the formatted time in the format HH:MM (24h format) + */ getTimeFromString(dateString: string): string { let date = new Date(dateString); return this.getTimeFromDate(date); } + /** + * Formats the given date + * @param date The date to format + * @return string the formatted date in the format DD.mm.YY, HH:MM (24h format) + */ getDateTimeFromDate(date: Date): string { let year = date.getFullYear().toString(); let month = date.getMonth().toString().padStart(2, '0'); @@ -27,6 +42,11 @@ export class UtilitiesService { return day + '.' + month + '.' + year + ', ' + hour + ':' + minute; } + /** + * Formats the given date + * @param dateString The date as a string to format + * @return string the formatted date in the format DD.mm.YY, HH:MM (24h format) + */ getDateTimeFromString(dateString: string): string { let date = new Date(dateString); return this.getDateTimeFromDate(date);