cleanup, prepare calendarModel

This commit is contained in:
marlon-erler
2024-07-25 19:11:34 +02:00
parent 2383e49189
commit 0c6609afb5
3 changed files with 85 additions and 1 deletions
+1 -1
View File
@@ -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 { import {
DATA_VERSION, DATA_VERSION,
+83
View File
@@ -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<string>): 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",
}
+1
View File
@@ -173,6 +173,7 @@ export enum FileModelSubPath {
Model = "model", Model = "model",
ModelView = "view", ModelView = "view",
ModelTask = "tasks", ModelTask = "tasks",
ModelCalendar = "calendar",
}; };
// types // types