clean file content handling
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -70,143 +70,150 @@ export default class FileModel {
|
|||||||
const didStore: boolean = this.storeFileContent(fileContent);
|
const didStore: boolean = this.storeFileContent(fileContent);
|
||||||
if (didStore == false) return;
|
if (didStore == false) return;
|
||||||
|
|
||||||
this.boardsAndTasksModel.handleFileContent(fileContent);
|
switch (fileContent.type) {
|
||||||
this.chatModel.handleReaction(fileContent);
|
case "board-info":
|
||||||
|
case "task":
|
||||||
|
this.boardsAndTasksModel.handleFileContent(fileContent);
|
||||||
|
break;
|
||||||
|
case "reaction":
|
||||||
|
this.chatModel.handleReaction(fileContent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
readonly addFileContentAndSend = (
|
readonly addFileContentAndSend = (
|
||||||
fileContent: FileContent<string>,
|
fileContent: FileContent<string>,
|
||||||
): void => {
|
): void => {
|
||||||
this.handleFileContent(fileContent);
|
this.handleFileContent(fileContent);
|
||||||
this.chatModel.sendMessage("", undefined, fileContent);
|
this.chatModel.sendMessage("", undefined, fileContent);
|
||||||
};
|
};
|
||||||
|
|
||||||
// storage
|
// storage
|
||||||
readonly storeFileContent = (fileContent: FileContent<string>): boolean => {
|
readonly storeFileContent = (fileContent: FileContent<string>): boolean => {
|
||||||
const fileContentPath: string[] = this.getFileContentPath(
|
const fileContentPath: string[] = this.getFileContentPath(
|
||||||
fileContent.fileId,
|
fileContent.fileId,
|
||||||
fileContent.fileContentId,
|
fileContent.fileContentId,
|
||||||
);
|
);
|
||||||
|
|
||||||
// check if fileContent already exists
|
// check if fileContent already exists
|
||||||
const existingFileContent: string | null =
|
const existingFileContent: string | null =
|
||||||
this.storageModel.read(fileContentPath);
|
this.storageModel.read(fileContentPath);
|
||||||
if (existingFileContent != null) return false;
|
if (existingFileContent != null) return false;
|
||||||
|
|
||||||
const stringifiedContent: string = stringify(fileContent);
|
const stringifiedContent: string = stringify(fileContent);
|
||||||
this.storageModel.write(fileContentPath, stringifiedContent);
|
this.storageModel.write(fileContentPath, stringifiedContent);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly listFileIds = (): string[] => {
|
readonly listFileIds = (): string[] => {
|
||||||
return this.storageModel.list(this.basePath);
|
return this.storageModel.list(this.basePath);
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly listFileContentIds = (fileId: string): string[] => {
|
readonly 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);
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly selectLatestFileContentId = (
|
readonly selectLatestFileContentId = (
|
||||||
fileContentIds: string[],
|
fileContentIds: string[],
|
||||||
): string | undefined => {
|
): string | undefined => {
|
||||||
return fileContentIds[fileContentIds.length - 1];
|
return fileContentIds[fileContentIds.length - 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly getFileContent = <T extends FileContent<string>>(
|
readonly getFileContent = <T extends FileContent<string>>(
|
||||||
fileId: string,
|
fileId: string,
|
||||||
fileContentName: string,
|
fileContentName: string,
|
||||||
reference: T,
|
reference: T,
|
||||||
): T | null => {
|
): T | null => {
|
||||||
const filePath: string[] = this.getFileContentPath(
|
const filePath: string[] = this.getFileContentPath(
|
||||||
fileId,
|
fileId,
|
||||||
fileContentName,
|
fileContentName,
|
||||||
);
|
);
|
||||||
const fileContentOrNull: T | null = this.storageModel.readStringifiable(
|
const fileContentOrNull: T | null = this.storageModel.readStringifiable(
|
||||||
filePath,
|
filePath,
|
||||||
reference,
|
reference,
|
||||||
);
|
);
|
||||||
return fileContentOrNull;
|
return fileContentOrNull;
|
||||||
};
|
};
|
||||||
|
|
||||||
readonly getLatestFileContent = <T extends FileContent<string>>(
|
readonly getLatestFileContent = <T extends FileContent<string>>(
|
||||||
fileId: string,
|
fileId: string,
|
||||||
reference: T,
|
reference: T,
|
||||||
): T | null => {
|
): T | null => {
|
||||||
const fileContentsIds: string[] = this.listFileContentIds(fileId);
|
const fileContentsIds: string[] = this.listFileContentIds(fileId);
|
||||||
const latestFileContentId: string | undefined =
|
const latestFileContentId: string | undefined =
|
||||||
this.selectLatestFileContentId(fileContentsIds);
|
this.selectLatestFileContentId(fileContentsIds);
|
||||||
if (latestFileContentId == undefined) return null;
|
if (latestFileContentId == undefined) return null;
|
||||||
|
|
||||||
const fileContent: T | null = this.getFileContent(
|
const fileContent: T | null = this.getFileContent(
|
||||||
fileId,
|
fileId,
|
||||||
latestFileContentId,
|
latestFileContentId,
|
||||||
reference,
|
reference,
|
||||||
);
|
);
|
||||||
return fileContent;
|
return fileContent;
|
||||||
};
|
};
|
||||||
|
|
||||||
// init
|
// init
|
||||||
constructor(
|
constructor(
|
||||||
storageModel: StorageModel,
|
storageModel: StorageModel,
|
||||||
settingsModel: SettingsModel,
|
settingsModel: SettingsModel,
|
||||||
chatModel: ChatModel,
|
chatModel: ChatModel,
|
||||||
) {
|
) {
|
||||||
this.chatModel = chatModel;
|
this.chatModel = chatModel;
|
||||||
this.settingsModel = settingsModel;
|
this.settingsModel = settingsModel;
|
||||||
this.storageModel = storageModel;
|
this.storageModel = storageModel;
|
||||||
|
|
||||||
this.boardsAndTasksModel = new BoardsAndTasksModel(
|
this.boardsAndTasksModel = new BoardsAndTasksModel(
|
||||||
this.storageModel,
|
this.storageModel,
|
||||||
this.settingsModel,
|
this.settingsModel,
|
||||||
chatModel,
|
chatModel,
|
||||||
this,
|
this,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// utility
|
// utility
|
||||||
static generateFileContentId = (creationDate: string): string => {
|
static generateFileContentId = (creationDate: string): string => {
|
||||||
return creationDate + v4();
|
return creationDate + v4();
|
||||||
};
|
};
|
||||||
|
|
||||||
static createFileContent = <T extends string>(
|
static createFileContent = <T extends string>(
|
||||||
fileId: string,
|
fileId: string,
|
||||||
type: T,
|
type: T,
|
||||||
): FileContent<T> => {
|
): FileContent<T> => {
|
||||||
const creationDate: string = createTimestamp();
|
const creationDate: string = createTimestamp();
|
||||||
const fileContentId: string =
|
const fileContentId: string =
|
||||||
FileModel.generateFileContentId(creationDate);
|
FileModel.generateFileContentId(creationDate);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dataVersion: DATA_VERSION,
|
dataVersion: DATA_VERSION,
|
||||||
|
|
||||||
fileId,
|
fileId,
|
||||||
fileContentId,
|
fileContentId,
|
||||||
creationDate,
|
creationDate,
|
||||||
type,
|
type,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// paths
|
// paths
|
||||||
export enum FileModelSubPath {
|
export enum FileModelSubPath {
|
||||||
Data = "data",
|
Data = "data",
|
||||||
Model = "model",
|
Model = "model",
|
||||||
ModelView = "view",
|
ModelView = "view",
|
||||||
ModelTask = "tasks",
|
ModelTask = "tasks",
|
||||||
ModelCalendar = "calendar",
|
ModelCalendar = "calendar",
|
||||||
}
|
}
|
||||||
|
|
||||||
// types
|
// types
|
||||||
export interface FileContent<T extends string>
|
export interface FileContent<T extends string>
|
||||||
extends ValidObject, StringEntryObject {
|
extends ValidObject, StringEntryObject {
|
||||||
readonly fileId: string;
|
readonly fileId: string;
|
||||||
readonly fileContentId: string;
|
readonly fileContentId: string;
|
||||||
readonly creationDate: string;
|
readonly creationDate: string;
|
||||||
|
|
||||||
readonly type: T;
|
readonly type: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
// references
|
// references
|
||||||
export const FileContentReference: FileContent<string> = {
|
export const FileContentReference: FileContent<string> = {
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ export enum CommonKeys {
|
|||||||
CloseOrCancel = "backspace",
|
CloseOrCancel = "backspace",
|
||||||
Apply = "enter",
|
Apply = "enter",
|
||||||
Settings = ",",
|
Settings = ",",
|
||||||
Create = ";",
|
Create = "a",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ export default class CoreViewModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
handleKeyDown = (e: KeyboardEvent): void => {
|
handleKeyDown = (e: KeyboardEvent): void => {
|
||||||
|
if (!(e instanceof KeyboardEvent)) return console.trace("NOT A KEY EVENT");
|
||||||
if (CoreViewModel.checkIsKeystroke(e) == false) return;
|
if (CoreViewModel.checkIsKeystroke(e) == false) return;
|
||||||
|
console.log(e.key);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const contexts: Context[] = this.contexts;
|
const contexts: Context[] = this.contexts;
|
||||||
while (contexts.length > 0) {
|
while (contexts.length > 0) {
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ export default class BoardViewModel extends TaskContainingPageViewModel {
|
|||||||
this,
|
this,
|
||||||
taskFileContent,
|
taskFileContent,
|
||||||
);
|
);
|
||||||
|
console.log("STILL HERE", taskFileContent.fileId);
|
||||||
this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
|
this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user