clean
This commit is contained in:
@@ -5,6 +5,7 @@ import { TaskFileContent } from "./boardsAndTasksModel";
|
|||||||
import StorageModel from "../Global/storageModel";
|
import StorageModel from "../Global/storageModel";
|
||||||
import SettingsModel from "../Global/settingsModel";
|
import SettingsModel from "../Global/settingsModel";
|
||||||
import CoreViewModel from "../../ViewModel/Global/coreViewModel";
|
import CoreViewModel from "../../ViewModel/Global/coreViewModel";
|
||||||
|
import {isoToMonthString, padZero} from "../Utility/utility";
|
||||||
|
|
||||||
export default class CalendarModel {
|
export default class CalendarModel {
|
||||||
readonly storageModel: StorageModel;
|
readonly storageModel: StorageModel;
|
||||||
@@ -34,7 +35,7 @@ export default class CalendarModel {
|
|||||||
readonly storeTaskReference = (taskFileContent: TaskFileContent): void => {
|
readonly storeTaskReference = (taskFileContent: TaskFileContent): void => {
|
||||||
if (taskFileContent.date == undefined) return;
|
if (taskFileContent.date == undefined) return;
|
||||||
|
|
||||||
const monthString: string = CalendarModel.isoToMonthString(
|
const monthString: string = isoToMonthString(
|
||||||
taskFileContent.date,
|
taskFileContent.date,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -102,8 +103,8 @@ export default class CalendarModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
for (let i = 0; i < daysInMonth; i++) {
|
for (let i = 0; i < daysInMonth; i++) {
|
||||||
const paddedDate: string = CalendarModel.padZero(
|
const paddedDate: string = padZero(
|
||||||
(i + 1).toString(),
|
(i + 1).toString(), 2
|
||||||
);
|
);
|
||||||
grid.days[paddedDate] = defaultValueCreator();
|
grid.days[paddedDate] = defaultValueCreator();
|
||||||
}
|
}
|
||||||
@@ -121,38 +122,6 @@ export default class CalendarModel {
|
|||||||
this.settingsModel = settingsModel;
|
this.settingsModel = settingsModel;
|
||||||
this.fileModel = fileModel;
|
this.fileModel = fileModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// utility
|
|
||||||
static isoToMonthString = (dateISOString: string): string => {
|
|
||||||
const [year, month, _] = dateISOString.split("-");
|
|
||||||
return CalendarModel.getMonthString(year, month);
|
|
||||||
};
|
|
||||||
|
|
||||||
static isoToDateString = (dateISOString: string): string => {
|
|
||||||
const [year, month, date, _] = dateISOString.split("-");
|
|
||||||
const paddedDate = CalendarModel.padZero(date ?? "");
|
|
||||||
return paddedDate;
|
|
||||||
};
|
|
||||||
|
|
||||||
static getMonthString = (year: string = "", month: string = ""): string => {
|
|
||||||
const paddedYear: string = year.padStart(4, "0");
|
|
||||||
const paddedMonth: string = CalendarModel.padZero(month);
|
|
||||||
return `${paddedYear}-${paddedMonth}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
static getISODateString = (
|
|
||||||
year: string,
|
|
||||||
month: string,
|
|
||||||
date: string,
|
|
||||||
): string => {
|
|
||||||
const monthString: string = CalendarModel.getMonthString(year, month);
|
|
||||||
const paddedDate: string = CalendarModel.padZero(date);
|
|
||||||
return `${monthString}-${paddedDate}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
static padZero = (input: string): string => {
|
|
||||||
return input.padStart(2, "0");
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum CalendarModelSubPaths {
|
export enum CalendarModelSubPaths {
|
||||||
|
|||||||
@@ -20,19 +20,36 @@ export function createTimestamp(): string {
|
|||||||
return new Date().toISOString();
|
return new Date().toISOString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isoToDateString (dateISOString: string): string {
|
||||||
|
const [year, month, date] = dateISOString.split("-");
|
||||||
|
const paddedDate = padZero(date ?? "", 2);
|
||||||
|
return paddedDate;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function isoToMonthString (dateISOString: string): string {
|
||||||
|
const [year, month, _] = dateISOString.split("-");
|
||||||
|
return formatMonthStringFromParts(year, month);
|
||||||
|
};
|
||||||
|
|
||||||
export function formatISO(date: Date): string {
|
export function formatISO(date: Date): string {
|
||||||
return formatISOFromParts(date.getFullYear(), date.getMonth()+1, date.getDate())
|
return formatISOFromParts(date.getFullYear(), date.getMonth()+1, date.getDate())
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatISOFromParts(year: number, month: number, date: number): string {
|
export function formatISOFromParts(year: number|string, month: number|string, date: number|string): string {
|
||||||
return [year, month, date]
|
return [year, month, date]
|
||||||
.map((x, i) => i == 0 ? x : CalendarModel.padZero(x.toString()))
|
.map((x, i) => i == 0 ? x : padZero(x.toString(), 2))
|
||||||
.join("-");
|
.join("-");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatMonthStringFromParts (year: string = "", month: string = ""): string {
|
||||||
|
const paddedYear: string = padZero(year, 4);
|
||||||
|
const paddedMonth: string = padZero(month, 2);
|
||||||
|
return `${paddedYear}-${paddedMonth}`;
|
||||||
|
};
|
||||||
|
|
||||||
export function formatTime(date: Date): string {
|
export function formatTime(date: Date): string {
|
||||||
return [date.getHours(), date.getMinutes()]
|
return [date.getHours(), date.getMinutes()]
|
||||||
.map(x => CalendarModel.padZero(x.toString()))
|
.map(x => padZero(x.toString(), 2))
|
||||||
.join(":");
|
.join(":");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +241,7 @@ export function parseValidObject<T>(string: string, reference: T): T | null {
|
|||||||
parsed,
|
parsed,
|
||||||
reference,
|
reference,
|
||||||
);
|
);
|
||||||
if (doesMatchReference == false) return null;
|
if (doesMatchReference == false) return null;
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ import CalendarModel, { MonthGrid } from "../../Model/Files/calendarModel";
|
|||||||
import BoardsAndTasksModel, {
|
import BoardsAndTasksModel, {
|
||||||
TaskFileContent,
|
TaskFileContent,
|
||||||
} from "../../Model/Files/boardsAndTasksModel";
|
} from "../../Model/Files/boardsAndTasksModel";
|
||||||
import {formatISO, formatISOFromParts, formatTime} from "../../Model/Utility/utility";
|
import {formatISO, formatISOFromParts, formatMonthStringFromParts, formatTime, isoToDateString, isoToMonthString, padZero} from "../../Model/Utility/utility";
|
||||||
|
|
||||||
export const CALENDAR_EVENT_BOARD_ID = "events";
|
export const CALENDAR_EVENT_BOARD_ID = "events";
|
||||||
|
|
||||||
export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
||||||
// data
|
// data
|
||||||
get monthString(): string {
|
get monthString(): string {
|
||||||
return CalendarModel.getMonthString(
|
return formatMonthStringFromParts(
|
||||||
this.selectedYear.value.toString(),
|
this.selectedYear.value.toString(),
|
||||||
this.selectedMonth.value.toString(),
|
this.selectedMonth.value.toString(),
|
||||||
);
|
);
|
||||||
@@ -46,7 +46,7 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
|||||||
createEvent = (): void => {
|
createEvent = (): void => {
|
||||||
const taskFileContent: TaskFileContent =
|
const taskFileContent: TaskFileContent =
|
||||||
this.boardsAndTasksModel.createTask(CALENDAR_EVENT_BOARD_ID);
|
this.boardsAndTasksModel.createTask(CALENDAR_EVENT_BOARD_ID);
|
||||||
taskFileContent.date = CalendarModel.getISODateString(
|
taskFileContent.date = formatISOFromParts(
|
||||||
this.selectedYear.value.toString(),
|
this.selectedYear.value.toString(),
|
||||||
this.selectedMonth.value.toString(),
|
this.selectedMonth.value.toString(),
|
||||||
this.selectedDate.value.toString(),
|
this.selectedDate.value.toString(),
|
||||||
@@ -65,8 +65,8 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getEventsForDate = (): React.MapState<TaskViewModel> | undefined => {
|
getEventsForDate = (): React.MapState<TaskViewModel> | undefined => {
|
||||||
const paddedDate: string = CalendarModel.padZero(
|
const paddedDate: string = padZero(
|
||||||
this.selectedDate.toString(),
|
this.selectedDate.toString(), 2
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.monthGrid.value == undefined) {
|
if (this.monthGrid.value == undefined) {
|
||||||
@@ -82,14 +82,14 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
|||||||
): React.MapState<TaskViewModel> | null => {
|
): React.MapState<TaskViewModel> | null => {
|
||||||
if (this.monthGrid.value == null) return null;
|
if (this.monthGrid.value == null) return null;
|
||||||
|
|
||||||
const date: string = CalendarModel.isoToDateString(
|
const date: string = isoToDateString(
|
||||||
taskFileContent.date ?? "",
|
taskFileContent.date ?? "",
|
||||||
);
|
);
|
||||||
return this.monthGrid.value.days[date];
|
return this.monthGrid.value.days[date];
|
||||||
};
|
};
|
||||||
|
|
||||||
showTask = (taskFileContent: TaskFileContent): void => {
|
showTask = (taskFileContent: TaskFileContent): void => {
|
||||||
const monthString: string | undefined = CalendarModel.isoToMonthString(
|
const monthString: string | undefined = isoToMonthString(
|
||||||
taskFileContent.date ?? "",
|
taskFileContent.date ?? "",
|
||||||
);
|
);
|
||||||
if (monthString == undefined || monthString != this.monthString) {
|
if (monthString == undefined || monthString != this.monthString) {
|
||||||
@@ -152,7 +152,7 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
handleDrop = (year: string, month: string, date: string): void => {
|
handleDrop = (year: string, month: string, date: string): void => {
|
||||||
const ISOString: string = CalendarModel.getISODateString(
|
const ISOString: string = formatISOFromParts(
|
||||||
year,
|
year,
|
||||||
month,
|
month,
|
||||||
date,
|
date,
|
||||||
|
|||||||
Reference in New Issue
Block a user