diff --git a/dist/index.js b/dist/index.js index 7f5170bc..a7861f52 100644 --- a/dist/index.js +++ b/dist/index.js @@ -386,6 +386,13 @@ } 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 writeStringifiable = (pathComponents, value) => { const valueString = stringify(value); @@ -468,11 +475,11 @@ info: (id) => [...filePaths.chat.chatBase(id), "info"], color: (id) => [...filePaths.chat.chatBase(id), "color"], messages: (id) => [...filePaths.chat.chatBase(id), "messages"], - files: (id) => [...filePaths.chat.chatBase(id), "files"], lastUsedPage: (id) => [ ...filePaths.chat.chatBase(id), "last-used-page" - ] + ], + files: (id) => [...filePaths.chat.chatBase(id), "files"] }, settingsModel: { username: ["user-name"], @@ -482,8 +489,28 @@ // src/Model/Files/taskModel.ts var TaskModel = class _TaskModel { + storageModel; chatModel; 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 handleTaskFileContent = (file, fileContent) => { if (checkMatchesObjectStructure(fileContent, TaskFileContentReference) == false) @@ -502,10 +529,26 @@ file.contentVersions.add(newTaskFileContent); 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 - constructor(chatModel, fileModel) { + constructor(storageModel2, chatModel, fileModel) { this.chatModel = chatModel; this.fileModel = fileModel; + this.storageModel = storageModel2; } // utility static createTaskFileContent = (name, board) => { @@ -517,6 +560,10 @@ }; }; }; + var subDirectories = { + locations: "locations", + boards: "boards" + }; var TaskFileContentReference = { dataVersion: DATA_VERSION, id: "", @@ -525,6 +572,10 @@ name: "", board: "" }; + var TaskLocationReference = { + dataVersion: DATA_VERSION, + board: "" + }; // src/Model/Files/fileModel.ts var FileModel = class _FileModel { @@ -538,6 +589,9 @@ filePaths.chat.files(this.chatModel.id) ); }; + getModelDirectoryPath = (modelName) => { + return [...this.getBasePath(), modelName]; + }; getFilePath = (fileId) => { return [...this.getBasePath(), fileId]; }; @@ -602,7 +656,7 @@ constructor(chatModel, storageModel2) { this.chatModel = chatModel; this.storageModel = storageModel2; - this.taskModel = new TaskModel(chatModel, this); + this.taskModel = new TaskModel(this.storageModel, chatModel, this); } // utility static getFileContentName = (fileContent) => { diff --git a/src/Model/Files/fileModel.ts b/src/Model/Files/fileModel.ts index 81e27f6b..e6e66a3e 100644 --- a/src/Model/Files/fileModel.ts +++ b/src/Model/Files/fileModel.ts @@ -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 | null => { - const filePath = this.getFileContentPath(file, fileContentName); + const filePath: string[] = this.getFileContentPath(file, fileContentName); const fileContentOrNull: FileContent | 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 diff --git a/src/Model/Files/taskModel.ts b/src/Model/Files/taskModel.ts index 78fcd2fe..9372ee12 100644 --- a/src/Model/Files/taskModel.ts +++ b/src/Model/Files/taskModel.ts @@ -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 diff --git a/src/index.tsx b/src/index.tsx index ba7ff69d..aafba104 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -63,4 +63,4 @@ document ChatPageWrapper(chatListViewModel), ConnectionModal(connectionViewModel), StorageModal(storageViewModel) - ); \ No newline at end of file + );