clean model (A)

This commit is contained in:
marlon-erler
2026-04-18 11:55:01 +00:00
parent cae717066a
commit 2ae00924c8
75 changed files with 5139 additions and 5147 deletions
+36 -37
View File
@@ -1,18 +1,17 @@
// this file is responsible for managing boards within chats and tasks within boards.
// cleanup: Phase A
import { v4 } from "uuid";
import FileModel, { FileContent, FileModelSubPath } from "./fileModel";
import CalendarModel from "./calendarModel";
import { HandlerManager } from "../Utility/utility";
import {
DATA_VERSION,
checkMatchesObjectStructure,
} from "../Utility/typeSafety";
import FileModel, { FileContent, FileModelSubPath } from "./fileModel";
import CalendarModel from "./calendarModel";
import StorageModel from "../Global/storageModel";
import SettingsModel from "../Global/settingsModel";
import ChatModel from "../Chat/chatModel";
import { Colors } from "../../colors";
import { HandlerManager } from "../Utility/utility";
import SettingsModel from "../Global/settingsModel";
import StorageModel from "../Global/storageModel";
import { v4 } from "uuid";
export default class BoardsAndTasksModel {
readonly storageModel: StorageModel;
@@ -27,43 +26,43 @@ export default class BoardsAndTasksModel {
readonly taskHandlerManager = new HandlerManager<TaskFileContent>();
// paths
getBasePath = (): string[] => {
readonly getBasePath = (): string[] => {
return this.fileModel.getModelContainerPath(FileModelSubPath.ModelTask);
};
getViewPath = (): string[] => {
readonly getViewPath = (): string[] => {
return [...this.getBasePath(), FileModelSubPath.ModelView];
};
getBoardFilePath = (boardId: string): string[] => {
readonly getBoardFilePath = (boardId: string): string[] => {
return [...this.fileModel.getFilePath(boardId)];
};
getTaskFilePath = (taskId: string): string[] => {
readonly getTaskFilePath = (taskId: string): string[] => {
return [...this.fileModel.getFilePath(taskId)];
};
getBoardContainerPath = (): string[] => {
readonly getBoardContainerPath = (): string[] => {
return [...this.getBasePath(), TaskModelSubPaths.Boards];
};
getBoardDirectoryPath = (boardId: string): string[] => {
readonly getBoardDirectoryPath = (boardId: string): string[] => {
return [...this.getBoardContainerPath(), boardId];
};
getTaskContainerPath = (boardId: string): string[] => {
readonly getTaskContainerPath = (boardId: string): string[] => {
return [
...this.getBoardDirectoryPath(boardId),
TaskModelSubPaths.BoardTasks,
];
};
getTaskReferencePath = (boardId: string, fileId: string): string[] => {
readonly getTaskReferencePath = (boardId: string, fileId: string): string[] => {
return [...this.getTaskContainerPath(boardId), fileId];
};
// handlers
handleFileContent = (fileContent: FileContent<string>): void => {
readonly handleFileContent = (fileContent: FileContent<string>): void => {
if (
checkMatchesObjectStructure(
fileContent,
@@ -81,16 +80,16 @@ export default class BoardsAndTasksModel {
}
};
handleBoard = (boardInfoFileContent: BoardInfoFileContent) => {
readonly handleBoard = (boardInfoFileContent: BoardInfoFileContent) => {
this.updateBoard(boardInfoFileContent);
};
handleTask = (taskFileContent: TaskFileContent) => {
readonly handleTask = (taskFileContent: TaskFileContent) => {
this.updateTask(taskFileContent);
};
// boards
createBoard = (name: string): BoardInfoFileContent => {
readonly createBoard = (name: string): BoardInfoFileContent => {
const boardInfoFileContent: BoardInfoFileContent =
BoardsAndTasksModel.createBoardInfoFileContent(
v4(),
@@ -100,17 +99,17 @@ export default class BoardsAndTasksModel {
return boardInfoFileContent;
};
updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
readonly updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
this.storeBoard(boardInfoFileContent);
this.boardHandlerManager.trigger(boardInfoFileContent);
};
updateBoardAndSend = (boardInfoFileContent: BoardInfoFileContent): void => {
readonly updateBoardAndSend = (boardInfoFileContent: BoardInfoFileContent): void => {
this.updateBoard(boardInfoFileContent);
this.chatModel.sendMessage("", undefined, boardInfoFileContent);
};
storeBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
readonly storeBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
// store info
this.fileModel.storeFileContent(boardInfoFileContent);
@@ -121,7 +120,7 @@ export default class BoardsAndTasksModel {
this.storageModel.write(boardDirectoryPath, "");
};
deleteBoard = (boardId: string): void => {
readonly deleteBoard = (boardId: string): void => {
const boardFilePath: string[] = this.getBoardFilePath(boardId);
const boardDirectoryPath: string[] =
this.getBoardDirectoryPath(boardId);
@@ -130,13 +129,13 @@ export default class BoardsAndTasksModel {
this.storageModel.removeRecursively(boardDirectoryPath);
};
listBoardIds = (): string[] => {
readonly listBoardIds = (): string[] => {
const boardContainerPath: string[] = this.getBoardContainerPath();
const boardIds: string[] = this.storageModel.list(boardContainerPath);
return boardIds;
};
getBoardInfo = (fileId: string): BoardInfoFileContent | null => {
readonly getBoardInfo = (fileId: string): BoardInfoFileContent | null => {
const boardInfoFileContentOrNull: BoardInfoFileContent | null =
this.fileModel.getLatestFileContent(
fileId,
@@ -145,7 +144,7 @@ export default class BoardsAndTasksModel {
return boardInfoFileContentOrNull;
};
getBoardName = (boardId: string): string => {
readonly getBoardName = (boardId: string): string => {
const boardInfo: BoardInfoFileContent | null =
this.getBoardInfo(boardId);
if (boardInfo == null) return "";
@@ -153,23 +152,23 @@ export default class BoardsAndTasksModel {
};
//tasks
createTask = (boardId: string): TaskFileContent => {
readonly createTask = (boardId: string): TaskFileContent => {
const taskFileContent: TaskFileContent =
BoardsAndTasksModel.createTaskFileContent(v4(), "", boardId);
return taskFileContent;
};
updateTask = (taskFileContent: TaskFileContent): void => {
readonly updateTask = (taskFileContent: TaskFileContent): void => {
this.storeTask(taskFileContent);
this.taskHandlerManager.trigger(taskFileContent);
};
updateTaskAndSend = (taskFileContent: TaskFileContent): void => {
readonly updateTaskAndSend = (taskFileContent: TaskFileContent): void => {
this.updateTask(taskFileContent);
this.chatModel.sendMessage("", undefined, taskFileContent);
};
storeTask = (taskFileContent: TaskFileContent): void => {
readonly storeTask = (taskFileContent: TaskFileContent): void => {
// store info
this.fileModel.storeFileContent(taskFileContent);
@@ -184,18 +183,18 @@ export default class BoardsAndTasksModel {
this.calendarModel.storeTaskReference(taskFileContent);
};
listTaskIds = (boardId: string): string[] => {
readonly listTaskIds = (boardId: string): string[] => {
const taskContainerPath: string[] = this.getTaskContainerPath(boardId);
const fileIds: string[] = this.storageModel.list(taskContainerPath);
return fileIds;
};
listTaskVersionIds = (taskId: string): string[] => {
readonly listTaskVersionIds = (taskId: string): string[] => {
const versionIds: string[] = this.fileModel.listFileContentIds(taskId);
return versionIds;
};
getLatestTaskFileContent = (taskId: string): TaskFileContent | null => {
readonly getLatestTaskFileContent = (taskId: string): TaskFileContent | null => {
const taskFileContentOrNull: TaskFileContent | null =
this.fileModel.getLatestFileContent(
taskId,
@@ -204,7 +203,7 @@ export default class BoardsAndTasksModel {
return taskFileContentOrNull;
};
getSpecificTaskFileContent = (
readonly getSpecificTaskFileContent = (
taskId: string,
versionId: string,
): TaskFileContent | null => {
@@ -217,14 +216,14 @@ export default class BoardsAndTasksModel {
return taskFileContentOrNull;
};
deleteTask = (boardId: string, taskId: string): void => {
readonly deleteTask = (boardId: string, taskId: string): void => {
const taskFilePath: string[] = this.getTaskFilePath(taskId);
this.storageModel.removeRecursively(taskFilePath);
this.deleteTaskReference(boardId, taskId);
};
deleteTaskReference = (boardId: string, taskId: string): void => {
readonly deleteTaskReference = (boardId: string, taskId: string): void => {
const taskReferencePath: string[] = this.getTaskReferencePath(
boardId,
taskId,
+16 -15
View File
@@ -1,10 +1,9 @@
// it is responsible for managing calendar-realted reference files for tasks.
// cleanup: Phase A
import FileModel, { FileModelSubPath } from "./fileModel";
import SettingsModel from "../Global/settingsModel";
import StorageModel from "../Global/storageModel";
import { TaskFileContent } from "./boardsAndTasksModel";
import StorageModel from "../Global/storageModel";
import SettingsModel from "../Global/settingsModel";
import CoreViewModel from "../../ViewModel/Global/coreViewModel";
export default class CalendarModel {
@@ -13,26 +12,26 @@ export default class CalendarModel {
readonly settingsModel: SettingsModel;
// paths
getBasePath = (): string[] => {
get basePath (): string[] {
return this.fileModel.getModelContainerPath(
FileModelSubPath.ModelCalendar,
);
};
getViewPath = (): string[] => {
return [...this.getBasePath(), FileModelSubPath.ModelView];
readonly getViewPath = (): string[] => {
return [...this.basePath, FileModelSubPath.ModelView];
};
getMonthContainerPath = (): string[] => {
return [...this.getBasePath(), CalendarModelSubPaths.Months];
readonly getMonthContainerPath = (): string[] => {
return [...this.basePath, CalendarModelSubPaths.Months];
};
getMonthPath = (monthString: string): string[] => {
readonly getMonthPath = (monthString: string): string[] => {
return [...this.getMonthContainerPath(), monthString];
};
// main
storeTaskReference = (taskFileContent: TaskFileContent): void => {
// task references
readonly storeTaskReference = (taskFileContent: TaskFileContent): void => {
if (taskFileContent.date == undefined) return;
const monthString: string = CalendarModel.isoToMonthString(
@@ -45,19 +44,21 @@ export default class CalendarModel {
this.storageModel.write(referencePath, "");
};
deleteTaskReference = (monthString: string, taskId: string): void => {
readonly deleteTaskReference = (monthString: string, taskId: string): void => {
const monthPath: string[] = this.getMonthPath(monthString);
const referencePath: string[] = [...monthPath, taskId];
this.storageModel.write(referencePath, "");
};
listTaskIds = (monthString: string): string[] => {
// data
readonly listTaskIds = (monthString: string): string[] => {
const monthPath: string[] = this.getMonthPath(monthString);
return this.storageModel.list(monthPath);
};
generateMonthGrid = <T>(
// util
readonly generateMonthGrid = <T>(
coreViewModel: CoreViewModel,
year: number,
month: number,
+26 -27
View File
@@ -1,21 +1,20 @@
// this file is responsible for managing files within chats.
// cleanup: Phase A
import { DATA_VERSION, ValidObject } from "../Utility/typeSafety";
import StorageModel, {
StorageModelSubPaths,
filePaths,
} from "../Global/storageModel";
import { v4 } from "uuid";
import BoardsAndTasksModel from "./boardsAndTasksModel";
import {
StringEntryObject,
createTimestamp,
parseValidObject,
stringify,
} from "../Utility/utility";
import BoardsAndTasksModel from "./boardsAndTasksModel";
import ChatModel from "../Chat/chatModel";
import { DATA_VERSION, ValidObject } from "../Utility/typeSafety";
import StorageModel, {
StorageModelSubPaths,
filePaths,
} from "../Global/storageModel";
import SettingsModel from "../Global/settingsModel";
import { v4 } from "uuid";
import ChatModel from "../Chat/chatModel";
export default class FileModel {
readonly storageModel: StorageModel;
@@ -25,32 +24,32 @@ export default class FileModel {
readonly boardsAndTasksModel: BoardsAndTasksModel;
// paths
getBasePath = (): string[] => {
get basePath(): string[] {
return StorageModel.getPath(
StorageModelSubPaths.Chat,
filePaths.chat.files(this.chatModel.id),
);
};
getFileContainerPath = (): string[] => {
return [...this.getBasePath(), FileModelSubPath.Data];
readonly getFileContainerPath = (): string[] => {
return [...this.basePath, FileModelSubPath.Data];
};
getModelContainerPath = (modelName: FileModelSubPath): string[] => {
return [...this.getBasePath(), FileModelSubPath.Model, modelName];
readonly getModelContainerPath = (modelName: FileModelSubPath): string[] => {
return [...this.basePath, FileModelSubPath.Model, modelName];
};
getFilePath = (fileId: string): string[] => {
readonly getFilePath = (fileId: string): string[] => {
return [...this.getFileContainerPath(), fileId];
};
getFileContentPath = (fileId: string, fileContentId: string): string[] => {
readonly getFileContentPath = (fileId: string, fileContentId: string): string[] => {
const filePath: string[] = this.getFilePath(fileId);
return [...filePath, fileContentId];
};
// handlers
handleStringifiedFileContent = (stringifiedFileContent: string): void => {
readonly handleStringifiedFileContent = (stringifiedFileContent: string): void => {
const fileContent: FileContent<string> | null = parseValidObject(
stringifiedFileContent,
FileContentReference,
@@ -60,7 +59,7 @@ export default class FileModel {
this.handleFileContent(fileContent);
};
handleFileContent = (fileContent: FileContent<string>): void => {
readonly handleFileContent = (fileContent: FileContent<string>): void => {
const didStore: boolean = this.storeFileContent(fileContent);
if (didStore == false) return;
@@ -69,13 +68,13 @@ export default class FileModel {
};
// methods
addFileContentAndSend = (fileContent: FileContent<string>): void => {
readonly addFileContentAndSend = (fileContent: FileContent<string>): void => {
this.handleFileContent(fileContent);
this.chatModel.sendMessage("", undefined, fileContent);
};
// storage
storeFileContent = (fileContent: FileContent<string>): boolean => {
readonly storeFileContent = (fileContent: FileContent<string>): boolean => {
const fileContentPath: string[] = this.getFileContentPath(
fileContent.fileId,
fileContent.fileContentId,
@@ -91,22 +90,22 @@ export default class FileModel {
return true;
};
listFileIds = (): string[] => {
return this.storageModel.list(this.getBasePath());
readonly listFileIds = (): string[] => {
return this.storageModel.list(this.basePath);
};
listFileContentIds = (fileId: string): string[] => {
readonly listFileContentIds = (fileId: string): string[] => {
const filePath: string[] = this.getFilePath(fileId);
return this.storageModel.list(filePath);
};
selectLatestFileContentId = (
readonly selectLatestFileContentId = (
fileContentIds: string[],
): string | undefined => {
return fileContentIds[fileContentIds.length - 1];
};
getFileContent = <T extends FileContent<string>>(
readonly getFileContent = <T extends FileContent<string>>(
fileId: string,
fileContentName: string,
reference: T,
@@ -122,7 +121,7 @@ export default class FileModel {
return fileContentOrNull;
};
getLatestFileContent = <T extends FileContent<string>>(
readonly getLatestFileContent = <T extends FileContent<string>>(
fileId: string,
reference: T,
): T | null => {