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",
"name": "OZ Calendar",
"version": "0.3.1",
"version": "0.3.4",
"minAppVersion": "0.15.0",
"description": "View your notes in Calendar using any YAML key with date",
"author": "Ozan Tellioglu",

View file

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

View file

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

View file

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

View file

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

View file

@ -25,6 +25,7 @@ export interface OZCalendarPluginSettings {
newNoteDate: NewNoteDateType;
newNoteCancelButtonReverse: boolean;
fileNameOverflowBehaviour: OverflowBehaviour;
showWeekNumbers: boolean;
}
export const DEFAULT_SETTINGS: OZCalendarPluginSettings = {
@ -43,6 +44,7 @@ export const DEFAULT_SETTINGS: OZCalendarPluginSettings = {
newNoteDate: 'current-date',
newNoteCancelButtonReverse: false,
fileNameOverflowBehaviour: 'hide',
showWeekNumbers: false,
};
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)
.setName('Open File Behaviour')
.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 {
[key: string]: string[];
[key: string]: OZItem[];
}
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
format: hex
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,
@ -48,6 +55,7 @@ settings:
--oz-calendar-selected-day-background: var(--interactive-accent);
--oz-calendar-header-date-color: var(--interactive-accent);
--oz-calendar-current-day-color: #74dd58;
--oz-calendar-weeknr-date-color: var(--color-accent-2);
}
.oz-cal-coffee-div,
@ -270,6 +278,14 @@ settings:
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 */
.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.0": "0.15.0",
"0.2.9": "0.15.0",