Comments and docs
Some checks failed
Jenkins Production Deployment

This commit is contained in:
Patrick Müller 2021-10-03 12:10:54 +02:00
parent 84aaa9ed99
commit 7cb3c12351
8 changed files with 88 additions and 1 deletions

View File

@ -170,6 +170,9 @@ export class DatepickerComponent implements OnInit {
return new Date(year, month, 0).getDate(); return new Date(year, month, 0).getDate();
} }
/**
* Switches the currently selected date to the next week
*/
switchToNextWeek() { switchToNextWeek() {
let currentDate = new Date(parseInt(this.selectedYear), parseInt(this.selectedMonth)-1, parseInt(this.selectedDay)); let currentDate = new Date(parseInt(this.selectedYear), parseInt(this.selectedMonth)-1, parseInt(this.selectedDay));
let newDate = currentDate; let newDate = currentDate;
@ -180,6 +183,9 @@ export class DatepickerComponent implements OnInit {
this.handleDateChange(); this.handleDateChange();
} }
/**
* Switches the currently selected date to the previous week
*/
switchToPreviousWeek() { switchToPreviousWeek() {
let currentDate = new Date(parseInt(this.selectedYear), parseInt(this.selectedMonth)-1, parseInt(this.selectedDay)); let currentDate = new Date(parseInt(this.selectedYear), parseInt(this.selectedMonth)-1, parseInt(this.selectedDay));
let newDate = currentDate; let newDate = currentDate;
@ -190,6 +196,9 @@ export class DatepickerComponent implements OnInit {
this.handleDateChange(); this.handleDateChange();
} }
/**
* Switches the currently selected date to today
*/
switchToToday() { switchToToday() {
let currentDate = new Date(); let currentDate = new Date();
this.selectedYear = currentDate.getFullYear().toString(); this.selectedYear = currentDate.getFullYear().toString();
@ -198,6 +207,9 @@ export class DatepickerComponent implements OnInit {
this.handleDateChange(); this.handleDateChange();
} }
/**
* Switches whether to show deleted events in the overview
*/
switchShowDeletedEvents() { switchShowDeletedEvents() {
if(this.internalShowDeletedEvents) { if(this.internalShowDeletedEvents) {
this.internalShowDeletedEvents = false; this.internalShowDeletedEvents = false;
@ -214,6 +226,9 @@ export class DatepickerComponent implements OnInit {
this.saveDetailsToLocalStorage(); this.saveDetailsToLocalStorage();
} }
/**
* Saves preferences like the selected week to the local storage
*/
saveDetailsToLocalStorage() { saveDetailsToLocalStorage() {
localStorage.setItem('has_saved_details', 'true'); localStorage.setItem('has_saved_details', 'true');
localStorage.setItem('selected_year', this.selectedYear); localStorage.setItem('selected_year', this.selectedYear);
@ -222,6 +237,9 @@ export class DatepickerComponent implements OnInit {
localStorage.setItem('show_deleted', this.internalShowDeletedEvents.toString()); localStorage.setItem('show_deleted', this.internalShowDeletedEvents.toString());
} }
/**
* Gets saved preferences from the local storage if there are any
*/
getDetailsFromLocalStorage() { getDetailsFromLocalStorage() {
if((localStorage.getItem('has_saved_details') ?? 'false') === 'true') { if((localStorage.getItem('has_saved_details') ?? 'false') === 'true') {
this.selectedYear = localStorage.getItem('selected_year')!; 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() { checkShowDeletedEventsBtn() {
if(this.internalShowDeletedEvents) { if(this.internalShowDeletedEvents) {
this.switchDeletedBtnClass = 'show'; this.switchDeletedBtnClass = 'show';

View File

@ -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() { generateChangeDetails() {
let changes = this.event.changes; 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 { closeTab(): void {
window.close(); window.close();
} }
/**
* Returns the formatted date for the given date
* @param date The date as a string to format
*/
getDateTime(date: string): string { getDateTime(date: string): string {
console.log(date);
return this.utilities.getDateTimeFromString(date); return this.utilities.getDateTimeFromString(date);
} }
} }

View File

@ -42,10 +42,16 @@ export class EventComponent implements OnInit {
} }
} }
/**
* Opens a new tab with the event details
*/
openEventDetails() { openEventDetails() {
this.router.navigate([]).then(result => { window.open('/eventDetails/'+this.event.event_uid, '_blank'); }); this.router.navigate([]).then(result => { window.open('/eventDetails/'+this.event.event_uid, '_blank'); });
} }
/**
* Formats the starting time of the event
*/
getTime(): string { getTime(): string {
return this.utilities.getTimeFromString(this.latestFullChange.new_start.toString()); return this.utilities.getTimeFromString(this.latestFullChange.new_start.toString());
} }

View File

@ -22,6 +22,10 @@ export class WeekComponent implements OnInit {
this.splitEventsIntoDays(); 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() { splitEventsIntoDays() {
// Pre-fill list with 7 empty days // Pre-fill list with 7 empty days
this.eventsPerDay = []; this.eventsPerDay = [];

View File

@ -1,5 +1,8 @@
import {Observable} from 'rxjs'; import {Observable} from 'rxjs';
/**
* Mock class for unit testing
*/
export abstract class AbstractMockObservableService { export abstract class AbstractMockObservableService {
protected _observable: Observable<any> | undefined; protected _observable: Observable<any> | undefined;
protected _fakeContent: any; protected _fakeContent: any;

View File

@ -22,6 +22,9 @@ export class LandingpageComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
} }
/**
* Fetches the events for the currently selected date from the API
*/
getEvents() { getEvents() {
this.apiService.getEvents(this.selectedDate).subscribe(events => { this.apiService.getEvents(this.selectedDate).subscribe(events => {
this.events = 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) { dateChangedFromPicker(newDate: string) {
this.selectedDate = newDate; this.selectedDate = newDate;
this.getEvents(); 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) { showDeletedChangedFromPicker(newShowDeleted: boolean) {
this.showDeletedEvents = newShowDeleted; this.showDeletedEvents = newShowDeleted;
} }

View File

@ -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<Event[]> A list of events
*/
getEvents(week: string): Observable<Event[]> { getEvents(week: string): Observable<Event[]> {
try { try {
let params = new HttpParams(); let params = new HttpParams();
@ -34,6 +40,11 @@ export class ApiService {
return new Observable<Event[]>(); return new Observable<Event[]>();
} }
/**
* Gets the event details for the specified event
* @param id The UID of the event as saved in SQL
* @return Observable<Event> The single event
*/
getEventById(id: string): Observable<Event> { getEventById(id: string): Observable<Event> {
try { try {
return this.http.get<Event>((this.apiUrl + '/' + id)); return this.http.get<Event>((this.apiUrl + '/' + id));

View File

@ -8,15 +8,30 @@ export class UtilitiesService {
constructor() { 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 { getTimeFromDate(date: Date): string {
return date.getHours().toString().padStart(2, '0') + ':' + date.getMinutes().toString().padStart(2, '0'); 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 { getTimeFromString(dateString: string): string {
let date = new Date(dateString); let date = new Date(dateString);
return this.getTimeFromDate(date); 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 { getDateTimeFromDate(date: Date): string {
let year = date.getFullYear().toString(); let year = date.getFullYear().toString();
let month = date.getMonth().toString().padStart(2, '0'); let month = date.getMonth().toString().padStart(2, '0');
@ -27,6 +42,11 @@ export class UtilitiesService {
return day + '.' + month + '.' + year + ', ' + hour + ':' + minute; 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 { getDateTimeFromString(dateString: string): string {
let date = new Date(dateString); let date = new Date(dateString);
return this.getDateTimeFromDate(date); return this.getDateTimeFromDate(date);