Commit 0580e986 authored by ransome1's avatar ransome1
Browse files

Fixed wrong date conversion, worked on ipc interactions, null is not any...

 Fixed wrong date conversion, worked on ipc interactions, null is not any longer added to text field
parent 72f499ab
{
"name": "sleek",
"productName": "sleek",
"version": "1.1.7",
"version": "1.1.8-rc.3",
"description": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)",
"synopsis": "todo.txt manager for Linux, Windows and MacOS, free and open-source (FOSS)",
"category": "ProjectManagement",
......
......@@ -152,6 +152,11 @@ body.dark a.projects:focus-visible {
background: #491949 !important;
color: white !important;
}
body.dark a.button.is-greyed-out {
background: #3273dc !important;
color: white !important;
filter: opacity(50%) grayscale(100%);
}
body.dark #drawerContainer .zoom svg {
color: white !important;
}
......
This diff is collapsed.
"use strict";
// converts a date object into a todo.txt compatible string xxxx-xx-xx
// https://bobbyhadz.com/blog/javascript-format-date-yyyy-mm-dd
function convertDate(date) {
let day = ("0" + (date.getDate())).slice(-2)
let month = ("0" + (date.getMonth() + 1)).slice(-2);
let year = date.getFullYear();
return year + "-" + month + "-" + day;
if(typeof date === "string") {
const datePieces = (date.split("-"));
return new Date( datePieces[0], datePieces[1] - 1, datePieces[2] );
}
const padTo2Digits = function(num) {
return num.toString().padStart(2, '0');
}
return [
date.getFullYear(),
padTo2Digits(date.getMonth() + 1),
padTo2Digits(date.getDate()),
].join('-');
}
function isToday(date) {
const today = new Date()
......
......@@ -9,7 +9,7 @@
import { userData } from "../render.js";
import { _paq } from "./matomo.mjs";
import { resizeInput } from "./form.mjs";
import { formatDate } from "./helper.mjs";
import { convertDate } from "./date.mjs";
import { generateTodoTxtObject, items, editTodo } from "./todos.mjs";
import Datepicker from "../../node_modules/vanillajs-datepicker/js/Datepicker.js";
import de from "../../node_modules/vanillajs-datepicker/js/i18n/locales/de.js";
......@@ -77,7 +77,7 @@ async function createDatepickerInstance(attachToElement, addDateToElement, exten
// fill in due date
if(date) {
todo[extension] = date;
todo[extension + "String"] = formatDate(date);
todo[extension + "String"] = convertDate(date);
// reset due date in object
} else {
todo[extension] = undefined;
......
......@@ -433,6 +433,7 @@ function generateFilterButtons(category, autoCompletePrefix) {
// add attributes
todoFiltersItem.setAttribute("data-filter", filter);
todoFiltersItem.setAttribute("data-category", category);
todoFiltersItem.setAttribute("data-prefix", autoCompletePrefix);
todoFiltersItem.classList.add("button", category);
todoFiltersItem.setAttribute("tabindex", 0)
todoFiltersItem.setAttribute("href", "#")
......
......@@ -59,7 +59,6 @@ export function jumpToItem(item) {
return Promise.reject(error);
}
}
export async function pasteItemToClipboard(item) {
try {
......@@ -73,7 +72,6 @@ export async function pasteItemToClipboard(item) {
return Promise.reject(error);
}
}
export async function pasteItemsToClipboard() {
try {
......@@ -180,11 +178,10 @@ export function initialSetupInterface() {
(userData.darkmode) ? body.classList.add("dark") : body.classList.remove("dark");
// set scaling factor if default font size has changed
//if(userData.zoom) {
document.getElementById("html").style.zoom = userData.zoom + "%";
document.getElementById("zoomStatus").innerHTML = userData.zoom + "%";
document.getElementById("zoom").value = userData.zoom;
//}
document.getElementById("html").style.zoom = userData.zoom + "%";
document.getElementById("zoomStatus").innerHTML = userData.zoom + "%";
document.getElementById("zoom").value = userData.zoom;
// add version number to about tab in settings modal
document.getElementById("version").innerHTML = appData.version;
......@@ -302,21 +299,6 @@ export function debounce(func, wait, immediate) {
if (callNow) func.apply(context, args);
};
}
// https://bobbyhadz.com/blog/javascript-format-date-yyyy-mm-dd
export function formatDate(date) {
const padTo2Digits = function(num) {
return num.toString().padStart(2, '0');
}
return [
date.getFullYear(),
padTo2Digits(date.getMonth() + 1),
padTo2Digits(date.getDate()),
].join('-');
}
export async function setDueDate(days) {
try {
......
......@@ -10,7 +10,7 @@ import { triggerToggle } from "./toggles.mjs";
//const render = await import("../render.js");
// receives todo.txt data from main process as string and passes it to build function
window.api.receive("buildTable", async (args) => {
window.api.receive("buildTable", (args) => {
buildTable(...args).then(function(response) {
console.info(response);
}).catch(function(error) {
......
......@@ -437,6 +437,7 @@ export async function registerShortcuts() {
// ******************************************************
if((event.ctrlKey || event.metaKey && userData.files) && event.key === "c" && !isInputFocused()) {
if(!getActiveFile()) return false;
pasteItemsToClipboard();
return false;
}
......@@ -447,22 +448,23 @@ export async function registerShortcuts() {
if((event.ctrlKey || event.metaKey) && event.key === "w") {
// if only 1 tab element is visible, if won't be removed and instead the browser window is being closed
const visibleTabs = userData.files.filter(file => file[2] === 1);
if(visibleTabs.length === 1) {
window.api.send("closeWindow");
return false;
}
// get active tab
const index = userData.files.findIndex(file => file[0] === 1);
// remove active file from tab bar
await removeFileFromList(index, false).then(function(response) {
removeFileFromList(index, false).then(function(response) {
console.info(response);
}).catch(function(error) {
handleError(error);
});
// if no visible tab is left, window is being closed
const visibleTabs = userData.files.findIndex(file => file[2] === 1);
// if all files are removed from tab bar, window will be closed
if(visibleTabs === -1) window.api.send("closeWindow");
return false;
}
......
......@@ -27,7 +27,7 @@ function configureMatomo() {
if(!navigator.onLine) return Promise.resolve("Info: App is offline, Matomo will not be loaded");
// only continue if machine is no dvelopment machine
if(appData.environment) return Promise.resolve("Info: No tracking in development and testing environment");
if(appData.environment || userData.uid === "development") return Promise.resolve("Info: No tracking in development and testing environment");
if(!userData.uid) {
// generate random number/string combination as user id and persist it
......
......@@ -9,7 +9,7 @@ import { convertDate, isToday, isTomorrow, isPast } from "./date.mjs";
import { createModalJail } from "./jail.mjs";
import { focusRow } from "./keyboard.mjs";
import { generateRecurrence } from "./recurrences.mjs";
import { getActiveFile, getDoneFile, handleError, formatDate, pasteItemToClipboard, generateGenericNotification, generateTodoNotification } from "./helper.mjs";
import { getActiveFile, getDoneFile, handleError, pasteItemToClipboard, generateGenericNotification, generateTodoNotification } from "./helper.mjs";
import { getConfirmation } from "./prompt.mjs";
import { show } from "./form.mjs";
import { SugarDueExtension, RecExtension, ThresholdExtension } from "./todotxtExtensions.mjs";
......@@ -73,7 +73,7 @@ async function generateTodoTxtObjects(fileContent) {
try {
// create todo.txt objects
items.objects = await TodoTxt.parse(fileContent, [ new SugarDueExtension(), new HiddenExtension(), new RecExtension(), new ThresholdExtension() ])
if(fileContent !== undefined) items.objects = await TodoTxt.parse(fileContent, [ new SugarDueExtension(), new HiddenExtension(), new RecExtension(), new ThresholdExtension() ])
// empty lines will be filtered
items.objects = items.objects.filter(function(item) { return item.toString() !== "" });
......@@ -123,11 +123,10 @@ function generateTable(loadAll) {
// this adds css classes for formatting
let groupFormattingClass = groupHeadline;
// TODO: beautify this
// in case a group headline is in fact a date
// add color coding for today, tomorrow and past and translations for today and tomorrow headlines
if(sortBy === "due" && !isNaN(Date.parse(groupHeadline))) {
const date = new Date(groupHeadline);
const date = convertDate(groupHeadline);
if(isToday(date)) {
groupHeadline = translations.today;
groupFormattingClass = "today";
......@@ -216,7 +215,7 @@ function generateGroupedObjects() {
// in case key is a date object it will be converted to todo.txt date string (xxxx-xx-xx)
} else if(a[sortBy] instanceof Date) {
object[formatDate(a[sortBy])] = [...object[formatDate(a[sortBy])] || [], a];
object[convertDate(a[sortBy])] = [...object[convertDate(a[sortBy])] || [], a];
// group for whatever sortBy has been defined: priority, context, project
// or in case value for sortBy key is empty, group will be null
......@@ -278,6 +277,7 @@ function generateGroupedObjects() {
}
function generateTableRow(todo) {
try {
// create nodes from templates
let todoTableBodyRow = todoTableBodyRowTemplate.cloneNode(true);
let todoTableBodyCellCheckbox = todoTableBodyCellCheckboxTemplate.cloneNode(true);
......
This diff is collapsed.
......@@ -116,19 +116,23 @@ window.onload = async function() {
const a0 = performance.now();
userData = await window.api.invoke("userData");
appData = await window.api.invoke("appData");
translations = await window.api.invoke("translations");
await import("./js/ipc.mjs");
translations = await getTranslations();
onboarding = await import("./js/onboarding.mjs");
helper = await import("./js/helper.mjs");
todos = await import("./js/todos.mjs");
filters = await import("./js/filters.mjs");
await import("./js/ipc.mjs");
import("./js/navigation.mjs");
import("./js/search.mjs");
// if active file is available, ask main process to start a file watcher
if(typeof userData.files === "object" && helper.getActiveFile()) {
if(helper.getActiveFile()) {
startFileWatcher(helper.getActiveFile()).then(function(response) {
console.info(response);
}).catch(function(error) {
......
......@@ -137,7 +137,6 @@ body.dark {
}
}
a.contexts {
color: $sleek-contexts-button!important;
background: darken($sleek-contexts-button, 60%)!important;
......@@ -164,6 +163,11 @@ body.dark {
background: darken($sleek-projects-button, 70%)!important;
color: white!important;
}
a.button.is-greyed-out {
background: $has-text-link!important;
color: white!important;
filter: opacity(50%) grayscale(100%);
}
#drawerContainer {
.zoom {
......
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