Commit b9d47c56 authored by Daniel Weisser's avatar Daniel Weisser
Browse files

Add stub due extension

parent 4f87df4e
"use strict";
import { translations, userData, _paq } from "../render.js";
import { resizeInput } from "./form.mjs";
import { RecExtension } from "./todotxtExtensions.mjs";
import { RecExtension, SugarDueExtension } from "./todotxtExtensions.mjs";
import Datepicker from "../../node_modules/vanillajs-datepicker/js/Datepicker.js";
import de from "../../node_modules/vanillajs-datepicker/js/i18n/locales/de.js";
import it from "../../node_modules/vanillajs-datepicker/js/i18n/locales/it.js";
......@@ -19,7 +19,7 @@ datePickerInput.addEventListener("changeDate", function (e) {
// we only update the object if there is a date selected. In case of a refresh it would throw an error otherwise
if(e.detail.date) {
// generate the object on what is written into input, so we don't overwrite previous inputs of user
let todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new DueExtension(), new HiddenExtension(), new RecExtension() ]);
let todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new SugarDueExtension(), new HiddenExtension(), new RecExtension() ]);
todo.due = new Date(e.detail.date);
todo.dueString = new Date(e.detail.date.getTime() - (e.detail.date.getTimezoneOffset() * 60000 )).toISOString().split("T")[0];
// if suggestion box was open, it needs to be closed
......@@ -51,7 +51,7 @@ const datePicker = new Datepicker(datePickerInput, {
}
});
document.querySelector(".datepicker .clear-btn").onclick = function() {
let todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new DueExtension(), new HiddenExtension(), new RecExtension() ]);
let todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new SugarDueExtension(), new HiddenExtension(), new RecExtension() ]);
todo.due = undefined;
todo.dueString = undefined;
document.getElementById("modalFormInput").value = todo.toString();
......
"use strict";
import { showMore, resetModal, handleError, userData, setUserData, translations, _paq } from "../render.js";
import { RecExtension } from "./todotxtExtensions.mjs";
import { RecExtension, SugarDueExtension } from "./todotxtExtensions.mjs";
import { generateFilterData } from "./filters.mjs";
import { items, item, setTodoComplete } from "./todos.mjs";
import { datePickerInput } from "./datePicker.mjs";
......@@ -179,7 +179,7 @@ function setPriority(priority) {
});
}
}
let todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new DueExtension(), new HiddenExtension(), new RecExtension() ]);
let todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new SugarDueExtension(), new HiddenExtension(), new RecExtension() ]);
if((priority==="down" || priority==="up") && !todo.priority) {
todo.priority = "A";
} else if(priority==="up" && todo.priority!="a") {
......@@ -206,7 +206,7 @@ function setPriority(priority) {
}
function setDueDate(days) {
try {
const todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new DueExtension(), new HiddenExtension(), new RecExtension() ]);
const todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new SugarDueExtension(), new HiddenExtension(), new RecExtension() ]);
if(days===0) {
todo.due = undefined;
todo.dueString = undefined;
......@@ -244,7 +244,7 @@ function show(todo, templated) {
// replace invisible multiline ascii character with new line
todo = todo.replaceAll(String.fromCharCode(16),"\r\n");
// we need to check if there already is a due date in the object
todo = new TodoTxtItem(todo, [ new DueExtension(), new HiddenExtension(), new RecExtension() ]);
todo = new TodoTxtItem(todo, [ new SugarDueExtension(), new HiddenExtension(), new RecExtension() ]);
// set the priority
setPriority(todo.priority);
//
......@@ -324,7 +324,7 @@ function submitForm() {
const index = items.objects.map(function(item) {return item.toString(); }).indexOf(modalForm.getAttribute("data-item"));
// create a todo.txt object
// replace new lines with spaces (https://stackoverflow.com/a/34936253)
let todo = new TodoTxtItem(modalForm.elements[0].value.replaceAll(/[\r\n]+/g, String.fromCharCode(16)), [ new DueExtension(), new HiddenExtension(), new RecExtension() ]);
let todo = new TodoTxtItem(modalForm.elements[0].value.replaceAll(/[\r\n]+/g, String.fromCharCode(16)), [ new SugarDueExtension(), new HiddenExtension(), new RecExtension() ]);
// check and prevent duplicate todo
if(items.objects.map(function(item) {return item.toString(); }).indexOf(todo.toString())!=-1) {
modalFormAlert.innerHTML = translations.formInfoDuplicate;
......@@ -344,7 +344,7 @@ function submitForm() {
} else if(modalForm.getAttribute("data-item")==null && modalForm.elements[0].value!="") {
// in case there hasn't been a passed data item, we just push the input value as a new item into the array
// replace new lines with spaces (https://stackoverflow.com/a/34936253)
let todo = new TodoTxtItem(modalForm.elements[0].value.replaceAll(/[\r\n]+/g, String.fromCharCode(16)), [ new DueExtension(), new HiddenExtension(), new RecExtension() ]);
let todo = new TodoTxtItem(modalForm.elements[0].value.replaceAll(/[\r\n]+/g, String.fromCharCode(16)), [ new SugarDueExtension(), new HiddenExtension(), new RecExtension() ]);
// we add the current date to the start date attribute of the todo.txt object
todo.date = new Date();
// check and prevent duplicate todo
......
......@@ -85,7 +85,7 @@ function showRecurrences() {
recurrencePickerContainer.focus();
recurrencePickerContainer.classList.toggle("is-active");
// get object from current input
let todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new DueExtension(), new HiddenExtension(), new RecExtension() ]);
let todo = new TodoTxtItem(document.getElementById("modalFormInput").value, [ new SugarDueExtension(), new HiddenExtension(), new RecExtension() ]);
let recSplit = recurrences.splitRecurrence(todo.rec);
setRecurrenceOptionLabels(recSplit.mul);
recurrencePickerSpinner.value = recSplit.mul;
......
"use strict";
import { userData, appData, handleError, translations, setUserData, _paq, startBuilding } from "../render.js";
import { RecExtension } from "./todotxtExtensions.mjs";
import { RecExtension, SugarDueExtension } from "./todotxtExtensions.mjs";
import { categories } from "./filters.mjs";
import { generateRecurrence } from "./recurrences.mjs";
import { convertDate, isToday, isTomorrow, isPast } from "./date.mjs";
......@@ -109,7 +109,7 @@ function configureTodoTableTemplate(append) {
}
function generateItems(content) {
try {
items = { objects: TodoTxt.parse(content, [ new DueExtension(), new RecExtension(), new HiddenExtension() ]) }
items = { objects: TodoTxt.parse(content, [ new SugarDueExtension(), new RecExtension(), new HiddenExtension() ]) }
items.objects = items.objects.filter(function(item) {
if(!item.text) return false;
return true;
......@@ -450,7 +450,7 @@ function setTodoComplete(todo) {
// in case edit form is open, text has changed and complete button is pressed, we do not fall back to the initial value of todo but instead choose input value
if(modalForm.elements[0].value) todo = modalForm.elements[0].value;
// first convert the string to a todo.txt object
todo = new TodoTxtItem(todo, [ new DueExtension(), new RecExtension(), new HiddenExtension() ]);
todo = new TodoTxtItem(todo, [ new SugarDueExtension(), new RecExtension(), new HiddenExtension() ]);
// get index of todo
const index = items.objects.map(function(item) {return item.toString(); }).indexOf(todo.toString());
// mark item as in progress
......@@ -493,7 +493,7 @@ function setTodoDelete(todo) {
// in case edit form is open, text has changed and complete button is pressed, we do not fall back to the initial value of todo but instead choose input value
if(modalForm.elements[0].value) todo = modalForm.elements[0].value;
// first convert the string to a todo.txt object
todo = new TodoTxtItem(todo, [ new DueExtension(), new RecExtension(), new HiddenExtension() ]);
todo = new TodoTxtItem(todo, [ new SugarDueExtension(), new RecExtension(), new HiddenExtension() ]);
// get index of todo
const index = items.objects.map(function(item) {return item.toString(); }).indexOf(todo.toString());
// Delete item
......@@ -534,7 +534,7 @@ async function archiveTodos() {
const getContentFromDoneFile = new Promise(function(resolve, reject) {
window.api.send("getContent", doneFile());
return window.api.receive("getContent", (content) => {
//resolve(TodoTxt.parse(content, [ new DueExtension(), new HiddenExtension(), new RecExtension() ]));
//resolve(TodoTxt.parse(content, [ new SugarDueExtension(), new HiddenExtension(), new RecExtension() ]));
resolve(content);
});
});
......
......@@ -14,3 +14,21 @@ RecExtension.prototype.parsingFunction = function(line) {
};
export { RecExtension };
function SugarDueExtension() {
this.name = "due";
}
SugarDueExtension.prototype = new TodoTxtExtension();
SugarDueExtension.prototype.parsingFunction = function(line) {
var dueDate = null;
var dueRegex = /due:([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})\s*/;
var matchDue = dueRegex.exec(line);
if ( matchDue !== null ) {
var datePieces = matchDue[1].split('-');
dueDate = new Date( datePieces[0], datePieces[1] - 1, datePieces[2] );
return [dueDate, line.replace(dueRegex, ''), matchDue[1]];
}
return [null, null, null];
};
export { SugarDueExtension };
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment