integrate CalendarModel

This commit is contained in:
marlon-erler
2024-07-25 19:14:30 +02:00
parent 0c6609afb5
commit 3fa3945b0d
4 changed files with 56 additions and 15 deletions
+51 -3
View File
@@ -777,7 +777,6 @@
this.chatModel = chatModel; this.chatModel = chatModel;
this.fileModel = fileModel; this.fileModel = fileModel;
this.storageModel = storageModel2; this.storageModel = storageModel2;
fileModel.fileContentHandlerManager.addHandler(this.handleFileContent);
} }
// utility // utility
static createBoardInfoFileContent = (fileId, name, color) => { static createBoardInfoFileContent = (fileId, name, color) => {
@@ -822,12 +821,60 @@
boardId: "" boardId: ""
}; };
// src/Model/Files/calendarModel.ts
var CalendarModel = class _CalendarModel {
storageModel;
fileModel;
// paths
getBasePath = () => {
return this.fileModel.getModelContainerPath("calendar" /* ModelCalendar */);
};
getViewPath = () => {
return [...this.getBasePath(), "view" /* ModelView */];
};
getMonthContainerPath = () => {
return [...this.getBasePath(), "months" /* Months */];
};
getMonthPath = (monthString) => {
return [...this.getMonthContainerPath(), monthString];
};
// handlers
handleFileContent = (fileContent) => {
if (checkMatchesObjectStructure(fileContent, TaskFileContentReference) == false)
return;
};
// main
storeTaskReference = (taskFileContent) => {
if (taskFileContent.date == void 0) return;
const monthString = _CalendarModel.isoToMonthString(
taskFileContent.date
);
const monthPath = this.getMonthPath(monthString);
const referencePath = [...monthPath, taskFileContent.fileId];
this.storageModel.write(referencePath, "");
};
listTaskIds = (monthString) => {
const monthPath = this.getMonthPath(monthString);
return this.storageModel.list(monthPath);
};
// init
constructor(storageModel2, fileModel) {
this.storageModel = storageModel2;
this.fileModel = fileModel;
}
// utility
static isoToMonthString = (dateISOString) => {
const [year, month, _] = dateISOString.split("-");
return `${year}-${month}`;
};
};
// src/Model/Files/fileModel.ts // src/Model/Files/fileModel.ts
var FileModel = class _FileModel { var FileModel = class _FileModel {
chatModel; chatModel;
storageModel; storageModel;
boardsAndTasksModel; boardsAndTasksModel;
fileContentHandlerManager = new HandlerManager(); calendarModel;
// paths // paths
getBasePath = () => { getBasePath = () => {
return StorageModel.getPath( return StorageModel.getPath(
@@ -861,7 +908,7 @@
const didStore = this.storeFileContent(fileContent); const didStore = this.storeFileContent(fileContent);
if (didStore == false) return; if (didStore == false) return;
this.boardsAndTasksModel.handleFileContent(fileContent); this.boardsAndTasksModel.handleFileContent(fileContent);
this.fileContentHandlerManager.trigger(fileContent); this.calendarModel.handleFileContent(fileContent);
}; };
// methods // methods
addFileContentAndSend = (fileContent) => { addFileContentAndSend = (fileContent) => {
@@ -914,6 +961,7 @@
this.chatModel = chatModel; this.chatModel = chatModel;
this.storageModel = storageModel2; this.storageModel = storageModel2;
this.boardsAndTasksModel = new BoardsAndTasksModel(this.storageModel, chatModel, this); this.boardsAndTasksModel = new BoardsAndTasksModel(this.storageModel, chatModel, this);
this.calendarModel = new CalendarModel(this.storageModel, this);
} }
// utility // utility
static generateFileContentId = (creationDate) => { static generateFileContentId = (creationDate) => {
-3
View File
@@ -220,9 +220,6 @@ export default class BoardsAndTasksModel {
this.chatModel = chatModel; this.chatModel = chatModel;
this.fileModel = fileModel; this.fileModel = fileModel;
this.storageModel = storageModel; this.storageModel = storageModel;
// handlers
fileModel.fileContentHandlerManager.addHandler(this.handleFileContent);
} }
// utility // utility
+1 -6
View File
@@ -14,8 +14,6 @@ export default class CalendarModel {
storageModel: StorageModel; storageModel: StorageModel;
fileModel: FileModel; fileModel: FileModel;
boardsAndTasksModel: BoardsAndTasksModel;
// paths // paths
getBasePath = (): string[] => { getBasePath = (): string[] => {
return this.fileModel.getModelContainerPath(FileModelSubPath.ModelCalendar); return this.fileModel.getModelContainerPath(FileModelSubPath.ModelCalendar);
@@ -63,12 +61,9 @@ export default class CalendarModel {
// init // init
constructor( constructor(
storageModel: StorageModel, storageModel: StorageModel,
fileModel: FileModel, fileModel: FileModel, ) {
boardsAndTasksModel: BoardsAndTasksModel
) {
this.storageModel = storageModel; this.storageModel = storageModel;
this.fileModel = fileModel; this.fileModel = fileModel;
this.boardsAndTasksModel = boardsAndTasksModel;
} }
// utility // utility
+4 -3
View File
@@ -11,6 +11,7 @@ import {
import StorageModel, { StorageModelSubPath, filePaths } from "../Global/storageModel"; import StorageModel, { StorageModelSubPath, filePaths } from "../Global/storageModel";
import BoardsAndTasksModel from "./boardsAndTasksModel"; import BoardsAndTasksModel from "./boardsAndTasksModel";
import CalendarModel from "./calendarModel";
import ChatModel from "../Chat/chatModel"; import ChatModel from "../Chat/chatModel";
import { v4 } from "uuid"; import { v4 } from "uuid";
@@ -19,8 +20,7 @@ export default class FileModel {
storageModel: StorageModel; storageModel: StorageModel;
boardsAndTasksModel: BoardsAndTasksModel; boardsAndTasksModel: BoardsAndTasksModel;
calendarModel: CalendarModel;
fileContentHandlerManager: HandlerManager<FileContent<string>> = new HandlerManager();
// paths // paths
getBasePath = (): string[] => { getBasePath = (): string[] => {
@@ -65,7 +65,7 @@ export default class FileModel {
if (didStore == false) return; if (didStore == false) return;
this.boardsAndTasksModel.handleFileContent(fileContent); this.boardsAndTasksModel.handleFileContent(fileContent);
this.fileContentHandlerManager.trigger(fileContent); this.calendarModel.handleFileContent(fileContent);
}; };
// methods // methods
@@ -142,6 +142,7 @@ export default class FileModel {
this.storageModel = storageModel; this.storageModel = storageModel;
this.boardsAndTasksModel = new BoardsAndTasksModel(this.storageModel, chatModel, this); this.boardsAndTasksModel = new BoardsAndTasksModel(this.storageModel, chatModel, this);
this.calendarModel = new CalendarModel(this.storageModel, this);
} }
// utility // utility