remodel fileModel, start board methods of taskModel

This commit is contained in:
marlon-erler
2024-07-22 17:23:48 +02:00
parent 76737a390a
commit 3cc961a82b
4 changed files with 328 additions and 308 deletions
+148 -135
View File
@@ -533,92 +533,81 @@
fileModel;
// paths
getBasePath = () => {
return this.fileModel.getModelDirectoryPath("taskModel");
return this.fileModel.getModelContainerPath("taskModel");
};
getLocationDirPath = () => {
return [...this.getBasePath(), subDirectories.locations];
getBoardFilePath = (boardId) => {
return [...this.fileModel.getFilePath(boardId), boardId];
};
getTaskLocationPath = (fileId) => {
return [...this.getLocationDirPath(), fileId];
};
getBoardDirPath = () => {
getBoardContainerPath = () => {
return [...this.getBasePath(), subDirectories.boards];
};
getBoardPath = (boardId) => {
return [...this.getBoardDirPath(), boardId];
getBoardDirectoryPath = (boardId) => {
return [...this.getBoardContainerPath(), boardId];
};
getBoardInfoPath = (boardId) => {
return [...this.getBoardPath(boardId), subDirectories.boardInfo];
};
getTaskDirPath = (boardId) => {
return [...this.getBoardPath(boardId), subDirectories.boardTasks];
getTaskContainerPath = (boardId) => {
return [...this.getBoardDirectoryPath(boardId), subDirectories.boardTasks];
};
getTaskPath = (boardId, fileId) => {
return [...this.getTaskDirPath(boardId), fileId];
return [...this.getTaskContainerPath(boardId), fileId];
};
getTaskContentPath = (boardId, fileId, contentName) => {
return [...this.getTaskPath(boardId, fileId), contentName];
getTaskContentPath = (boardId, fileId, versionId) => {
return [...this.getTaskPath(boardId, fileId), versionId];
};
// handler
handleFileContent = (file, fileContent) => {
if (checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true) {
} else if (checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true) {
handleFileVersion = (fileVersion) => {
if (checkMatchesObjectStructure(fileVersion, BoardInfoFileVersionReference) == true) {
this.handleBoard(fileVersion);
} else if (checkMatchesObjectStructure(fileVersion, TaskFileVersionReference) == true) {
this.handleTask(fileVersion);
}
};
handleBoard = (boardInfoFileVersion) => {
console.log("board", boardInfoFileVersion);
};
handleTask = (taskFileVersion) => {
};
// boards
createBoard = (name) => {
const file = FileModel.createFile();
const boardInfoFileContent = _TaskModel.createBoardInfoFileContent(name, "standard" /* Standard */);
this.fileModel.addOrUpdateFile(file, boardInfoFileContent);
const boardInfoFileVersion = _TaskModel.createBoardInfoFileVersion(v4_default(), name, "standard" /* Standard */);
this.createOrUpdateBoard(boardInfoFileVersion);
};
listBoardIds = () => {
const boardDirPath = this.getBoardDirPath();
const boardNames = this.storageModel.list(boardDirPath);
const boardContainerPath = this.getBoardContainerPath();
const boardNames = this.storageModel.list(boardContainerPath);
return boardNames;
};
getBoardInfo = (boardId) => {
const boardInfoPath = this.getBoardInfoPath(boardId);
const boardInfoFileContentOrNull = this.storageModel.readStringifiable(
boardInfoPath,
BoardInfoFileContentReference
getBoardInfo = (fileId) => {
const boardInfoFileVersionOrNull = this.fileModel.getLatestFileVersion(
fileId,
BoardInfoFileVersionReference
);
return boardInfoFileContentOrNull;
return boardInfoFileVersionOrNull;
};
createOrUpdateBoard = (boardInfoFileVersion) => {
this.fileModel.addFileVersion(boardInfoFileVersion);
const boardDirectoryPath = this.getBoardDirectoryPath(
boardInfoFileVersion.fileId
);
this.storageModel.write(boardDirectoryPath, "");
};
//tasks
createTask = (boardId, name) => {
const file = FileModel.createFile();
const taskFileContent = _TaskModel.createTaskFileContent(
const taskFileVersion = _TaskModel.createTaskFileVersion(
v4_default(),
boardId,
name
);
this.fileModel.addOrUpdateFile(file, taskFileContent);
this.fileModel.addFileVersion(taskFileVersion);
};
listTaskIds = (boardName) => {
const getTaskDirPath = this.getTaskDirPath(boardName);
const getTaskDirPath = this.getTaskContainerPath(boardName);
const fileIds = this.storageModel.list(getTaskDirPath);
return fileIds;
};
getTaskVersionNames = (boardName, fileId) => {
const fileDirectoryPath = this.getTaskPath(boardName, fileId);
const versionNames = this.storageModel.list(fileDirectoryPath);
return versionNames;
};
getTaskFileContent = (boardName, fileId, versionName) => {
const fileContentPath = this.getTaskContentPath(
boardName,
fileId,
versionName
);
const taskFileContentOrNull = this.storageModel.readStringifiable(
fileContentPath,
TaskFileContentReference
);
return taskFileContentOrNull;
};
moveTask = (taskFileId, oldBoardId, newBoardId) => {
const sourcePath = this.getTaskPath(oldBoardId, taskFileId);
const destinationPath = this.getTaskPath(newBoardId, taskFileId);
return this.storageModel.rename(sourcePath, destinationPath);
this.storageModel.renameRecursively(sourcePath, destinationPath);
};
// init
constructor(storageModel2, chatModel, fileModel) {
@@ -627,40 +616,46 @@
this.storageModel = storageModel2;
}
// utility
static createBoardInfoFileContent = (name, color) => {
const fileContent = FileModel.createFileContent("board");
static createBoardInfoFileVersion = (fileId, name, color) => {
const fileVersion = FileModel.createFileVersion(
fileId,
"board-info"
);
return {
...fileContent,
...fileVersion,
name,
color
};
};
static createTaskFileContent = (name, boardId) => {
const fileContent = FileModel.createFileContent("task");
static createTaskFileVersion = (fileId, name, boardId) => {
const fileVersion = FileModel.createFileVersion(
fileId,
"task"
);
return {
...fileContent,
...fileVersion,
name,
boardId
};
};
};
var subDirectories = {
locations: "locations",
boards: "boards",
boardInfo: "info",
boardTasks: "tasks"
};
var BoardInfoFileContentReference = {
var BoardInfoFileVersionReference = {
dataVersion: DATA_VERSION,
id: "",
fileId: "string",
fileVersionId: "",
creationDate: "",
type: "board",
type: "board-info",
name: "",
color: ""
};
var TaskFileContentReference = {
var TaskFileVersionReference = {
dataVersion: DATA_VERSION,
id: "",
fileId: "string",
fileVersionId: "",
creationDate: "",
type: "task",
name: "",
@@ -679,107 +674,125 @@
filePaths.chat.files(this.chatModel.id)
);
};
getModelDirectoryPath = (modelName) => {
return [...this.getBasePath(), modelName];
getFileContainerPath = () => {
return [...this.getBasePath(), subDirectories2.data];
};
getModelContainerPath = (modelName) => {
return [...this.getBasePath(), subDirectories2.model, modelName];
};
getFilePath = (fileId) => {
return [...this.getBasePath(), fileId];
return [...this.getFileContainerPath(), fileId];
};
getFileContentPath = (file, fileContentName) => {
const filePath = this.getFilePath(file.id);
return [...filePath, fileContentName];
getFileVersionPath = (fileId, fileVersionId) => {
const filePath = this.getFilePath(fileId);
return [...filePath, fileVersionId];
};
// handler
handleStringifiedFile = (stringifiedFile) => {
const file = parseValidObject(stringifiedFile, FileReference);
if (file == null) return;
this.handleFileAndClearContents(file);
handleStringifiedFileVersion = (stringifiedFileVersion) => {
const fileVersion = parseValidObject(
stringifiedFileVersion,
FileVersionReference
);
if (fileVersion == null) return;
this.handleFileVersion(fileVersion);
};
handleFileAndClearContents = (file) => {
for (const fileContent of file.contentVersions) {
this.storeFileContent(file, fileContent);
this.taskModel.handleFileContent(file, fileContent);
}
file.contentVersions = [];
handleFileVersion = (fileVersion) => {
const didStore = this.storeFileVersion(fileVersion);
if (didStore == false) return;
this.taskModel.handleFileVersion(fileVersion);
};
// methods
addOrUpdateFile = (file, fileContent) => {
file.contentVersions.push(fileContent);
this.chatModel.sendMessage("", file);
this.handleFileAndClearContents(file);
addFileVersion = (fileVersion) => {
this.handleFileVersion(fileVersion);
this.chatModel.sendMessage("", fileVersion);
};
// storage
storeFileContent = (file, fileContent) => {
const fileContentName = _FileModel.getFileContentName(fileContent);
const fileContentPath = this.getFileContentPath(
file,
fileContentName
storeFileVersion = (fileVersion) => {
const fileVersionPath = this.getFileVersionPath(
fileVersion.fileId,
fileVersion.fileVersionId
);
const existingFileContent = this.storageModel.read(fileContentPath);
if (existingFileContent != null) return;
const stringifiedContent = stringify(fileContent);
this.storageModel.write(fileContentPath, stringifiedContent);
const existingFileVersion = this.storageModel.read(fileVersionPath);
if (existingFileVersion != null) return false;
const stringifiedContent = stringify(fileVersion);
this.storageModel.write(fileVersionPath, stringifiedContent);
return true;
};
listFileIds = () => {
return this.storageModel.list(this.getBasePath());
};
getFile = (fileId) => {
listFileVersionIds = (fileId) => {
const filePath = this.getFilePath(fileId);
const fileOrNull = this.storageModel.readStringifiable(
filePath,
FileReference
);
return fileOrNull;
};
listFileContents = (file) => {
const filePath = this.getFilePath(file.id);
return this.storageModel.list(filePath);
};
getLatestFileContentName = (fileContentNames) => {
return fileContentNames[fileContentNames.length - 1];
selectLatestFileVersionId = (fileVersionIds) => {
return fileVersionIds[fileVersionIds.length - 1];
};
getFileContent = (file, fileContentName) => {
const filePath = this.getFileContentPath(file, fileContentName);
const fileContentOrNull = this.storageModel.readStringifiable(filePath, FileContentReference2);
return fileContentOrNull;
getFileVersion = (fileId, fileVersionName, reference) => {
const filePath = this.getFileVersionPath(fileId, fileVersionName);
const fileVersionOrNull = this.storageModel.readStringifiable(
filePath,
reference
);
return fileVersionOrNull;
};
getLatestFileVersion = (fileId, reference) => {
const fileVersionsIds = this.listFileVersionIds(fileId);
const latestFileVersionId = this.selectLatestFileVersionId(fileVersionsIds);
if (latestFileVersionId == void 0) return null;
const fileVersion = this.getFileVersion(
fileId,
latestFileVersionId,
reference
);
return fileVersion;
};
// init
constructor(chatModel, storageModel2) {
this.chatModel = chatModel;
this.storageModel = storageModel2;
this.taskModel = new TaskModel(this.storageModel, chatModel, this);
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.createBoardInfoFileVersion(
boardId,
"renamed",
"coral" /* Coral */
);
this.taskModel.createOrUpdateBoard(newInfo);
}
// utility
static getFileContentName = (fileContent) => {
return fileContent.creationDate + fileContent.id;
static generateFileVersionId = (creationDate) => {
return creationDate + v4_default();
};
static createFile = () => {
static createFileVersion = (fileId, type) => {
const creationDate = createTimestamp();
const fileVersionId = _FileModel.generateFileVersionId(creationDate);
return {
dataVersion: DATA_VERSION,
id: v4_default(),
contentVersions: []
};
};
static createFileContent = (type) => {
return {
dataVersion: DATA_VERSION,
id: v4_default(),
creationDate: createTimestamp(),
fileId,
fileVersionId,
creationDate,
type
};
};
};
var FileContentReference2 = {
var subDirectories2 = {
data: "data",
model: "model",
taskModel: "tasks"
};
var FileVersionReference = {
dataVersion: DATA_VERSION,
id: "",
fileId: "",
fileVersionId: "",
creationDate: "",
type: ""
};
var FileReference = {
dataVersion: DATA_VERSION,
id: "",
contentVersions: [FileContentReference2]
};
// src/Model/Utility/crypto.ts
var IV_SIZE = 12;
@@ -909,7 +922,7 @@
this.storeColor();
};
// messaging
sendMessage = async (body, file) => {
sendMessage = async (body, fileVersion) => {
const senderName = this.settingsModel.username;
if (senderName == "") return false;
const allChannels = [this.info.primaryChannel];
@@ -922,7 +935,7 @@
senderName,
this.info.encryptionKey,
body,
file
fileVersion
);
this.addMessage(chatMessage);
this.connectionModel.sendMessageOrStore(chatMessage);
@@ -973,7 +986,7 @@
this.storageModel.writeStringifiable(messagePath, chatMessage);
this.chatMessageHandler(chatMessage);
}
this.fileModel.handleStringifiedFile(chatMessage.stringifiedFile);
this.fileModel.handleStringifiedFileVersion(chatMessage.stringifiedFile);
};
delete = () => {
this.chatListModel.untrackChat(this);
@@ -1040,7 +1053,7 @@
hasUnreadMessages: false
};
};
static createChatMessage = async (channel, sender, encryptionKey, body, file) => {
static createChatMessage = async (channel, sender, encryptionKey, body, fileVersion) => {
const chatMessage = {
dataVersion: DATA_VERSION,
id: v4_default(),
@@ -1051,8 +1064,8 @@
status: "outbox" /* Outbox */,
stringifiedFile: ""
};
if (file != void 0) {
const stringifiedFile = stringify(file);
if (fileVersion != void 0) {
const stringifiedFile = stringify(fileVersion);
chatMessage.stringifiedFile = stringifiedFile;
}
if (encryptionKey != "") {
+10 -7
View File
@@ -1,7 +1,7 @@
// this file is responsible for managing chats.
import { DATA_VERSION, ValidObject } from "../Utility/typeSafety";
import FileModel, { File } from "../Files/fileModel";
import FileModel, { FileVersion } from "../Files/fileModel";
import StorageModel, { filePaths } from "../Global/storageModel";
import {
createTimestamp,
@@ -83,7 +83,10 @@ export default class ChatModel {
};
// messaging
sendMessage = async (body: string, file?: File): Promise<boolean> => {
sendMessage = async (
body: string,
fileVersion: FileVersion<string>
): Promise<boolean> => {
const senderName = this.settingsModel.username;
if (senderName == "") return false;
@@ -99,7 +102,7 @@ export default class ChatModel {
senderName,
this.info.encryptionKey,
body,
file
fileVersion
);
this.addMessage(chatMessage);
@@ -164,7 +167,7 @@ export default class ChatModel {
}
// file
this.fileModel.handleStringifiedFile(chatMessage.stringifiedFile);
this.fileModel.handleStringifiedFileVersion(chatMessage.stringifiedFile);
};
delete = () => {
@@ -260,7 +263,7 @@ export default class ChatModel {
sender: string,
encryptionKey: string,
body: string,
file?: File
fileVersion: FileVersion<string>
): Promise<ChatMessage> => {
const chatMessage: ChatMessage = {
dataVersion: DATA_VERSION,
@@ -275,8 +278,8 @@ export default class ChatModel {
status: ChatMessageStatus.Outbox,
stringifiedFile: "",
};
if (file != undefined) {
const stringifiedFile = stringify(file);
if (fileVersion != undefined) {
const stringifiedFile = stringify(fileVersion);
chatMessage.stringifiedFile = stringifiedFile;
}
+92 -83
View File
@@ -9,6 +9,7 @@ import {
} from "../Utility/utility";
import ChatModel from "../Chat/chatModel";
import { Color } from "../../ViewModel/colors";
import TaskModel from "./taskModel";
import { v4 } from "uuid";
@@ -26,92 +27,109 @@ export default class FileModel {
);
};
getModelDirectoryPath = (
modelName: keyof typeof modelDirectories
getFileContainerPath = (): string[] => {
return [...this.getBasePath(), subDirectories.data];
};
getModelContainerPath = (
modelName: keyof typeof subDirectories
): string[] => {
return [...this.getBasePath(), modelName];
return [...this.getBasePath(), subDirectories.model, modelName];
};
getFilePath = (fileId: string): string[] => {
return [...this.getBasePath(), fileId];
return [...this.getFileContainerPath(), fileId];
};
getFileContentPath = (file: File, fileContentName: string): string[] => {
const filePath: string[] = this.getFilePath(file.id);
return [...filePath, fileContentName];
getFileVersionPath = (fileId: string, fileVersionId: string): string[] => {
const filePath: string[] = this.getFilePath(fileId);
return [...filePath, fileVersionId];
};
// handler
handleStringifiedFile = (stringifiedFile: string): void => {
const file: File | null = parseValidObject(stringifiedFile, FileReference);
if (file == null) return;
handleStringifiedFileVersion = (stringifiedFileVersion: string): void => {
const fileVersion: FileVersion<string> | null = parseValidObject(
stringifiedFileVersion,
FileVersionReference
);
if (fileVersion == null) return;
this.handleFileAndClearContents(file);
this.handleFileVersion(fileVersion);
};
handleFileAndClearContents = (file: File): void => {
for (const fileContent of file.contentVersions) {
this.storeFileContent(file, fileContent);
this.taskModel.handleFileContent(file, fileContent);
}
handleFileVersion = (fileVersion: FileVersion<string>): void => {
const didStore: boolean = this.storeFileVersion(fileVersion);
if (didStore == false) return;
file.contentVersions = [];
this.taskModel.handleFileVersion(fileVersion);
};
// methods
addOrUpdateFile = (file: File, fileContent: FileContent<string>): void => {
file.contentVersions.push(fileContent);
this.chatModel.sendMessage("", file);
this.handleFileAndClearContents(file);
addFileVersion = (fileVersion: FileVersion<string>): void => {
this.handleFileVersion(fileVersion);
this.chatModel.sendMessage("", fileVersion);
};
// storage
storeFileContent = (file: File, fileContent: FileContent<string>): void => {
const fileContentName: string = FileModel.getFileContentName(fileContent);
const fileContentPath: string[] = this.getFileContentPath(
file,
fileContentName
storeFileVersion = (fileVersion: FileVersion<string>): boolean => {
const fileVersionPath: string[] = this.getFileVersionPath(
fileVersion.fileId,
fileVersion.fileVersionId
);
// check if fileContent already exists
const existingFileContent: string | null =
this.storageModel.read(fileContentPath);
if (existingFileContent != null) return;
// check if fileVersion already exists
const existingFileVersion: string | null =
this.storageModel.read(fileVersionPath);
if (existingFileVersion != null) return false;
const stringifiedContent: string = stringify(fileContent);
this.storageModel.write(fileContentPath, stringifiedContent);
const stringifiedContent: string = stringify(fileVersion);
this.storageModel.write(fileVersionPath, stringifiedContent);
return true;
};
listFileIds = (): string[] => {
return this.storageModel.list(this.getBasePath());
};
getFile = (fileId: string): File | null => {
listFileVersionIds = (fileId: string): string[] => {
const filePath: string[] = this.getFilePath(fileId);
const fileOrNull: File | null = this.storageModel.readStringifiable(
filePath,
FileReference
);
return fileOrNull;
};
listFileContents = (file: File): string[] => {
const filePath: string[] = this.getFilePath(file.id);
return this.storageModel.list(filePath);
};
getLatestFileContentName = (fileContentNames: string[]): string | null => {
return fileContentNames[fileContentNames.length - 1];
selectLatestFileVersionId = (
fileVersionIds: string[]
): string | undefined => {
return fileVersionIds[fileVersionIds.length - 1];
};
getFileContent = (
file: File,
fileContentName: string
): FileContent<string> | null => {
const filePath: string[] = this.getFileContentPath(file, fileContentName);
const fileContentOrNull: FileContent<string> | null =
this.storageModel.readStringifiable(filePath, FileContentReference);
return fileContentOrNull;
getFileVersion = <T extends FileVersion<string>>(
fileId: string,
fileVersionName: string,
reference: T
): T | null => {
const filePath: string[] = this.getFileVersionPath(fileId, fileVersionName);
const fileVersionOrNull: T | null = this.storageModel.readStringifiable(
filePath,
reference
);
return fileVersionOrNull;
};
getLatestFileVersion = <T extends FileVersion<string>>(
fileId: string,
reference: T
): T | null => {
const fileVersionsIds: string[] = this.listFileVersionIds(fileId);
const latestFileVersionId: string | undefined =
this.selectLatestFileVersionId(fileVersionsIds);
if (latestFileVersionId == undefined) return null;
const fileVersion: T | null = this.getFileVersion(
fileId,
latestFileVersionId,
reference
);
return fileVersion;
};
// init
@@ -123,60 +141,51 @@ export default class FileModel {
}
// utility
static getFileContentName = (fileContent: FileContent<string>): string => {
return fileContent.creationDate + fileContent.id;
static generateFileVersionId = (creationDate): string => {
return creationDate + v4();
};
static createFile = (): File => {
static createFileVersion = <T extends string>(
fileId: string,
type: T
): FileVersion<T> => {
const creationDate: string = createTimestamp();
const fileVersionId: string = FileModel.generateFileVersionId(creationDate);
return {
dataVersion: DATA_VERSION,
id: v4(),
contentVersions: [],
};
};
static createFileContent = <T extends string>(type: T): FileContent<T> => {
return {
dataVersion: DATA_VERSION,
id: v4(),
creationDate: createTimestamp(),
fileId,
fileVersionId,
creationDate,
type,
};
};
}
// paths
export const modelDirectories = {
export const subDirectories = {
data: "data",
model: "model",
taskModel: "tasks",
};
// types
export interface File extends ValidObject {
id: string;
contentVersions: FileContent<string>[];
}
export interface FileContent<T extends string> extends ValidObject {
id: string;
export interface FileVersion<T extends string> extends ValidObject {
fileId: string;
fileVersionId: string;
creationDate: string;
type: T;
}
// references
export const FileContentReference: FileContent<string> = {
export const FileVersionReference: FileVersion<string> = {
dataVersion: DATA_VERSION,
id: "",
fileId: "",
fileVersionId: "",
creationDate: "",
type: "",
};
export const FileReference: File = {
dataVersion: DATA_VERSION,
id: "",
contentVersions: [FileContentReference],
};
+78 -83
View File
@@ -2,18 +2,14 @@
import {
DATA_VERSION,
ValidObject,
checkMatchesObjectStructure,
} from "../Utility/typeSafety";
import FileModel, {
File,
FileContent,
FileContentReference,
} from "./fileModel";
import FileModel, { FileVersion } from "./fileModel";
import ChatModel from "../Chat/chatModel";
import { Color } from "../../ViewModel/colors";
import StorageModel from "../Global/storageModel";
import { v4 } from "uuid";
export default class TaskModel {
storageModel: StorageModel;
@@ -22,115 +18,106 @@ export default class TaskModel {
// paths
getBasePath = (): string[] => {
return this.fileModel.getModelDirectoryPath("taskModel");
return this.fileModel.getModelContainerPath("taskModel");
};
getBoardDirPath = (): string[] => {
getBoardFilePath = (boardId: string): string[] => {
return [...this.fileModel.getFilePath(boardId), boardId];
};
getBoardContainerPath = (): string[] => {
return [...this.getBasePath(), subDirectories.boards];
};
getBoardPath = (boardId: string): string[] => {
return [...this.getBoardDirPath(), boardId];
getBoardDirectoryPath = (boardId: string): string[] => {
return [...this.getBoardContainerPath(), boardId];
};
getBoardInfoPath = (boardId: string): string[] => {
return [...this.getBoardPath(boardId), subDirectories.boardInfo];
};
getTaskDirPath = (boardId: string): string[] => {
return [...this.getBoardPath(boardId), subDirectories.boardTasks];
getTaskContainerPath = (boardId: string): string[] => {
return [...this.getBoardDirectoryPath(boardId), subDirectories.boardTasks];
};
getTaskPath = (boardId: string, fileId: string): string[] => {
return [...this.getTaskDirPath(boardId), fileId];
return [...this.getTaskContainerPath(boardId), fileId];
};
getTaskContentPath = (
boardId: string,
fileId: string,
contentName: string
versionId: string
): string[] => {
return [...this.getTaskPath(boardId, fileId), contentName];
return [...this.getTaskPath(boardId, fileId), versionId];
};
// handler
handleFileContent = (file: File, fileContent: FileContent<string>): void => {
handleFileVersion = (fileVersion: FileVersion<string>): void => {
if (
checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) ==
checkMatchesObjectStructure(fileVersion, BoardInfoFileVersionReference) ==
true
) {
// todo
this.handleBoard(fileVersion as BoardInfoVersion);
} else if (
checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true
checkMatchesObjectStructure(fileVersion, TaskFileVersionReference) == true
) {
// todo
this.handleTask(fileVersion as TaskFileVersion);
}
};
handleBoard = (boardInfoFileVersion: BoardInfoVersion) => {
console.log("board", boardInfoFileVersion);
};
handleTask = (taskFileVersion: TaskFileVersion) => {};
// boards
createBoard = (name: string): void => {
const file: File = FileModel.createFile();
const boardInfoFileContent: BoardInfoFileContent =
TaskModel.createBoardInfoFileContent(name, Color.Standard);
this.fileModel.addOrUpdateFile(file, boardInfoFileContent);
const boardInfoFileVersion: BoardInfoVersion =
TaskModel.createBoardInfoFileVersion(v4(), name, Color.Standard);
this.createOrUpdateBoard(boardInfoFileVersion);
};
listBoardIds = (): string[] => {
const boardDirPath: string[] = this.getBoardDirPath();
const boardNames: string[] = this.storageModel.list(boardDirPath);
const boardContainerPath: string[] = this.getBoardContainerPath();
const boardNames: string[] = this.storageModel.list(boardContainerPath);
return boardNames;
};
getBoardInfo = (boardId: string): BoardInfoFileContent | null => {
const boardInfoPath: string[] = this.getBoardInfoPath(boardId);
const boardInfoFileContentOrNull: BoardInfoFileContent | null =
this.storageModel.readStringifiable(
boardInfoPath,
BoardInfoFileContentReference
getBoardInfo = (fileId: string): BoardInfoVersion | null => {
const boardInfoFileVersionOrNull: BoardInfoVersion | null =
this.fileModel.getLatestFileVersion(
fileId,
BoardInfoFileVersionReference
);
return boardInfoFileContentOrNull;
return boardInfoFileVersionOrNull;
};
createOrUpdateBoard = (boardInfoFileVersion: BoardInfoVersion): void => {
// store info
this.fileModel.addFileVersion(boardInfoFileVersion);
// add to list
const boardDirectoryPath: string[] = this.getBoardDirectoryPath(
boardInfoFileVersion.fileId
);
this.storageModel.write(boardDirectoryPath, "");
};
//tasks
createTask = (boardId: string, name: string): void => {
const file: File = FileModel.createFile();
const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent(
const taskFileVersion: TaskFileVersion = TaskModel.createTaskFileVersion(
v4(),
boardId,
name
);
this.fileModel.addOrUpdateFile(file, taskFileContent);
this.fileModel.addFileVersion(taskFileVersion);
};
listTaskIds = (boardName: string): string[] => {
const getTaskDirPath: string[] = this.getTaskDirPath(boardName);
const getTaskDirPath: string[] = this.getTaskContainerPath(boardName);
const fileIds: string[] = this.storageModel.list(getTaskDirPath);
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;
};
moveTask = (
taskFileId: string,
oldBoardId: string,
@@ -153,28 +140,34 @@ export default class TaskModel {
}
// utility
static createBoardInfoFileContent = (
static createBoardInfoFileVersion = (
fileId: string,
name: string,
color: Color
): BoardInfoFileContent => {
const fileContent: FileContent<"board"> =
FileModel.createFileContent("board");
): BoardInfoVersion => {
const fileVersion: FileVersion<"board-info"> = FileModel.createFileVersion(
fileId,
"board-info"
);
return {
...fileContent,
...fileVersion,
name,
color,
};
};
static createTaskFileContent = (
static createTaskFileVersion = (
fileId: string,
name: string,
boardId: string
): TaskFileContent => {
const fileContent: FileContent<"task"> =
FileModel.createFileContent("task");
): TaskFileVersion => {
const fileVersion: FileVersion<"task"> = FileModel.createFileVersion(
fileId,
"task"
);
return {
...fileContent,
...fileVersion,
name,
boardId,
@@ -184,17 +177,16 @@ export default class TaskModel {
export const subDirectories = {
boards: "boards",
boardInfo: "info",
boardTasks: "tasks",
};
// types
export interface BoardInfoFileContent extends FileContent<"board"> {
export interface BoardInfoVersion extends FileVersion<"board-info"> {
name: string;
color: Color;
}
export interface TaskFileContent extends FileContent<"task"> {
export interface TaskFileVersion extends FileVersion<"task"> {
name: string;
boardId: string;
@@ -209,21 +201,24 @@ export interface TaskFileContent extends FileContent<"task"> {
}
// reference
export const BoardInfoFileContentReference: BoardInfoFileContent = {
export const BoardInfoFileVersionReference: BoardInfoVersion = {
dataVersion: DATA_VERSION,
id: "",
fileId: "string",
fileVersionId: "",
creationDate: "",
type: "board",
type: "board-info",
name: "",
color: "" as Color,
};
export const TaskFileContentReference: TaskFileContent = {
export const TaskFileVersionReference: TaskFileVersion = {
dataVersion: DATA_VERSION,
id: "",
fileId: "string",
fileVersionId: "",
creationDate: "",
type: "task",