add handlers in TaskModel
This commit is contained in:
Vendored
+68
-13
@@ -289,11 +289,14 @@
|
||||
const requiredType = typeof reference[key];
|
||||
const actualType = typeof objectToCheck[key];
|
||||
if (requiredType != actualType) return false;
|
||||
if (Array.isArray(reference[key])) {
|
||||
if (Array.isArray(reference[key]) || reference[key] instanceof Set) {
|
||||
if (objectToCheck[key].length == 0) continue;
|
||||
if (objectToCheck[key].size == 0) continue;
|
||||
const [firstOfObjectToCheck] = objectToCheck[key];
|
||||
const [fisrtOfReference] = reference[key];
|
||||
const doesFirstItemMatch = checkMatchesObjectStructure(
|
||||
objectToCheck[key][0],
|
||||
reference[key][0]
|
||||
firstOfObjectToCheck,
|
||||
fisrtOfReference
|
||||
);
|
||||
if (doesFirstItemMatch == false) return false;
|
||||
} else if (requiredType == "object") {
|
||||
@@ -478,14 +481,50 @@
|
||||
};
|
||||
|
||||
// src/Model/Files/taskModel.ts
|
||||
var TaskModel = class {
|
||||
var TaskModel = class _TaskModel {
|
||||
chatModel;
|
||||
fileModel;
|
||||
// handler
|
||||
handleTaskFileContent = (file, fileContent) => {
|
||||
if (checkMatchesObjectStructure(fileContent, TaskFileContentReference) == false)
|
||||
return;
|
||||
};
|
||||
// methods
|
||||
createTask = (board, name) => {
|
||||
const file = FileModel.createFile();
|
||||
const taskFileContent = _TaskModel.createTaskFileContent(
|
||||
board,
|
||||
name
|
||||
);
|
||||
file.contentVersions.add(taskFileContent);
|
||||
this.fileModel.addOrUpdateFile(file);
|
||||
};
|
||||
saveTask = (file, newTaskFileContent) => {
|
||||
file.contentVersions.add(newTaskFileContent);
|
||||
this.fileModel.addOrUpdateFile(file);
|
||||
};
|
||||
// init
|
||||
constructor(chatModel, fileModel) {
|
||||
this.chatModel = chatModel;
|
||||
this.fileModel = fileModel;
|
||||
}
|
||||
// utility
|
||||
static createTaskFileContent = (name, board) => {
|
||||
const fileContent = FileModel.createFileContent("task");
|
||||
return {
|
||||
...fileContent,
|
||||
name,
|
||||
board
|
||||
};
|
||||
};
|
||||
};
|
||||
var TaskFileContentReference = {
|
||||
dataVersion: DATA_VERSION,
|
||||
id: "",
|
||||
creationDate: "",
|
||||
type: "task",
|
||||
name: "",
|
||||
board: ""
|
||||
};
|
||||
|
||||
// src/Model/Files/fileModel.ts
|
||||
@@ -511,18 +550,20 @@
|
||||
handleStringifiedFile = (stringifiedFile) => {
|
||||
const file = parseValidObject(stringifiedFile, FileReference);
|
||||
if (file == null) return;
|
||||
this.storeFile(file);
|
||||
this.handleFile(file);
|
||||
};
|
||||
handleFile = (file) => {
|
||||
for (const fileContent of file.contentVersions) {
|
||||
this.storeFileContent(file, fileContent);
|
||||
this.taskModel.handleTaskFileContent(file, fileContent);
|
||||
}
|
||||
};
|
||||
// methods
|
||||
addFile = (file) => {
|
||||
addOrUpdateFile = (file) => {
|
||||
this.handleFile(file);
|
||||
this.chatModel.sendMessage("", file);
|
||||
};
|
||||
// storage
|
||||
storeFile = (file) => {
|
||||
for (const fileContent of file.contentVersions) {
|
||||
this.storeFileContent(file, fileContent);
|
||||
}
|
||||
};
|
||||
storeFileContent = (file, fileContent) => {
|
||||
const fileContentName = _FileModel.getFileContentName(fileContent);
|
||||
const fileContentPath = this.getFileContentPath(
|
||||
@@ -571,7 +612,15 @@
|
||||
return {
|
||||
dataVersion: DATA_VERSION,
|
||||
id: v4_default(),
|
||||
contentVersions: []
|
||||
contentVersions: /* @__PURE__ */ new Set()
|
||||
};
|
||||
};
|
||||
static createFileContent = (type) => {
|
||||
return {
|
||||
dataVersion: DATA_VERSION,
|
||||
id: v4_default(),
|
||||
creationDate: createTimestamp(),
|
||||
type
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -584,7 +633,7 @@
|
||||
var FileReference = {
|
||||
dataVersion: DATA_VERSION,
|
||||
id: "",
|
||||
contentVersions: [FileContentReference]
|
||||
contentVersions: /* @__PURE__ */ new Set([FileContentReference])
|
||||
};
|
||||
|
||||
// src/Model/Utility/crypto.ts
|
||||
@@ -2518,4 +2567,10 @@
|
||||
ConnectionModal(connectionViewModel),
|
||||
StorageModal(storageViewModel)
|
||||
);
|
||||
console.log(
|
||||
checkMatchesObjectStructure(
|
||||
{ a: 1, c: /* @__PURE__ */ new Set() },
|
||||
{ a: 2, c: /* @__PURE__ */ new Set(["bla"]) }
|
||||
)
|
||||
);
|
||||
})();
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
|
||||
import { DATA_VERSION, ValidObject } from "../Utility/typeSafety";
|
||||
import StorageModel, { filePaths } from "../Global/storageModel";
|
||||
import { parseValidObject, stringify } from "../Utility/utility";
|
||||
import {
|
||||
createTimestamp,
|
||||
parseValidObject,
|
||||
stringify,
|
||||
} from "../Utility/utility";
|
||||
|
||||
import ChatModel from "../Chat/chatModel";
|
||||
import TaskModel from "./taskModel";
|
||||
@@ -36,22 +40,26 @@ export default class FileModel {
|
||||
const file: File | null = parseValidObject(stringifiedFile, FileReference);
|
||||
if (file == null) return;
|
||||
|
||||
this.storeFile(file);
|
||||
this.handleFileAndClearContents(file);
|
||||
};
|
||||
|
||||
// methods
|
||||
addFile = (file: File): void => {
|
||||
this.chatModel.sendMessage("", file);
|
||||
};
|
||||
|
||||
// storage
|
||||
storeFile = (file: File): void => {
|
||||
handleFileAndClearContents = (file: File): void => {
|
||||
for (const fileContent of file.contentVersions) {
|
||||
this.storeFileContent(file, fileContent);
|
||||
this.taskModel.handleTaskFileContent(file, fileContent);
|
||||
|
||||
file.contentVersions.delete(fileContent);
|
||||
}
|
||||
};
|
||||
|
||||
storeFileContent = (file: File, fileContent: FileContent): void => {
|
||||
// methods
|
||||
addOrUpdateFile = (file: File): void => {
|
||||
this.chatModel.sendMessage("", file);
|
||||
this.handleFileAndClearContents(file);
|
||||
};
|
||||
|
||||
// storage
|
||||
storeFileContent = (file: File, fileContent: FileContent<string>): void => {
|
||||
const fileContentName: string = FileModel.getFileContentName(fileContent);
|
||||
const fileContentPath: string[] = this.getFileContentPath(
|
||||
file,
|
||||
@@ -92,9 +100,9 @@ export default class FileModel {
|
||||
getFileContent = (
|
||||
file: File,
|
||||
fileContentName: string
|
||||
): FileContent | null => {
|
||||
): FileContent<string> | null => {
|
||||
const filePath = this.getFileContentPath(file, fileContentName);
|
||||
const fileContentOrNull: FileContent | null =
|
||||
const fileContentOrNull: FileContent<string> | null =
|
||||
this.storageModel.readStringifiable(filePath, FileContentReference);
|
||||
return fileContentOrNull;
|
||||
};
|
||||
@@ -108,7 +116,7 @@ export default class FileModel {
|
||||
}
|
||||
|
||||
// utility
|
||||
static getFileContentName = (fileContent: FileContent): string => {
|
||||
static getFileContentName = (fileContent: FileContent<string>): string => {
|
||||
return fileContent.creationDate + fileContent.id;
|
||||
};
|
||||
|
||||
@@ -117,7 +125,17 @@ export default class FileModel {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
id: v4(),
|
||||
contentVersions: [],
|
||||
contentVersions: new Set(),
|
||||
};
|
||||
};
|
||||
|
||||
static createFileContent = <T extends string>(type: T): FileContent<T> => {
|
||||
return {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
id: v4(),
|
||||
creationDate: createTimestamp(),
|
||||
type,
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -125,18 +143,18 @@ export default class FileModel {
|
||||
// types
|
||||
export interface File extends ValidObject {
|
||||
id: string;
|
||||
contentVersions: FileContent[];
|
||||
contentVersions: Set<FileContent<string>>;
|
||||
}
|
||||
|
||||
export interface FileContent extends ValidObject {
|
||||
export interface FileContent<T extends string> extends ValidObject {
|
||||
id: string;
|
||||
creationDate: string;
|
||||
|
||||
type: string;
|
||||
type: T;
|
||||
}
|
||||
|
||||
// references
|
||||
export const FileContentReference: FileContent = {
|
||||
export const FileContentReference: FileContent<string> = {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
id: "",
|
||||
@@ -148,5 +166,5 @@ export const FileReference: File = {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
id: "",
|
||||
contentVersions: [FileContentReference],
|
||||
contentVersions: new Set([FileContentReference]),
|
||||
};
|
||||
|
||||
@@ -1,26 +1,73 @@
|
||||
// thile file is responsible for managing task files within chats.
|
||||
|
||||
import FileModel, { FileContent } from "./fileModel";
|
||||
import {
|
||||
DATA_VERSION,
|
||||
checkMatchesObjectStructure,
|
||||
} from "../Utility/typeSafety";
|
||||
import FileModel, { File, FileContent } from "./fileModel";
|
||||
|
||||
import ChatModel from "../Chat/chatModel";
|
||||
import { DATA_VERSION } from "../Utility/typeSafety";
|
||||
|
||||
export default class TaskModel {
|
||||
chatModel: ChatModel;
|
||||
fileModel: FileModel;
|
||||
|
||||
// handler
|
||||
handleTaskFileContent = (
|
||||
file: File,
|
||||
fileContent: FileContent<string>
|
||||
): void => {
|
||||
if (
|
||||
checkMatchesObjectStructure(fileContent, TaskFileContentReference) ==
|
||||
false
|
||||
)
|
||||
return;
|
||||
|
||||
// TODO handle
|
||||
};
|
||||
|
||||
// methods
|
||||
createTask = (board: string, name: string): void => {
|
||||
const file: File = FileModel.createFile();
|
||||
const taskFileContent: TaskFileContent = TaskModel.createTaskFileContent(
|
||||
board,
|
||||
name
|
||||
);
|
||||
this.saveTask(file, taskFileContent);
|
||||
};
|
||||
|
||||
saveTask = (file: File, newTaskFileContent: TaskFileContent): void => {
|
||||
file.contentVersions.add(newTaskFileContent);
|
||||
this.fileModel.addOrUpdateFile(file);
|
||||
};
|
||||
|
||||
// init
|
||||
constructor(chatModel: ChatModel, fileModel: FileModel) {
|
||||
this.chatModel = chatModel;
|
||||
this.fileModel = fileModel;
|
||||
}
|
||||
|
||||
// utility
|
||||
static createTaskFileContent = (
|
||||
name: string,
|
||||
board: string
|
||||
): TaskFileContent => {
|
||||
const fileContent: FileContent<"task"> =
|
||||
FileModel.createFileContent("task");
|
||||
return {
|
||||
...fileContent,
|
||||
|
||||
name,
|
||||
board,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// types
|
||||
export interface TaskFileContent extends FileContent {
|
||||
type: "task";
|
||||
|
||||
export interface TaskFileContent extends FileContent<"task"> {
|
||||
name: string;
|
||||
board: string;
|
||||
|
||||
category?: string;
|
||||
status?: string;
|
||||
|
||||
@@ -37,6 +84,7 @@ export const TaskFileContentReference: TaskFileContent = {
|
||||
id: "",
|
||||
creationDate: "",
|
||||
type: "task",
|
||||
|
||||
|
||||
name: "",
|
||||
board: "",
|
||||
};
|
||||
|
||||
+1
-1
@@ -63,4 +63,4 @@ document
|
||||
ChatPageWrapper(chatListViewModel),
|
||||
ConnectionModal(connectionViewModel),
|
||||
StorageModal(storageViewModel)
|
||||
);
|
||||
);
|
||||
Reference in New Issue
Block a user