Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project One Todo App #84

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
29 changes: 29 additions & 0 deletions projectone/tauqueerdanish/todo/Todos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"tasks": [
{
"id": 1,
"task": "Buy Flowers",
"complete": false
},
{
"id": 2,
"task": "Water Plants",
"complete": false
},
{
"id": 3,
"task": "Eating Breakfast",
"complete": false
},
{
"id": 4,
"task": "Having a tight sleep",
"complete": true
},
{
"id": 5,
"task": "Happy Coding",
"complete": true
}
]
}
101 changes: 101 additions & 0 deletions projectone/tauqueerdanish/todo/dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const todoItem_1 = require("./todoItem");
const inquirer = require("inquirer");
const jsonTodoCollection_1 = require("./jsonTodoCollection");
//console.clear();
//console.log("Dan's File");
let todos = [
new todoItem_1.Todoitem(1, "Buy Flowers"),
new todoItem_1.Todoitem(2, "Water Plants"),
new todoItem_1.Todoitem(3, "Eating Breakfast"),
new todoItem_1.Todoitem(4, "Having a tight sleep", true)
];
//let collection: Todocollection = new Todocollection("Dan",todos);
let collection = new jsonTodoCollection_1.JsonTodoCollection("Dan's", todos);
let showCompleted = true;
function displayTodoList() {
console.log(`${collection.userName}'s Todo List (${collection.getItemCounts().incomplete} Items Todo)'`);
collection.getTodoItems(showCompleted).forEach(item => item.printDetails());
}
var Commands;
(function (Commands) {
Commands["Add"] = "Add New Task";
Commands["Complete"] = "Complete Task";
Commands["Toggle"] = "Show/Hide Completed";
Commands["Purge"] = "Remove Completed Task";
Commands["Quit"] = "Quit";
})(Commands || (Commands = {}));
function promptAdd() {
console.clear();
inquirer.prompt({
type: "input",
name: "add",
message: "Enter Task:",
}).then(answers => {
if (answers.add !== "") {
collection.addTodo(answers["add"]);
}
promptUser();
});
}
function promptComplete() {
console.clear();
inquirer.prompt({
type: "checkbox",
name: "complete",
message: "Mark Task Complete",
choices: collection.getTodoItems(showCompleted).map(item => ({ name: item.task, value: item.id, checked: item.complete }))
}).then(answers => {
let completedTasks = answers["complete"];
collection.getTodoItems(true).forEach(item => collection.markComplete(item.id, completedTasks.find(id => id === item.id) != undefined));
promptUser();
});
}
function promptUser() {
console.clear();
displayTodoList();
inquirer.prompt({
type: "list",
name: "command",
message: "Choose Option",
choices: Object.values(Commands),
//badProperty:true
}).then(answers => {
//if (answers["command"] != Commands.Quit){
// promptUser();
//}
switch (answers["command"]) {
case Commands.Toggle:
showCompleted = !showCompleted;
promptUser();
break;
case Commands.Add:
promptAdd();
break;
case Commands.Complete:
if (collection.getItemCounts().incomplete > 0) {
promptComplete();
}
else {
promptUser();
}
break;
case Commands.Purge:
collection.removeComplete();
promptUser();
break;
}
});
}
promptUser();
//console.clear();
//console.log(`${collection.userName}'s Todo List`);
//console.log(`${collection.getItemCounts().incomplete} items to do`);
//let newid: number = collection.addTodo("Go for run");
//let todoItem: Todoitem = collection.getTodoById(newid);
//todoItem.printDetails();
//collection.addTodo(todoItem);
//collection.removeComplete();
//collection.getTodoItems(true).forEach(item => item.printDetails());
//console.log(JSON.stringify(todoItem));
39 changes: 39 additions & 0 deletions projectone/tauqueerdanish/todo/dist/jsonTodoCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonTodoCollection = void 0;
const todoItem_1 = require("./todoItem");
const todoCollection_1 = require("./todoCollection");
const lowdb = require("lowdb");
const FileSync = require("lowdb/adapters/FileSync");
class JsonTodoCollection extends todoCollection_1.Todocollection {
constructor(userName, todoItems = []) {
super(userName, []);
this.userName = userName;
this.database = lowdb(new FileSync("Todos.json"));
if (this.database.has("tasks").value()) {
let dbItems = this.database.get("tasks").value();
dbItems.forEach(item => this.itemMap.set(item.id, new todoItem_1.Todoitem(item.id, item.task, item.complete)));
}
else {
this.database.set("tasks", todoItems).write();
todoItems.forEach(item => this.itemMap.set(item.id, item));
}
}
addTodo(task) {
let result = super.addTodo(task);
this.storeTasks();
return result;
}
markComplete(id, complete) {
super.markComplete(id, complete);
this.storeTasks();
}
removeComplete() {
super.removeComplete();
this.storeTasks();
}
storeTasks() {
this.database.set("tasks", [...this.itemMap.values()]).write();
}
}
exports.JsonTodoCollection = JsonTodoCollection;
48 changes: 48 additions & 0 deletions projectone/tauqueerdanish/todo/dist/todoCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Todocollection = void 0;
const todoItem_1 = require("./todoItem");
class Todocollection {
constructor(userName, todoitems = []) {
this.userName = userName;
this.todoitems = todoitems;
this.nextid = 1;
this.itemMap = new Map();
todoitems.forEach(item => this.itemMap.set(item.id, item));
}
addTodo(task) {
while (this.getTodoById(this.nextid)) {
this.nextid++;
}
//this.todoitems.push(new Todoitem(this.nextid, task));
this.itemMap.set(this.nextid, new todoItem_1.Todoitem(this.nextid, task));
return this.nextid;
}
getTodoById(id) {
//return this.todoitems.find(item => item.id == id);
return this.itemMap.get(id);
}
getTodoItems(includeComplete) {
return [...this.itemMap.values()].filter(item => includeComplete || !item.complete);
}
markComplete(id, complete) {
const todoItem = this.getTodoById(id);
if (todoItem) {
todoItem.complete = complete;
}
}
removeComplete() {
this.itemMap.forEach(item => {
if (item.complete) {
this.itemMap.delete(item.id);
}
});
}
getItemCounts() {
return {
total: this.itemMap.size,
incomplete: this.getTodoItems(false).length
};
}
}
exports.Todocollection = Todocollection;
20 changes: 20 additions & 0 deletions projectone/tauqueerdanish/todo/dist/todoItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Todoitem = void 0;
class Todoitem {
//public id: number;
//public task:string;
//public complete: boolean=false;
constructor(id, task, complete = false) {
this.id = id;
this.task = task;
this.complete = complete;
this.id = id;
this.task = task;
this.complete = complete;
}
printDetails() {
console.log(`${this.id}\t${this.task} ${this.complete ? "\t(Complete)" : ""}`);
}
}
exports.Todoitem = Todoitem;

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

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

Loading