From ae4339b4d2eac22692e80fe16e10adf6a121f0f1 Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Mon, 22 Jul 2024 14:36:03 +0200 Subject: [PATCH] remodel tasks and boards --- dist/index.js | 159 +++++++++++++++++++------------- src/Model/Files/fileModel.ts | 15 +-- src/Model/Files/taskModel.ts | 173 ++++++++++++++++++++--------------- 3 files changed, 199 insertions(+), 148 deletions(-) diff --git a/dist/index.js b/dist/index.js index 17e4fa2c..8d878b2a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -487,6 +487,18 @@ } }; + // src/ViewModel/colors.ts + var Color = /* @__PURE__ */ ((Color2) => { + Color2["Standard"] = "standard"; + Color2["Coral"] = "coral"; + Color2["Yellow"] = "yellow"; + Color2["Mint"] = "mint"; + Color2["LightBlue"] = "lightblue"; + Color2["Blue"] = "blue"; + Color2["purple"] = "purple"; + return Color2; + })(Color || {}); + // src/Model/Files/taskModel.ts var TaskModel = class _TaskModel { storageModel; @@ -505,61 +517,50 @@ getBoardDirPath = () => { return [...this.getBasePath(), subDirectories.boards]; }; - getBoardPath = (boardName) => { - return [...this.getBoardDirPath(), boardName]; + getBoardPath = (boardId) => { + return [...this.getBoardDirPath(), boardId]; }; - getTaskPath = (boardName, fileId) => { - return [...this.getBoardPath(boardName), fileId]; + getBoardInfoPath = (boardId) => { + return [...this.getBoardPath(boardId), subDirectories.boardInfo]; }; - getTaskContentPath = (boardName, fileId, contentName) => { - return [...this.getTaskPath(boardName, fileId), contentName]; + getTaskDirPath = (boardId) => { + return [...this.getBoardPath(boardId), subDirectories.boardTasks]; + }; + getTaskPath = (boardId, fileId) => { + return [...this.getTaskDirPath(boardId), fileId]; + }; + getTaskContentPath = (boardId, fileId, contentName) => { + return [...this.getTaskPath(boardId, fileId), contentName]; }; // handler - handleTaskFileContent = (file, fileContent) => { - if (checkMatchesObjectStructure(fileContent, TaskFileContentReference) == false) - return; + handleFileContent = (file, fileContent) => { + if (checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true) { + } else if (checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true) { + } }; - // methods - createTask = (board, name) => { + // boards + createBoard = (name) => { const file = FileModel.createFile(); - const taskFileContent = _TaskModel.createTaskFileContent( - board, - name - ); - this.saveTask(file, taskFileContent); + const boardInfoFileContent = _TaskModel.createBoardInfoFileContent(name, "standard" /* Standard */); + this.fileModel.addOrUpdateFile(file, boardInfoFileContent); }; - saveTask = (file, newTaskFileContent) => { - 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, taskLocation) => { - const locationPath = this.getTaskLocationPath(file.id); - this.storageModel.writeStringifiable(locationPath, taskLocation); - }; - updateTaskLocation = (file, newLocation) => { - const previousLocation = this.getTaskLocation(file); - if (previousLocation == null) return false; - const oldBoardName = previousLocation.board; - const sourcePath = this.getTaskPath(oldBoardName, file.id); - const newBoardName = newLocation.board; - const destinationPath = this.getTaskPath(newBoardName, file.id); - return this.storageModel.rename(sourcePath, destinationPath); - }; - // storage - listBoardsNames = () => { + listBoardIds = () => { const boardDirPath = this.getBoardDirPath(); const boardNames = this.storageModel.list(boardDirPath); return boardNames; }; - listFileIdsOfBoard = (boardName) => { - const boardPath = this.getBoardPath(boardName); - const fileIds = this.storageModel.list(boardPath); + //tasks + createTask = (boardId, name) => { + const file = FileModel.createFile(); + const taskFileContent = _TaskModel.createTaskFileContent( + boardId, + name + ); + this.fileModel.addOrUpdateFile(file, taskFileContent); + }; + listTaskIds = (boardName) => { + const getTaskDirPath = this.getTaskDirPath(boardName); + const fileIds = this.storageModel.list(getTaskDirPath); return fileIds; }; getTaskVersionNames = (boardName, fileId) => { @@ -579,6 +580,25 @@ ); return taskFileContentOrNull; }; + // locations + getTaskLocation = (file) => { + const locationPath = this.getTaskLocationPath(file.id); + const locationOrNull = this.storageModel.readStringifiable(locationPath, TaskLocationReference); + return locationOrNull; + }; + storeTaskLocation = (file, taskLocation) => { + const locationPath = this.getTaskLocationPath(file.id); + this.storageModel.writeStringifiable(locationPath, taskLocation); + }; + updateTaskLocation = (file, newLocation) => { + const previousLocation = this.getTaskLocation(file); + if (previousLocation == null) return false; + const oldBoardName = previousLocation.boardId; + const sourcePath = this.getTaskPath(oldBoardName, file.id); + const newBoardName = newLocation.boardId; + const destinationPath = this.getTaskPath(newBoardName, file.id); + return this.storageModel.rename(sourcePath, destinationPath); + }; // init constructor(storageModel2, chatModel, fileModel) { this.chatModel = chatModel; @@ -586,18 +606,36 @@ this.storageModel = storageModel2; } // utility - static createTaskFileContent = (name, board) => { + static createBoardInfoFileContent = (name, color) => { + const fileContent = FileModel.createFileContent("board"); + return { + ...fileContent, + name, + color + }; + }; + static createTaskFileContent = (name, boardId) => { const fileContent = FileModel.createFileContent("task"); return { ...fileContent, name, - board + boardId }; }; }; var subDirectories = { locations: "locations", - boards: "boards" + boards: "boards", + boardInfo: "info", + boardTasks: "tasks" + }; + var BoardInfoFileContentReference = { + dataVersion: DATA_VERSION, + id: "", + creationDate: "", + type: "board", + name: "", + color: "" }; var TaskFileContentReference = { dataVersion: DATA_VERSION, @@ -605,11 +643,11 @@ creationDate: "", type: "task", name: "", - board: "" + boardId: "" }; var TaskLocationReference = { dataVersion: DATA_VERSION, - board: "" + boardId: "" }; // src/Model/Files/fileModel.ts @@ -643,12 +681,13 @@ handleFileAndClearContents = (file) => { for (const fileContent of file.contentVersions) { this.storeFileContent(file, fileContent); - this.taskModel.handleTaskFileContent(file, fileContent); - file.contentVersions.delete(fileContent); + this.taskModel.handleFileContent(file, fileContent); } + file.contentVersions = []; }; // methods - addOrUpdateFile = (file) => { + addOrUpdateFile = (file, fileContent) => { + file.contentVersions.push(fileContent); this.chatModel.sendMessage("", file); this.handleFileAndClearContents(file); }; @@ -701,7 +740,7 @@ return { dataVersion: DATA_VERSION, id: v4_default(), - contentVersions: /* @__PURE__ */ new Set() + contentVersions: [] }; }; static createFileContent = (type) => { @@ -722,7 +761,7 @@ var FileReference = { dataVersion: DATA_VERSION, id: "", - contentVersions: /* @__PURE__ */ new Set([FileContentReference2]) + contentVersions: [FileContentReference2] }; // src/Model/Utility/crypto.ts @@ -798,18 +837,6 @@ return new Uint8Array(array); } - // src/ViewModel/colors.ts - var Color = /* @__PURE__ */ ((Color2) => { - Color2["Standard"] = "standard"; - Color2["Coral"] = "coral"; - Color2["Yellow"] = "yellow"; - Color2["Mint"] = "mint"; - Color2["LightBlue"] = "lightblue"; - Color2["Blue"] = "blue"; - Color2["purple"] = "purple"; - return Color2; - })(Color || {}); - // src/Model/Chat/chatModel.ts var ChatModel = class _ChatModel { connectionModel; diff --git a/src/Model/Files/fileModel.ts b/src/Model/Files/fileModel.ts index e6e66a3e..bc5364df 100644 --- a/src/Model/Files/fileModel.ts +++ b/src/Model/Files/fileModel.ts @@ -52,14 +52,15 @@ export default class FileModel { handleFileAndClearContents = (file: File): void => { for (const fileContent of file.contentVersions) { this.storeFileContent(file, fileContent); - this.taskModel.handleTaskFileContent(file, fileContent); - - file.contentVersions.delete(fileContent); + this.taskModel.handleFileContent(file, fileContent); } + + file.contentVersions = []; }; // methods - addOrUpdateFile = (file: File): void => { + addOrUpdateFile = (file: File, fileContent: FileContent): void => { + file.contentVersions.push(fileContent); this.chatModel.sendMessage("", file); this.handleFileAndClearContents(file); }; @@ -131,7 +132,7 @@ export default class FileModel { dataVersion: DATA_VERSION, id: v4(), - contentVersions: new Set(), + contentVersions: [], }; }; @@ -154,7 +155,7 @@ export const modelDirectories = { // types export interface File extends ValidObject { id: string; - contentVersions: Set>; + contentVersions: FileContent[]; } export interface FileContent extends ValidObject { @@ -177,5 +178,5 @@ export const FileReference: File = { dataVersion: DATA_VERSION, id: "", - contentVersions: new Set([FileContentReference]), + contentVersions: [FileContentReference], }; diff --git a/src/Model/Files/taskModel.ts b/src/Model/Files/taskModel.ts index 9372ee12..b6af31a6 100644 --- a/src/Model/Files/taskModel.ts +++ b/src/Model/Files/taskModel.ts @@ -12,6 +12,7 @@ import FileModel, { } from "./fileModel"; import ChatModel from "../Chat/chatModel"; +import { Color } from "../../ViewModel/colors"; import StorageModel from "../Global/storageModel"; export default class TaskModel { @@ -36,87 +37,81 @@ export default class TaskModel { return [...this.getBasePath(), subDirectories.boards]; }; - getBoardPath = (boardName: string): string[] => { - return [...this.getBoardDirPath(), boardName]; + getBoardPath = (boardId: string): string[] => { + return [...this.getBoardDirPath(), boardId]; }; - getTaskPath = (boardName: string, fileId: string): string[] => { - return [...this.getBoardPath(boardName), fileId]; + getBoardInfoPath = (boardId: string): string[] => { + return [...this.getBoardPath(boardId), subDirectories.boardInfo]; + }; + + getTaskDirPath = (boardId: string): string[] => { + return [...this.getBoardPath(boardId), subDirectories.boardTasks]; + }; + + getTaskPath = (boardId: string, fileId: string): string[] => { + return [...this.getTaskDirPath(boardId), fileId]; }; getTaskContentPath = ( - boardName: string, + boardId: string, fileId: string, - contentName + contentName: string ): string[] => { - return [...this.getTaskPath(boardName, fileId), contentName]; + return [...this.getTaskPath(boardId, fileId), contentName]; }; // handler - handleTaskFileContent = ( - file: File, - fileContent: FileContent - ): void => { + handleFileContent = (file: File, fileContent: FileContent): void => { if ( - checkMatchesObjectStructure(fileContent, TaskFileContentReference) == - false - ) - return; - - // TODO handle + checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == + true + ) { + // todo + } else if ( + checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true + ) { + // todo + } }; - // methods - createTask = (board: string, name: string): void => { + // boards + createBoard = (name: string): void => { const file: File = FileModel.createFile(); - const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent( - board, - name - ); - this.saveTask(file, taskFileContent); + const boardInfoFileContent: BoardInfoFileContent = + TaskModel.createBoardInfoFileContent(name, Color.Standard); + this.fileModel.addOrUpdateFile(file, boardInfoFileContent); }; - saveTask = (file: File, newTaskFileContent: TaskFileContent): void => { - file.contentVersions.add(newTaskFileContent); - this.fileModel.addOrUpdateFile(file); - }; - - // locations - 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[] => { + listBoardIds = (): 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); + getBoardInfo = (boardId: string): BoardInfoFileContent | null => { + const boardInfoPath: string[] = this.getBoardInfoPath(boardId); + const boardInfoFileContentOrNull: BoardInfoFileContent | null = + this.storageModel.readStringifiable( + boardInfoPath, + BoardInfoFileContentReference + ); + return boardInfoFileContentOrNull; + }; + + //tasks + createTask = (boardId: string, name: string): void => { + const file: File = FileModel.createFile(); + const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent( + boardId, + name + ); + this.fileModel.addOrUpdateFile(file, taskFileContent); + }; + + listTaskIds = (boardName: string): string[] => { + const getTaskDirPath: string[] = this.getTaskDirPath(boardName); + const fileIds: string[] = this.storageModel.list(getTaskDirPath); return fileIds; }; @@ -144,6 +139,12 @@ export default class TaskModel { return taskFileContentOrNull; }; + moveTask = (taskFileId: string, oldBoardId: string, newBoardId: string): boolean => { + const sourcePath: string[] = this.getTaskPath(oldBoardId, taskFileId); + const destinationPath: string[] = this.getTaskPath(newBoardId, taskFileId); + return this.storageModel.rename(sourcePath, destinationPath); + } + // init constructor( storageModel: StorageModel, @@ -156,9 +157,23 @@ export default class TaskModel { } // utility + static createBoardInfoFileContent = ( + name: string, + color: Color + ): BoardInfoFileContent => { + const fileContent: FileContent<"board"> = + FileModel.createFileContent("board"); + return { + ...fileContent, + + name, + color, + }; + }; + static createTaskFileContent = ( name: string, - board: string + boardId: string ): TaskFileContent => { const fileContent: FileContent<"task"> = FileModel.createFileContent("task"); @@ -166,7 +181,7 @@ export default class TaskModel { ...fileContent, name, - board, + boardId, }; }; } @@ -174,12 +189,19 @@ export default class TaskModel { export const subDirectories = { locations: "locations", boards: "boards", + boardInfo: "info", + boardTasks: "tasks", }; // types +export interface BoardInfoFileContent extends FileContent<"board"> { + name: string; + color: Color; +} + export interface TaskFileContent extends FileContent<"task"> { name: string; - board: string; + boardId: string; category?: string; status?: string; @@ -191,11 +213,18 @@ export interface TaskFileContent extends FileContent<"task"> { time?: string; } -export interface TaskLocation extends ValidObject { - board: string; -} - // reference +export const BoardInfoFileContentReference: BoardInfoFileContent = { + dataVersion: DATA_VERSION, + + id: "", + creationDate: "", + type: "board", + + name: "", + color: "" as Color, +}; + export const TaskFileContentReference: TaskFileContent = { dataVersion: DATA_VERSION, @@ -204,11 +233,5 @@ export const TaskFileContentReference: TaskFileContent = { type: "task", name: "", - board: "", -}; - -export const TaskLocationReference: TaskLocation = { - dataVersion: DATA_VERSION, - - board: "", -}; + boardId: "", +}; \ No newline at end of file