Commit 3ed3f1d6 authored by ransome1's avatar ransome1
Browse files

Saving to file will only affect single lines. Archiving is WIP

parent 117ae0d0
......@@ -132,10 +132,11 @@
"sass": "sass -w src/scss/style.scss:src/css/style.css",
"start": "yarn sass & electron .",
"test": "yarn playwright test --config=test/playwright.config.js",
"test1": "yarn playwright test -g 'Check if multi line items are displayed correctly' --config=test/playwright.config.js"
"test1": "yarn playwright test -g 'Add a new todo and delete it' --config=test/playwright.config.js"
},
"dependencies": {
"@fortawesome/fontawesome-free": "^6.1.1",
"@playwright/test": "^1.23.1",
"bulma": "^0.9.2",
"chokidar": "^3.5.1",
"electron-notarize": "^1.1.1",
......@@ -146,6 +147,7 @@
"jstodotxt": "^0.10.0",
"marked": "^4.0.12",
"peggy": "^1.2.0",
"playwright": "^1.23.1",
"sass": "^1.34.1",
"sugar": "^2.0.6",
"vanillajs-datepicker": "^1.1.4"
......
......@@ -126,7 +126,8 @@ modalForm.onsubmit = async function(event) {
item.previous = todo;
// send file to main process to save it
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
//window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
window.api.send("writeToFile", [todo.toString(), index]);
// close and clean up the modal
resetForm().then(function(response) {
......
......@@ -566,11 +566,9 @@ async function createTodoContext(todoTableRow) {
if(userData.matomoEvents) _paq.push(["trackEvent", "Todo-Table-Context", "Click on Copy"]);
}
const deleteTodo = async function() {
// remove item at index
items.objects.splice(index, 1);
//write the data to the file
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
//send index to main process in order to delete line
window.api.send("writeToFile", [undefined, index, undefined]);
todoContext.classList.remove("is-active");
todoContext.removeAttribute("data-item");
......@@ -580,25 +578,27 @@ async function createTodoContext(todoTableRow) {
}
const changePriority = function(direction) {
const todo = items.objects[index];
let nextIndex = 97;
// in case a todo has no priority and the 1st grouping method is priority
if(!items.objects[index].priority && userData.sortBy[0] === "priority") {
if(!todo.priority && userData.sortBy[0] === "priority") {
const index = items.grouped.length - 2;
// this receives the lowest available priority group
(index >= 0) ? nextIndex = items.grouped[index][0].toLowerCase().charCodeAt(0) : nextIndex = 97
// change priority based on current priority
} else if(items.objects[index].priority) {
const currentPriority = items.objects[index].priority.toLowerCase().charCodeAt(0)
} else if(todo.priority) {
const currentPriority = todo.priority.toLowerCase().charCodeAt(0)
nextIndex = currentPriority + direction;
}
if(nextIndex <= 96 || nextIndex >= 123) return false
items.objects[index].priority = String.fromCharCode(nextIndex).toUpperCase();
todo.priority = String.fromCharCode(nextIndex).toUpperCase();
//write the data to the file
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
window.api.send("writeToFile", [todo.toString(), index]);
todoContext.classList.remove("is-active");
todoContext.removeAttribute("data-item");
......@@ -756,11 +756,8 @@ async function setTodoComplete(todo) {
}
// delete old todo from array and add the new one at it's position
await items.objects.splice(index, 1, todo);
//write the data to the file and advice to focus the row after reload
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
window.api.send("writeToFile", [todo.toString(), index]);
return Promise.resolve("Success: Changes written to file: " + getActiveFile());
......@@ -789,11 +786,8 @@ async function addTodo(todo) {
const index = items.objects.map(function(item) { return item.toString(); }).indexOf(todo.toString());
if(index === -1) {
// we build the array
items.objects.push(todo);
//write the data to the file
// a newline character is added to prevent other todo.txt apps to append new todos to the last line
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
window.api.send("writeToFile", [todo.toString(), index]);
return Promise.resolve("Success: New todo added to file: " + getActiveFile());
......@@ -806,11 +800,8 @@ async function addTodo(todo) {
}
function editTodo(index, todo) {
try {
// put changed todo at old position
items.objects.splice(index, 1, todo);
// save to file
window.api.send("writeToFile", [items.objects.join("\n").toString() + "\n"]);
window.api.send("writeToFile", [todo.toString(), index]);
return Promise.resolve("Success: Todo edited");
......@@ -852,10 +843,10 @@ async function archiveTodos() {
}
//write completed items to done file
window.api.send("writeToFile", [completeTodos.join("\n").toString() + "\n", doneFile]);
window.api.send("replaceFileContent", [completeTodos.join("\n").toString(), doneFile]);
// write incompleted items to todo file
window.api.send("writeToFile", [incompleteTodos.join("\n").toString() + "\n", activeFile]);
window.api.send("replaceFileContent", [incompleteTodos.join("\n").toString(), activeFile]);
// send notifcation on success
generateGenericNotification(translations.archivingCompletedTitle, translations.archivingCompletedBody + doneFile).then(function(response) {
......
......@@ -453,15 +453,45 @@ function configureWindowEvents() {
nativeTheme.themeSource = theme;
userData.set("theme", nativeTheme.themeSource);
})
.on("writeToFile", function(event, args) {
.on("replaceFileContent", async function(event, args) {
const content = args[0];
let file = args[1];
if(!file) file = getActiveFile()[1]
const file = args[1];
if(process.mas) stopAccessingSecurityScopedResource = app.startAccessingSecurityScopedResource(getActiveFile()[3])
fs.writeFileSync(file, content, {encoding: "utf-8"});
if(process.mas) stopAccessingSecurityScopedResource()
})
.on("writeToFile", async function(event, args) {
const index = args[1];
console.log(index)
const data = args[0];
const file = (args[2]) ? args[2] : await getActiveFile()[1];
const fileContent = await getContent(file);
let fileAsArray = fileContent.split("\n");
// adding a new line or replacing an existing one
(index === -1 && data) ? fileAsArray.push(data) : fileAsArray.splice(index, 1, data);
// delete element in array
if(index >= 0 && !data) fileAsArray.splice(index, 1);
//if(index === undefined && data) contentToWrite = data;
// building string to write in file
// when file is defined, but no index, it will be an archiving operation
const contentToWrite = fileAsArray.join("\n");
// only for MAS (Sandboxed)
// https://gist.github.com/ngehlert/74d5a26990811eed59c635e49134d669
if(process.mas) stopAccessingSecurityScopedResource = app.startAccessingSecurityScopedResource(getActiveFile()[3])
fs.writeFileSync(file, content, {encoding: "utf-8"});
fs.writeFileSync(file, contentToWrite, {encoding: "utf-8"});
if(process.mas) stopAccessingSecurityScopedResource()
......
......@@ -6,6 +6,7 @@ const validChannels = [
"getContent",
"translations",
"showNotification",
"replaceFileContent",
"writeToFile",
"startFileWatcher",
"buildTable",
......
This is a test todo that needs to be cleaned up
\ No newline at end of file
......@@ -25,3 +25,4 @@ x 2022-04-07 This is a test todo that needs to be archived
x 2022-04-08 This is a test todo that needs to be archived
x 2022-04-12 This is a test todo that needs to be archived
x 2022-06-13 This is a test todo that needs to be archived
x 2022-07-01 This is a test todo that needs to be archived
\ No newline at end of file
......@@ -8,9 +8,9 @@
integrity sha512-sAP4LldeWNz0lNzmTird3uWfFDWWTeg6V/MsmyyLR9X1idwKBWIgt/ZvinqQldJm3LecKEs1emkbquO6PCiLVQ==
"@babel/runtime@^7.17.2":
version "7.18.3"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.18.3.tgz#c7b654b57f6f63cf7f8b418ac9ca04408c4579f4"
integrity sha512-38Y8f7YUhce/K7RMwTp7m0uCumpv9hZkitCbBClqQIow1qSbCvGkcegKOXpEWCQLfWmevgRiWokZ1GkpfhbZug==
version "7.18.6"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.18.6.tgz#6a1ef59f838debd670421f8c7f2cbb8da9751580"
integrity sha512-t9wi7/AW6XtKahAe20Yw0/mMljKq0B1r2fPdvaAdV/KPDZewFXdaaa6K7lxmZBZ8FBNpCiAT6iHPmd6QO9bKfQ==
dependencies:
regenerator-runtime "^0.13.4"
......@@ -102,6 +102,14 @@
lodash "^4.17.15"
tmp-promise "^3.0.2"
"@playwright/test@^1.23.1":
version "1.23.1"
resolved "https://registry.yarnpkg.com/@playwright/test/-/test-1.23.1.tgz#209cceb81c579d1cd2835f15c2bb3a8345103d60"
integrity sha512-dKplLPSYPZgnsBk1xxOophhpx3ZVg8DveoNJgLPe096lDCfmaIIreLsYF+4hqzy3PG61IP+aEnG5VAOjC3bhbA==
dependencies:
"@types/node" "*"
playwright-core "1.23.1"
"@sindresorhus/is@^0.14.0":
version "0.14.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
......@@ -905,9 +913,9 @@ electron-windows-badge@^1.1.0:
integrity sha512-hWFbUk9u3fQHcKzTAcjZAN7XH9bL9oH9g20RRDU/DVDNqdMI03GzlBZfR/R8R1krYu9AT4biLqSCAxnt9LMAfA==
electron@^17.2.0:
version "17.4.8"
resolved "https://registry.yarnpkg.com/electron/-/electron-17.4.8.tgz#a7940d125c120d51aa0c737c10d17851dada295d"
integrity sha512-JUHTFcBCXols+REajy9YQNypcgRGu35u/8oDmLIvjvrfIL4/Z3YAiq8HN4mhclWfuSmznrLeZ8uMktZWmvPOAg==
version "17.4.9"
resolved "https://registry.yarnpkg.com/electron/-/electron-17.4.9.tgz#d323dac4151e24f7345250414c3bc540c6576811"
integrity sha512-DuoCyjTo29TNAaI2eEurN78zvzKQBBZGKjmsy0qEyUaJmgAFzPHDGwVsX9BqativzkboNvXEKXnseHe5CbLiyg==
dependencies:
"@electron/get" "^1.13.0"
"@types/node" "^14.6.2"
......@@ -1129,9 +1137,9 @@ flat-cache@^3.0.4:
rimraf "^3.0.2"
flatted@^3.1.0:
version "3.2.5"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3"
integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==
version "3.2.6"
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.6.tgz#022e9218c637f9f3fc9c35ab9c9193f05add60b2"
integrity sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==
form-data@^4.0.0:
version "4.0.0"
......@@ -1378,9 +1386,9 @@ i18next-fs-backend@^1.1.1:
integrity sha512-/MfAGMP0jHonV966uFf9PkWWuDjPYLIcsipnSO3NxpNtAgRUKLTwvm85fEmsF6hGeu0zbZiCQ3W74jwO6K9uXA==
i18next@^21.6.6:
version "21.8.10"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-21.8.10.tgz#12f164cc0f5f7904f0d4e0cfdf5950b93793d171"
integrity sha512-7xRb6y4QlSqZRZ3uA5BIEsLuZpmxpzHLizQyKjDDThOcvdfgICOX7aFoBnh4BSWcLtJamTqSweaOuK22A2xqkA==
version "21.8.11"
resolved "https://registry.yarnpkg.com/i18next/-/i18next-21.8.11.tgz#197aac04be51b7083999a2cb63deb831cf1ba4c8"
integrity sha512-+s8N6kQShwNK+Ua/+VsS/Sji24NUJJLBk9QIucygj1f97f4hPNDWmLP9fQCI4d5+XLfXJ3JctX4g+zJla967Vw==
dependencies:
"@babel/runtime" "^7.17.2"
......@@ -1894,6 +1902,18 @@ pify@^3.0.0:
resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176"
integrity sha512-C3FsVNH1udSEX48gGX1xfvwTWfsYWj5U+8/uK15BGzIGrKoUpghX8hWZwa/OFnakBiiVNmBvemTJR5mcy7iPcg==
playwright-core@1.23.1:
version "1.23.1"
resolved "https://registry.yarnpkg.com/playwright-core/-/playwright-core-1.23.1.tgz#af02bd7568af1017e477433b1b003ba84e1eb312"
integrity sha512-9CXsE0gawph4KXl6oUaa0ehHRySZjHvly4TybcBXDvzK3N3o6L/eZ8Q6iVWUiMn0LLS5bRFxo1qEtOETlYJxjw==
playwright@^1.23.1:
version "1.23.1"
resolved "https://registry.yarnpkg.com/playwright/-/playwright-1.23.1.tgz#b029885e995aa1f9626aac851410c5ef615718f4"
integrity sha512-+lgiy1JZMNPwpBp5tsUdjTGxuJ+lXZbtSKmMDc0/f1oVsNDXXA+r7zeC9Kzd+4jSHteoJJocargxVx2Mn1o2kw==
dependencies:
playwright-core "1.23.1"
plist@^3.0.1, plist@^3.0.4:
version "3.0.5"
resolved "https://registry.yarnpkg.com/plist/-/plist-3.0.5.tgz#2cbeb52d10e3cdccccf0c11a63a85d830970a987"
......
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