Global rename of scale => groupType
This commit is contained in:
parent
5836dfdb2e
commit
a1d1621a75
@ -11,12 +11,12 @@ export default class Calendar {
|
|||||||
constructor(json) {
|
constructor(json) {
|
||||||
this.jsonContent = json;
|
this.jsonContent = json;
|
||||||
this.config = new Config({
|
this.config = new Config({
|
||||||
scale: json["scale"].charAt(0),
|
groupTypes: json["group"].charAt(0),
|
||||||
});
|
});
|
||||||
this.events = new Events(json["events"]);
|
this.events = new Events(json["events"]);
|
||||||
this.eventGrouping = new EventGrouping(
|
this.eventGrouping = new EventGrouping(
|
||||||
this.events.sortedEvents,
|
this.events.sortedEvents,
|
||||||
this.config.scale
|
this.config.groupTypes
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { Scale } from "../types";
|
import { GroupTypes } from "../types";
|
||||||
|
|
||||||
export default class Config {
|
export default class Config {
|
||||||
scale: Scale;
|
groupTypes: GroupTypes;
|
||||||
|
|
||||||
constructor({ scale }) {
|
constructor({ groupTypes }) {
|
||||||
this.scale = scale.toUpperCase() || Scale.Week;
|
this.groupTypes = groupTypes.toUpperCase() || GroupTypes.Week;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
const EventGrouping = require("./index").default;
|
const EventGrouping = require("./index").default;
|
||||||
const { Scale } = require("../types");
|
const { GroupTypes } = require("../types");
|
||||||
|
|
||||||
const mockSortedEvents = [
|
const mockSortedEvents = [
|
||||||
{
|
{
|
||||||
@ -23,7 +23,7 @@ const mockSortedEvents = [
|
|||||||
console.log(EventGrouping);
|
console.log(EventGrouping);
|
||||||
|
|
||||||
describe("groupEventsByDay should", () => {
|
describe("groupEventsByDay should", () => {
|
||||||
const eventGrouping = new EventGrouping(mockSortedEvents, Scale.Day);
|
const eventGrouping = new EventGrouping(mockSortedEvents, GroupTypes.Day);
|
||||||
|
|
||||||
test("generate the correct number of groups", () => {
|
test("generate the correct number of groups", () => {
|
||||||
expect(eventGrouping.groups.length).toEqual(8);
|
expect(eventGrouping.groups.length).toEqual(8);
|
||||||
@ -35,7 +35,7 @@ describe("groupEventsByDay should", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("groupEventsByWeek 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", () => {
|
test("generate the correct number of groups", () => {
|
||||||
expect(eventGrouping.groups.length).toEqual(2);
|
expect(eventGrouping.groups.length).toEqual(2);
|
||||||
@ -47,7 +47,7 @@ describe("groupEventsByWeek should", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("groupEventsByMonth 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", () => {
|
test("generate the correct number of groups", () => {
|
||||||
expect(eventGrouping.groups.length).toEqual(1);
|
expect(eventGrouping.groups.length).toEqual(1);
|
||||||
|
|||||||
@ -5,13 +5,13 @@ import {
|
|||||||
differenceInCalendarMonths,
|
differenceInCalendarMonths,
|
||||||
} from "date-fns";
|
} from "date-fns";
|
||||||
|
|
||||||
import { Event, Groups, Scale } from "../types";
|
import { Event, Groups, GroupTypes } from "../types";
|
||||||
|
|
||||||
export default class EventGrouping {
|
export default class EventGrouping {
|
||||||
private readonly sortedEvents: Event[];
|
private readonly sortedEvents: Event[];
|
||||||
private readonly firstEvent: Event;
|
private readonly firstEvent: Event;
|
||||||
private readonly lastEvent: Event;
|
private readonly lastEvent: Event;
|
||||||
public readonly scale: Scale;
|
public readonly groupTypes: GroupTypes;
|
||||||
public readonly groups: Groups;
|
public readonly groups: Groups;
|
||||||
|
|
||||||
public static generateEmptyGroups(length: number): Groups {
|
public static generateEmptyGroups(length: number): Groups {
|
||||||
@ -24,21 +24,21 @@ export default class EventGrouping {
|
|||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(sortedEvents: Event[], scale: Scale) {
|
constructor(sortedEvents: Event[], groupTypes: GroupTypes) {
|
||||||
this.sortedEvents = sortedEvents;
|
this.sortedEvents = sortedEvents;
|
||||||
this.firstEvent = this.sortedEvents[0];
|
this.firstEvent = this.sortedEvents[0];
|
||||||
this.lastEvent = this.sortedEvents[this.sortedEvents.length - 1];
|
this.lastEvent = this.sortedEvents[this.sortedEvents.length - 1];
|
||||||
this.scale = scale;
|
this.groupTypes = groupTypes;
|
||||||
this.groups = this.group(scale);
|
this.groups = this.group(groupTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private group(scale: Scale): Groups {
|
private group(groupTypes: GroupTypes): Groups {
|
||||||
switch (scale) {
|
switch (groupTypes) {
|
||||||
case Scale.Day:
|
case GroupTypes.Day:
|
||||||
return this.byDay();
|
return this.byDay();
|
||||||
case Scale.Week:
|
case GroupTypes.Week:
|
||||||
return this.byWeek();
|
return this.byWeek();
|
||||||
case Scale.Month:
|
case GroupTypes.Month:
|
||||||
return this.byMonth();
|
return this.byMonth();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,12 +100,12 @@ export default class EventGrouping {
|
|||||||
public getDateFromGroupIndex(index: number): Date {
|
public getDateFromGroupIndex(index: number): Date {
|
||||||
const startDate = this.firstEvent.date;
|
const startDate = this.firstEvent.date;
|
||||||
|
|
||||||
switch (this.scale) {
|
switch (this.groupTypes) {
|
||||||
case Scale.Day:
|
case GroupTypes.Day:
|
||||||
return add(startDate, { days: index });
|
return add(startDate, { days: index });
|
||||||
case Scale.Week:
|
case GroupTypes.Week:
|
||||||
return add(startDate, { weeks: index });
|
return add(startDate, { weeks: index });
|
||||||
case Scale.Month:
|
case GroupTypes.Month:
|
||||||
return add(startDate, { months: index });
|
return add(startDate, { months: index });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Scale } from "./types";
|
import { GroupTypes } from "./types";
|
||||||
|
|
||||||
const YAML = require("yaml");
|
const YAML = require("yaml");
|
||||||
|
|
||||||
@ -38,14 +38,14 @@ export default function () {
|
|||||||
try {
|
try {
|
||||||
jsonContent = YAML.parse(markdownIt.utils.escapeHtml(token.content));
|
jsonContent = YAML.parse(markdownIt.utils.escapeHtml(token.content));
|
||||||
calendar = new Calendar(jsonContent);
|
calendar = new Calendar(jsonContent);
|
||||||
switch (calendar.config.scale) {
|
switch (calendar.config.groupTypes) {
|
||||||
case Scale.Day:
|
case GroupTypes.Day:
|
||||||
contentHtml = new DayRenderer(calendar.eventGrouping).render();
|
contentHtml = new DayRenderer(calendar.eventGrouping).render();
|
||||||
break;
|
break;
|
||||||
case Scale.Week:
|
case GroupTypes.Week:
|
||||||
contentHtml = new WeekRenderer(calendar.eventGrouping).render();
|
contentHtml = new WeekRenderer(calendar.eventGrouping).render();
|
||||||
break;
|
break;
|
||||||
case Scale.Month:
|
case GroupTypes.Month:
|
||||||
contentHtml = new MonthRenderer(calendar.eventGrouping).render();
|
contentHtml = new MonthRenderer(calendar.eventGrouping).render();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
export enum Scale {
|
export enum GroupTypes {
|
||||||
Day = "D",
|
Day = "D",
|
||||||
Week = "W",
|
Week = "W",
|
||||||
Month = "M",
|
Month = "M",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user