docs: add JSDoc comments to OverlayComponents
This commit is contained in:
parent
c2ea6c8762
commit
d2f9734b83
4 changed files with 124 additions and 13 deletions
|
|
@ -18,6 +18,11 @@ export class DialogOverlayComponent {
|
||||||
|
|
||||||
constructor(public sharedService: SharedService, private router: Router) {}
|
constructor(public sharedService: SharedService, private router: Router) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigates to the login route and emits an empty string via the
|
||||||
|
* "closeDialogEmitter" output event, which can be used to close the overlay
|
||||||
|
* from the parent component.
|
||||||
|
*/
|
||||||
closeOverlay() {
|
closeOverlay() {
|
||||||
this.router.navigate(['/login']);
|
this.router.navigate(['/login']);
|
||||||
this.closeDialogEmitter.emit('');
|
this.closeDialogEmitter.emit('');
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,19 @@ export class OverlayComponent implements OnInit {
|
||||||
|
|
||||||
constructor(private overlayService: OverlayService, private router: Router) {}
|
constructor(private overlayService: OverlayService, private router: Router) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Angular lifecycle hook that is called after the component's view has been fully initialized.
|
||||||
|
* Invokes `checkOverlayData` to subscribe to overlay data changes and update the component's state accordingly.
|
||||||
|
*/
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.checkOverlayData();
|
this.checkOverlayData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribes to the overlay data observable from the OverlayService.
|
||||||
|
* Updates the component's `overlayType` and `overlayData` properties
|
||||||
|
* whenever new overlay data is emitted.
|
||||||
|
*/
|
||||||
checkOverlayData() {
|
checkOverlayData() {
|
||||||
this.overlayService.overlayData$.subscribe((data) => {
|
this.overlayService.overlayData$.subscribe((data) => {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
@ -39,12 +48,21 @@ export class OverlayComponent implements OnInit {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emits an event to close the overlay and set the overlay type/data to the provided string.
|
||||||
|
* If the overlay type is 'dialog', navigates to the login route.
|
||||||
|
* @param emitter The string to be emitted, which will also be set as the overlay data.
|
||||||
|
*/
|
||||||
onCloseOverlay(emitter: string) {
|
onCloseOverlay(emitter: string) {
|
||||||
this.overlayType === 'dialog' && this.router.navigate(['/login']);
|
this.overlayType === 'dialog' && this.router.navigate(['/login']);
|
||||||
this.overlayData = emitter;
|
this.overlayData = emitter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('document:click', ['$event'])
|
@HostListener('document:click', ['$event'])
|
||||||
|
/**
|
||||||
|
* Listens for clicks on the overlay background and closes the overlay if the target element does not have the class 'overlay-content'.
|
||||||
|
* @param event The click event.
|
||||||
|
*/
|
||||||
checkOpenContactEdit(event: MouseEvent) {
|
checkOpenContactEdit(event: MouseEvent) {
|
||||||
const targetElement = event.target as HTMLElement;
|
const targetElement = event.target as HTMLElement;
|
||||||
if (
|
if (
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
||||||
import { FirebaseService } from '../../../../services/firebase.service';
|
import { FirebaseService } from '../../../../services/firebase.service';
|
||||||
import { OverlayService } from '../../../../services/overlay.service';
|
|
||||||
import { BtnCloseComponent } from '../../buttons/btn-close/btn-close.component';
|
import { BtnCloseComponent } from '../../buttons/btn-close/btn-close.component';
|
||||||
import { FormsModule } from '@angular/forms';
|
import { FormsModule } from '@angular/forms';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
|
|
@ -12,14 +11,7 @@ import { BtnBackComponent } from '../../buttons/btn-back/btn-back.component';
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-task-edit-overlay',
|
selector: 'app-task-edit-overlay',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [
|
imports: [BtnCloseComponent, FormsModule, CommonModule, AddTaskComponent],
|
||||||
BtnCloseComponent,
|
|
||||||
FormsModule,
|
|
||||||
CommonModule,
|
|
||||||
AssignedComponent,
|
|
||||||
AddTaskComponent,
|
|
||||||
BtnBackComponent,
|
|
||||||
],
|
|
||||||
templateUrl: './task-edit-overlay.component.html',
|
templateUrl: './task-edit-overlay.component.html',
|
||||||
styleUrl: './task-edit-overlay.component.scss',
|
styleUrl: './task-edit-overlay.component.scss',
|
||||||
})
|
})
|
||||||
|
|
@ -36,6 +28,13 @@ export class TaskEditOverlayComponent {
|
||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OnInit lifecycle hook.
|
||||||
|
*
|
||||||
|
* If the overlay data is empty, this hook subscribes to the route parameters
|
||||||
|
* and sets the overlay data and type from the route parameters. It also sets
|
||||||
|
* the overlay mobile flag to true.
|
||||||
|
*/
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.overlayData == '') {
|
if (this.overlayData == '') {
|
||||||
if (this.route.params.subscribe()) {
|
if (this.route.params.subscribe()) {
|
||||||
|
|
@ -48,12 +47,24 @@ export class TaskEditOverlayComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the task data from the Firebase service for the given task id.
|
||||||
|
* @param taskId the id of the task
|
||||||
|
* @returns {Task[]} an array of tasks with the given id
|
||||||
|
*/
|
||||||
getTaskData(taskId: string) {
|
getTaskData(taskId: string) {
|
||||||
return this.firebaseService
|
return this.firebaseService
|
||||||
.getAllTasks()
|
.getAllTasks()
|
||||||
.filter((task) => task.id === taskId);
|
.filter((task) => task.id === taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the task edit overlay dialog.
|
||||||
|
*
|
||||||
|
* If the overlay is being displayed in mobile view, this function navigates to
|
||||||
|
* the board page. Otherwise, it emits a close dialog event. It also removes
|
||||||
|
* the task data from local storage.
|
||||||
|
*/
|
||||||
closeDialog() {
|
closeDialog() {
|
||||||
this.overlayMobile
|
this.overlayMobile
|
||||||
? this.router.navigate(['/board'])
|
? this.router.navigate(['/board'])
|
||||||
|
|
@ -61,6 +72,9 @@ export class TaskEditOverlayComponent {
|
||||||
this.removeTaskData();
|
this.removeTaskData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the task data from local storage.
|
||||||
|
*/
|
||||||
removeTaskData() {
|
removeTaskData() {
|
||||||
localStorage.removeItem('taskData');
|
localStorage.removeItem('taskData');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,13 @@ export class TaskOverlayComponent implements OnInit {
|
||||||
['Technical Task', '#20d7c2'],
|
['Technical Task', '#20d7c2'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
closeDialog() {
|
/**
|
||||||
this.closeDialogEmitter.emit('');
|
* OnInit lifecycle hook.
|
||||||
}
|
*
|
||||||
|
* Initializes the overlay component by checking if the `overlayData` is empty.
|
||||||
|
* If it is, subscribes to route parameters to obtain and assign the `id` to `overlayData`.
|
||||||
|
* Also sets `overlayMobile` to `true` if parameters are successfully retrieved.
|
||||||
|
*/
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.overlayData == '') {
|
if (this.overlayData == '') {
|
||||||
if (this.route.params.subscribe()) {
|
if (this.route.params.subscribe()) {
|
||||||
|
|
@ -47,6 +50,24 @@ export class TaskOverlayComponent implements OnInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close the task overlay.
|
||||||
|
*
|
||||||
|
* Emits an empty string via the "closeDialogEmitter" output event, which
|
||||||
|
* can be used to close the overlay from the parent component.
|
||||||
|
*/
|
||||||
|
closeDialog() {
|
||||||
|
this.closeDialogEmitter.emit('');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits the task with the given overlay data.
|
||||||
|
*
|
||||||
|
* Closes the task overlay and then either:
|
||||||
|
* - Opens the task edit overlay if the window width is >= 650px
|
||||||
|
* - Navigates to the task edit page if the window width is < 650px
|
||||||
|
* @param overlayData the overlay data of the task to be edited
|
||||||
|
*/
|
||||||
editTask(overlayData: string) {
|
editTask(overlayData: string) {
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
@ -58,17 +79,42 @@ export class TaskOverlayComponent implements OnInit {
|
||||||
}, 10);
|
}, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the task with the given overlay data from the Firebase Realtime Database and closes the overlay.
|
||||||
|
* @param overlayData the overlay data of the task to be deleted
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
deleteTask(overlayData: string) {
|
deleteTask(overlayData: string) {
|
||||||
this.firebaseService.deleteTask(overlayData);
|
this.firebaseService.deleteTask(overlayData);
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the task data from the Firebase Realtime Database for the given task id.
|
||||||
|
*
|
||||||
|
* This function takes a task id and returns an array of tasks with the given id.
|
||||||
|
* The function uses the Firebase service to get all tasks from the Realtime Database
|
||||||
|
* and then filters the result to return only the task with the given id.
|
||||||
|
*
|
||||||
|
* @param taskId The id of the task to be retrieved.
|
||||||
|
* @returns {Task[]} An array of tasks with the given id.
|
||||||
|
*/
|
||||||
getTaskData(taskId: string) {
|
getTaskData(taskId: string) {
|
||||||
return this.firebaseService
|
return this.firebaseService
|
||||||
.getAllTasks()
|
.getAllTasks()
|
||||||
.filter((task) => task.id === taskId);
|
.filter((task) => task.id === taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the status of a single subtask of a task.
|
||||||
|
*
|
||||||
|
* This function takes the task id and the index of the subtask
|
||||||
|
* and returns the status of the subtask at the given index.
|
||||||
|
*
|
||||||
|
* @param taskId The task id of the task containing the subtask.
|
||||||
|
* @param index The index of the subtask.
|
||||||
|
* @returns {boolean} The status of the subtask at the given index.
|
||||||
|
*/
|
||||||
getSubTaskStatus(taskId: string, index: number) {
|
getSubTaskStatus(taskId: string, index: number) {
|
||||||
const subtask = this.firebaseService
|
const subtask = this.firebaseService
|
||||||
.getAllTasks()
|
.getAllTasks()
|
||||||
|
|
@ -77,6 +123,20 @@ export class TaskOverlayComponent implements OnInit {
|
||||||
return subtask[0].subtasksDone[index];
|
return subtask[0].subtasksDone[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles the status of a single subtask of a task.
|
||||||
|
*
|
||||||
|
* This function takes the task id, the index of the subtask,
|
||||||
|
* the array of subtask statuses, and the status of the subtask.
|
||||||
|
* It toggles the status of the subtask at the given index
|
||||||
|
* and updates the subtasksDone property of the task in the
|
||||||
|
* Firebase Realtime Database.
|
||||||
|
*
|
||||||
|
* @param taskId The task id of the task containing the subtask.
|
||||||
|
* @param index The index of the subtask.
|
||||||
|
* @param array The array of subtask statuses.
|
||||||
|
* @param status The status of the subtask at the given index.
|
||||||
|
*/
|
||||||
toggleSubtaskStatus(
|
toggleSubtaskStatus(
|
||||||
taskId: string,
|
taskId: string,
|
||||||
index: number,
|
index: number,
|
||||||
|
|
@ -87,10 +147,24 @@ export class TaskOverlayComponent implements OnInit {
|
||||||
this.firebaseService.updateSubTask(taskId, array);
|
this.firebaseService.updateSubTask(taskId, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Capitalizes the first letter of a given string.
|
||||||
|
*
|
||||||
|
* This function takes a string as an argument and returns a new string
|
||||||
|
* with the first letter capitalized.
|
||||||
|
* @param data The string to capitalize.
|
||||||
|
* @returns {string} A new string with the first letter capitalized.
|
||||||
|
*/
|
||||||
capitalizeFirstLetter(data: string) {
|
capitalizeFirstLetter(data: string) {
|
||||||
return data.charAt(0).toUpperCase() + data.slice(1);
|
return data.charAt(0).toUpperCase() + data.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a date string to a human-readable format.
|
||||||
|
*
|
||||||
|
* @param dateString - The date string to convert.
|
||||||
|
* @returns A string representing the date in the format "MMM. DD, YYYY".
|
||||||
|
*/
|
||||||
timeConverter(dateString: string) {
|
timeConverter(dateString: string) {
|
||||||
var a = new Date(dateString);
|
var a = new Date(dateString);
|
||||||
var months = [
|
var months = [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue