-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
116bfba
commit 8893677
Showing
8 changed files
with
178 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import css from "./style.css"; | ||
import '@fortawesome/fontawesome-free/js/fontawesome' | ||
import '@fortawesome/fontawesome-free/js/solid' | ||
import {listenForAdd} from "./modules/controller"; | ||
import {Controller} from "./modules/controller"; | ||
|
||
|
||
window.addEventListener("load", () => { | ||
listenForAdd(); | ||
const controller = new Controller(); | ||
controller.listenForProjectAdd(); | ||
controller.listenForTodoAdd(); | ||
controller.listenForProjects(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,52 @@ | ||
import {addTodo} from "./model.js"; | ||
import {display} from "./view.js"; | ||
import { View } from "./view"; | ||
import { Model } from "./model.js"; | ||
|
||
let todoInputField = document.querySelector("#todoInputField"); | ||
const addButton = document.querySelector(".addTodoButton"); | ||
class Controller { | ||
model; | ||
view; | ||
todoInputField; | ||
addTodoButton; | ||
projectInputField; | ||
addProjectButton; | ||
currentProjectId; | ||
allCurrentProjects; | ||
|
||
function listenForAdd() { | ||
console.log(addButton); | ||
addButton.addEventListener("click", () => { | ||
let todoTitle = todoInputField.value; | ||
display(addTodo(todoTitle)); | ||
constructor() { | ||
this.model = new Model(); | ||
this.view = new View(); | ||
this.todoInputField = document.querySelector("#todoInputField"); | ||
this.addTodoButton = document.querySelector(".addTodoButton"); | ||
this.projectInputField = document.querySelector("#projectsInputField"); | ||
this.addProjectButton = document.querySelector(".addProjectButton"); | ||
this.currentProjectId = 0; | ||
this.allCurrentProjects = document.querySelector("li"); | ||
} | ||
|
||
listenForProjects() { | ||
this.allCurrentProjects?.forEach((project) => { | ||
project.addEventListener("click", (e) => { | ||
this.currentProjectId = e.target.getAttribute("id"); | ||
}); | ||
}); | ||
} | ||
|
||
listenForProjectAdd() { | ||
this.addProjectButton.addEventListener("click", () => { | ||
let projectTitle = this.projectInputField.value; | ||
this.model.addProject(projectTitle); | ||
this.view.displayProjects(this.model.getProjects()); | ||
}); | ||
} | ||
|
||
listenForTodoAdd() { | ||
this.addTodoButton.addEventListener("click", () => { | ||
let todoTitle = this.todoInputField.value; | ||
this.model.addTodoToProject(this.currentProjectId); | ||
this.view.displayTodos( | ||
this.model.getProject(this.currentProjectId).getTodos() | ||
); | ||
}); | ||
} | ||
} | ||
|
||
export {listenForAdd}; | ||
export { Controller }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
import {Todo} from "./entities"; | ||
import {Project} from "./entities"; | ||
|
||
const todoList = []; | ||
class Model { | ||
projectList; | ||
|
||
constructor(){ | ||
const defaultProject = new Project("default"); | ||
this.projectList = [defaultProject]; | ||
} | ||
|
||
addProject(title){ | ||
console.log("inside model: add project"); | ||
this.projectList.push(new Project(title)); | ||
} | ||
|
||
getProject(id){ | ||
console.log(this.projectList[id]); | ||
return this.projectList[id]; | ||
} | ||
|
||
getProjects(){ | ||
console.log("inside model: get projects"); | ||
return this.projectList; | ||
} | ||
|
||
addTodoToProject(id, title, due, prio){ | ||
this.projectList[id].addTodo(title,due,prio); | ||
} | ||
|
||
function addTodo(title, due, prio){ | ||
let newTodo = new Todo(title, due, prio); | ||
todoList.push(newTodo); | ||
return todoList; | ||
} | ||
|
||
export {addTodo}; | ||
|
||
export {Model}; |
Oops, something went wrong.