Skip to content

Commit

Permalink
Refactored to MVC architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Re committed Apr 13, 2022
1 parent 56cb73f commit 116bfba
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 112 deletions.
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</aside>
<main>
<input type="text" name="todoInputField" id="todoInputField">
<button>+</button>
<button class="addTodoButton">+</button>
<div class="content">
<table>
<thead>
Expand Down
52 changes: 37 additions & 15 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 0 additions & 46 deletions src/create.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</aside>
<main>
<input type="text" name="todoInputField" id="todoInputField">
<button>+</button>
<button class="addTodoButton">+</button>
<div class="content">
<table>
<thead>
Expand Down
38 changes: 2 additions & 36 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
import {createTodo} from "./create.js";
// import {} from "./project";
import css from "./style.css";
import '@fortawesome/fontawesome-free/js/fontawesome'
import '@fortawesome/fontawesome-free/js/solid'

import {listenForAdd} from "./modules/controller";

window.addEventListener("load", () => {
createTodo();
listenForAdd();
});




// // Set todo status to complete module
// // Get all check icons and add event listeners to them
// let done = document.querySelectorAll(".fa-circle-check");
// done.forEach((item) => {
// item.addEventListener("click", (event) => {
// completeTask(event);
// });
// });

// // Mark task complete
// const completeTask = (event) => {
// let task = event.target.nextElementSibling;
// let text = task.innerHTML;
// if (text.includes("<del>")) {
// task.parentNode.parentNode.setAttribute("data-complete", "false");
// text = task.firstElementChild.textContent;
// task.innerHTML = text;
// } else {
// task.innerHTML = `<del>${text}</del>`;
// task.parentNode.parentNode.setAttribute("data-complete", "true");
// }
// };

// Changing todo priority module

// Dom manipulation module

// Popup form https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_popup_form
15 changes: 15 additions & 0 deletions src/modules/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {addTodo} from "./model.js";
import {display} from "./view.js";

let todoInputField = document.querySelector("#todoInputField");
const addButton = document.querySelector(".addTodoButton");

function listenForAdd() {
console.log(addButton);
addButton.addEventListener("click", () => {
let todoTitle = todoInputField.value;
display(addTodo(todoTitle));
});
}

export {listenForAdd};
11 changes: 2 additions & 9 deletions src/todo.js → src/modules/entities.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
/* Todo objects
- Title
- Description
- DueDate
- Priority
*/

export default class Todo {
class Todo {
title;
description;
dueDate;
Expand Down Expand Up @@ -49,6 +42,6 @@ export default class Todo {
getPriority() {
return this.priority;
}

}

export {Todo};
11 changes: 11 additions & 0 deletions src/modules/model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Todo} from "./entities";

const todoList = [];

function addTodo(title, due, prio){
let newTodo = new Todo(title, due, prio);
todoList.push(newTodo);
return todoList;
}

export {addTodo};
20 changes: 20 additions & 0 deletions src/modules/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const todoTable = document.querySelector("table");

function display(currentTodoArray){
// Wipeout current list
todoTable.innerHTML = "";
// loop through list
currentTodoArray.forEach((todo)=>{
// Create and add a new row to the table
todoTable.appendChild(createRow(todo.title));
})
}

function createRow(title) {
console.log(title);
const newRow = document.createElement("tr");
newRow.innerHTML=`<td>${title}</td>`;
return newRow;
}

export {display};
4 changes: 0 additions & 4 deletions src/project.js

This file was deleted.

0 comments on commit 116bfba

Please sign in to comment.