docs: add JSDoc comments to BoardComponent
This commit is contained in:
parent
45697d688d
commit
090a8eb803
3 changed files with 115 additions and 0 deletions
|
|
@ -39,6 +39,18 @@ export class BoardComponent {
|
||||||
taskMovedFrom: string = '';
|
taskMovedFrom: string = '';
|
||||||
taskDropped: boolean = false;
|
taskDropped: boolean = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OnInit lifecycle hook. Subscribes to the following events:
|
||||||
|
*
|
||||||
|
* - itemDropped: updates the taskMovedTo and taskMovedFrom properties
|
||||||
|
* - itemMovedTo: updates the taskMovedTo property
|
||||||
|
* - itemMovedFrom: updates the taskMovedFrom property
|
||||||
|
*
|
||||||
|
* These properties are used to conditionally render a highlighted task
|
||||||
|
* component when a task is moved.
|
||||||
|
*
|
||||||
|
* @returns void
|
||||||
|
*/
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.dragDropService.itemDropped.subscribe(({ id, status }) => {
|
this.dragDropService.itemDropped.subscribe(({ id, status }) => {
|
||||||
this.handleItemDropped(id, status);
|
this.handleItemDropped(id, status);
|
||||||
|
|
@ -51,12 +63,25 @@ export class BoardComponent {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new task by opening a new route if the user is in page view mode,
|
||||||
|
* or by setting the overlay data to open a new task overlay in overlay mode.
|
||||||
|
* @param status The status of the task to be added.
|
||||||
|
*/
|
||||||
addNewTaskOverlay(status: string) {
|
addNewTaskOverlay(status: string) {
|
||||||
this.sharedService.isPageViewMedia
|
this.sharedService.isPageViewMedia
|
||||||
? this.router.navigate(['/add-task', status])
|
? this.router.navigate(['/add-task', status])
|
||||||
: this.overlayService.setOverlayData('newTaskOverlay', status);
|
: this.overlayService.setOverlayData('newTaskOverlay', status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves tasks based on their status.
|
||||||
|
* If a search input is active, it filters the tasks from the filteredTasks list.
|
||||||
|
* Otherwise, it filters from the complete list of tasks.
|
||||||
|
*
|
||||||
|
* @param status The status of the tasks to be retrieved.
|
||||||
|
* @returns A list of tasks matching the given status.
|
||||||
|
*/
|
||||||
getTaskStatus(status: string) {
|
getTaskStatus(status: string) {
|
||||||
if (this.updateSearchInput()) {
|
if (this.updateSearchInput()) {
|
||||||
return this.firebaseService
|
return this.firebaseService
|
||||||
|
|
@ -69,6 +94,13 @@ export class BoardComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the status of a task in both the complete and filtered lists
|
||||||
|
* of tasks when it is dropped.
|
||||||
|
*
|
||||||
|
* @param id The id of the task to be updated.
|
||||||
|
* @param status The new status of the task.
|
||||||
|
*/
|
||||||
handleItemDropped(id: string, status: string): void {
|
handleItemDropped(id: string, status: string): void {
|
||||||
const index = this.firebaseService.allTasks.findIndex(
|
const index = this.firebaseService.allTasks.findIndex(
|
||||||
(task) => task.id === id
|
(task) => task.id === id
|
||||||
|
|
@ -85,12 +117,23 @@ export class BoardComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the search input by resetting the search input flag and the search value, and
|
||||||
|
* then calling searchTask() to update the list of tasks.
|
||||||
|
*/
|
||||||
clearInput() {
|
clearInput() {
|
||||||
this.searchInput = false;
|
this.searchInput = false;
|
||||||
this.searchValue = '';
|
this.searchValue = '';
|
||||||
this.searchTask();
|
this.searchTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the search input flag and the search value by stripping any XSS
|
||||||
|
* characters from the search value, and then setting the search input flag
|
||||||
|
* to true if the search value is not empty, and false otherwise.
|
||||||
|
*
|
||||||
|
* @returns The updated search input flag.
|
||||||
|
*/
|
||||||
updateSearchInput() {
|
updateSearchInput() {
|
||||||
this.searchValue = this.sharedService.replaceXSSChars(this.searchValue);
|
this.searchValue = this.sharedService.replaceXSSChars(this.searchValue);
|
||||||
if (this.searchValue) {
|
if (this.searchValue) {
|
||||||
|
|
@ -101,6 +144,14 @@ export class BoardComponent {
|
||||||
return this.searchInput;
|
return this.searchInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the list of tasks based on the current search value.
|
||||||
|
*
|
||||||
|
* It first calls updateSearchInput() to update the search input flag and the search value.
|
||||||
|
* Then it sets the filteredTasks property of the FirebaseService to the result of calling
|
||||||
|
* filter() on the list of all tasks, where the filter condition is that any of the
|
||||||
|
* task's title, description, or category includes the search value (case-insensitive).
|
||||||
|
*/
|
||||||
searchTask(): void {
|
searchTask(): void {
|
||||||
this.updateSearchInput();
|
this.updateSearchInput();
|
||||||
this.firebaseService.filteredTasks = this.firebaseService
|
this.firebaseService.filteredTasks = this.firebaseService
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,16 @@ export class TaskMenuComponent {
|
||||||
|
|
||||||
constructor(private firebaseService: FirebaseService) {}
|
constructor(private firebaseService: FirebaseService) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves the task to a specified status.
|
||||||
|
*
|
||||||
|
* This function updates the status of the task identified by `taskId`
|
||||||
|
* in both `allTasks` and `filteredTasks` lists to the new status
|
||||||
|
* specified by `moveTo`. It also updates the task status in the
|
||||||
|
* Firestore database.
|
||||||
|
*
|
||||||
|
* @param moveTo - The new status to move the task to.
|
||||||
|
*/
|
||||||
moveTask(moveTo: string) {
|
moveTask(moveTo: string) {
|
||||||
const index = this.firebaseService.allTasks.findIndex(
|
const index = this.firebaseService.allTasks.findIndex(
|
||||||
(task) => task.id === this.taskId
|
(task) => task.id === this.taskId
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,14 @@ export class TaskComponent {
|
||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the button click event on a task in the board
|
||||||
|
* @param event the MouseEvent
|
||||||
|
* @param taskId the id of the task
|
||||||
|
*
|
||||||
|
* If the event target is a menu button or menu img, toggle the task menu
|
||||||
|
* If the event target is anything else, open the task details overlay
|
||||||
|
*/
|
||||||
handleMenuButtonClick(event: MouseEvent, taskId: string) {
|
handleMenuButtonClick(event: MouseEvent, taskId: string) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const targetElement = event.target as HTMLElement;
|
const targetElement = event.target as HTMLElement;
|
||||||
|
|
@ -44,10 +52,21 @@ export class TaskComponent {
|
||||||
: this.openTaskDetailsOverlay(taskId);
|
: this.openTaskDetailsOverlay(taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggle the task menu for the current task
|
||||||
|
*/
|
||||||
toggleTaskMenu() {
|
toggleTaskMenu() {
|
||||||
this.isMenuOpen = !this.isMenuOpen;
|
this.isMenuOpen = !this.isMenuOpen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open the task details overlay for the given task id
|
||||||
|
* @param taskId the id of the task
|
||||||
|
*
|
||||||
|
* If the task menu is open, close it
|
||||||
|
* If the page is in the media view, navigate to the task details page
|
||||||
|
* If the page is not in the media view, open the task overlay
|
||||||
|
*/
|
||||||
openTaskDetailsOverlay(taskId: string) {
|
openTaskDetailsOverlay(taskId: string) {
|
||||||
if (this.isMenuOpen) {
|
if (this.isMenuOpen) {
|
||||||
this.toggleTaskMenu();
|
this.toggleTaskMenu();
|
||||||
|
|
@ -58,6 +77,11 @@ export class TaskComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostListener('document:click', ['$event'])
|
@HostListener('document:click', ['$event'])
|
||||||
|
/**
|
||||||
|
* If the target element of the event is not a task menu button,
|
||||||
|
* task menu img, or the task menu itself, close the task menu
|
||||||
|
* @param event the MouseEvent
|
||||||
|
*/
|
||||||
checkToggleTaskMenu(event: MouseEvent) {
|
checkToggleTaskMenu(event: MouseEvent) {
|
||||||
const targetElement = event.target as HTMLElement;
|
const targetElement = event.target as HTMLElement;
|
||||||
const menuSelectors = ['.menu-btn', '.menu-img', 'app-task-menu'];
|
const menuSelectors = ['.menu-btn', '.menu-img', 'app-task-menu'];
|
||||||
|
|
@ -72,27 +96,47 @@ export class TaskComponent {
|
||||||
|
|
||||||
// User Dialog
|
// User Dialog
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens the user dialog for the given user id at the position of the mouse click
|
||||||
|
* @param userId the id of the user
|
||||||
|
* @param event the MouseEvent that triggered the dialog
|
||||||
|
*/
|
||||||
openDialog(userId: any, event: MouseEvent) {
|
openDialog(userId: any, event: MouseEvent) {
|
||||||
this.AssignedDialogId = userId;
|
this.AssignedDialogId = userId;
|
||||||
this.updateDialogPosition(event);
|
this.updateDialogPosition(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the position of the user dialog based on the MouseEvent
|
||||||
|
* @param event the MouseEvent that triggered the dialog
|
||||||
|
*/
|
||||||
updateDialogPosition(event: MouseEvent) {
|
updateDialogPosition(event: MouseEvent) {
|
||||||
this.dialogX = event.clientX + 25;
|
this.dialogX = event.clientX + 25;
|
||||||
this.dialogY = event.clientY + 10;
|
this.dialogY = event.clientY + 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the user dialog
|
||||||
|
*/
|
||||||
closeDialog() {
|
closeDialog() {
|
||||||
this.AssignedDialogId = '';
|
this.AssignedDialogId = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtasks
|
// Subtasks
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of completed subtasks of the task
|
||||||
|
* @returns the number of completed subtasks
|
||||||
|
*/
|
||||||
completedSubtasks(): number {
|
completedSubtasks(): number {
|
||||||
return this.task.subtasksDone.filter((subtask: boolean) => subtask === true)
|
return this.task.subtasksDone.filter((subtask: boolean) => subtask === true)
|
||||||
.length;
|
.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the percentage of completed subtasks
|
||||||
|
* @returns the percentage of completed subtasks as a number
|
||||||
|
*/
|
||||||
completedSubtasksPercent(): number {
|
completedSubtasksPercent(): number {
|
||||||
const subtasks = this.task.subtasksDone;
|
const subtasks = this.task.subtasksDone;
|
||||||
const completedSubtasksCount = subtasks.filter(
|
const completedSubtasksCount = subtasks.filter(
|
||||||
|
|
@ -104,6 +148,11 @@ export class TaskComponent {
|
||||||
|
|
||||||
// Assigned
|
// Assigned
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the initials of the user
|
||||||
|
* @param id the id of the user
|
||||||
|
* @returns the initials of the user as a string
|
||||||
|
*/
|
||||||
userBadged(id: string) {
|
userBadged(id: string) {
|
||||||
const userId = String(id);
|
const userId = String(id);
|
||||||
const user = this.firebaseService
|
const user = this.firebaseService
|
||||||
|
|
@ -122,6 +171,11 @@ export class TaskComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the color of the user with the given id
|
||||||
|
* @param id the id of the user
|
||||||
|
* @returns the color of the user as a string
|
||||||
|
*/
|
||||||
userBadgedColor(id: string) {
|
userBadgedColor(id: string) {
|
||||||
const userId = String(id);
|
const userId = String(id);
|
||||||
const user = this.firebaseService
|
const user = this.firebaseService
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue