clean
This commit is contained in:
@@ -5,6 +5,7 @@ import { TaskFileContent } from "./boardsAndTasksModel";
|
||||
import StorageModel from "../Global/storageModel";
|
||||
import SettingsModel from "../Global/settingsModel";
|
||||
import CoreViewModel from "../../ViewModel/Global/coreViewModel";
|
||||
import {isoToMonthString, padZero} from "../Utility/utility";
|
||||
|
||||
export default class CalendarModel {
|
||||
readonly storageModel: StorageModel;
|
||||
@@ -34,7 +35,7 @@ export default class CalendarModel {
|
||||
readonly storeTaskReference = (taskFileContent: TaskFileContent): void => {
|
||||
if (taskFileContent.date == undefined) return;
|
||||
|
||||
const monthString: string = CalendarModel.isoToMonthString(
|
||||
const monthString: string = isoToMonthString(
|
||||
taskFileContent.date,
|
||||
);
|
||||
|
||||
@@ -102,8 +103,8 @@ export default class CalendarModel {
|
||||
};
|
||||
|
||||
for (let i = 0; i < daysInMonth; i++) {
|
||||
const paddedDate: string = CalendarModel.padZero(
|
||||
(i + 1).toString(),
|
||||
const paddedDate: string = padZero(
|
||||
(i + 1).toString(), 2
|
||||
);
|
||||
grid.days[paddedDate] = defaultValueCreator();
|
||||
}
|
||||
@@ -121,38 +122,6 @@ export default class CalendarModel {
|
||||
this.settingsModel = settingsModel;
|
||||
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 {
|
||||
|
||||
@@ -20,19 +20,36 @@ export function createTimestamp(): string {
|
||||
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 {
|
||||
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]
|
||||
.map((x, i) => i == 0 ? x : CalendarModel.padZero(x.toString()))
|
||||
.map((x, i) => i == 0 ? x : padZero(x.toString(), 2))
|
||||
.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 {
|
||||
return [date.getHours(), date.getMinutes()]
|
||||
.map(x => CalendarModel.padZero(x.toString()))
|
||||
.map(x => padZero(x.toString(), 2))
|
||||
.join(":");
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@ import CalendarModel, { MonthGrid } from "../../Model/Files/calendarModel";
|
||||
import BoardsAndTasksModel, {
|
||||
TaskFileContent,
|
||||
} 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 default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
||||
// data
|
||||
get monthString(): string {
|
||||
return CalendarModel.getMonthString(
|
||||
return formatMonthStringFromParts(
|
||||
this.selectedYear.value.toString(),
|
||||
this.selectedMonth.value.toString(),
|
||||
);
|
||||
@@ -46,7 +46,7 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
||||
createEvent = (): void => {
|
||||
const taskFileContent: TaskFileContent =
|
||||
this.boardsAndTasksModel.createTask(CALENDAR_EVENT_BOARD_ID);
|
||||
taskFileContent.date = CalendarModel.getISODateString(
|
||||
taskFileContent.date = formatISOFromParts(
|
||||
this.selectedYear.value.toString(),
|
||||
this.selectedMonth.value.toString(),
|
||||
this.selectedDate.value.toString(),
|
||||
@@ -65,8 +65,8 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
||||
};
|
||||
|
||||
getEventsForDate = (): React.MapState<TaskViewModel> | undefined => {
|
||||
const paddedDate: string = CalendarModel.padZero(
|
||||
this.selectedDate.toString(),
|
||||
const paddedDate: string = padZero(
|
||||
this.selectedDate.toString(), 2
|
||||
);
|
||||
|
||||
if (this.monthGrid.value == undefined) {
|
||||
@@ -82,14 +82,14 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
||||
): React.MapState<TaskViewModel> | null => {
|
||||
if (this.monthGrid.value == null) return null;
|
||||
|
||||
const date: string = CalendarModel.isoToDateString(
|
||||
const date: string = isoToDateString(
|
||||
taskFileContent.date ?? "",
|
||||
);
|
||||
return this.monthGrid.value.days[date];
|
||||
};
|
||||
|
||||
showTask = (taskFileContent: TaskFileContent): void => {
|
||||
const monthString: string | undefined = CalendarModel.isoToMonthString(
|
||||
const monthString: string | undefined = isoToMonthString(
|
||||
taskFileContent.date ?? "",
|
||||
);
|
||||
if (monthString == undefined || monthString != this.monthString) {
|
||||
@@ -152,7 +152,7 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
||||
};
|
||||
|
||||
handleDrop = (year: string, month: string, date: string): void => {
|
||||
const ISOString: string = CalendarModel.getISODateString(
|
||||
const ISOString: string = formatISOFromParts(
|
||||
year,
|
||||
month,
|
||||
date,
|
||||
|
||||
Reference in New Issue
Block a user