add methods for accessing and storing tasks

This commit is contained in:
marlon-erler
2024-07-22 13:09:33 +02:00
parent b20f7c072e
commit 3304949d1a
4 changed files with 144 additions and 16 deletions
+3 -3
View File
@@ -86,7 +86,7 @@ export default class FileModel {
};
getFile = (fileId: string): File | null => {
const filePath = this.getFilePath(fileId);
const filePath: string[] = this.getFilePath(fileId);
const fileOrNull: File | null = this.storageModel.readStringifiable(
filePath,
FileReference
@@ -107,7 +107,7 @@ export default class FileModel {
file: File,
fileContentName: string
): FileContent<string> | null => {
const filePath = this.getFileContentPath(file, fileContentName);
const filePath: string[] = this.getFileContentPath(file, fileContentName);
const fileContentOrNull: FileContent<string> | null =
this.storageModel.readStringifiable(filePath, FileContentReference);
return fileContentOrNull;
@@ -118,7 +118,7 @@ export default class FileModel {
this.chatModel = chatModel;
this.storageModel = storageModel;
this.taskModel = new TaskModel(chatModel, this);
this.taskModel = new TaskModel(this.storageModel, chatModel, this);
}
// utility
+82 -8
View File
@@ -5,11 +5,17 @@ import {
ValidObject,
checkMatchesObjectStructure,
} from "../Utility/typeSafety";
import FileModel, { File, FileContent } from "./fileModel";
import FileModel, {
File,
FileContent,
FileContentReference,
} from "./fileModel";
import ChatModel from "../Chat/chatModel";
import StorageModel from "../Global/storageModel";
export default class TaskModel {
storageModel: StorageModel;
chatModel: ChatModel;
fileModel: FileModel;
@@ -38,6 +44,14 @@ export default class TaskModel {
return [...this.getBoardPath(boardName), fileId];
};
getTaskContentPath = (
boardName: string,
fileId: string,
contentName
): string[] => {
return [...this.getTaskPath(boardName, fileId), contentName];
};
// handler
handleTaskFileContent = (
file: File,
@@ -68,15 +82,77 @@ export default class TaskModel {
};
// locations
updateTaskLocation = (
file: File,
taskFileContent: TaskFileContent
): void => {};
getTaskLocation = (file: File): TaskLocation | null => {
const locationPath: string[] = this.getTaskLocationPath(file.id);
const locationOrNull: TaskLocation | null =
this.storageModel.readStringifiable(locationPath, TaskLocationReference);
return locationOrNull;
};
storeTaskLocation = (file: File, taskLocation: TaskLocation): void => {
const locationPath: string[] = this.getTaskLocationPath(file.id);
this.storageModel.writeStringifiable(locationPath, taskLocation);
};
updateTaskLocation = (file: File, newLocation: TaskLocation): boolean => {
const previousLocation: TaskLocation | null = this.getTaskLocation(file);
if (previousLocation == null) return false;
const oldBoardName: string = previousLocation.board;
const sourcePath: string[] = this.getTaskPath(oldBoardName, file.id);
const newBoardName: string = newLocation.board;
const destinationPath: string[] = this.getTaskPath(newBoardName, file.id);
return this.storageModel.rename(sourcePath, destinationPath);
};
// storage
listBoardsNames = (): string[] => {
const boardDirPath: string[] = this.getBoardDirPath();
const boardNames: string[] = this.storageModel.list(boardDirPath);
return boardNames;
};
listFileIdsOfBoard = (boardName: string): string[] => {
const boardPath: string[] = this.getBoardPath(boardName);
const fileIds: string[] = this.storageModel.list(boardPath);
return fileIds;
};
getTaskVersionNames = (boardName: string, fileId: string): string[] => {
const fileDirectoryPath: string[] = this.getTaskPath(boardName, fileId);
const versionNames: string[] = this.storageModel.list(fileDirectoryPath);
return versionNames;
};
getTaskFileContent = (
boardName: string,
fileId: string,
versionName: string
): TaskFileContent | null => {
const fileContentPath: string[] = this.getTaskContentPath(
boardName,
fileId,
versionName
);
const taskFileContentOrNull: TaskFileContent | null =
this.storageModel.readStringifiable(
fileContentPath,
TaskFileContentReference
);
return taskFileContentOrNull;
};
// init
constructor(chatModel: ChatModel, fileModel: FileModel) {
constructor(
storageModel: StorageModel,
chatModel: ChatModel,
fileModel: FileModel
) {
this.chatModel = chatModel;
this.fileModel = fileModel;
this.storageModel = storageModel;
}
// utility
@@ -117,8 +193,6 @@ export interface TaskFileContent extends FileContent<"task"> {
export interface TaskLocation extends ValidObject {
board: string;
category?: string;
status?: string;
}
// reference
+1 -1
View File
@@ -63,4 +63,4 @@ document
ChatPageWrapper(chatListViewModel),
ConnectionModal(connectionViewModel),
StorageModal(storageViewModel)
);
);