cleanup, prepare calendarModel
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
@@ -173,6 +173,7 @@ export enum FileModelSubPath {
|
||||
Model = "model",
|
||||
ModelView = "view",
|
||||
ModelTask = "tasks",
|
||||
ModelCalendar = "calendar",
|
||||
};
|
||||
|
||||
// types
|
||||
|
||||
Reference in New Issue
Block a user