diff --git a/src/Calendar/index.ts b/src/Calendar/index.ts index 6d4d882..1229d31 100644 --- a/src/Calendar/index.ts +++ b/src/Calendar/index.ts @@ -11,12 +11,12 @@ export default class Calendar { constructor(json) { this.jsonContent = json; this.config = new Config({ - scale: json["scale"].charAt(0), + groupTypes: json["group"].charAt(0), }); this.events = new Events(json["events"]); this.eventGrouping = new EventGrouping( this.events.sortedEvents, - this.config.scale + this.config.groupTypes ); } } diff --git a/src/Config/Config.ts b/src/Config/Config.ts index ee71a94..fa65db6 100644 --- a/src/Config/Config.ts +++ b/src/Config/Config.ts @@ -1,9 +1,9 @@ -import { Scale } from "../types"; +import { GroupTypes } from "../types"; export default class Config { - scale: Scale; + groupTypes: GroupTypes; - constructor({ scale }) { - this.scale = scale.toUpperCase() || Scale.Week; + constructor({ groupTypes }) { + this.groupTypes = groupTypes.toUpperCase() || GroupTypes.Week; } } diff --git a/src/EventGrouping/index.test.ts b/src/EventGrouping/index.test.ts index 7399ff5..cc76777 100644 --- a/src/EventGrouping/index.test.ts +++ b/src/EventGrouping/index.test.ts @@ -1,5 +1,5 @@ const EventGrouping = require("./index").default; -const { Scale } = require("../types"); +const { GroupTypes } = require("../types"); const mockSortedEvents = [ { @@ -23,7 +23,7 @@ const mockSortedEvents = [ console.log(EventGrouping); describe("groupEventsByDay should", () => { - const eventGrouping = new EventGrouping(mockSortedEvents, Scale.Day); + const eventGrouping = new EventGrouping(mockSortedEvents, GroupTypes.Day); test("generate the correct number of groups", () => { expect(eventGrouping.groups.length).toEqual(8); @@ -35,7 +35,7 @@ describe("groupEventsByDay should", () => { }); describe("groupEventsByWeek should", () => { - const eventGrouping = new EventGrouping(mockSortedEvents, Scale.Week); + const eventGrouping = new EventGrouping(mockSortedEvents, GroupTypes.Week); test("generate the correct number of groups", () => { expect(eventGrouping.groups.length).toEqual(2); @@ -47,7 +47,7 @@ describe("groupEventsByWeek should", () => { }); describe("groupEventsByMonth should", () => { - const eventGrouping = new EventGrouping(mockSortedEvents, Scale.Month); + const eventGrouping = new EventGrouping(mockSortedEvents, GroupTypes.Month); test("generate the correct number of groups", () => { expect(eventGrouping.groups.length).toEqual(1); diff --git a/src/EventGrouping/index.ts b/src/EventGrouping/index.ts index 0d53144..ea80eb9 100644 --- a/src/EventGrouping/index.ts +++ b/src/EventGrouping/index.ts @@ -5,13 +5,13 @@ import { differenceInCalendarMonths, } from "date-fns"; -import { Event, Groups, Scale } from "../types"; +import { Event, Groups, GroupTypes } from "../types"; export default class EventGrouping { private readonly sortedEvents: Event[]; private readonly firstEvent: Event; private readonly lastEvent: Event; - public readonly scale: Scale; + public readonly groupTypes: GroupTypes; public readonly groups: Groups; public static generateEmptyGroups(length: number): Groups { @@ -24,21 +24,21 @@ export default class EventGrouping { return groups; } - constructor(sortedEvents: Event[], scale: Scale) { + constructor(sortedEvents: Event[], groupTypes: GroupTypes) { this.sortedEvents = sortedEvents; this.firstEvent = this.sortedEvents[0]; this.lastEvent = this.sortedEvents[this.sortedEvents.length - 1]; - this.scale = scale; - this.groups = this.group(scale); + this.groupTypes = groupTypes; + this.groups = this.group(groupTypes); } - private group(scale: Scale): Groups { - switch (scale) { - case Scale.Day: + private group(groupTypes: GroupTypes): Groups { + switch (groupTypes) { + case GroupTypes.Day: return this.byDay(); - case Scale.Week: + case GroupTypes.Week: return this.byWeek(); - case Scale.Month: + case GroupTypes.Month: return this.byMonth(); } } @@ -100,12 +100,12 @@ export default class EventGrouping { public getDateFromGroupIndex(index: number): Date { const startDate = this.firstEvent.date; - switch (this.scale) { - case Scale.Day: + switch (this.groupTypes) { + case GroupTypes.Day: return add(startDate, { days: index }); - case Scale.Week: + case GroupTypes.Week: return add(startDate, { weeks: index }); - case Scale.Month: + case GroupTypes.Month: return add(startDate, { months: index }); } } diff --git a/src/joplin-plugin-event-calendar.ts b/src/joplin-plugin-event-calendar.ts index 8a8e10e..926cc08 100644 --- a/src/joplin-plugin-event-calendar.ts +++ b/src/joplin-plugin-event-calendar.ts @@ -1,4 +1,4 @@ -import { Scale } from "./types"; +import { GroupTypes } from "./types"; const YAML = require("yaml"); @@ -38,14 +38,14 @@ export default function () { try { jsonContent = YAML.parse(markdownIt.utils.escapeHtml(token.content)); calendar = new Calendar(jsonContent); - switch (calendar.config.scale) { - case Scale.Day: + switch (calendar.config.groupTypes) { + case GroupTypes.Day: contentHtml = new DayRenderer(calendar.eventGrouping).render(); break; - case Scale.Week: + case GroupTypes.Week: contentHtml = new WeekRenderer(calendar.eventGrouping).render(); break; - case Scale.Month: + case GroupTypes.Month: contentHtml = new MonthRenderer(calendar.eventGrouping).render(); break; } diff --git a/src/types.ts b/src/types.ts index 7b484f9..a550dc4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -export enum Scale { +export enum GroupTypes { Day = "D", Week = "W", Month = "M",