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
+58 -4
View File
@@ -386,6 +386,13 @@
} }
return [...Object.keys(currentParent).sort(localeCompare)]; return [...Object.keys(currentParent).sort(localeCompare)];
}; };
rename = (sourcePathComponents, destinationPathComponents) => {
const content = this.read(sourcePathComponents);
if (content == null) return false;
this.write(destinationPathComponents, content);
this.remove(sourcePathComponents);
return true;
};
// stringifiable // stringifiable
writeStringifiable = (pathComponents, value) => { writeStringifiable = (pathComponents, value) => {
const valueString = stringify(value); const valueString = stringify(value);
@@ -468,11 +475,11 @@
info: (id) => [...filePaths.chat.chatBase(id), "info"], info: (id) => [...filePaths.chat.chatBase(id), "info"],
color: (id) => [...filePaths.chat.chatBase(id), "color"], color: (id) => [...filePaths.chat.chatBase(id), "color"],
messages: (id) => [...filePaths.chat.chatBase(id), "messages"], messages: (id) => [...filePaths.chat.chatBase(id), "messages"],
files: (id) => [...filePaths.chat.chatBase(id), "files"],
lastUsedPage: (id) => [ lastUsedPage: (id) => [
...filePaths.chat.chatBase(id), ...filePaths.chat.chatBase(id),
"last-used-page" "last-used-page"
] ],
files: (id) => [...filePaths.chat.chatBase(id), "files"]
}, },
settingsModel: { settingsModel: {
username: ["user-name"], username: ["user-name"],
@@ -482,8 +489,28 @@
// src/Model/Files/taskModel.ts // src/Model/Files/taskModel.ts
var TaskModel = class _TaskModel { var TaskModel = class _TaskModel {
storageModel;
chatModel; chatModel;
fileModel; fileModel;
// paths
getBasePath = () => {
return this.fileModel.getModelDirectoryPath("taskModel");
};
getLocationDirPath = () => {
return [...this.getBasePath(), subDirectories.locations];
};
getTaskLocationPath = (fileId) => {
return [...this.getLocationDirPath(), fileId];
};
getBoardDirPath = () => {
return [...this.getBasePath(), subDirectories.boards];
};
getBoardPath = (boardName) => {
return [...this.getBoardDirPath(), boardName];
};
getTaskPath = (boardName, fileId) => {
return [...this.getBoardPath(boardName), fileId];
};
// handler // handler
handleTaskFileContent = (file, fileContent) => { handleTaskFileContent = (file, fileContent) => {
if (checkMatchesObjectStructure(fileContent, TaskFileContentReference) == false) if (checkMatchesObjectStructure(fileContent, TaskFileContentReference) == false)
@@ -502,10 +529,26 @@
file.contentVersions.add(newTaskFileContent); file.contentVersions.add(newTaskFileContent);
this.fileModel.addOrUpdateFile(file); this.fileModel.addOrUpdateFile(file);
}; };
// locations
getTaskLocation = (file) => {
const locationPath = this.getTaskLocationPath(file.id);
const locationOrNull = this.storageModel.readStringifiable(locationPath, TaskLocationReference);
return locationOrNull;
};
storeTaskLocation = (file, taskFileContent) => {
const locationPath = this.getTaskLocationPath(file.id);
this.storageModel.writeStringifiable(locationPath, taskFileContent);
};
updateTaskLocation = (file, newTaskFileContent) => {
const previousLocation = this.getTaskLocation(file);
if (previousLocation != null) {
}
};
// init // init
constructor(chatModel, fileModel) { constructor(storageModel2, chatModel, fileModel) {
this.chatModel = chatModel; this.chatModel = chatModel;
this.fileModel = fileModel; this.fileModel = fileModel;
this.storageModel = storageModel2;
} }
// utility // utility
static createTaskFileContent = (name, board) => { static createTaskFileContent = (name, board) => {
@@ -517,6 +560,10 @@
}; };
}; };
}; };
var subDirectories = {
locations: "locations",
boards: "boards"
};
var TaskFileContentReference = { var TaskFileContentReference = {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
id: "", id: "",
@@ -525,6 +572,10 @@
name: "", name: "",
board: "" board: ""
}; };
var TaskLocationReference = {
dataVersion: DATA_VERSION,
board: ""
};
// src/Model/Files/fileModel.ts // src/Model/Files/fileModel.ts
var FileModel = class _FileModel { var FileModel = class _FileModel {
@@ -538,6 +589,9 @@
filePaths.chat.files(this.chatModel.id) filePaths.chat.files(this.chatModel.id)
); );
}; };
getModelDirectoryPath = (modelName) => {
return [...this.getBasePath(), modelName];
};
getFilePath = (fileId) => { getFilePath = (fileId) => {
return [...this.getBasePath(), fileId]; return [...this.getBasePath(), fileId];
}; };
@@ -602,7 +656,7 @@
constructor(chatModel, storageModel2) { constructor(chatModel, storageModel2) {
this.chatModel = chatModel; this.chatModel = chatModel;
this.storageModel = storageModel2; this.storageModel = storageModel2;
this.taskModel = new TaskModel(chatModel, this); this.taskModel = new TaskModel(this.storageModel, chatModel, this);
} }
// utility // utility
static getFileContentName = (fileContent) => { static getFileContentName = (fileContent) => {
+3 -3
View File
@@ -86,7 +86,7 @@ export default class FileModel {
}; };
getFile = (fileId: string): File | null => { getFile = (fileId: string): File | null => {
const filePath = this.getFilePath(fileId); const filePath: string[] = this.getFilePath(fileId);
const fileOrNull: File | null = this.storageModel.readStringifiable( const fileOrNull: File | null = this.storageModel.readStringifiable(
filePath, filePath,
FileReference FileReference
@@ -107,7 +107,7 @@ export default class FileModel {
file: File, file: File,
fileContentName: string fileContentName: string
): FileContent<string> | null => { ): FileContent<string> | null => {
const filePath = this.getFileContentPath(file, fileContentName); const filePath: string[] = this.getFileContentPath(file, fileContentName);
const fileContentOrNull: FileContent<string> | null = const fileContentOrNull: FileContent<string> | null =
this.storageModel.readStringifiable(filePath, FileContentReference); this.storageModel.readStringifiable(filePath, FileContentReference);
return fileContentOrNull; return fileContentOrNull;
@@ -118,7 +118,7 @@ export default class FileModel {
this.chatModel = chatModel; this.chatModel = chatModel;
this.storageModel = storageModel; this.storageModel = storageModel;
this.taskModel = new TaskModel(chatModel, this); this.taskModel = new TaskModel(this.storageModel, chatModel, this);
} }
// utility // utility
+82 -8
View File
@@ -5,11 +5,17 @@ import {
ValidObject, ValidObject,
checkMatchesObjectStructure, checkMatchesObjectStructure,
} from "../Utility/typeSafety"; } from "../Utility/typeSafety";
import FileModel, { File, FileContent } from "./fileModel"; import FileModel, {
File,
FileContent,
FileContentReference,
} from "./fileModel";
import ChatModel from "../Chat/chatModel"; import ChatModel from "../Chat/chatModel";
import StorageModel from "../Global/storageModel";
export default class TaskModel { export default class TaskModel {
storageModel: StorageModel;
chatModel: ChatModel; chatModel: ChatModel;
fileModel: FileModel; fileModel: FileModel;
@@ -38,6 +44,14 @@ export default class TaskModel {
return [...this.getBoardPath(boardName), fileId]; return [...this.getBoardPath(boardName), fileId];
}; };
getTaskContentPath = (
boardName: string,
fileId: string,
contentName
): string[] => {
return [...this.getTaskPath(boardName, fileId), contentName];
};
// handler // handler
handleTaskFileContent = ( handleTaskFileContent = (
file: File, file: File,
@@ -68,15 +82,77 @@ export default class TaskModel {
}; };
// locations // locations
updateTaskLocation = ( getTaskLocation = (file: File): TaskLocation | null => {
file: File, const locationPath: string[] = this.getTaskLocationPath(file.id);
taskFileContent: TaskFileContent const locationOrNull: TaskLocation | null =
): void => {}; 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 // init
constructor(chatModel: ChatModel, fileModel: FileModel) { constructor(
storageModel: StorageModel,
chatModel: ChatModel,
fileModel: FileModel
) {
this.chatModel = chatModel; this.chatModel = chatModel;
this.fileModel = fileModel; this.fileModel = fileModel;
this.storageModel = storageModel;
} }
// utility // utility
@@ -117,8 +193,6 @@ export interface TaskFileContent extends FileContent<"task"> {
export interface TaskLocation extends ValidObject { export interface TaskLocation extends ValidObject {
board: string; board: string;
category?: string;
status?: string;
} }
// reference // reference