Compare commits

...

5 commits

Author SHA1 Message Date
Ozan Tellioglu
5565665d44 v0.3.4 Release 2024-03-31 14:22:46 +02:00
Ozan Tellioglu
f8741bdbf8 More Flexible Calendar Items Handling 2024-03-31 14:20:34 +02:00
Ozan Tellioglu
3504b38540 v.0.3.3 Release 2024-02-10 21:15:26 +01:00
Ozan Tellioglu
0a5ae28292 #11 Week Numbers 2024-02-10 21:14:55 +01:00
Ozan Tellioglu
f383375883 v.0.3.2 Release 2023-12-07 22:11:54 +01:00
9 changed files with 103 additions and 36 deletions

View file

@ -1,7 +1,7 @@
{ {
"id": "oz-calendar", "id": "oz-calendar",
"name": "OZ Calendar", "name": "OZ Calendar",
"version": "0.3.1", "version": "0.3.4",
"minAppVersion": "0.15.0", "minAppVersion": "0.15.0",
"description": "View your notes in Calendar using any YAML key with date", "description": "View your notes in Calendar using any YAML key with date",
"author": "Ozan Tellioglu", "author": "Ozan Tellioglu",

View file

@ -1,6 +1,6 @@
{ {
"name": "oz-calendar", "name": "oz-calendar",
"version": "0.3.1", "version": "0.3.4",
"description": "View your notes in Calendar using any YAML key with date", "description": "View your notes in Calendar using any YAML key with date",
"main": "main.js", "main": "main.js",
"scripts": { "scripts": {

View file

@ -105,6 +105,7 @@ export default function MyCalendar(params: { plugin: OZCalendarPlugin }) {
value={selectedDay} value={selectedDay}
maxDetail="month" maxDetail="month"
minDetail="month" minDetail="month"
showWeekNumbers={plugin.settings.showWeekNumbers}
view="month" view="month"
tileContent={customTileContent} tileContent={customTileContent}
tileClassName={customTileClass} tileClassName={customTileClass}

View file

@ -8,6 +8,7 @@ import OZCalendarPlugin from 'main';
import { isMouseEvent, openFile } from '../util/utils'; import { isMouseEvent, openFile } from '../util/utils';
import { Menu, TFile } from 'obsidian'; import { Menu, TFile } from 'obsidian';
import { VIEW_TYPE } from 'view'; import { VIEW_TYPE } from 'view';
import { OZNote } from 'types';
interface NoteListComponentParams { interface NoteListComponentParams {
selectedDay: Date; selectedDay: Date;
@ -57,13 +58,18 @@ export default function NoteListComponent(params: NoteListComponentParams) {
} }
}; };
const selectedDayNotes = useMemo(() => { const selectedDayNotes: OZNote[] = useMemo(() => {
const selectedDayIso = dayjs(selectedDay).format('YYYY-MM-DD'); const selectedDayIso = dayjs(selectedDay).format('YYYY-MM-DD');
let sortedList = let sortedList: OZNote[] = [];
selectedDayIso in plugin.OZCALENDARDAYS_STATE ? plugin.OZCALENDARDAYS_STATE[selectedDayIso] : []; if (selectedDayIso in plugin.OZCALENDARDAYS_STATE) {
sortedList = plugin.OZCALENDARDAYS_STATE[selectedDayIso].filter(
(ozItem) => ozItem.type === 'note'
) as OZNote[];
}
sortedList = sortedList.sort((a, b) => { sortedList = sortedList.sort((a, b) => {
if (plugin.settings.sortingOption === 'name-rev') [a, b] = [b, a]; if (plugin.settings.sortingOption === 'name-rev')
return extractFileName(a).localeCompare(extractFileName(b), 'en', { numeric: true }); [a.displayName, b.displayName] = [b.displayName, a.displayName];
return a.displayName.localeCompare(b.displayName, 'en', { numeric: true });
}); });
return sortedList; return sortedList;
}, [selectedDay, forceValue]); }, [selectedDay, forceValue]);
@ -122,7 +128,7 @@ export default function NoteListComponent(params: NoteListComponentParams) {
No note found No note found
</div> </div>
)} )}
{selectedDayNotes.map((notePath) => { {selectedDayNotes.map((ozNote) => {
return ( return (
<div <div
className={ className={
@ -131,12 +137,12 @@ export default function NoteListComponent(params: NoteListComponentParams) {
? ' oz-calendar-overflow-hide' ? ' oz-calendar-overflow-hide'
: '') : '')
} }
id={notePath} id={ozNote.path}
key={notePath} key={ozNote.path}
onClick={(e) => openFilePath(e, notePath)} onClick={(e) => openFilePath(e, ozNote.path)}
onContextMenu={(e) => triggerFileContextMenu(e, notePath)}> onContextMenu={(e) => triggerFileContextMenu(e, ozNote.path)}>
<HiOutlineDocumentText className="oz-calendar-note-line-icon" /> <HiOutlineDocumentText className="oz-calendar-note-line-icon" />
<span>{extractFileName(notePath)}</span> <span>{ozNote.displayName}</span>
</div> </div>
); );
})} })}

View file

@ -2,7 +2,7 @@ import { CachedMetadata, Menu, Plugin, TAbstractFile, TFile, addIcon } from 'obs
import { OZCalendarView, VIEW_TYPE } from 'view'; import { OZCalendarView, VIEW_TYPE } from 'view';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat'; import customParseFormat from 'dayjs/plugin/customParseFormat';
import { DayChangeCommandAction, OZCalendarDaysMap } from 'types'; import { DayChangeCommandAction, OZCalendarDaysMap, fileToOZItem } from 'types';
import { OZCAL_ICON } from './util/icons'; import { OZCAL_ICON } from './util/icons';
import { OZCalendarPluginSettings, DEFAULT_SETTINGS, OZCalendarPluginSettingsTab } from './settings/settings'; import { OZCalendarPluginSettings, DEFAULT_SETTINGS, OZCalendarPluginSettingsTab } from './settings/settings';
import { CreateNoteModal } from 'modal'; import { CreateNoteModal } from 'modal';
@ -140,13 +140,13 @@ export default class OZCalendarPlugin extends Plugin {
* @param date * @param date
* @param filePath * @param filePath
*/ */
addFilePathToState = (date: string, filePath: string) => { addFilePathToState = (date: string, file: TFile) => {
let newStateMap = this.OZCALENDARDAYS_STATE; let newStateMap = this.OZCALENDARDAYS_STATE;
// if exists, add the new file path // if exists, add the new file path
if (date in newStateMap) { if (date in newStateMap) {
newStateMap[date] = [...newStateMap[date], filePath]; newStateMap[date] = [...newStateMap[date], fileToOZItem({ note: file })];
} else { } else {
newStateMap[date] = [filePath]; newStateMap[date] = [fileToOZItem({ note: file })];
} }
this.OZCALENDARDAYS_STATE = newStateMap; this.OZCALENDARDAYS_STATE = newStateMap;
}; };
@ -160,8 +160,10 @@ export default class OZCalendarPlugin extends Plugin {
let changeFlag = false; let changeFlag = false;
let newStateMap = this.OZCALENDARDAYS_STATE; let newStateMap = this.OZCALENDARDAYS_STATE;
for (let k of Object.keys(newStateMap)) { for (let k of Object.keys(newStateMap)) {
if (newStateMap[k].contains(filePath)) { if (newStateMap[k].some((ozItem) => ozItem.type === 'note' && ozItem.path === filePath)) {
newStateMap[k] = newStateMap[k].filter((p) => p !== filePath); newStateMap[k] = newStateMap[k].filter((ozItem) => {
return !(ozItem.type === 'note' && ozItem.path === filePath);
});
changeFlag = true; changeFlag = true;
} }
} }
@ -183,7 +185,7 @@ export default class OZCalendarPlugin extends Plugin {
if (k === this.settings.yamlKey) { if (k === this.settings.yamlKey) {
let fmValue = String(fm[k]); let fmValue = String(fm[k]);
let parsedDayISOString = dayjs(fmValue, this.settings.dateFormat).format('YYYY-MM-DD'); let parsedDayISOString = dayjs(fmValue, this.settings.dateFormat).format('YYYY-MM-DD');
this.addFilePathToState(parsedDayISOString, file.path); this.addFilePathToState(parsedDayISOString, file);
changeFlag = true; changeFlag = true;
} }
} }
@ -215,11 +217,11 @@ export default class OZCalendarPlugin extends Plugin {
let parsedDayISOString = dayjs(fmValue, this.settings.dateFormat).format('YYYY-MM-DD'); let parsedDayISOString = dayjs(fmValue, this.settings.dateFormat).format('YYYY-MM-DD');
// If date doesn't exist, create a new one // If date doesn't exist, create a new one
if (!(parsedDayISOString in this.OZCALENDARDAYS_STATE)) { if (!(parsedDayISOString in this.OZCALENDARDAYS_STATE)) {
this.addFilePathToState(parsedDayISOString, file.path); this.addFilePathToState(parsedDayISOString, file);
} else { } else {
// if date exists and note is not in the date list // if date exists and note is not in the date list
if (!(file.path in this.OZCALENDARDAYS_STATE[parsedDayISOString])) { if (!(file.path in this.OZCALENDARDAYS_STATE[parsedDayISOString])) {
this.addFilePathToState(parsedDayISOString, file.path); this.addFilePathToState(parsedDayISOString, file);
} }
} }
} }
@ -235,14 +237,16 @@ export default class OZCalendarPlugin extends Plugin {
let changeFlag = false; let changeFlag = false;
if (file instanceof TFile && file.extension === 'md') { if (file instanceof TFile && file.extension === 'md') {
for (let k of Object.keys(this.OZCALENDARDAYS_STATE)) { for (let k of Object.keys(this.OZCALENDARDAYS_STATE)) {
for (let filePath of this.OZCALENDARDAYS_STATE[k]) { for (let ozItem of this.OZCALENDARDAYS_STATE[k]) {
if (filePath === oldPath) { if (ozItem.type === 'note' && ozItem.path === oldPath) {
let oldIndex = this.OZCALENDARDAYS_STATE[k].indexOf(filePath);
if (this.settings.dateSource === 'yaml') { if (this.settings.dateSource === 'yaml') {
this.OZCALENDARDAYS_STATE[k][oldIndex] = file.path; ozItem.path = file.path;
ozItem.displayName = file.basename;
changeFlag = true; changeFlag = true;
} else if (this.settings.dateSource === 'filename') { } else if (this.settings.dateSource === 'filename') {
this.OZCALENDARDAYS_STATE[k].splice(oldIndex, 1); this.OZCALENDARDAYS_STATE[k] = this.OZCALENDARDAYS_STATE[k].filter((ozItem) => {
return !(ozItem.type === 'note' && ozItem.path === oldPath);
});
changeFlag = true; changeFlag = true;
} }
} }
@ -256,10 +260,10 @@ export default class OZCalendarPlugin extends Plugin {
if (parsedDayISOString in this.OZCALENDARDAYS_STATE) { if (parsedDayISOString in this.OZCALENDARDAYS_STATE) {
this.OZCALENDARDAYS_STATE[parsedDayISOString] = [ this.OZCALENDARDAYS_STATE[parsedDayISOString] = [
...this.OZCALENDARDAYS_STATE[parsedDayISOString], ...this.OZCALENDARDAYS_STATE[parsedDayISOString],
file.path, fileToOZItem({ note: file }),
]; ];
} else { } else {
this.OZCALENDARDAYS_STATE[parsedDayISOString] = [file.path]; this.OZCALENDARDAYS_STATE[parsedDayISOString] = [fileToOZItem({ note: file })];
} }
changeFlag = true; changeFlag = true;
} }
@ -280,10 +284,10 @@ export default class OZCalendarPlugin extends Plugin {
if (parsedDayISOString in this.OZCALENDARDAYS_STATE) { if (parsedDayISOString in this.OZCALENDARDAYS_STATE) {
this.OZCALENDARDAYS_STATE[parsedDayISOString] = [ this.OZCALENDARDAYS_STATE[parsedDayISOString] = [
...this.OZCALENDARDAYS_STATE[parsedDayISOString], ...this.OZCALENDARDAYS_STATE[parsedDayISOString],
file.path, fileToOZItem({ note: file }),
]; ];
} else { } else {
this.OZCALENDARDAYS_STATE[parsedDayISOString] = [file.path]; this.OZCALENDARDAYS_STATE[parsedDayISOString] = [fileToOZItem({ note: file })];
} }
} }
this.calendarForceUpdate(); this.calendarForceUpdate();
@ -335,10 +339,10 @@ export default class OZCalendarPlugin extends Plugin {
if (parsedDayISOString in OZCalendarDays) { if (parsedDayISOString in OZCalendarDays) {
OZCalendarDays[parsedDayISOString] = [ OZCalendarDays[parsedDayISOString] = [
...OZCalendarDays[parsedDayISOString], ...OZCalendarDays[parsedDayISOString],
mdFile.path, fileToOZItem({ note: mdFile }),
]; ];
} else { } else {
OZCalendarDays[parsedDayISOString] = [mdFile.path]; OZCalendarDays[parsedDayISOString] = [fileToOZItem({ note: mdFile })];
} }
} }
} }
@ -351,10 +355,10 @@ export default class OZCalendarPlugin extends Plugin {
if (parsedDayISOString in OZCalendarDays) { if (parsedDayISOString in OZCalendarDays) {
OZCalendarDays[parsedDayISOString] = [ OZCalendarDays[parsedDayISOString] = [
...OZCalendarDays[parsedDayISOString], ...OZCalendarDays[parsedDayISOString],
mdFile.path, fileToOZItem({ note: mdFile }),
]; ];
} else { } else {
OZCalendarDays[parsedDayISOString] = [mdFile.path]; OZCalendarDays[parsedDayISOString] = [fileToOZItem({ note: mdFile })];
} }
} }
} }

View file

@ -25,6 +25,7 @@ export interface OZCalendarPluginSettings {
newNoteDate: NewNoteDateType; newNoteDate: NewNoteDateType;
newNoteCancelButtonReverse: boolean; newNoteCancelButtonReverse: boolean;
fileNameOverflowBehaviour: OverflowBehaviour; fileNameOverflowBehaviour: OverflowBehaviour;
showWeekNumbers: boolean;
} }
export const DEFAULT_SETTINGS: OZCalendarPluginSettings = { export const DEFAULT_SETTINGS: OZCalendarPluginSettings = {
@ -43,6 +44,7 @@ export const DEFAULT_SETTINGS: OZCalendarPluginSettings = {
newNoteDate: 'current-date', newNoteDate: 'current-date',
newNoteCancelButtonReverse: false, newNoteCancelButtonReverse: false,
fileNameOverflowBehaviour: 'hide', fileNameOverflowBehaviour: 'hide',
showWeekNumbers: false,
}; };
export class OZCalendarPluginSettingsTab extends PluginSettingTab { export class OZCalendarPluginSettingsTab extends PluginSettingTab {
@ -114,6 +116,17 @@ export class OZCalendarPluginSettingsTab extends PluginSettingTab {
}); });
}); });
new Setting(containerEl)
.setName('Show Week Numbers')
.setDesc('Enable if you want to have week numbers within the calendar view')
.addToggle((toggle) => {
toggle.setValue(this.plugin.settings.showWeekNumbers).onChange((newValue) => {
this.plugin.settings.showWeekNumbers = newValue;
this.plugin.saveSettings();
this.plugin.calendarForceUpdate();
});
});
new Setting(containerEl) new Setting(containerEl)
.setName('Open File Behaviour') .setName('Open File Behaviour')
.setDesc('Select the behaviour you want to have when you click on file name in the calendar view') .setDesc('Select the behaviour you want to have when you click on file name in the calendar view')

View file

@ -1,5 +1,29 @@
import { TFile } from 'obsidian';
export type OZNote = {
type: 'note';
displayName: string;
path: string;
};
export type OZReminder = {
type: 'task' | 'periodic';
displayName: string;
date: string;
};
type OZItem = OZNote | OZReminder;
export interface OZCalendarDaysMap { export interface OZCalendarDaysMap {
[key: string]: string[]; [key: string]: OZItem[];
} }
export type DayChangeCommandAction = 'next-day' | 'previous-day' | 'today'; export type DayChangeCommandAction = 'next-day' | 'previous-day' | 'today';
export const fileToOZItem = (params: { note: TFile }): OZItem => {
return {
type: 'note',
displayName: params.note.basename,
path: params.note.path,
};
};

View file

@ -39,6 +39,13 @@ settings:
type: variable-color type: variable-color
format: hex format: hex
default: '#' default: '#'
-
id: oz-calendar-weeknr-date-color
title: Week Number Text Color
description: Set the color of week numbers, defaulted to the interactive-accent
type: variable-color
format: hex
default: '#'
*/ */
.theme-light, .theme-light,
@ -48,6 +55,7 @@ settings:
--oz-calendar-selected-day-background: var(--interactive-accent); --oz-calendar-selected-day-background: var(--interactive-accent);
--oz-calendar-header-date-color: var(--interactive-accent); --oz-calendar-header-date-color: var(--interactive-accent);
--oz-calendar-current-day-color: #74dd58; --oz-calendar-current-day-color: #74dd58;
--oz-calendar-weeknr-date-color: var(--color-accent-2);
} }
.oz-cal-coffee-div, .oz-cal-coffee-div,
@ -270,6 +278,14 @@ settings:
vertical-align: top; vertical-align: top;
} }
.oz-calendar-plugin-view .react-calendar__month-view__weekNumbers {
display: block !important;
color: var(--oz-calendar-weeknr-date-color);
flex-basis: auto !important;
background-color: var(--background-modifier-cover);
font-size: var(--nav-item-size);
}
/* END - Fixed Calendar */ /* END - Fixed Calendar */
.oz-calendar-modal-inputel { .oz-calendar-modal-inputel {

View file

@ -1,4 +1,7 @@
{ {
"0.3.4": "0.15.0",
"0.3.3": "0.15.0",
"0.3.2": "0.15.0",
"0.3.1": "0.15.0", "0.3.1": "0.15.0",
"0.3.0": "0.15.0", "0.3.0": "0.15.0",
"0.2.9": "0.15.0", "0.2.9": "0.15.0",