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