Removed year grouping
This commit is contained in:
parent
904a9c0691
commit
b18c50c205
@ -4,7 +4,7 @@ This is a plugin for the [Joplin](https://joplinapp.org/) note-taking app.
|
|||||||
|
|
||||||
It creates a calendar view of events that have been specified using the [YAML](https://yaml.org/) syntax within a fenced block.
|
It creates a calendar view of events that have been specified using the [YAML](https://yaml.org/) syntax within a fenced block.
|
||||||
|
|
||||||
- Organises events into "groupings"; you can group events by **day**, **week**, **month** or **year**
|
- Organises events into "groupings"; you can group events by **day**, **week**, or **month**
|
||||||
- Focus is on readability and simplicity of content, which is why the **YAML** is simple in structure
|
- Focus is on readability and simplicity of content, which is why the **YAML** is simple in structure
|
||||||
|
|
||||||
###### Example Day view
|
###### Example Day view
|
||||||
@ -41,7 +41,7 @@ Events are specified using the YAML syntax, with the following keys:
|
|||||||
> Sets the grouping for the view
|
> Sets the grouping for the view
|
||||||
> - _**optional**_
|
> - _**optional**_
|
||||||
> - **default** `day`
|
> - **default** `day`
|
||||||
> - **accepts** : `day`, `week`, `month`, `year`, `d`, `w`, `m`, `y`
|
> - **accepts** : `day`, `week`, `month`, `d`, `w`, `m`
|
||||||
|
|
||||||
### events:
|
### events:
|
||||||
> Each individual event is a list with its own properties
|
> Each individual event is a list with its own properties
|
||||||
|
|||||||
@ -1,42 +0,0 @@
|
|||||||
import EventGrouping from "./EventGrouping";
|
|
||||||
import { Event, Groups } from "../../types";
|
|
||||||
import {
|
|
||||||
add,
|
|
||||||
differenceInCalendarYears,
|
|
||||||
isThisYear as dateFnsIsThisYear,
|
|
||||||
} from "date-fns";
|
|
||||||
|
|
||||||
export default class YearGrouping extends EventGrouping {
|
|
||||||
static isThisYear(date: Date): boolean {
|
|
||||||
return dateFnsIsThisYear(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
constructor(sortedEvents: Event[]) {
|
|
||||||
super(sortedEvents);
|
|
||||||
this.groups = this.group();
|
|
||||||
}
|
|
||||||
|
|
||||||
group(): Groups {
|
|
||||||
const numberOfGroups = differenceInCalendarYears(
|
|
||||||
this.lastEvent.date,
|
|
||||||
this.firstEvent.date
|
|
||||||
);
|
|
||||||
|
|
||||||
return this.sortedEvents.reduce((prev, event) => {
|
|
||||||
const groupNumber = differenceInCalendarYears(
|
|
||||||
event.date,
|
|
||||||
this.firstEvent.date
|
|
||||||
);
|
|
||||||
|
|
||||||
prev[groupNumber].push(event);
|
|
||||||
|
|
||||||
return prev;
|
|
||||||
}, this.generateEmptyGroups(numberOfGroups));
|
|
||||||
}
|
|
||||||
|
|
||||||
public getDateFromGroupIndex(index: number): Date {
|
|
||||||
const startDate = this.firstEvent.date;
|
|
||||||
|
|
||||||
return add(startDate, { years: index });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
import { Event } from "../../../types";
|
|
||||||
import YearGrouping from "../../EventGrouping/YearGrouping";
|
|
||||||
|
|
||||||
import GroupRenderer from "../Abstract/GroupRenderer";
|
|
||||||
|
|
||||||
export default class GroupYearRenderer extends GroupRenderer {
|
|
||||||
constructor(group: Event[], groupDate: Date, groupIndex: number) {
|
|
||||||
super(group, groupDate, groupIndex);
|
|
||||||
|
|
||||||
if (YearGrouping.isThisYear(groupDate)) {
|
|
||||||
this.highlightGroup();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected renderDateAsIcon(eventDate, groupIndex): HTMLSpanElement {
|
|
||||||
const html = document.createElement("span");
|
|
||||||
html.className = "icon";
|
|
||||||
|
|
||||||
html.textContent = eventDate.toLocaleDateString(undefined, {
|
|
||||||
year: "numeric",
|
|
||||||
});
|
|
||||||
html.className += " primary";
|
|
||||||
|
|
||||||
if (YearGrouping.isThisYear(eventDate)) {
|
|
||||||
html.className += " highlighted";
|
|
||||||
}
|
|
||||||
|
|
||||||
return html;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
import { Event } from "../../../types";
|
|
||||||
import YearGrouping from "../../EventGrouping/YearGrouping";
|
|
||||||
import Renderer from "../Abstract/Renderer";
|
|
||||||
import GroupYearRenderer from "./GroupYearRenderer";
|
|
||||||
|
|
||||||
export default class YearRenderer extends Renderer {
|
|
||||||
constructor(eventGrouping: YearGrouping) {
|
|
||||||
super(eventGrouping);
|
|
||||||
this.container.className += " scale-year";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected renderGroups(
|
|
||||||
group: Event[],
|
|
||||||
groupDate: Date,
|
|
||||||
groupIndex: number
|
|
||||||
): HTMLDivElement {
|
|
||||||
return new GroupYearRenderer(group, groupDate, groupIndex).render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -3,11 +3,9 @@ import Events from "./Events/";
|
|||||||
import DayGrouping from "./EventGrouping/DayGrouping";
|
import DayGrouping from "./EventGrouping/DayGrouping";
|
||||||
import MonthGrouping from "./EventGrouping/MonthGrouping";
|
import MonthGrouping from "./EventGrouping/MonthGrouping";
|
||||||
import WeekGrouping from "./EventGrouping/MonthGrouping";
|
import WeekGrouping from "./EventGrouping/MonthGrouping";
|
||||||
import YearGrouping from "./EventGrouping/YearGrouping";
|
|
||||||
import DayRenderer from "./HtmlRenderer/Day";
|
import DayRenderer from "./HtmlRenderer/Day";
|
||||||
import MonthRenderer from "./HtmlRenderer/Month";
|
import MonthRenderer from "./HtmlRenderer/Month";
|
||||||
import WeekRenderer from "./HtmlRenderer/Week";
|
import WeekRenderer from "./HtmlRenderer/Week";
|
||||||
import YearRenderer from "./HtmlRenderer/Year";
|
|
||||||
|
|
||||||
export default class Calendar {
|
export default class Calendar {
|
||||||
public readonly jsonContent: object;
|
public readonly jsonContent: object;
|
||||||
@ -36,10 +34,6 @@ export default class Calendar {
|
|||||||
return new MonthRenderer(
|
return new MonthRenderer(
|
||||||
new MonthGrouping(this.events.sortedEvents)
|
new MonthGrouping(this.events.sortedEvents)
|
||||||
).render();
|
).render();
|
||||||
case GroupTypes.Year:
|
|
||||||
return new YearRenderer(
|
|
||||||
new YearGrouping(this.events.sortedEvents)
|
|
||||||
).render();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ export enum GroupTypes {
|
|||||||
Day = "D",
|
Day = "D",
|
||||||
Week = "W",
|
Week = "W",
|
||||||
Month = "M",
|
Month = "M",
|
||||||
Year = "Y",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Event {
|
export interface Event {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user