Task Planner

Run Settings
LanguageJavaScript
Language Version
Run Command
const TaskType = { STORY: "STORY", FEATURE: "FEATURE", BUG: "BUG", }; const TaskStatus = { OPEN: "OPEN", IN_PROGRESS: "IN_PROGRESS", RESOLVED: "RESOLVED", DELAYED: "DELAYED", COMPLETED: "COMPLETED", }; class Sprint { #begin; #end; #name; #tasks = []; //Array of Tasks related to a sprint get getTasks() { return this.#tasks; } set setTasks(tasks) { this.#tasks = tasks; } get getName() { return this.#name; } get getBegin() { return this.#begin; } get getEnd() { return this.#end; } constructor(begin, end, name) { this.#begin = begin; this.#end = end; this.#name = name; } addTask(task) { //Add object if Taask class in Tasks of a sprint this.#tasks.push(task); } printDetails() { console.log(`Sprint Name: ${this.#name}`); console.log(`Sprint Begins: ${this.#begin}`); console.log(`Sprint Ends: ${this.#end}`); } } class Task { #id; #subtract; #user; //Object of User class to determine which user is assigned this task #taskType; #taskStatus; static #taskId = 1; #getUniqueId() { return Task.#taskId++; } constructor() { this.#id = this.#getUniqueId(); this.taskStatus = TaskStatus.OPEN; } get getId() { return this.#id; } set setSubtract(sub) { this.#subtract = sub; } set setUser(user) { this.#user = user; } set setTaskType(type) { this.#taskType = type; } set setTaskStatus(status) { this.#taskStatus = status; } } class User { #taskList = []; //Tasks list of a particular user #sprintList = []; createTask(taskType, subtract) { //TaskType if (!subtract) { if (taskType === TaskType.STORY) { console.log( "Warning! Task of type STORY is being created with no subtract" ); } } const task = new Task(); task.setTaskType = subtract ? TaskType.STORY : TaskType[taskType]; task.setSubtract = subtract; task.setUser = this; this.#taskList.push(task); return task; } createSprint(begin, end, name) { const sprint = new Sprint(begin, end, name); this.#sprintList.push(sprint); return sprint; } addToSprint(sprint, task) { for (let spr of this.#sprintList) { if ( spr.getBegin === sprint.getBegin && spr.getEnd === sprint.getEnd && spr.getName === sprint.getName ) { sprint.addTask(task); return true; } } return false; } removeFromSprint(sprint, task) { let isSprintValid = false; for (let spr of this.#sprintList) { if ( spr.getBegin === sprint.getBegin && spr.getEnd === sprint.getEnd && spr.getName === sprint.getName ) { isSprintValid = true; } } if (isSprintValid) { let taskList = sprint.getTasks; for (let t = 0; t < taskList.length; t++) { if (taskList[t].getId === task.getId) { taskList.splice(t, 1); sprint.setTasks = taskList; return true; } } } return false; } printAllTasks() { for (let task of this.#taskList) { console.log(task.getId); } } changeTaskStatus(task, taskStatus) { for (let t of this.#taskList) { if (t.getId === task.getId) { t.setTaskStatus = TaskStatus[taskStatus]; return true; } } return false; } } const user1 = new User(); const user2 = new User(); const task1 = user1.createTask(TaskType.FEATURE); const task11 = user1.createTask(TaskType.BUG); const task112 = user1.createTask(TaskType.STORY); const task2 = user2.createTask(TaskType.BUG); const task22 = user2.createTask("", "This is a subtract"); const sprint1 = user1.createSprint(22, 33, "Sprint1"); const sprint2 = user2.createSprint(44, 55, "Sprint2"); console.log(user1.changeTaskStatus(task11, TaskStatus.IN_PROGRESS)); console.log(user1.addToSprint(sprint1, task1)); //1 console.log(user1.addToSprint(sprint1, task11)); //1 console.log(user1.addToSprint(sprint2, task1)); //0 console.log(user1.removeFromSprint(sprint1, task11)); //1 console.log(user2.addToSprint(sprint1, task1)); //0 console.log(user2.removeFromSprint(sprint1, task2)); //0 console.log(user2.addToSprint(sprint2, task1)); //1 console.log(user2.addToSprint(sprint2, task2)); //1 sprint1.printDetails(); user1.printAllTasks(); user2.printAllTasks();
Editor Settings
Theme
Key bindings
Full width
Lines