Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions typescript-todo/components/todo/todo.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { TodoControllerInterface } from "../../interfaces/todo.controller.interface";
import { Task, DeadlineTask, Todo, TaskType } from "./todo.model"

class TodoController implements TodoControllerInterface {
model: Todo;

constructor(model: Todo){
this.model = model
}

findTaskIndex(id: string) {
return this.model.items.findIndex((task) => task.id == id)
}

createTask(type: TaskType) {
let defaultName = "New Task"

switch (type) {
case TaskType.DEFAULT:
return new Task("1", defaultName)
case TaskType.DEADLINE:
return new DeadlineTask("1", defaultName)
default:
return new Task("1", defaultName)
}
}

addTask(type: TaskType) {
this.model.addTask(this.createTask(type))
}

removeTask(id: string) {
let index = this.findTaskIndex(id)

if (index === -1) return;

this.model.removeTask(index)
}

updateTask(id: string, task: Task) {
let index = this.findTaskIndex(id)

if (index === -1) return;

this.model.updateTask(index, task)
}

changeTaskType(id: string, type: TaskType) {
let index = this.findTaskIndex(id)

if (index === -1) return;

let oTask = this.model.items[index]
let newTask = this.createTask(type)

newTask.id = oTask.id
newTask.name = oTask.name
newTask.detail = oTask.detail
newTask.completed = oTask.completed

this.model.updateTask(index, newTask)
}

}

export { TodoController }
82 changes: 82 additions & 0 deletions typescript-todo/components/todo/todo.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { DeadlineInterface } from "../../interfaces/deadline.interface";
import { TaskInterface } from "../../interfaces/task.interface";
import { TodoModelInterface } from "../../interfaces/todo.model.interface";

enum TaskType {
DEFAULT,
DEADLINE,
}

class Task implements TaskInterface {
id: string;
name: string;
detail: string;
completed: boolean;

constructor(id: string, name: string) {
this.id = id;
this.name = name;
this.detail = "";
this.completed = false;
}
}

class DeadlineTask extends Task implements DeadlineInterface {
due: Date;

constructor(id: string, name: string){
super(id, name);
this.due = new Date();
}

setDate(date: Date) {
this.due = date;
}
}

class NestedTask extends Task {
children: Task[]

constructor(id: string, name: string) {
super(id, name)
this.children = new Array<Task>()
}

addChild() {

}

removeChild() {

}

updateChild() {

}
}

class Todo implements TodoModelInterface{
items: Task[]

constructor(){
this.items = new Array<Task>()
}

addTask(task: Task) {
this.items.push(task)
}

updateTask(index: number, task: Task) {
if (index < 0 || index >= this.items.length) return;

this.items[index] = task;
}

removeTask(index: number) {
if (index < 0 || index >= this.items.length) return;

this.items.splice(index, 1)
}
}

export {Task, DeadlineTask, Todo, TaskType}
Empty file.
Empty file added typescript-todo/dummy.data.ts
Empty file.
12 changes: 12 additions & 0 deletions typescript-todo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { DeadlineTask, Todo, TaskType } from "./components/todo/todo.model";
import { TodoController } from "./components/todo/todo.controller"

let dtask = new DeadlineTask("2", "Task 2")
let todo = new Todo()
let controller = new TodoController(todo)

controller.addTask(TaskType.DEFAULT)
controller.updateTask("1", dtask)
controller.addTask(TaskType.DEFAULT)
controller.changeTaskType("1", TaskType.DEADLINE)
console.log(controller.model)
3 changes: 3 additions & 0 deletions typescript-todo/interfaces/deadline.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface DeadlineInterface {
due: Date;
}
6 changes: 6 additions & 0 deletions typescript-todo/interfaces/task.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface TaskInterface {
id: string;
name: string;
detail: string;
completed: boolean;
}
8 changes: 8 additions & 0 deletions typescript-todo/interfaces/todo.controller.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Task, TaskType, Todo } from "../components/todo/todo.model";

export interface TodoControllerInterface {
model: Todo
addTask: (type: TaskType) => void
removeTask: (id: string) => void
updateTask: (id: string, task: Task) => void
}
5 changes: 5 additions & 0 deletions typescript-todo/interfaces/todo.model.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { TaskInterface } from "./task.interface";

export interface TodoModelInterface {
items: TaskInterface[];
}
51 changes: 51 additions & 0 deletions typescript-todo/ts-out/components/todo/todo.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TodoController = void 0;
const todo_model_1 = require("./todo.model");
class TodoController {
constructor(model) {
this.model = model;
}
findTaskIndex(id) {
return this.model.items.findIndex((task) => task.id == id);
}
createTask(type) {
let defaultName = "New Task";
switch (type) {
case todo_model_1.TaskType.DEFAULT:
return new todo_model_1.Task("1", defaultName);
case todo_model_1.TaskType.DEADLINE:
return new todo_model_1.DeadlineTask("1", defaultName);
default:
return new todo_model_1.Task("1", defaultName);
}
}
addTask(type) {
this.model.addTask(this.createTask(type));
}
removeTask(id) {
let index = this.findTaskIndex(id);
if (index === -1)
return;
this.model.removeTask(index);
}
updateTask(id, task) {
let index = this.findTaskIndex(id);
if (index === -1)
return;
this.model.updateTask(index, task);
}
changeTaskType(id, type) {
let index = this.findTaskIndex(id);
if (index === -1)
return;
let oTask = this.model.items[index];
let newTask = this.createTask(type);
newTask.id = oTask.id;
newTask.name = oTask.name;
newTask.detail = oTask.detail;
newTask.completed = oTask.completed;
this.model.updateTask(index, newTask);
}
}
exports.TodoController = TodoController;
59 changes: 59 additions & 0 deletions typescript-todo/ts-out/components/todo/todo.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskType = exports.Todo = exports.DeadlineTask = exports.Task = void 0;
var TaskType;
(function (TaskType) {
TaskType[TaskType["DEFAULT"] = 0] = "DEFAULT";
TaskType[TaskType["DEADLINE"] = 1] = "DEADLINE";
})(TaskType || (TaskType = {}));
exports.TaskType = TaskType;
class Task {
constructor(id, name) {
this.id = id;
this.name = name;
this.detail = "";
this.completed = false;
}
}
exports.Task = Task;
class DeadlineTask extends Task {
constructor(id, name) {
super(id, name);
this.due = new Date();
}
setDate(date) {
this.due = date;
}
}
exports.DeadlineTask = DeadlineTask;
class NestedTask extends Task {
constructor(id, name) {
super(id, name);
this.children = new Array();
}
addChild() {
}
removeChild() {
}
updateChild() {
}
}
class Todo {
constructor() {
this.items = new Array();
}
addTask(task) {
this.items.push(task);
}
updateTask(index, task) {
if (index < 0 || index >= this.items.length)
return;
this.items[index] = task;
}
removeTask(index) {
if (index < 0 || index >= this.items.length)
return;
this.items.splice(index, 1);
}
}
exports.Todo = Todo;
12 changes: 12 additions & 0 deletions typescript-todo/ts-out/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const todo_model_1 = require("./components/todo/todo.model");
const todo_controller_1 = require("./components/todo/todo.controller");
let dtask = new todo_model_1.DeadlineTask("2", "Task 2");
let todo = new todo_model_1.Todo();
let controller = new todo_controller_1.TodoController(todo);
controller.addTask(todo_model_1.TaskType.DEFAULT);
controller.updateTask("1", dtask);
controller.addTask(todo_model_1.TaskType.DEFAULT);
controller.changeTaskType("1", todo_model_1.TaskType.DEADLINE);
console.log(controller.model);
2 changes: 2 additions & 0 deletions typescript-todo/ts-out/interfaces/deadline.interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 2 additions & 0 deletions typescript-todo/ts-out/interfaces/task.interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 2 additions & 0 deletions typescript-todo/ts-out/interfaces/todo.model.interface.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Loading