diff --git a/src/Model/Files/boardsAndTasksModel.ts b/src/Model/Files/boardsAndTasksModel.ts index f92db82d..85feae48 100644 --- a/src/Model/Files/boardsAndTasksModel.ts +++ b/src/Model/Files/boardsAndTasksModel.ts @@ -1,4 +1,4 @@ -// thile file is responsible for managing boards within chats and tasks within boards. +// this file is responsible for managing boards within chats and tasks within boards. import { DATA_VERSION, diff --git a/src/Model/Files/calendarModel.ts b/src/Model/Files/calendarModel.ts new file mode 100644 index 00000000..a4428a7a --- /dev/null +++ b/src/Model/Files/calendarModel.ts @@ -0,0 +1,83 @@ +// this file extends the BoardsAndTasksModel regarding calendar features. +// it is responsible for managing calendar-realted reference files for tasks. + +import BoardsAndTasksModel, { + TaskFileContent, + TaskFileContentReference, +} from "./boardsAndTasksModel"; +import FileModel, { FileContent, FileModelSubPath } from "./fileModel"; + +import StorageModel from "../Global/storageModel"; +import { checkMatchesObjectStructure } from "../Utility/typeSafety"; + +export default class CalendarModel { + storageModel: StorageModel; + fileModel: FileModel; + + boardsAndTasksModel: BoardsAndTasksModel; + + // paths + getBasePath = (): string[] => { + return this.fileModel.getModelContainerPath(FileModelSubPath.ModelCalendar); + }; + + getViewPath = (): string[] => { + return [...this.getBasePath(), FileModelSubPath.ModelView]; + }; + + getMonthContainerPath = (): string[] => { + return [...this.getBasePath(), CalendarModelSubPaths.Months]; + }; + + getMonthPath = (monthString: string): string[] => { + return [...this.getMonthContainerPath(), monthString]; + }; + + // handlers + handleFileContent = (fileContent: FileContent): void => { + if ( + checkMatchesObjectStructure(fileContent, TaskFileContentReference) == + false + ) + return; + }; + + // main + storeTaskReference = (taskFileContent: TaskFileContent): void => { + if (taskFileContent.date == undefined) return; + const monthString: string = CalendarModel.isoToMonthString( + taskFileContent.date + ); + + const monthPath: string[] = this.getMonthPath(monthString); + const referencePath: string[] = [...monthPath, taskFileContent.fileId]; + + this.storageModel.write(referencePath, ""); + }; + + listTaskIds = (monthString: string): string[] => { + const monthPath: string[] = this.getMonthPath(monthString); + return this.storageModel.list(monthPath); + }; + + // init + constructor( + storageModel: StorageModel, + fileModel: FileModel, + boardsAndTasksModel: BoardsAndTasksModel + ) { + this.storageModel = storageModel; + this.fileModel = fileModel; + this.boardsAndTasksModel = boardsAndTasksModel; + } + + // utility + static isoToMonthString = (dateISOString: string): string => { + const [year, month, _] = dateISOString.split("-"); + return `${year}-${month}`; + }; +} + +export enum CalendarModelSubPaths { + Months = "months", +} diff --git a/src/Model/Files/fileModel.ts b/src/Model/Files/fileModel.ts index 31f7e89a..6075543b 100644 --- a/src/Model/Files/fileModel.ts +++ b/src/Model/Files/fileModel.ts @@ -173,6 +173,7 @@ export enum FileModelSubPath { Model = "model", ModelView = "view", ModelTask = "tasks", + ModelCalendar = "calendar", }; // types