From 07d438a6381c11588aa4ca37c89a660710c57b00 Mon Sep 17 00:00:00 2001 From: FReenen Date: Wed, 6 Dec 2023 21:37:48 +0100 Subject: [PATCH] fix scan all and update styling --- fr-calendar.css | 32 +++++++++++++++-- main.js | 92 ++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 104 insertions(+), 20 deletions(-) diff --git a/fr-calendar.css b/fr-calendar.css index d3e6202..f0eafde 100644 --- a/fr-calendar.css +++ b/fr-calendar.css @@ -3,6 +3,10 @@ padding: 5px 10px; display: block; } +.workspace-leaf-content[data-type="fr-calendar"] .view-content { + min-width: 750px; + overflow-x: auto; +} .frcal__time { flex: 2; @@ -105,12 +109,34 @@ margin: 0 3px; } -.frcal__event[data-state="canceled"] span { +.frcal__event[data-state="canceled"] span, +.frcal__event[data-state="moved"] span { opacity: 0.3; filter: saturate(0.4); } - -.frcal__event[data-state="done"] span { +.frcal__event[data-state="done"] span, +.frcal__event[data-state="partly finished"] span { opacity: 0.5; /* filter: saturate(0.4); */ } + +.frcal__event[data-group="volta"] span { + background-color: var(--color-green); + color: black; +} +.frcal__event[data-group="hr"] span { + background-color: var(--color-yellow); + color: black; +} +.frcal__event[data-group="mbc"] span { + background-color: var(--color-purple); + color: white; +} +.frcal__event[data-group="eriks"] span { + background-color: var(--color-blue); + color: white; +} +.frcal__event[data-group="woco"] span { + background-color: var(--color-red); + color: black; +} diff --git a/main.js b/main.js index 131f805..10fa409 100644 --- a/main.js +++ b/main.js @@ -103,21 +103,7 @@ function parseDate(d, defal) return [start, end] } -function findDate(line, defal) -{ - let res = line.match("\\[(" + DateFormat.date + "(?:-" + DateFormat.date + ")?)\\]"); - if (res !== null) - { - res[1] = parseDate(res[1], defal); - } - return { - "line": line, - "dateRemoved": (res === null) ? line : line.replace(res[0], ''), - 'date': (res === null) ? null : res[1] - } -} - -function scanFile(editor, data) +function scanEditor(editor, data) { let lineNum = 0, lineCount = editor.lineCount(); let defal = parseSingleDate("00:00am", moment()); @@ -154,6 +140,39 @@ function scanFile(editor, data) return data; } +function scanFile(content, data) +{ + let lines = content.split('\n'); + let defal = parseSingleDate("00:00am", moment()); + + for (let lineNum in lines) + { + let res = lines[lineNum].match("weekboek: \"?(" + DateFormat.date + ")\"?"); + if (res != null) + { + defal = parseSingleDate(res[1], defal); + } + + res = [...lines[lineNum].matchAll("\\[(" + DateFormat.date + "(?:-" + DateFormat.date + ")?)\\]")]; + if (res.length > 0) + { + if (res[0][0] == "[-]" && res.length > 1) + { + res[0] = res[1]; + } + if (res[0][0] != "[-]") + { + res = res[0] + res[1] = parseDate(res[1], defal); + let procesed = processLine(lines[lineNum], lines[lineNum].replace(res[0], ''), res[1], data); + data = procesed['data']; + lines[lineNum] = procesed['line']; + } + } + } + return { data: data, content: lines.join('\n') }; +} + function processLine(line, noDate, date, data) { let res; @@ -505,12 +524,51 @@ class FRCalander extends Plugin this.registerView(VIEW_TYPE_CALENDAR, (leaf) => { return new CalendarView(leaf, this) }); this.addCommand({ - id: 'calnder-scan', + id: 'fr-calendar-scan-active', name: 'scan active file', + repeatable: false, editorCallback: (editor) => { //TODO: check if editor is valid if (this.data == null) this.data = this.loadData(); - this.data = scanFile(editor, this.data); + this.data = scanEditor(editor, this.data); + this.saveData(this.data); + } + }); + this.addCommand({ + id: 'fr-calendar-scan-test', + name: 'scan active file updated', + repeatable: false, + callback: async () => { + let file = this.app.workspace.getActiveFile(); + if (file !== null) + { + let content = await this.app.vault.read(file); + let res = scanFile(content, this.data); + this.data = res.data; + this.app.vault.modify(file, res.content); + } + this.saveData(this.data); + } + }); + this.addCommand({ + id: 'fr-calendar-scan-all', + name: 'scan all files conaining the tag', + repeatable: false, + callback: async () => { + var events = {}; + const notes = this.app.vault.getMarkdownFiles(); + for (const noteFile of notes) { + const fileCachedData = this.app.metadataCache.getFileCache(noteFile) || {}; + const tags = obsidian.getAllTags(fileCachedData); + if (tags.contains('#fr-calendar')) + { + let content = await this.app.vault.read(noteFile); + let res = scanFile(content, events); + events = res.data; + this.app.vault.modify(noteFile, res.content); + } + } + this.data = events; this.saveData(this.data); } });