Global rename of scale => groupType
This commit is contained in:
parent
5836dfdb2e
commit
a1d1621a75
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
export enum Scale {
|
||||
export enum GroupTypes {
|
||||
Day = "D",
|
||||
Week = "W",
|
||||
Month = "M",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user