rename FileVersion -> FIleContent

This commit is contained in:
marlon-erler
2024-07-22 18:11:18 +02:00
parent 8a3b63ea7c
commit 066a773a3a
4 changed files with 168 additions and 183 deletions
+76 -91
View File
@@ -554,22 +554,22 @@
return [...this.getTaskPath(boardId, fileId), versionId]; return [...this.getTaskPath(boardId, fileId), versionId];
}; };
// handler // handler
handleFileVersion = (fileVersion) => { handleFileContent = (fileContent) => {
if (checkMatchesObjectStructure(fileVersion, BoardInfoFileVersionReference) == true) { if (checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) == true) {
this.handleBoard(fileVersion); this.handleBoard(fileContent);
} else if (checkMatchesObjectStructure(fileVersion, TaskFileVersionReference) == true) { } else if (checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true) {
this.handleTask(fileVersion); this.handleTask(fileContent);
} }
}; };
handleBoard = (boardInfoFileVersion) => { handleBoard = (boardInfoFileContent) => {
console.log("board", boardInfoFileVersion); console.log("board", boardInfoFileContent);
}; };
handleTask = (taskFileVersion) => { handleTask = (taskFileContent) => {
}; };
// boards // boards
createBoard = (name) => { createBoard = (name) => {
const boardInfoFileVersion = _TaskModel.createBoardInfoFileVersion(v4_default(), name, "standard" /* Standard */); const boardInfoFileContent = _TaskModel.createBoardInfoFileContent(v4_default(), name, "standard" /* Standard */);
this.createOrUpdateBoard(boardInfoFileVersion); this.createOrUpdateBoard(boardInfoFileContent);
}; };
listBoardIds = () => { listBoardIds = () => {
const boardContainerPath = this.getBoardContainerPath(); const boardContainerPath = this.getBoardContainerPath();
@@ -577,35 +577,33 @@
return boardNames; return boardNames;
}; };
getBoardInfo = (fileId) => { getBoardInfo = (fileId) => {
const boardInfoFileVersionOrNull = this.fileModel.getLatestFileVersion( const boardInfoFileContentOrNull = this.fileModel.getLatestFileContent(
fileId, fileId,
BoardInfoFileVersionReference BoardInfoFileContentReference
); );
return boardInfoFileVersionOrNull; return boardInfoFileContentOrNull;
}; };
createOrUpdateBoard = (boardInfoFileVersion) => { createOrUpdateBoard = (boardInfoFileContent) => {
this.fileModel.addFileVersion(boardInfoFileVersion); this.fileModel.addFileContent(boardInfoFileContent);
const boardDirectoryPath = this.getBoardDirectoryPath( const boardDirectoryPath = this.getBoardDirectoryPath(
boardInfoFileVersion.fileId boardInfoFileContent.fileId
); );
this.storageModel.write(boardDirectoryPath, ""); this.storageModel.write(boardDirectoryPath, "");
}; };
deleteBoard = (boardId) => { deleteBoard = (boardId) => {
const boardFilePath = this.getBoardFilePath(boardId); const boardFilePath = this.getBoardFilePath(boardId);
const boardDirectoryPath = this.getBoardDirectoryPath(boardId); const boardDirectoryPath = this.getBoardDirectoryPath(boardId);
console.log(boardFilePath);
console.log(boardDirectoryPath);
this.storageModel.removeRecursively(boardFilePath); this.storageModel.removeRecursively(boardFilePath);
this.storageModel.removeRecursively(boardDirectoryPath); this.storageModel.removeRecursively(boardDirectoryPath);
}; };
//tasks //tasks
createTask = (boardId, name) => { createTask = (boardId, name) => {
const taskFileVersion = _TaskModel.createTaskFileVersion( const taskFileContent = _TaskModel.createTaskFileContent(
v4_default(), v4_default(),
boardId, boardId,
name name
); );
this.fileModel.addFileVersion(taskFileVersion); this.fileModel.addFileContent(taskFileContent);
}; };
listTaskIds = (boardName) => { listTaskIds = (boardName) => {
const getTaskDirPath = this.getTaskContainerPath(boardName); const getTaskDirPath = this.getTaskContainerPath(boardName);
@@ -624,24 +622,24 @@
this.storageModel = storageModel2; this.storageModel = storageModel2;
} }
// utility // utility
static createBoardInfoFileVersion = (fileId, name, color) => { static createBoardInfoFileContent = (fileId, name, color) => {
const fileVersion = FileModel.createFileVersion( const fileContent = FileModel.createFileContent(
fileId, fileId,
"board-info" "board-info"
); );
return { return {
...fileVersion, ...fileContent,
name, name,
color color
}; };
}; };
static createTaskFileVersion = (fileId, name, boardId) => { static createTaskFileContent = (fileId, name, boardId) => {
const fileVersion = FileModel.createFileVersion( const fileContent = FileModel.createFileContent(
fileId, fileId,
"task" "task"
); );
return { return {
...fileVersion, ...fileContent,
name, name,
boardId boardId
}; };
@@ -651,19 +649,19 @@
boards: "boards", boards: "boards",
boardTasks: "tasks" boardTasks: "tasks"
}; };
var BoardInfoFileVersionReference = { var BoardInfoFileContentReference = {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
fileId: "string", fileId: "string",
fileVersionId: "", fileContentId: "",
creationDate: "", creationDate: "",
type: "board-info", type: "board-info",
name: "", name: "",
color: "" color: ""
}; };
var TaskFileVersionReference = { var TaskFileContentReference = {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
fileId: "string", fileId: "string",
fileVersionId: "", fileContentId: "",
creationDate: "", creationDate: "",
type: "task", type: "task",
name: "", name: "",
@@ -691,100 +689,87 @@
getFilePath = (fileId) => { getFilePath = (fileId) => {
return [...this.getFileContainerPath(), fileId]; return [...this.getFileContainerPath(), fileId];
}; };
getFileVersionPath = (fileId, fileVersionId) => { getFileContentPath = (fileId, fileContentId) => {
const filePath = this.getFilePath(fileId); const filePath = this.getFilePath(fileId);
return [...filePath, fileVersionId]; return [...filePath, fileContentId];
}; };
// handler // handler
handleStringifiedFileVersion = (stringifiedFileVersion) => { handleStringifiedFileContent = (stringifiedFileContent) => {
const fileVersion = parseValidObject( const fileContent = parseValidObject(
stringifiedFileVersion, stringifiedFileContent,
FileVersionReference FileContentReference
); );
if (fileVersion == null) return; if (fileContent == null) return;
this.handleFileVersion(fileVersion); this.handleFileContent(fileContent);
}; };
handleFileVersion = (fileVersion) => { handleFileContent = (fileContent) => {
const didStore = this.storeFileVersion(fileVersion); const didStore = this.storeFileContent(fileContent);
if (didStore == false) return; if (didStore == false) return;
this.taskModel.handleFileVersion(fileVersion); this.taskModel.handleFileContent(fileContent);
}; };
// methods // methods
addFileVersion = (fileVersion) => { addFileContent = (fileContent) => {
this.handleFileVersion(fileVersion); this.handleFileContent(fileContent);
this.chatModel.sendMessage("", fileVersion); this.chatModel.sendMessage("", fileContent);
}; };
// storage // storage
storeFileVersion = (fileVersion) => { storeFileContent = (fileContent) => {
const fileVersionPath = this.getFileVersionPath( const fileContentPath = this.getFileContentPath(
fileVersion.fileId, fileContent.fileId,
fileVersion.fileVersionId fileContent.fileContentId
); );
const existingFileVersion = this.storageModel.read(fileVersionPath); const existingFileContent = this.storageModel.read(fileContentPath);
if (existingFileVersion != null) return false; if (existingFileContent != null) return false;
const stringifiedContent = stringify(fileVersion); const stringifiedContent = stringify(fileContent);
this.storageModel.write(fileVersionPath, stringifiedContent); this.storageModel.write(fileContentPath, stringifiedContent);
return true; return true;
}; };
listFileIds = () => { listFileIds = () => {
return this.storageModel.list(this.getBasePath()); return this.storageModel.list(this.getBasePath());
}; };
listFileVersionIds = (fileId) => { listFileContentIds = (fileId) => {
const filePath = this.getFilePath(fileId); const filePath = this.getFilePath(fileId);
return this.storageModel.list(filePath); return this.storageModel.list(filePath);
}; };
selectLatestFileVersionId = (fileVersionIds) => { selectLatestFileContentId = (fileContentIds) => {
return fileVersionIds[fileVersionIds.length - 1]; return fileContentIds[fileContentIds.length - 1];
}; };
getFileVersion = (fileId, fileVersionName, reference) => { getFileContent = (fileId, fileContentName, reference) => {
const filePath = this.getFileVersionPath(fileId, fileVersionName); const filePath = this.getFileContentPath(fileId, fileContentName);
const fileVersionOrNull = this.storageModel.readStringifiable( const fileContentOrNull = this.storageModel.readStringifiable(
filePath, filePath,
reference reference
); );
return fileVersionOrNull; return fileContentOrNull;
}; };
getLatestFileVersion = (fileId, reference) => { getLatestFileContent = (fileId, reference) => {
const fileVersionsIds = this.listFileVersionIds(fileId); const fileContentsIds = this.listFileContentIds(fileId);
const latestFileVersionId = this.selectLatestFileVersionId(fileVersionsIds); const latestFileContentId = this.selectLatestFileContentId(fileContentsIds);
if (latestFileVersionId == void 0) return null; if (latestFileContentId == void 0) return null;
const fileVersion = this.getFileVersion( const fileContent = this.getFileContent(
fileId, fileId,
latestFileVersionId, latestFileContentId,
reference reference
); );
return fileVersion; return fileContent;
}; };
// init // init
constructor(chatModel, storageModel2) { constructor(chatModel, storageModel2) {
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);
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);
setTimeout(() => this.taskModel.deleteBoard(boardId), 7e3);
} }
// utility // utility
static generateFileVersionId = (creationDate) => { static generateFileContentId = (creationDate) => {
return creationDate + v4_default(); return creationDate + v4_default();
}; };
static createFileVersion = (fileId, type) => { static createFileContent = (fileId, type) => {
const creationDate = createTimestamp(); const creationDate = createTimestamp();
const fileVersionId = _FileModel.generateFileVersionId(creationDate); const fileContentId = _FileModel.generateFileContentId(creationDate);
return { return {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
fileId, fileId,
fileVersionId, fileContentId,
creationDate, creationDate,
type type
}; };
@@ -795,10 +780,10 @@
model: "model", model: "model",
taskModel: "tasks" taskModel: "tasks"
}; };
var FileVersionReference = { var FileContentReference = {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
fileId: "", fileId: "",
fileVersionId: "", fileContentId: "",
creationDate: "", creationDate: "",
type: "" type: ""
}; };
@@ -931,7 +916,7 @@
this.storeColor(); this.storeColor();
}; };
// messaging // messaging
sendMessage = async (body, fileVersion) => { sendMessage = async (body, fileContent) => {
const senderName = this.settingsModel.username; const senderName = this.settingsModel.username;
if (senderName == "") return false; if (senderName == "") return false;
const allChannels = [this.info.primaryChannel]; const allChannels = [this.info.primaryChannel];
@@ -944,7 +929,7 @@
senderName, senderName,
this.info.encryptionKey, this.info.encryptionKey,
body, body,
fileVersion fileContent
); );
this.addMessage(chatMessage); this.addMessage(chatMessage);
this.connectionModel.sendMessageOrStore(chatMessage); this.connectionModel.sendMessageOrStore(chatMessage);
@@ -995,7 +980,7 @@
this.storageModel.writeStringifiable(messagePath, chatMessage); this.storageModel.writeStringifiable(messagePath, chatMessage);
this.chatMessageHandler(chatMessage); this.chatMessageHandler(chatMessage);
} }
this.fileModel.handleStringifiedFileVersion(chatMessage.stringifiedFile); this.fileModel.handleStringifiedFileContent(chatMessage.stringifiedFile);
}; };
delete = () => { delete = () => {
this.chatListModel.untrackChat(this); this.chatListModel.untrackChat(this);
@@ -1062,7 +1047,7 @@
hasUnreadMessages: false hasUnreadMessages: false
}; };
}; };
static createChatMessage = async (channel, sender, encryptionKey, body, fileVersion) => { static createChatMessage = async (channel, sender, encryptionKey, body, fileContent) => {
const chatMessage = { const chatMessage = {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
id: v4_default(), id: v4_default(),
@@ -1073,8 +1058,8 @@
status: "outbox" /* Outbox */, status: "outbox" /* Outbox */,
stringifiedFile: "" stringifiedFile: ""
}; };
if (fileVersion != void 0) { if (fileContent != void 0) {
const stringifiedFile = stringify(fileVersion); const stringifiedFile = stringify(fileContent);
chatMessage.stringifiedFile = stringifiedFile; chatMessage.stringifiedFile = stringifiedFile;
} }
if (encryptionKey != "") { if (encryptionKey != "") {
+7 -7
View File
@@ -1,7 +1,7 @@
// this file is responsible for managing chats. // this file is responsible for managing chats.
import { DATA_VERSION, ValidObject } from "../Utility/typeSafety"; import { DATA_VERSION, ValidObject } from "../Utility/typeSafety";
import FileModel, { FileVersion } from "../Files/fileModel"; import FileModel, { FileContent } from "../Files/fileModel";
import StorageModel, { filePaths } from "../Global/storageModel"; import StorageModel, { filePaths } from "../Global/storageModel";
import { import {
createTimestamp, createTimestamp,
@@ -85,7 +85,7 @@ export default class ChatModel {
// messaging // messaging
sendMessage = async ( sendMessage = async (
body: string, body: string,
fileVersion: FileVersion<string> fileContent: FileContent<string>
): Promise<boolean> => { ): Promise<boolean> => {
const senderName = this.settingsModel.username; const senderName = this.settingsModel.username;
if (senderName == "") return false; if (senderName == "") return false;
@@ -102,7 +102,7 @@ export default class ChatModel {
senderName, senderName,
this.info.encryptionKey, this.info.encryptionKey,
body, body,
fileVersion fileContent
); );
this.addMessage(chatMessage); this.addMessage(chatMessage);
@@ -167,7 +167,7 @@ export default class ChatModel {
} }
// file // file
this.fileModel.handleStringifiedFileVersion(chatMessage.stringifiedFile); this.fileModel.handleStringifiedFileContent(chatMessage.stringifiedFile);
}; };
delete = () => { delete = () => {
@@ -263,7 +263,7 @@ export default class ChatModel {
sender: string, sender: string,
encryptionKey: string, encryptionKey: string,
body: string, body: string,
fileVersion: FileVersion<string> fileContent: FileContent<string>
): Promise<ChatMessage> => { ): Promise<ChatMessage> => {
const chatMessage: ChatMessage = { const chatMessage: ChatMessage = {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
@@ -278,8 +278,8 @@ export default class ChatModel {
status: ChatMessageStatus.Outbox, status: ChatMessageStatus.Outbox,
stringifiedFile: "", stringifiedFile: "",
}; };
if (fileVersion != undefined) { if (fileContent != undefined) {
const stringifiedFile = stringify(fileVersion); const stringifiedFile = stringify(fileContent);
chatMessage.stringifiedFile = stringifiedFile; chatMessage.stringifiedFile = stringifiedFile;
} }
+51 -51
View File
@@ -41,49 +41,49 @@ export default class FileModel {
return [...this.getFileContainerPath(), fileId]; return [...this.getFileContainerPath(), fileId];
}; };
getFileVersionPath = (fileId: string, fileVersionId: string): string[] => { getFileContentPath = (fileId: string, fileContentId: string): string[] => {
const filePath: string[] = this.getFilePath(fileId); const filePath: string[] = this.getFilePath(fileId);
return [...filePath, fileVersionId]; return [...filePath, fileContentId];
}; };
// handler // handler
handleStringifiedFileVersion = (stringifiedFileVersion: string): void => { handleStringifiedFileContent = (stringifiedFileContent: string): void => {
const fileVersion: FileVersion<string> | null = parseValidObject( const fileContent: FileContent<string> | null = parseValidObject(
stringifiedFileVersion, stringifiedFileContent,
FileVersionReference FileContentReference
); );
if (fileVersion == null) return; if (fileContent == null) return;
this.handleFileVersion(fileVersion); this.handleFileContent(fileContent);
}; };
handleFileVersion = (fileVersion: FileVersion<string>): void => { handleFileContent = (fileContent: FileContent<string>): void => {
const didStore: boolean = this.storeFileVersion(fileVersion); const didStore: boolean = this.storeFileContent(fileContent);
if (didStore == false) return; if (didStore == false) return;
this.taskModel.handleFileVersion(fileVersion); this.taskModel.handleFileContent(fileContent);
}; };
// methods // methods
addFileVersion = (fileVersion: FileVersion<string>): void => { addFileContent = (fileContent: FileContent<string>): void => {
this.handleFileVersion(fileVersion); this.handleFileContent(fileContent);
this.chatModel.sendMessage("", fileVersion); this.chatModel.sendMessage("", fileContent);
}; };
// storage // storage
storeFileVersion = (fileVersion: FileVersion<string>): boolean => { storeFileContent = (fileContent: FileContent<string>): boolean => {
const fileVersionPath: string[] = this.getFileVersionPath( const fileContentPath: string[] = this.getFileContentPath(
fileVersion.fileId, fileContent.fileId,
fileVersion.fileVersionId fileContent.fileContentId
); );
// check if fileVersion already exists // check if fileContent already exists
const existingFileVersion: string | null = const existingFileContent: string | null =
this.storageModel.read(fileVersionPath); this.storageModel.read(fileContentPath);
if (existingFileVersion != null) return false; if (existingFileContent != null) return false;
const stringifiedContent: string = stringify(fileVersion); const stringifiedContent: string = stringify(fileContent);
this.storageModel.write(fileVersionPath, stringifiedContent); this.storageModel.write(fileContentPath, stringifiedContent);
return true; return true;
}; };
@@ -91,45 +91,45 @@ export default class FileModel {
return this.storageModel.list(this.getBasePath()); return this.storageModel.list(this.getBasePath());
}; };
listFileVersionIds = (fileId: string): string[] => { listFileContentIds = (fileId: string): string[] => {
const filePath: string[] = this.getFilePath(fileId); const filePath: string[] = this.getFilePath(fileId);
return this.storageModel.list(filePath); return this.storageModel.list(filePath);
}; };
selectLatestFileVersionId = ( selectLatestFileContentId = (
fileVersionIds: string[] fileContentIds: string[]
): string | undefined => { ): string | undefined => {
return fileVersionIds[fileVersionIds.length - 1]; return fileContentIds[fileContentIds.length - 1];
}; };
getFileVersion = <T extends FileVersion<string>>( getFileContent = <T extends FileContent<string>>(
fileId: string, fileId: string,
fileVersionName: string, fileContentName: string,
reference: T reference: T
): T | null => { ): T | null => {
const filePath: string[] = this.getFileVersionPath(fileId, fileVersionName); const filePath: string[] = this.getFileContentPath(fileId, fileContentName);
const fileVersionOrNull: T | null = this.storageModel.readStringifiable( const fileContentOrNull: T | null = this.storageModel.readStringifiable(
filePath, filePath,
reference reference
); );
return fileVersionOrNull; return fileContentOrNull;
}; };
getLatestFileVersion = <T extends FileVersion<string>>( getLatestFileContent = <T extends FileContent<string>>(
fileId: string, fileId: string,
reference: T reference: T
): T | null => { ): T | null => {
const fileVersionsIds: string[] = this.listFileVersionIds(fileId); const fileContentsIds: string[] = this.listFileContentIds(fileId);
const latestFileVersionId: string | undefined = const latestFileContentId: string | undefined =
this.selectLatestFileVersionId(fileVersionsIds); this.selectLatestFileContentId(fileContentsIds);
if (latestFileVersionId == undefined) return null; if (latestFileContentId == undefined) return null;
const fileVersion: T | null = this.getFileVersion( const fileContent: T | null = this.getFileContent(
fileId, fileId,
latestFileVersionId, latestFileContentId,
reference reference
); );
return fileVersion; return fileContent;
}; };
// init // init
@@ -149,7 +149,7 @@ export default class FileModel {
// const firstBoardInfo = this.taskModel.getBoardInfo(boardId); // const firstBoardInfo = this.taskModel.getBoardInfo(boardId);
// console.log(firstBoardInfo); // console.log(firstBoardInfo);
// const newInfo = TaskModel.createBoardInfoFileVersion( // const newInfo = TaskModel.createBoardInfoFileContent(
// boardId, // boardId,
// "renamed", // "renamed",
// Color.Coral // Color.Coral
@@ -160,22 +160,22 @@ export default class FileModel {
} }
// utility // utility
static generateFileVersionId = (creationDate): string => { static generateFileContentId = (creationDate): string => {
return creationDate + v4(); return creationDate + v4();
}; };
static createFileVersion = <T extends string>( static createFileContent = <T extends string>(
fileId: string, fileId: string,
type: T type: T
): FileVersion<T> => { ): FileContent<T> => {
const creationDate: string = createTimestamp(); const creationDate: string = createTimestamp();
const fileVersionId: string = FileModel.generateFileVersionId(creationDate); const fileContentId: string = FileModel.generateFileContentId(creationDate);
return { return {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
fileId, fileId,
fileVersionId, fileContentId,
creationDate, creationDate,
type, type,
}; };
@@ -190,20 +190,20 @@ export const subDirectories = {
}; };
// types // types
export interface FileVersion<T extends string> extends ValidObject { export interface FileContent<T extends string> extends ValidObject {
fileId: string; fileId: string;
fileVersionId: string; fileContentId: string;
creationDate: string; creationDate: string;
type: T; type: T;
} }
// references // references
export const FileVersionReference: FileVersion<string> = { export const FileContentReference: FileContent<string> = {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
fileId: "", fileId: "",
fileVersionId: "", fileContentId: "",
creationDate: "", creationDate: "",
type: "", type: "",
+34 -34
View File
@@ -4,7 +4,7 @@ import {
DATA_VERSION, DATA_VERSION,
checkMatchesObjectStructure, checkMatchesObjectStructure,
} from "../Utility/typeSafety"; } from "../Utility/typeSafety";
import FileModel, { FileVersion } from "./fileModel"; import FileModel, { FileContent } from "./fileModel";
import ChatModel from "../Chat/chatModel"; import ChatModel from "../Chat/chatModel";
import { Color } from "../../ViewModel/colors"; import { Color } from "../../ViewModel/colors";
@@ -50,30 +50,30 @@ export default class TaskModel {
}; };
// handler // handler
handleFileVersion = (fileVersion: FileVersion<string>): void => { handleFileContent = (fileContent: FileContent<string>): void => {
if ( if (
checkMatchesObjectStructure(fileVersion, BoardInfoFileVersionReference) == checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) ==
true true
) { ) {
this.handleBoard(fileVersion as BoardInfoVersion); this.handleBoard(fileContent as BoardInfoVersion);
} else if ( } else if (
checkMatchesObjectStructure(fileVersion, TaskFileVersionReference) == true checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true
) { ) {
this.handleTask(fileVersion as TaskFileVersion); this.handleTask(fileContent as TaskFileContent);
} }
}; };
handleBoard = (boardInfoFileVersion: BoardInfoVersion) => { handleBoard = (boardInfoFileContent: BoardInfoVersion) => {
console.log("board", boardInfoFileVersion); console.log("board", boardInfoFileContent);
}; };
handleTask = (taskFileVersion: TaskFileVersion) => {}; handleTask = (taskFileContent: TaskFileContent) => {};
// boards // boards
createBoard = (name: string): void => { createBoard = (name: string): void => {
const boardInfoFileVersion: BoardInfoVersion = const boardInfoFileContent: BoardInfoVersion =
TaskModel.createBoardInfoFileVersion(v4(), name, Color.Standard); TaskModel.createBoardInfoFileContent(v4(), name, Color.Standard);
this.createOrUpdateBoard(boardInfoFileVersion); this.createOrUpdateBoard(boardInfoFileContent);
}; };
listBoardIds = (): string[] => { listBoardIds = (): string[] => {
@@ -83,21 +83,21 @@ export default class TaskModel {
}; };
getBoardInfo = (fileId: string): BoardInfoVersion | null => { getBoardInfo = (fileId: string): BoardInfoVersion | null => {
const boardInfoFileVersionOrNull: BoardInfoVersion | null = const boardInfoFileContentOrNull: BoardInfoVersion | null =
this.fileModel.getLatestFileVersion( this.fileModel.getLatestFileContent(
fileId, fileId,
BoardInfoFileVersionReference BoardInfoFileContentReference
); );
return boardInfoFileVersionOrNull; return boardInfoFileContentOrNull;
}; };
createOrUpdateBoard = (boardInfoFileVersion: BoardInfoVersion): void => { createOrUpdateBoard = (boardInfoFileContent: BoardInfoVersion): void => {
// store info // store info
this.fileModel.addFileVersion(boardInfoFileVersion); this.fileModel.addFileContent(boardInfoFileContent);
// add to list // add to list
const boardDirectoryPath: string[] = this.getBoardDirectoryPath( const boardDirectoryPath: string[] = this.getBoardDirectoryPath(
boardInfoFileVersion.fileId boardInfoFileContent.fileId
); );
this.storageModel.write(boardDirectoryPath, ""); this.storageModel.write(boardDirectoryPath, "");
}; };
@@ -112,12 +112,12 @@ export default class TaskModel {
//tasks //tasks
createTask = (boardId: string, name: string): void => { createTask = (boardId: string, name: string): void => {
const taskFileVersion: TaskFileVersion = TaskModel.createTaskFileVersion( const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent(
v4(), v4(),
boardId, boardId,
name name
); );
this.fileModel.addFileVersion(taskFileVersion); this.fileModel.addFileContent(taskFileContent);
}; };
listTaskIds = (boardName: string): string[] => { listTaskIds = (boardName: string): string[] => {
@@ -148,34 +148,34 @@ export default class TaskModel {
} }
// utility // utility
static createBoardInfoFileVersion = ( static createBoardInfoFileContent = (
fileId: string, fileId: string,
name: string, name: string,
color: Color color: Color
): BoardInfoVersion => { ): BoardInfoVersion => {
const fileVersion: FileVersion<"board-info"> = FileModel.createFileVersion( const fileContent: FileContent<"board-info"> = FileModel.createFileContent(
fileId, fileId,
"board-info" "board-info"
); );
return { return {
...fileVersion, ...fileContent,
name, name,
color, color,
}; };
}; };
static createTaskFileVersion = ( static createTaskFileContent = (
fileId: string, fileId: string,
name: string, name: string,
boardId: string boardId: string
): TaskFileVersion => { ): TaskFileContent => {
const fileVersion: FileVersion<"task"> = FileModel.createFileVersion( const fileContent: FileContent<"task"> = FileModel.createFileContent(
fileId, fileId,
"task" "task"
); );
return { return {
...fileVersion, ...fileContent,
name, name,
boardId, boardId,
@@ -189,12 +189,12 @@ export const subDirectories = {
}; };
// types // types
export interface BoardInfoVersion extends FileVersion<"board-info"> { export interface BoardInfoVersion extends FileContent<"board-info"> {
name: string; name: string;
color: Color; color: Color;
} }
export interface TaskFileVersion extends FileVersion<"task"> { export interface TaskFileContent extends FileContent<"task"> {
name: string; name: string;
boardId: string; boardId: string;
@@ -209,11 +209,11 @@ export interface TaskFileVersion extends FileVersion<"task"> {
} }
// reference // reference
export const BoardInfoFileVersionReference: BoardInfoVersion = { export const BoardInfoFileContentReference: BoardInfoVersion = {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
fileId: "string", fileId: "string",
fileVersionId: "", fileContentId: "",
creationDate: "", creationDate: "",
type: "board-info", type: "board-info",
@@ -222,11 +222,11 @@ export const BoardInfoFileVersionReference: BoardInfoVersion = {
color: "" as Color, color: "" as Color,
}; };
export const TaskFileVersionReference: TaskFileVersion = { export const TaskFileContentReference: TaskFileContent = {
dataVersion: DATA_VERSION, dataVersion: DATA_VERSION,
fileId: "string", fileId: "string",
fileVersionId: "", fileContentId: "",
creationDate: "", creationDate: "",
type: "task", type: "task",