diff --git a/Taskido/view.js b/Taskido/view.js index 229aca0..e1b15d9 100644 --- a/Taskido/view.js +++ b/Taskido/view.js @@ -1,4 +1,4 @@ -let {pages, inbox, select, taskfiles, globalTaskFilter, dailyNoteFolder, dailyNoteFormat, counterAction, done, sort, carryForwardOverdue, carryForwardUnplanned, carryForwardStars, dateFormat, options} = input; +let {pages, inbox, select, taskOrder, taskFiles, globalTaskFilter, dailyNoteFolder, dailyNoteFormat, done, sort, carryForwardOverdue, carryForwardUnplanned, carryForwardStars, dateFormat, options} = input; // Error Handling if (!pages && pages!="") { dv.span('> [!ERROR] Missing pages parameter\n> \n> Please set the pages parameter like\n> \n> `pages: ""`'); return false }; @@ -6,20 +6,17 @@ if (dailyNoteFormat) { if (dailyNoteFormat.match(/[|\\YMDWwd.,-: \[\]]/g).length // Get, Set, Eval Pages if (pages=="") { var tasks = dv.pages().file.tasks } else { if (pages.startsWith("dv.pages")) { var tasks = eval(pages) } else { var tasks = dv.pages(pages).file.tasks } }; -if (!taskfiles) { taskfiles = [...new Set(dv.pages().file.map(f=>f.tasks.filter(t=>!t.completed)).path)].sort(); } else { if (taskfiles.startsWith("dv.pages")) { taskfiles = eval(taskfiles) } else { taskfiles = dv.pages(taskfiles).file.path } }; - +if (!taskFiles) { taskFiles = [...new Set(dv.pages().file.map(f=>f.tasks.filter(t=>!t.completed)).path)].sort(); } else { taskFiles = [...new Set(dv.pagePaths(taskFiles))].sort() }; if (!options) {options = ""}; if (!dailyNoteFolder) {dailyNoteFolder = ""} else {dailyNoteFolder = dailyNoteFolder+"/"}; if (!dailyNoteFormat) {dailyNoteFormat = "YYYY-MM-DD"}; -var taskOrder = ["done", "overdue", "due", "scheduled", "start", "process", "unplanned", "star"] -if (!sort) {sort = "t => t.order"}; -if (!counterAction) {counterAction = "Focus"} else { counterAction = counterAction[0].toUpperCase() + counterAction.slice(1);}; +if (!taskOrder) {taskOrder = ["overdue", "due", "scheduled", "start", "process", "unplanned","done"]}; +if (!sort) {sort = "t=>t.order"}; if (!dateFormat) {dateFormat = "ddd, MMM D"}; -if (!select) {select = "todaysDailyNote"}; +if (!select) {select = "dailyNote"}; // Variables var timelineDates = []; -var timelineNotes = dv.pages().file.filter(f=>f.starred == true && timelineDates.push(moment(f.cday.toString()).format("YYYY-MM-DD")) ); var tid = (new Date()).getTime(); var today = moment().format("YYYY-MM-DD"); var dailyNoteRegEx = momentToRegex(dailyNoteFormat); @@ -40,7 +37,6 @@ var addIcon = ' moment().format("YYYY-MM-DD") ) { happens["due"] = fieldDate; tasks[i].order = 7; + tasks[i].order = taskOrder.indexOf("due"); timelineDates.push(fieldDate); }; } else if (tasks[i].completed == true) { if (fieldKey == "completion") { happens["done"] = fieldDate; tasks[i].order = 1; + tasks[i].order = taskOrder.indexOf("done"); }; }; }; @@ -143,9 +148,11 @@ function getMeta(tasks) { if ( startMatch[1] < moment().format("YYYY-MM-DD") ) { happens["process"] = moment().format("YYYY-MM-DD"); tasks[i].order = 6; + tasks[i].order = taskOrder.indexOf("process"); } else { happens["start"] = startMatch[1]; tasks[i].order = 8; + tasks[i].order = taskOrder.indexOf("start"); timelineDates.push(startMatch[1]); }; } else if (startMatch && tasks[i].completed == true) { @@ -157,9 +164,11 @@ function getMeta(tasks) { if ( scheduledMatch[1] < moment().format("YYYY-MM-DD") ) { happens["process"] = moment().format("YYYY-MM-DD"); tasks[i].order = 6; + tasks[i].order = taskOrder.indexOf("process"); } else { happens["scheduled"] = scheduledMatch[1]; tasks[i].order = 4; + tasks[i].order = taskOrder.indexOf("scheduled"); timelineDates.push(scheduledMatch[1]); }; } else if (scheduledMatch && tasks[i].completed == true) { @@ -172,20 +181,24 @@ function getMeta(tasks) { if (carryForwardOverdue == true) { happens["overdue"] = moment().format("YYYY-MM-DD"); tasks[i].order = 2; + tasks[i].order = taskOrder.indexOf("overdue"); tasks[i].relative = moment(dueMatch[1]).fromNow(); } else { happens["overdue"] = dueMatch[1]; tasks[i].order = 2; + tasks[i].order = taskOrder.indexOf("overdue"); timelineDates.push(dueMatch[1]); }; } else if ( dueMatch[1] == moment().format("YYYY-MM-DD") ) { happens = {}; // Clear Object !!! happens["due"] = dueMatch[1]; tasks[i].order = 3; + tasks[i].order = taskOrder.indexOf("due"); timelineDates.push(dueMatch[1]); } else if ( dueMatch[1] > moment().format("YYYY-MM-DD") ) { happens["due"] = dueMatch[1]; tasks[i].order = 3; + tasks[i].order = taskOrder.indexOf("due"); timelineDates.push(dueMatch[1]); }; } else if (dueMatch && tasks[i].completed == true) { @@ -198,6 +211,7 @@ function getMeta(tasks) { timelineDates.push(doneMatch[1]); happens["done"] = doneMatch[1]; tasks[i].order = 1; + tasks[i].order = taskOrder.indexOf("done"); }; }; var repeatMatch = taskText.match(/🔁 ?([a-zA-Z0-9, !]+)/) @@ -260,13 +274,13 @@ function getMeta(tasks) { function getSelectOptions() { // Push daily note and Inbox files - const currentDailyNote = dailyNoteFolder + moment().format(dailyNoteFormat) + ".md" - taskfiles.push(currentDailyNote); - if (inbox) {taskfiles.push(inbox)}; - taskfiles = [...new Set(taskfiles)].sort(); + const currentDailyNote = dailyNoteFolder + moment().format(dailyNoteFormat) + ".md"; + taskFiles.push(currentDailyNote); + if (inbox) {taskFiles.push(inbox)}; + taskFiles = [...new Set(taskFiles)].sort(); // Loop files const fileSelect = rootNode.querySelector('.fileSelect'); - taskfiles.forEach(function(file) { + taskFiles.forEach(function(file) { var opt = document.createElement('option'); opt.value = file; var secondParentFolder = file.split("/")[file.split("/").length - 3] == null ? "" : "… / "; @@ -276,7 +290,7 @@ function getSelectOptions() { opt.title = file; if (select && file == select) { opt.setAttribute('selected', true); - } else if (select && select == "todaysDailyNote" && file == currentDailyNote) { + } else if (select && select == "dailyNote" && file == currentDailyNote) { opt.setAttribute('selected', true); }; fileSelect.appendChild(opt); @@ -285,13 +299,13 @@ function getSelectOptions() { function setEvents() { rootNode.querySelectorAll('.counter').forEach(cnt => cnt.addEventListener('click', (() => { - var activeFocus = Array.from(rootNode.classList).filter(c=>c.endsWith(counterAction) && !c.startsWith("today")); - if (activeFocus == cnt.id+counterAction) { + var activeFocus = Array.from(rootNode.classList).filter(c=>c.endsWith("Filter") && !c.startsWith("today")); + if (activeFocus == cnt.id+"Filter") { rootNode.classList.remove(activeFocus); return false; }; - rootNode.classList.remove.apply(rootNode.classList, Array.from(rootNode.classList).filter(c=>c.endsWith(counterAction) && !c.startsWith("today"))); - rootNode.classList.add(cnt.id+counterAction); + rootNode.classList.remove.apply(rootNode.classList, Array.from(rootNode.classList).filter(c=>c.endsWith("Filter") && !c.startsWith("today"))); + rootNode.classList.add(cnt.id+"Filter"); }))); rootNode.querySelector('.todayHeader').addEventListener('click', (() => { rootNode.classList.toggle("todayFocus"); @@ -483,7 +497,6 @@ function getTimeline(tasks) { for (i=0; imoment(n.cday.toString()).format("YYYY-MM-DD") == timelineDates[i]); var tasksFiltered = tasks.filter(t=>Object.values(t.happens).includes(timelineDates[i].toString())).sort(eval(sort)); var relative = moment(timelineDates[i].toString()).fromNow(); var date = moment(timelineDates[i].toString()).format(dateFormat); @@ -599,13 +612,6 @@ function getTimeline(tasks) { var task = "
" + eval(cls+"Icon") + "
" + info + "
" + text + "
"; content += task; }); - - notesFiltered.forEach(function(note) { - var star = "
" + starIcon + "
" + note.name + "
"; - content += star; - containedTypesPerDay.push("star"); - containedTypesPerYear.push("star"); - }); // Add Task For Today if (timelineDates[i] == today) {