This commit is contained in:
marlon-erler
2024-07-22 19:28:39 +02:00
parent 066a773a3a
commit 036dc5a805
5 changed files with 156 additions and 99 deletions
+82 -30
View File
@@ -538,6 +538,9 @@
getBoardFilePath = (boardId) => { getBoardFilePath = (boardId) => {
return [...this.fileModel.getFilePath(boardId)]; return [...this.fileModel.getFilePath(boardId)];
}; };
getTaskFilePath = (taskId) => {
return [...this.fileModel.getFilePath(taskId)];
};
getBoardContainerPath = () => { getBoardContainerPath = () => {
return [...this.getBasePath(), subDirectories.boards]; return [...this.getBasePath(), subDirectories.boards];
}; };
@@ -547,12 +550,9 @@
getTaskContainerPath = (boardId) => { getTaskContainerPath = (boardId) => {
return [...this.getBoardDirectoryPath(boardId), subDirectories.boardTasks]; return [...this.getBoardDirectoryPath(boardId), subDirectories.boardTasks];
}; };
getTaskPath = (boardId, fileId) => { getTaskReferencePath = (boardId, fileId) => {
return [...this.getTaskContainerPath(boardId), fileId]; return [...this.getTaskContainerPath(boardId), fileId];
}; };
getTaskContentPath = (boardId, fileId, versionId) => {
return [...this.getTaskPath(boardId, fileId), versionId];
};
// handler // handler
handleFileContent = (fileContent) => { handleFileContent = (fileContent) => {
if (checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true) { if (checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true) {
@@ -562,14 +562,32 @@
} }
}; };
handleBoard = (boardInfoFileContent) => { handleBoard = (boardInfoFileContent) => {
console.log("board", boardInfoFileContent); this.storeBoard(boardInfoFileContent);
}; };
handleTask = (taskFileContent) => { handleTask = (taskFileContent) => {
this.storeTask(taskFileContent);
}; };
// boards // boards
createBoard = (name) => { createBoard = (name) => {
const boardInfoFileContent = _TaskModel.createBoardInfoFileContent(v4_default(), name, "standard" /* Standard */); const boardInfoFileContent = _TaskModel.createBoardInfoFileContent(v4_default(), name, "standard" /* Standard */);
this.createOrUpdateBoard(boardInfoFileContent); this.updateBoard(boardInfoFileContent);
};
updateBoard = (boardInfoFileContent) => {
this.storeBoard(boardInfoFileContent);
this.chatModel.sendMessage("", boardInfoFileContent);
};
storeBoard = (boardInfoFileContent) => {
this.fileModel.addFileContent(boardInfoFileContent);
const boardDirectoryPath = this.getBoardDirectoryPath(
boardInfoFileContent.fileId
);
this.storageModel.write(boardDirectoryPath, "");
};
deleteBoard = (boardId) => {
const boardFilePath = this.getBoardFilePath(boardId);
const boardDirectoryPath = this.getBoardDirectoryPath(boardId);
this.storageModel.removeRecursively(boardFilePath);
this.storageModel.removeRecursively(boardDirectoryPath);
}; };
listBoardIds = () => { listBoardIds = () => {
const boardContainerPath = this.getBoardContainerPath(); const boardContainerPath = this.getBoardContainerPath();
@@ -583,37 +601,42 @@
); );
return boardInfoFileContentOrNull; return boardInfoFileContentOrNull;
}; };
createOrUpdateBoard = (boardInfoFileContent) => {
this.fileModel.addFileContent(boardInfoFileContent);
const boardDirectoryPath = this.getBoardDirectoryPath(
boardInfoFileContent.fileId
);
this.storageModel.write(boardDirectoryPath, "");
};
deleteBoard = (boardId) => {
const boardFilePath = this.getBoardFilePath(boardId);
const boardDirectoryPath = this.getBoardDirectoryPath(boardId);
this.storageModel.removeRecursively(boardFilePath);
this.storageModel.removeRecursively(boardDirectoryPath);
};
//tasks //tasks
createTask = (boardId, name) => { createTask = (boardId, name) => {
const taskFileContent = _TaskModel.createTaskFileContent( const taskFileContent = _TaskModel.createTaskFileContent(
v4_default(), v4_default(),
boardId, name,
name boardId
); );
this.fileModel.addFileContent(taskFileContent); this.updateTask(taskFileContent);
}; };
listTaskIds = (boardName) => { updateTask = (taskFileContent) => {
const getTaskDirPath = this.getTaskContainerPath(boardName); this.storeTask(taskFileContent);
const fileIds = this.storageModel.list(getTaskDirPath); this.chatModel.sendMessage("", taskFileContent);
};
storeTask = (taskFileContent) => {
this.fileModel.addFileContent(taskFileContent);
const taskReferencePath = this.getTaskReferencePath(
taskFileContent.boardId,
taskFileContent.fileId
);
console.log("storing", taskReferencePath);
this.storageModel.write(taskReferencePath, "");
};
listTaskIds = (boardId) => {
const taskContainerPath = this.getTaskContainerPath(boardId);
console.log("listing", taskContainerPath);
const fileIds = this.storageModel.list(taskContainerPath);
return fileIds; return fileIds;
}; };
moveTask = (taskFileId, oldBoardId, newBoardId) => { deleteTask = (boardId, taskId) => {
const sourcePath = this.getTaskPath(oldBoardId, taskFileId); const taskFilePath = this.getTaskFilePath(taskId);
const destinationPath = this.getTaskPath(newBoardId, taskFileId); const taskReferencePath = this.getTaskReferencePath(
this.storageModel.renameRecursively(sourcePath, destinationPath); boardId,
taskId
);
this.storageModel.removeRecursively(taskFilePath);
this.storageModel.removeRecursively(taskReferencePath);
}; };
// init // init
constructor(storageModel2, chatModel, fileModel) { constructor(storageModel2, chatModel, fileModel) {
@@ -758,6 +781,35 @@
this.chatModel = chatModel; this.chatModel = chatModel;
this.storageModel = storageModel2; this.storageModel = storageModel2;
this.taskModel = new TaskModel(this.storageModel, chatModel, this); this.taskModel = new TaskModel(this.storageModel, chatModel, this);
this.taskModel.createBoard("Hello");
const boards = this.taskModel.listBoardIds();
console.log("boards", boards);
const boardId = boards[0];
console.log("board id", this.taskModel.getBoardInfo(boardId));
const newInfo = TaskModel.createBoardInfoFileContent(
boardId,
"renamed",
"coral" /* Coral */
);
this.taskModel.updateBoard(newInfo);
console.log("info", this.taskModel.getBoardInfo(boardId));
this.taskModel.createTask(boardId, "New task");
const tasks = this.taskModel.listTaskIds(boardId);
console.log("tasks", tasks);
const taskId = tasks[0];
console.log("task id", taskId);
const newTaskContent = TaskModel.createTaskFileContent(
taskId,
"renamed",
boardId
);
this.taskModel.updateTask(newTaskContent);
setTimeout(() => {
this.taskModel.deleteTask(boardId, taskId);
}, 2e4);
setTimeout(() => {
this.taskModel.deleteBoard(boardId);
}, 3e4);
} }
// utility // utility
static generateFileContentId = (creationDate) => { static generateFileContentId = (creationDate) => {
@@ -2540,7 +2592,7 @@
const path = StorageModel.stringToPathComponents(pathString); const path = StorageModel.stringToPathComponents(pathString);
const fileName = StorageModel.getFileName(path); const fileName = StorageModel.getFileName(path);
const items = new ListState(); const items = new ListState();
const style = `text-indent: ${path.length * 2}rem`; const style = `text-indent: ${path.length}rem`;
function loadItems() { function loadItems() {
items.clear(); items.clear();
const directoryItems = storageViewModel2.storageModel.list(path); const directoryItems = storageViewModel2.storageModel.list(path);
-19
View File
@@ -138,25 +138,6 @@ export default class FileModel {
this.storageModel = storageModel; this.storageModel = storageModel;
this.taskModel = new TaskModel(this.storageModel, chatModel, this); this.taskModel = new TaskModel(this.storageModel, chatModel, this);
// DEV
// this.taskModel.createBoard("Hello");
// const boards = this.taskModel.listBoardIds();
// console.log(boards);
// const boardId = boards[0];
// const firstBoardInfo = this.taskModel.getBoardInfo(boardId);
// console.log(firstBoardInfo);
// const newInfo = TaskModel.createBoardInfoFileContent(
// boardId,
// "renamed",
// Color.Coral
// );
// this.taskModel.createOrUpdateBoard(newInfo);
// setTimeout(() => this.taskModel.deleteBoard(boardId), 7000);
} }
// utility // utility
+69 -46
View File
@@ -25,6 +25,10 @@ export default class TaskModel {
return [...this.fileModel.getFilePath(boardId)]; return [...this.fileModel.getFilePath(boardId)];
}; };
getTaskFilePath = (taskId: string): string[] => {
return [...this.fileModel.getFilePath(taskId)];
};
getBoardContainerPath = (): string[] => { getBoardContainerPath = (): string[] => {
return [...this.getBasePath(), subDirectories.boards]; return [...this.getBasePath(), subDirectories.boards];
}; };
@@ -37,25 +41,17 @@ export default class TaskModel {
return [...this.getBoardDirectoryPath(boardId), subDirectories.boardTasks]; return [...this.getBoardDirectoryPath(boardId), subDirectories.boardTasks];
}; };
getTaskPath = (boardId: string, fileId: string): string[] => { getTaskReferencePath = (boardId: string, fileId: string): string[] => {
return [...this.getTaskContainerPath(boardId), fileId]; return [...this.getTaskContainerPath(boardId), fileId];
}; };
getTaskContentPath = (
boardId: string,
fileId: string,
versionId: string
): string[] => {
return [...this.getTaskPath(boardId, fileId), versionId];
};
// handler // handler
handleFileContent = (fileContent: FileContent<string>): void => { handleFileContent = (fileContent: FileContent<string>): void => {
if ( if (
checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) ==
true true
) { ) {
this.handleBoard(fileContent as BoardInfoVersion); this.handleBoard(fileContent as BoardInfoFileContent);
} else if ( } else if (
checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true
) { ) {
@@ -63,35 +59,27 @@ export default class TaskModel {
} }
}; };
handleBoard = (boardInfoFileContent: BoardInfoVersion) => { handleBoard = (boardInfoFileContent: BoardInfoFileContent) => {
console.log("board", boardInfoFileContent); this.storeBoard(boardInfoFileContent);
}; };
handleTask = (taskFileContent: TaskFileContent) => {}; handleTask = (taskFileContent: TaskFileContent) => {
this.storeTask(taskFileContent);
};
// boards // boards
createBoard = (name: string): void => { createBoard = (name: string): void => {
const boardInfoFileContent: BoardInfoVersion = const boardInfoFileContent: BoardInfoFileContent =
TaskModel.createBoardInfoFileContent(v4(), name, Color.Standard); TaskModel.createBoardInfoFileContent(v4(), name, Color.Standard);
this.createOrUpdateBoard(boardInfoFileContent); this.updateBoard(boardInfoFileContent);
}; };
listBoardIds = (): string[] => { updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
const boardContainerPath: string[] = this.getBoardContainerPath(); this.storeBoard(boardInfoFileContent);
const boardNames: string[] = this.storageModel.list(boardContainerPath); this.chatModel.sendMessage("", boardInfoFileContent);
return boardNames;
}; };
getBoardInfo = (fileId: string): BoardInfoVersion | null => { storeBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
const boardInfoFileContentOrNull: BoardInfoVersion | null =
this.fileModel.getLatestFileContent(
fileId,
BoardInfoFileContentReference
);
return boardInfoFileContentOrNull;
};
createOrUpdateBoard = (boardInfoFileContent: BoardInfoVersion): void => {
// store info // store info
this.fileModel.addFileContent(boardInfoFileContent); this.fileModel.addFileContent(boardInfoFileContent);
@@ -110,30 +98,65 @@ export default class TaskModel {
this.storageModel.removeRecursively(boardDirectoryPath); this.storageModel.removeRecursively(boardDirectoryPath);
}; };
listBoardIds = (): string[] => {
const boardContainerPath: string[] = this.getBoardContainerPath();
const boardNames: string[] = this.storageModel.list(boardContainerPath);
return boardNames;
};
getBoardInfo = (fileId: string): BoardInfoFileContent | null => {
const boardInfoFileContentOrNull: BoardInfoFileContent | null =
this.fileModel.getLatestFileContent(
fileId,
BoardInfoFileContentReference
);
return boardInfoFileContentOrNull;
};
//tasks //tasks
createTask = (boardId: string, name: string): void => { createTask = (boardId: string, name: string): void => {
const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent( const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent(
v4(), v4(),
boardId, name,
name boardId
); );
this.fileModel.addFileContent(taskFileContent); this.updateTask(taskFileContent);
}; };
listTaskIds = (boardName: string): string[] => { updateTask = (taskFileContent: TaskFileContent): void => {
const getTaskDirPath: string[] = this.getTaskContainerPath(boardName); this.storeTask(taskFileContent);
const fileIds: string[] = this.storageModel.list(getTaskDirPath); this.chatModel.sendMessage("", taskFileContent);
};
storeTask = (taskFileContent: TaskFileContent): void => {
// store info
this.fileModel.addFileContent(taskFileContent);
// add to board
const taskReferencePath: string[] = this.getTaskReferencePath(
taskFileContent.boardId,
taskFileContent.fileId
);
console.log("storing", taskReferencePath);
this.storageModel.write(taskReferencePath, "");
};
listTaskIds = (boardId: string): string[] => {
const taskContainerPath: string[] = this.getTaskContainerPath(boardId);
console.log("listing", taskContainerPath);
const fileIds: string[] = this.storageModel.list(taskContainerPath);
return fileIds; return fileIds;
}; };
moveTask = ( deleteTask = (boardId: string, taskId: string): void => {
taskFileId: string, const taskFilePath: string[] = this.getTaskFilePath(taskId);
oldBoardId: string, const taskReferencePath: string[] = this.getTaskReferencePath(
newBoardId: string boardId,
): void => { taskId
const sourcePath: string[] = this.getTaskPath(oldBoardId, taskFileId); );
const destinationPath: string[] = this.getTaskPath(newBoardId, taskFileId);
this.storageModel.renameRecursively(sourcePath, destinationPath); this.storageModel.removeRecursively(taskFilePath);
this.storageModel.removeRecursively(taskReferencePath);
}; };
// init // init
@@ -152,7 +175,7 @@ export default class TaskModel {
fileId: string, fileId: string,
name: string, name: string,
color: Color color: Color
): BoardInfoVersion => { ): BoardInfoFileContent => {
const fileContent: FileContent<"board-info"> = FileModel.createFileContent( const fileContent: FileContent<"board-info"> = FileModel.createFileContent(
fileId, fileId,
"board-info" "board-info"
@@ -189,7 +212,7 @@ export const subDirectories = {
}; };
// types // types
export interface BoardInfoVersion extends FileContent<"board-info"> { export interface BoardInfoFileContent extends FileContent<"board-info"> {
name: string; name: string;
color: Color; color: Color;
} }
@@ -209,7 +232,7 @@ export interface TaskFileContent extends FileContent<"task"> {
} }
// reference // reference
export const BoardInfoFileContentReference: BoardInfoVersion = { export const BoardInfoFileContentReference: BoardInfoFileContent = {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
fileId: "string", fileId: "string",
-1
View File
@@ -3,7 +3,6 @@
import { import {
DATA_VERSION, DATA_VERSION,
ValidObject, ValidObject,
checkMatchesObjectStructure,
} from "../Utility/typeSafety"; } from "../Utility/typeSafety";
import { localeCompare, parseValidObject, stringify } from "../Utility/utility"; import { localeCompare, parseValidObject, stringify } from "../Utility/utility";
+5 -3
View File
@@ -1,6 +1,8 @@
import * as React from "bloatless-react"; import * as React from "bloatless-react";
import StorageModel, { PATH_COMPONENT_SEPARATOR } from "../../Model/Global/storageModel"; import StorageModel, {
PATH_COMPONENT_SEPARATOR,
} from "../../Model/Global/storageModel";
import StorageViewModel from "../../ViewModel/storageViewModel"; import StorageViewModel from "../../ViewModel/storageViewModel";
@@ -18,7 +20,7 @@ export function DirectoryItemList(
const fileName = StorageModel.getFileName(path); const fileName = StorageModel.getFileName(path);
const items = new React.ListState<string>(); const items = new React.ListState<string>();
const style = `text-indent: ${path.length * 2}rem`; const style = `text-indent: ${path.length}rem`;
// methods // methods
function loadItems() { function loadItems() {
@@ -42,7 +44,7 @@ export function DirectoryItemList(
if (!items.value.has(lastDeletedItemPath)) return; if (!items.value.has(lastDeletedItemPath)) return;
select(); select();
setTimeout(() => loadItems(), 50) setTimeout(() => loadItems(), 50);
}); });
// state // state