-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
122 lines (113 loc) · 3.31 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import readline from 'readline';
import TaskManager from './taskManager.js';
import Task from './task.js';
import chalk from 'chalk';
// Create a new TaskManager and a Readline interface for user input
const taskManager = new TaskManager();
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Display the main menu
function displayMenu() {
console.log(chalk.bold.blue('Task Manager'));
console.log(chalk.yellow('1. Add Task'));
console.log(chalk.yellow('2. Update Task Status'));
console.log(chalk.yellow('3. Delete Task'));
console.log(chalk.yellow('4. Prioritize Task'));
console.log(chalk.yellow('5. View All Tasks'));
console.log(chalk.yellow('6. Exit'));
}
// Function to add a new task
function addTask() {
rl.question(chalk.cyan('Enter task title: '), title => {
rl.question(chalk.cyan('Enter task description: '), description => {
const task = new Task(
taskManager.tasks.length + 1,
title,
description,
'Pending'
);
taskManager.addTask(task);
console.log(chalk.green('Task added successfully! Task ID: ' + task.id));
displayMenu();
processInput();
});
});
}
// Function to update the status of a task
function updateTaskStatus() {
rl.question(chalk.cyan('Enter task ID: '), taskId => {
rl.question(chalk.cyan('Enter new status (Pending/Completed): '), status => {
taskManager.updateTaskStatus(parseInt(taskId), status);
console.log(chalk.green('Task status updated successfully!'));
displayMenu();
processInput();
});
});
}
// Function to delete a task
function deleteTask() {
rl.question(chalk.cyan('Enter task ID: '), taskId => {
taskManager.deleteTask(parseInt(taskId));
console.log(chalk.green('Task deleted successfully!'));
displayMenu();
processInput();
});
}
// Function to prioritize a task
function prioritizeTask() {
rl.question(chalk.cyan('Enter task ID: '), taskId => {
taskManager.prioritizeTask(parseInt(taskId));
console.log(chalk.green('Task prioritized successfully!'));
displayMenu();
processInput();
});
}
// Function to view all tasks
function viewAllTasks() {
const tasks = taskManager.getAllTasks();
console.log(chalk.bold.yellow('All Tasks:'));
tasks.forEach(task => {
console.log(chalk.cyan('ID: ' + task.id));
console.log(chalk.cyan('Title: ' + task.title));
console.log(chalk.cyan('Description: ' + task.description));
console.log(chalk.cyan('Status: ' + task.status));
console.log(chalk.yellow('------------------------'));
});
displayMenu();
processInput();
}
// Function to process user input and make menu choices
function processInput() {
rl.question(chalk.cyan('Enter your choice: '), choice => {
switch (choice) {
case '1':
addTask();
break;
case '2':
updateTaskStatus();
break;
case '3':
deleteTask();
break;
case '4':
prioritizeTask();
break;
case '5':
viewAllTask();
break;
case '6':
rl.close();
break;
default:
console.log(chalk.red('Invalid choice. Please try again.'));
displayMenu();
processInput();
break;
}
});
}
// Start by displaying the menu and processing user input
displayMenu();
processInput();