rename FileVersion -> FIleContent
This commit is contained in:
@@ -41,49 +41,49 @@ export default class FileModel {
|
||||
return [...this.getFileContainerPath(), fileId];
|
||||
};
|
||||
|
||||
getFileVersionPath = (fileId: string, fileVersionId: string): string[] => {
|
||||
getFileContentPath = (fileId: string, fileContentId: string): string[] => {
|
||||
const filePath: string[] = this.getFilePath(fileId);
|
||||
return [...filePath, fileVersionId];
|
||||
return [...filePath, fileContentId];
|
||||
};
|
||||
|
||||
// handler
|
||||
handleStringifiedFileVersion = (stringifiedFileVersion: string): void => {
|
||||
const fileVersion: FileVersion<string> | null = parseValidObject(
|
||||
stringifiedFileVersion,
|
||||
FileVersionReference
|
||||
handleStringifiedFileContent = (stringifiedFileContent: string): void => {
|
||||
const fileContent: FileContent<string> | null = parseValidObject(
|
||||
stringifiedFileContent,
|
||||
FileContentReference
|
||||
);
|
||||
if (fileVersion == null) return;
|
||||
if (fileContent == null) return;
|
||||
|
||||
this.handleFileVersion(fileVersion);
|
||||
this.handleFileContent(fileContent);
|
||||
};
|
||||
|
||||
handleFileVersion = (fileVersion: FileVersion<string>): void => {
|
||||
const didStore: boolean = this.storeFileVersion(fileVersion);
|
||||
handleFileContent = (fileContent: FileContent<string>): void => {
|
||||
const didStore: boolean = this.storeFileContent(fileContent);
|
||||
if (didStore == false) return;
|
||||
|
||||
this.taskModel.handleFileVersion(fileVersion);
|
||||
this.taskModel.handleFileContent(fileContent);
|
||||
};
|
||||
|
||||
// methods
|
||||
addFileVersion = (fileVersion: FileVersion<string>): void => {
|
||||
this.handleFileVersion(fileVersion);
|
||||
this.chatModel.sendMessage("", fileVersion);
|
||||
addFileContent = (fileContent: FileContent<string>): void => {
|
||||
this.handleFileContent(fileContent);
|
||||
this.chatModel.sendMessage("", fileContent);
|
||||
};
|
||||
|
||||
// storage
|
||||
storeFileVersion = (fileVersion: FileVersion<string>): boolean => {
|
||||
const fileVersionPath: string[] = this.getFileVersionPath(
|
||||
fileVersion.fileId,
|
||||
fileVersion.fileVersionId
|
||||
storeFileContent = (fileContent: FileContent<string>): boolean => {
|
||||
const fileContentPath: string[] = this.getFileContentPath(
|
||||
fileContent.fileId,
|
||||
fileContent.fileContentId
|
||||
);
|
||||
|
||||
// check if fileVersion already exists
|
||||
const existingFileVersion: string | null =
|
||||
this.storageModel.read(fileVersionPath);
|
||||
if (existingFileVersion != null) return false;
|
||||
// check if fileContent already exists
|
||||
const existingFileContent: string | null =
|
||||
this.storageModel.read(fileContentPath);
|
||||
if (existingFileContent != null) return false;
|
||||
|
||||
const stringifiedContent: string = stringify(fileVersion);
|
||||
this.storageModel.write(fileVersionPath, stringifiedContent);
|
||||
const stringifiedContent: string = stringify(fileContent);
|
||||
this.storageModel.write(fileContentPath, stringifiedContent);
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -91,45 +91,45 @@ export default class FileModel {
|
||||
return this.storageModel.list(this.getBasePath());
|
||||
};
|
||||
|
||||
listFileVersionIds = (fileId: string): string[] => {
|
||||
listFileContentIds = (fileId: string): string[] => {
|
||||
const filePath: string[] = this.getFilePath(fileId);
|
||||
return this.storageModel.list(filePath);
|
||||
};
|
||||
|
||||
selectLatestFileVersionId = (
|
||||
fileVersionIds: string[]
|
||||
selectLatestFileContentId = (
|
||||
fileContentIds: string[]
|
||||
): string | undefined => {
|
||||
return fileVersionIds[fileVersionIds.length - 1];
|
||||
return fileContentIds[fileContentIds.length - 1];
|
||||
};
|
||||
|
||||
getFileVersion = <T extends FileVersion<string>>(
|
||||
getFileContent = <T extends FileContent<string>>(
|
||||
fileId: string,
|
||||
fileVersionName: string,
|
||||
fileContentName: string,
|
||||
reference: T
|
||||
): T | null => {
|
||||
const filePath: string[] = this.getFileVersionPath(fileId, fileVersionName);
|
||||
const fileVersionOrNull: T | null = this.storageModel.readStringifiable(
|
||||
const filePath: string[] = this.getFileContentPath(fileId, fileContentName);
|
||||
const fileContentOrNull: T | null = this.storageModel.readStringifiable(
|
||||
filePath,
|
||||
reference
|
||||
);
|
||||
return fileVersionOrNull;
|
||||
return fileContentOrNull;
|
||||
};
|
||||
|
||||
getLatestFileVersion = <T extends FileVersion<string>>(
|
||||
getLatestFileContent = <T extends FileContent<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 fileContentsIds: string[] = this.listFileContentIds(fileId);
|
||||
const latestFileContentId: string | undefined =
|
||||
this.selectLatestFileContentId(fileContentsIds);
|
||||
if (latestFileContentId == undefined) return null;
|
||||
|
||||
const fileVersion: T | null = this.getFileVersion(
|
||||
const fileContent: T | null = this.getFileContent(
|
||||
fileId,
|
||||
latestFileVersionId,
|
||||
latestFileContentId,
|
||||
reference
|
||||
);
|
||||
return fileVersion;
|
||||
return fileContent;
|
||||
};
|
||||
|
||||
// init
|
||||
@@ -149,7 +149,7 @@ export default class FileModel {
|
||||
// const firstBoardInfo = this.taskModel.getBoardInfo(boardId);
|
||||
// console.log(firstBoardInfo);
|
||||
|
||||
// const newInfo = TaskModel.createBoardInfoFileVersion(
|
||||
// const newInfo = TaskModel.createBoardInfoFileContent(
|
||||
// boardId,
|
||||
// "renamed",
|
||||
// Color.Coral
|
||||
@@ -160,22 +160,22 @@ export default class FileModel {
|
||||
}
|
||||
|
||||
// utility
|
||||
static generateFileVersionId = (creationDate): string => {
|
||||
static generateFileContentId = (creationDate): string => {
|
||||
return creationDate + v4();
|
||||
};
|
||||
|
||||
static createFileVersion = <T extends string>(
|
||||
static createFileContent = <T extends string>(
|
||||
fileId: string,
|
||||
type: T
|
||||
): FileVersion<T> => {
|
||||
): FileContent<T> => {
|
||||
const creationDate: string = createTimestamp();
|
||||
const fileVersionId: string = FileModel.generateFileVersionId(creationDate);
|
||||
const fileContentId: string = FileModel.generateFileContentId(creationDate);
|
||||
|
||||
return {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
fileId,
|
||||
fileVersionId,
|
||||
fileContentId,
|
||||
creationDate,
|
||||
type,
|
||||
};
|
||||
@@ -190,20 +190,20 @@ export const subDirectories = {
|
||||
};
|
||||
|
||||
// types
|
||||
export interface FileVersion<T extends string> extends ValidObject {
|
||||
export interface FileContent<T extends string> extends ValidObject {
|
||||
fileId: string;
|
||||
fileVersionId: string;
|
||||
fileContentId: string;
|
||||
creationDate: string;
|
||||
|
||||
type: T;
|
||||
}
|
||||
|
||||
// references
|
||||
export const FileVersionReference: FileVersion<string> = {
|
||||
export const FileContentReference: FileContent<string> = {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
fileId: "",
|
||||
fileVersionId: "",
|
||||
fileContentId: "",
|
||||
creationDate: "",
|
||||
|
||||
type: "",
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
DATA_VERSION,
|
||||
checkMatchesObjectStructure,
|
||||
} from "../Utility/typeSafety";
|
||||
import FileModel, { FileVersion } from "./fileModel";
|
||||
import FileModel, { FileContent } from "./fileModel";
|
||||
|
||||
import ChatModel from "../Chat/chatModel";
|
||||
import { Color } from "../../ViewModel/colors";
|
||||
@@ -50,30 +50,30 @@ export default class TaskModel {
|
||||
};
|
||||
|
||||
// handler
|
||||
handleFileVersion = (fileVersion: FileVersion<string>): void => {
|
||||
handleFileContent = (fileContent: FileContent<string>): void => {
|
||||
if (
|
||||
checkMatchesObjectStructure(fileVersion, BoardInfoFileVersionReference) ==
|
||||
checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) ==
|
||||
true
|
||||
) {
|
||||
this.handleBoard(fileVersion as BoardInfoVersion);
|
||||
this.handleBoard(fileContent as BoardInfoVersion);
|
||||
} else if (
|
||||
checkMatchesObjectStructure(fileVersion, TaskFileVersionReference) == true
|
||||
checkMatchesObjectStructure(fileContent, TaskFileContentReference) == true
|
||||
) {
|
||||
this.handleTask(fileVersion as TaskFileVersion);
|
||||
this.handleTask(fileContent as TaskFileContent);
|
||||
}
|
||||
};
|
||||
|
||||
handleBoard = (boardInfoFileVersion: BoardInfoVersion) => {
|
||||
console.log("board", boardInfoFileVersion);
|
||||
handleBoard = (boardInfoFileContent: BoardInfoVersion) => {
|
||||
console.log("board", boardInfoFileContent);
|
||||
};
|
||||
|
||||
handleTask = (taskFileVersion: TaskFileVersion) => {};
|
||||
handleTask = (taskFileContent: TaskFileContent) => {};
|
||||
|
||||
// boards
|
||||
createBoard = (name: string): void => {
|
||||
const boardInfoFileVersion: BoardInfoVersion =
|
||||
TaskModel.createBoardInfoFileVersion(v4(), name, Color.Standard);
|
||||
this.createOrUpdateBoard(boardInfoFileVersion);
|
||||
const boardInfoFileContent: BoardInfoVersion =
|
||||
TaskModel.createBoardInfoFileContent(v4(), name, Color.Standard);
|
||||
this.createOrUpdateBoard(boardInfoFileContent);
|
||||
};
|
||||
|
||||
listBoardIds = (): string[] => {
|
||||
@@ -83,21 +83,21 @@ export default class TaskModel {
|
||||
};
|
||||
|
||||
getBoardInfo = (fileId: string): BoardInfoVersion | null => {
|
||||
const boardInfoFileVersionOrNull: BoardInfoVersion | null =
|
||||
this.fileModel.getLatestFileVersion(
|
||||
const boardInfoFileContentOrNull: BoardInfoVersion | null =
|
||||
this.fileModel.getLatestFileContent(
|
||||
fileId,
|
||||
BoardInfoFileVersionReference
|
||||
BoardInfoFileContentReference
|
||||
);
|
||||
return boardInfoFileVersionOrNull;
|
||||
return boardInfoFileContentOrNull;
|
||||
};
|
||||
|
||||
createOrUpdateBoard = (boardInfoFileVersion: BoardInfoVersion): void => {
|
||||
createOrUpdateBoard = (boardInfoFileContent: BoardInfoVersion): void => {
|
||||
// store info
|
||||
this.fileModel.addFileVersion(boardInfoFileVersion);
|
||||
this.fileModel.addFileContent(boardInfoFileContent);
|
||||
|
||||
// add to list
|
||||
const boardDirectoryPath: string[] = this.getBoardDirectoryPath(
|
||||
boardInfoFileVersion.fileId
|
||||
boardInfoFileContent.fileId
|
||||
);
|
||||
this.storageModel.write(boardDirectoryPath, "");
|
||||
};
|
||||
@@ -112,12 +112,12 @@ export default class TaskModel {
|
||||
|
||||
//tasks
|
||||
createTask = (boardId: string, name: string): void => {
|
||||
const taskFileVersion: TaskFileVersion = TaskModel.createTaskFileVersion(
|
||||
const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent(
|
||||
v4(),
|
||||
boardId,
|
||||
name
|
||||
);
|
||||
this.fileModel.addFileVersion(taskFileVersion);
|
||||
this.fileModel.addFileContent(taskFileContent);
|
||||
};
|
||||
|
||||
listTaskIds = (boardName: string): string[] => {
|
||||
@@ -148,34 +148,34 @@ export default class TaskModel {
|
||||
}
|
||||
|
||||
// utility
|
||||
static createBoardInfoFileVersion = (
|
||||
static createBoardInfoFileContent = (
|
||||
fileId: string,
|
||||
name: string,
|
||||
color: Color
|
||||
): BoardInfoVersion => {
|
||||
const fileVersion: FileVersion<"board-info"> = FileModel.createFileVersion(
|
||||
const fileContent: FileContent<"board-info"> = FileModel.createFileContent(
|
||||
fileId,
|
||||
"board-info"
|
||||
);
|
||||
return {
|
||||
...fileVersion,
|
||||
...fileContent,
|
||||
|
||||
name,
|
||||
color,
|
||||
};
|
||||
};
|
||||
|
||||
static createTaskFileVersion = (
|
||||
static createTaskFileContent = (
|
||||
fileId: string,
|
||||
name: string,
|
||||
boardId: string
|
||||
): TaskFileVersion => {
|
||||
const fileVersion: FileVersion<"task"> = FileModel.createFileVersion(
|
||||
): TaskFileContent => {
|
||||
const fileContent: FileContent<"task"> = FileModel.createFileContent(
|
||||
fileId,
|
||||
"task"
|
||||
);
|
||||
return {
|
||||
...fileVersion,
|
||||
...fileContent,
|
||||
|
||||
name,
|
||||
boardId,
|
||||
@@ -189,12 +189,12 @@ export const subDirectories = {
|
||||
};
|
||||
|
||||
// types
|
||||
export interface BoardInfoVersion extends FileVersion<"board-info"> {
|
||||
export interface BoardInfoVersion extends FileContent<"board-info"> {
|
||||
name: string;
|
||||
color: Color;
|
||||
}
|
||||
|
||||
export interface TaskFileVersion extends FileVersion<"task"> {
|
||||
export interface TaskFileContent extends FileContent<"task"> {
|
||||
name: string;
|
||||
boardId: string;
|
||||
|
||||
@@ -209,11 +209,11 @@ export interface TaskFileVersion extends FileVersion<"task"> {
|
||||
}
|
||||
|
||||
// reference
|
||||
export const BoardInfoFileVersionReference: BoardInfoVersion = {
|
||||
export const BoardInfoFileContentReference: BoardInfoVersion = {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
fileId: "string",
|
||||
fileVersionId: "",
|
||||
fileContentId: "",
|
||||
creationDate: "",
|
||||
|
||||
type: "board-info",
|
||||
@@ -222,11 +222,11 @@ export const BoardInfoFileVersionReference: BoardInfoVersion = {
|
||||
color: "" as Color,
|
||||
};
|
||||
|
||||
export const TaskFileVersionReference: TaskFileVersion = {
|
||||
export const TaskFileContentReference: TaskFileContent = {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
fileId: "string",
|
||||
fileVersionId: "",
|
||||
fileContentId: "",
|
||||
creationDate: "",
|
||||
type: "task",
|
||||
|
||||
|
||||
Reference in New Issue
Block a user