-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from thesamim/master
Additional functionality
Showing
8 changed files
with
808 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,206 @@ | ||
import { Tick } from '../src/index' | ||
import dotenv from 'dotenv' | ||
import { ITask } from '../src/types/Task' | ||
dotenv.config() | ||
import { isValid } from '../src/utils/validate' | ||
|
||
async function main() { | ||
let allAllTasks: ITask[] = null; | ||
let donePrinted: string[] = []; | ||
|
||
export async function testTick() { | ||
try { | ||
const envUSERNAME = process.env.TICK_USERNAME | ||
const envPASSWORD = process.env.TICK_PASSWORD | ||
// const envUSERNAME = process.env.TICK_USERNAME | ||
// const envPASSWORD = process.env.TICK_PASSWORD | ||
const envUSERNAME = "[email protected]" | ||
const envPASSWORD = "Howdy0021!" | ||
if (!envUSERNAME || !envPASSWORD){ | ||
throw new Error('parameters username/password were not set in .env file.'); | ||
} | ||
|
||
|
||
const projectID = "65159d5d8f08a002fd167ce8"; | ||
const tickSession = new Tick({ username: envUSERNAME, password: envPASSWORD }); | ||
const hasLoggedIn = await tickSession.login(); | ||
if (!hasLoggedIn) { | ||
throw new Error('Coudnt login with this username/password.'); | ||
} | ||
// let myTask: ITask = { | ||
// "projectId": projectID, | ||
// "title": "Trying too many things. #otherNewTest 10/21/2023 -- latest.", | ||
// "tags": ["NewTest"] | ||
// } | ||
// let addResult = await tickSession.addTask(myTask); | ||
// console.log("Add Result : ", addResult); | ||
|
||
const userPreferences = await tickSession.getUserSettings() | ||
console.log(Object.keys(userPreferences)) | ||
|
||
const allAllTasks = await tickSession.getAllTasks(); | ||
console.log(allAllTasks.map((item) => item.title)); | ||
|
||
const tasks = await tickSession.getTasks(); | ||
console.log(tasks.map((item) => item.title)); | ||
// let newTaskId = "6515b1642b3163961425bb73"; | ||
// let newTaskTitle = ""; | ||
// console.log("New Id: ", newTaskId, "New Title: ", newTaskTitle); | ||
// let addedTask = await tickSession.getTask(newTaskId, projectID) | ||
// console.log("getTask result: ", addedTask); | ||
|
||
const filters = await tickSession.getFilters(); | ||
console.log(filters.map((item) => item.name)); | ||
// let myTask: ITask = { | ||
// "projectId": projectID, | ||
// "title": addedTask.title + " just add something.", | ||
// // "tags": ["NewTest"], | ||
// "id": newTaskId, | ||
// "status": 3 | ||
// } | ||
// let addResult = await tickSession.updateTask(myTask); | ||
// console.log("Update Result : ", addResult); | ||
// const allAllTasks = await tickSession.getAllTasks(); | ||
// if (allAllTasks !== undefined && allAllTasks !== null) { | ||
// console.log("==== allAllTasks") | ||
// console.log(allAllTasks.map((item) => item.title)); | ||
// console.log("==== items of allAllTasks") | ||
// console.log(allAllTasks.map((item) => item.items)) | ||
// console.log("==== content of allAllTasks") | ||
// console.log(allAllTasks.map((item) => item.content)) | ||
// }else { | ||
// console.log("==== No allAllTasks") | ||
// } | ||
allAllTasks = await tickSession.getAllTasks(); | ||
if (allAllTasks !== undefined && allAllTasks !== null) { | ||
allAllTasks = allAllTasks.filter((currentTask) => currentTask.status == 0); | ||
//make sure top level tasks are first | ||
allAllTasks.sort((a, b) => { | ||
if (isValid(a.parentId) && isValid(b.parentId)) { | ||
return (a.parentId < b.parentId) | ||
} else if (isValid(a.parentId)) { | ||
return 1; | ||
} else { | ||
return -1; | ||
} | ||
}); | ||
// allAllTasks.forEach(task => console.log(task.title)) | ||
|
||
const projectGroups = await tickSession.getProjectGroups(); | ||
console.log(projectGroups.map((item) => item.name)); | ||
|
||
const projects = await tickSession.getProjects(); | ||
console.log(projects.map((item) => item.name)); | ||
|
||
const habits = await tickSession.getHabits(); | ||
console.log(habits.map((item) => item.name)); | ||
|
||
const tags = await tickSession.getTags(); | ||
console.log(tags); | ||
console.log(allAllTasks.map((currentTask) => `${currentTask.title}, ${currentTask.sortOrder}`)) | ||
printTasks(allAllTasks); | ||
// let oneLevelTasks = allAllTasks.filter((currentTask) => !isAChild(currentTask.parentId)); | ||
// let taskWithChildren = allAllTasks.filter((currentTask) => isAChild(currentTask.parentId)); | ||
// console.log(`No Parent tasks: \n ${oneLevelTasks.map((currentTask) => currentTask.title)}\n`) | ||
// console.log(`Parent tasks:\n ${taskWithChildren.map((currentTask) => currentTask.title)}\n`) | ||
|
||
// allAllTasks.forEach(task => { | ||
// if (task.status == 0) { | ||
// // if (!(isValid(task.parentId))) { | ||
// console.log(`${task.status} -- ${task.title} -- ${task.id} -- ${isAChild(task.parentId) ? 'is a parent' : 'is not a parent'}`); | ||
// // console.log(task); | ||
// // } | ||
// if (isValid(task.childIds)) { | ||
// task.childIds.forEach(child => { | ||
// console.log(`\t ${child}`) | ||
// let childrens = allAllTasks.filter((currentTask) => currentTask.id==child) | ||
// console.log(`====children of ${child}========`) | ||
// console.log(childrens) | ||
// }); | ||
// } | ||
// } | ||
// }); | ||
}else { | ||
console.log("==== No allAllTasks") | ||
} | ||
|
||
// const projects = await tickSession.getProjects(); | ||
// if (projects !== undefined && projects !== null) { | ||
// console.log("==== projects") | ||
// // console.log(projects.map((item) => item.name)); | ||
// console.log(`Got ${projects.length} projects.`) | ||
// projects.forEach(async project => { | ||
// console.log("Prj nm: ",project.name); | ||
// const sections = await tickSession.getProjectSections(project.id); | ||
// // console.log(`Project: ${project.name} -- ${sections}`); | ||
// if (sections !== undefined && sections !== null && sections.length > 0) { | ||
// sections.forEach(section => { | ||
// console.log(project.name + '--' + section.name); | ||
// }) | ||
// } else { | ||
// console.log(project.name + '--' + 'no sections') | ||
// } | ||
// }) | ||
|
||
// // projects.forEach(project => { | ||
// // console.log(project.name); | ||
// // const sections = await tickSession.getProjectSections(project.id); | ||
// // if (sections !== undefined && sections !== null) { | ||
// // console.log(sections); | ||
// // }); | ||
// // } | ||
|
||
// } else { | ||
// console.log("==== No projects") | ||
// } | ||
} catch (e: any) { | ||
console.log(e.message); | ||
} | ||
console.log("\n\nDone") | ||
} | ||
|
||
function isAChild(idToCheck: string) { | ||
console.log(`input: ${idToCheck}`); | ||
if (!isValid(idToCheck)) { | ||
console.log('is a child.') | ||
return false; | ||
} else { | ||
console.log("is not a child") | ||
return true | ||
} | ||
} | ||
|
||
function printTasks(allTheTasks: ITask[]) { | ||
console.log("=== Print Tasks =="); | ||
|
||
allTheTasks.forEach(task => { | ||
// if (!isAChild(task.parentId)) { | ||
// console.log(task.title); | ||
// } else { | ||
if (donePrinted.indexOf(task.id) < 1) { | ||
printTaskAndChildren(task, 0); | ||
} | ||
// } | ||
}); | ||
} | ||
|
||
function printTaskAndChildren(task: ITask, depth: number) { | ||
// console.log(`printTasks+ ${task.title}, ${depth}`) | ||
let childCount = 0; | ||
//There's probably a more js way of doing this | ||
let tabs: string = ''; | ||
childCount = childCount + depth; | ||
for (let index = 0; index < childCount; index++) { | ||
tabs += '\t'; | ||
}; | ||
// console.log(`[${tabs}], ${tabs.length}, ${childCount}`); | ||
if (donePrinted.indexOf(task.id) < 1) { | ||
console.log(`${tabs}title: ${task.title} -- ${task.id} -- parent ${task.parentId} --- project: ${task.projectId}`) | ||
donePrinted.push(task.id); | ||
} | ||
if (isValid(task.childIds)) | ||
{ | ||
// console.log("-- has children") | ||
let newDepth = depth + 1; | ||
// console.log(`new depth: ${newDepth}`); | ||
task.childIds.forEach(currentChildId => { | ||
let childTask: ITask = allAllTasks.find(currentTask => currentTask.id == currentChildId); | ||
if (isValid(childTask)) { | ||
printTaskAndChildren(childTask, newDepth); | ||
} else { | ||
console.log(`found no child: for ${task.title}`) | ||
} | ||
|
||
|
||
}); | ||
// printTaskAndChildren(---) | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
testTick(); | ||
|
||
|
||
|
||
|
||
main(); |
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 |
---|---|---|
@@ -0,0 +1,243 @@ | ||
import { Tick } from '../src/index' | ||
import dotenv from 'dotenv' | ||
import { ITask } from '../src/types/Task' | ||
dotenv.config() | ||
import { isValid } from '../src/utils/validate' | ||
|
||
let allAllTasks: ITask[] = null; | ||
let donePrinted: string[] = []; | ||
|
||
export async function testTick() { | ||
try { | ||
// const envUSERNAME = process.env.TICK_USERNAME | ||
// const envPASSWORD = process.env.TICK_PASSWORD | ||
const envUSERNAME = "thesamim@yahoo.com" | ||
const envPASSWORD = "howdy002" | ||
if (!envUSERNAME || !envPASSWORD){ | ||
throw new Error('parameters username/password were not set in .env file.'); | ||
} | ||
|
||
const tickSession = new Tick({ username: envUSERNAME, password: envPASSWORD }); | ||
const hasLoggedIn = await tickSession.login(); | ||
if (!hasLoggedIn) { | ||
throw new Error('Coudnt login with this username/password.'); | ||
} | ||
// let myTask: ITask = { | ||
// "projectId": "inbox121990985", | ||
// "title": "This is the one I want to add right now. ", | ||
// "tags": ["mod1"] | ||
// } | ||
// const addResult = await tickSession.addTask(myTask, false); | ||
// console.log(addResult); | ||
|
||
// const userPreferences = await tickSession.getUserSettings() | ||
// if (userPreferences !== undefined && userPreferences !== null) { | ||
// console.log("==== userPreferences") | ||
// console.log(Object.keys(userPreferences)) | ||
// } else { | ||
// console.log("==== No userPreferences") | ||
// } | ||
|
||
// const allAllTasks = await tickSession.getAllTasks(); | ||
// if (allAllTasks !== undefined && allAllTasks !== null) { | ||
// console.log("==== allAllTasks") | ||
// console.log(allAllTasks.map((item) => item.title)); | ||
// console.log("==== items of allAllTasks") | ||
// console.log(allAllTasks.map((item) => item.items)) | ||
// console.log("==== content of allAllTasks") | ||
// console.log(allAllTasks.map((item) => item.content)) | ||
// }else { | ||
// console.log("==== No allAllTasks") | ||
// } | ||
allAllTasks = await tickSession.getAllTasks(); | ||
if (allAllTasks !== undefined && allAllTasks !== null) { | ||
allAllTasks = allAllTasks.filter((currentTask) => currentTask.status == 0); | ||
//make sure top level tasks are first | ||
allAllTasks.sort((a, b) => { | ||
if (isValid(a.parentId) && isValid(b.parentId)) { | ||
return (a.parentId < b.parentId) | ||
} else if (isValid(a.parentId)) { | ||
return 1; | ||
} else { | ||
return -1; | ||
} | ||
}); | ||
|
||
console.log(allAllTasks.map((currentTask) => `${currentTask.title}, ${currentTask.sortOrder}`)) | ||
printTasks(allAllTasks); | ||
// let oneLevelTasks = allAllTasks.filter((currentTask) => !isAChild(currentTask.parentId)); | ||
// let taskWithChildren = allAllTasks.filter((currentTask) => isAChild(currentTask.parentId)); | ||
// console.log(`No Parent tasks: \n ${oneLevelTasks.map((currentTask) => currentTask.title)}\n`) | ||
// console.log(`Parent tasks:\n ${taskWithChildren.map((currentTask) => currentTask.title)}\n`) | ||
|
||
// allAllTasks.forEach(task => { | ||
// if (task.status == 0) { | ||
// // if (!(isValid(task.parentId))) { | ||
// console.log(`${task.status} -- ${task.title} -- ${task.id} -- ${isAChild(task.parentId) ? 'is a parent' : 'is not a parent'}`); | ||
// // console.log(task); | ||
// // } | ||
// if (isValid(task.childIds)) { | ||
// task.childIds.forEach(child => { | ||
// console.log(`\t ${child}`) | ||
// let childrens = allAllTasks.filter((currentTask) => currentTask.id==child) | ||
// console.log(`====children of ${child}========`) | ||
// console.log(childrens) | ||
// }); | ||
// } | ||
// } | ||
// }); | ||
}else { | ||
console.log("==== No allAllTasks") | ||
} | ||
|
||
// const tasks = await tickSession.getTasks(); | ||
// if (tasks !== undefined && tasks !== null) { | ||
// console.log("==== tasks") | ||
// console.log(tasks.map((item) => item.title)); | ||
// console.log("==== items of tasks") | ||
// console.log(tasks.map((item) => item.items)) | ||
// console.log("==== content of tasks") | ||
// console.log(tasks.map((item) => item.content)) | ||
// }else { | ||
// console.log("==== No tasks") | ||
// } | ||
|
||
// const filters = await tickSession.getFilters(); | ||
// if (filters !== undefined && filters !== null) { | ||
// console.log("==== filters") | ||
// console.log(filters.map((item) => item.name)); | ||
// }else { | ||
// console.log("==== No filters") | ||
// } | ||
|
||
const projectGroups = await tickSession.getProjectGroups(); | ||
if (projectGroups !== undefined && projectGroups !== null) { | ||
console.log("==== projectGroups") | ||
console.log(projectGroups.map((item) => item.name)); | ||
}else { | ||
console.log("==== No projectGroups") | ||
} | ||
|
||
const projects = await tickSession.getProjects(); | ||
if (projects !== undefined && projects !== null) { | ||
console.log("==== projects") | ||
// console.log(projects.map((item) => item.name)); | ||
projects.forEach(async project => { | ||
// console.log(project.name); | ||
const singleProject = await tickSession.getProject(project.id); | ||
console.log(singleProject); | ||
const sections = await tickSession.getProjectSections(project.id); | ||
// console.log(`Project: ${project.name} -- ${sections}`); | ||
if (sections !== undefined && sections !== null && sections.length > 0) { | ||
sections.forEach(section => { | ||
console.log(project.name + '--' + section.name); | ||
}) | ||
} else { | ||
console.log(project.name + '--' + 'no sections') | ||
} | ||
}) | ||
|
||
// projects.forEach(project => { | ||
// console.log(project.name); | ||
// const sections = await tickSession.getProjectSections(project.id); | ||
// if (sections !== undefined && sections !== null) { | ||
// console.log(sections); | ||
// }); | ||
// } | ||
|
||
|
||
|
||
|
||
} else { | ||
console.log("==== No projects") | ||
} | ||
|
||
const habits = await tickSession.getHabits(); | ||
if (habits !== undefined && habits !== null) { | ||
console.log("==== habits") | ||
console.log(habits.map((item) => item.name)); | ||
}else { | ||
console.log("==== No habits") | ||
} | ||
const tags = await tickSession.getTags(); | ||
if (tags !== undefined && tags !== null) { | ||
console.log("==== tags") | ||
console.log(tags); | ||
}else { | ||
console.log("==== No tags") | ||
} | ||
|
||
} catch (e: any) { | ||
console.log(e.message); | ||
} | ||
} | ||
|
||
function isAChild(idToCheck: string) { | ||
console.log(`input: ${idToCheck}`); | ||
if (!isValid(idToCheck)) { | ||
console.log('is a child.') | ||
return false; | ||
} else { | ||
console.log("is not a child") | ||
return true | ||
} | ||
} | ||
|
||
function printTasks(allTheTasks: ITask[]) { | ||
console.log("=== Print Tasks =="); | ||
|
||
allTheTasks.forEach(task => { | ||
// if (!isAChild(task.parentId)) { | ||
// console.log(task.title); | ||
// } else { | ||
if (donePrinted.indexOf(task.id) < 1) { | ||
printTaskAndChildren(task, 0); | ||
} | ||
// } | ||
}); | ||
} | ||
|
||
function printTaskAndChildren(task: ITask, depth: number) { | ||
// console.log(`printTasks+ ${task.title}, ${depth}`) | ||
let childCount = 0; | ||
//There's probably a more js way of doing this | ||
let tabs: string = ''; | ||
childCount = childCount + depth; | ||
for (let index = 0; index < childCount; index++) { | ||
tabs += '\t'; | ||
}; | ||
// console.log(`[${tabs}], ${tabs.length}, ${childCount}`); | ||
if (donePrinted.indexOf(task.id) < 1) { | ||
console.log(`${tabs}title: ${task.title} -- ${task.id} -- parent ${task.parentId} --- project: ${task.projectId}`) | ||
donePrinted.push(task.id); | ||
} | ||
if (isValid(task.childIds)) | ||
{ | ||
// console.log("-- has children") | ||
let newDepth = depth + 1; | ||
// console.log(`new depth: ${newDepth}`); | ||
task.childIds.forEach(currentChildId => { | ||
let childTask: ITask = allAllTasks.find(currentTask => currentTask.id == currentChildId); | ||
if (isValid(childTask)) { | ||
printTaskAndChildren(childTask, newDepth); | ||
} else { | ||
console.log(`found no child: for ${task.title}`) | ||
} | ||
|
||
|
||
}); | ||
// printTaskAndChildren(---) | ||
|
||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
testTick(); | ||
|
||
|
||
|
||
|
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
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
export function isValid(variable: any) | ||
{ | ||
// console.log(`${variable} is ${typeof variable}`) | ||
let retValue = false; | ||
if (variable != null && variable !== 'undefined') { | ||
if (Array.isArray(variable) && variable.length > 0) { | ||
retValue = true; | ||
} else { | ||
// console.log(typeof variable) | ||
if (typeof variable == 'string') { | ||
retValue = variable.length > 0; | ||
} else if (typeof variable == 'object') { | ||
// console.log(Object.keys(variable)) | ||
retValue = Object.keys(variable).length !== 0; | ||
} | ||
} | ||
retValue = true; | ||
} else { | ||
retValue = false; | ||
} | ||
// console.log(`is valid: ${retValue}`) | ||
return retValue; | ||
} |