fix scan all and update styling
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
92
main.js
92
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);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user