format
This commit is contained in:
@@ -2,10 +2,10 @@
|
||||
|
||||
import FileModel, { FileModelSubPath } from "./fileModel";
|
||||
import { TaskFileContent } from "./boardsAndTasksModel";
|
||||
import { isoToMonthString, padZero } from "../Utility/utility";
|
||||
import StorageModel from "../Global/storageModel";
|
||||
import SettingsModel from "../Global/settingsModel";
|
||||
import CoreViewModel from "../../ViewModel/Global/coreViewModel";
|
||||
import {isoToMonthString, padZero} from "../Utility/utility";
|
||||
|
||||
export default class CalendarModel {
|
||||
readonly storageModel: StorageModel;
|
||||
@@ -35,9 +35,7 @@ export default class CalendarModel {
|
||||
readonly storeTaskReference = (taskFileContent: TaskFileContent): void => {
|
||||
if (taskFileContent.date == undefined) return;
|
||||
|
||||
const monthString: string = isoToMonthString(
|
||||
taskFileContent.date,
|
||||
);
|
||||
const monthString: string = isoToMonthString(taskFileContent.date);
|
||||
|
||||
const monthPath: string[] = this.getMonthPath(monthString);
|
||||
const referencePath: string[] = [...monthPath, taskFileContent.fileId];
|
||||
@@ -103,9 +101,7 @@ export default class CalendarModel {
|
||||
};
|
||||
|
||||
for (let i = 0; i < daysInMonth; i++) {
|
||||
const paddedDate: string = padZero(
|
||||
(i + 1).toString(), 2
|
||||
);
|
||||
const paddedDate: string = padZero((i + 1).toString(), 2);
|
||||
grid.days[paddedDate] = defaultValueCreator();
|
||||
}
|
||||
|
||||
|
||||
+108
-96
@@ -8,13 +8,21 @@ import {
|
||||
parseValidObject,
|
||||
stringify,
|
||||
} from "../Utility/utility";
|
||||
import { checkIsValidObject, checkMatchesObjectStructure, DATA_VERSION, ValidObject } from "../Utility/typeSafety";
|
||||
import {
|
||||
checkIsValidObject,
|
||||
checkMatchesObjectStructure,
|
||||
DATA_VERSION,
|
||||
ValidObject,
|
||||
} from "../Utility/typeSafety";
|
||||
import StorageModel, {
|
||||
StorageModelSubPaths,
|
||||
filePaths,
|
||||
} from "../Global/storageModel";
|
||||
import SettingsModel from "../Global/settingsModel";
|
||||
import ChatModel, {ChatInfoFileContent, ChatInfoReference} from "../Chat/chatModel";
|
||||
import ChatModel, {
|
||||
ChatInfoFileContent,
|
||||
ChatInfoReference,
|
||||
} from "../Chat/chatModel";
|
||||
|
||||
export default class FileModel {
|
||||
readonly storageModel: StorageModel;
|
||||
@@ -67,161 +75,165 @@ export default class FileModel {
|
||||
};
|
||||
|
||||
readonly handleFileContent = (fileContent: FileContent<string>): void => {
|
||||
console.log(fileContent.type);
|
||||
console.log(fileContent.type);
|
||||
|
||||
if (fileContent.type == "chat-info") {
|
||||
if (checkMatchesObjectStructure(fileContent, ChatInfoReference) == false) return;
|
||||
this.chatModel.handleInfo(fileContent as ChatInfoFileContent);
|
||||
}
|
||||
if (fileContent.type == "chat-info") {
|
||||
if (
|
||||
checkMatchesObjectStructure(fileContent, ChatInfoReference) ==
|
||||
false
|
||||
)
|
||||
return;
|
||||
this.chatModel.handleInfo(fileContent as ChatInfoFileContent);
|
||||
}
|
||||
|
||||
const didStore: boolean = this.storeFileContent(fileContent);
|
||||
if (didStore == false) return;
|
||||
const didStore: boolean = this.storeFileContent(fileContent);
|
||||
if (didStore == false) return;
|
||||
|
||||
switch (fileContent.type) {
|
||||
case "board-info":
|
||||
case "task":
|
||||
this.boardsAndTasksModel.handleFileContent(fileContent);
|
||||
break;
|
||||
case "reaction":
|
||||
this.chatModel.handleReaction(fileContent);
|
||||
break;
|
||||
}
|
||||
switch (fileContent.type) {
|
||||
case "board-info":
|
||||
case "task":
|
||||
this.boardsAndTasksModel.handleFileContent(fileContent);
|
||||
break;
|
||||
case "reaction":
|
||||
this.chatModel.handleReaction(fileContent);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// methods
|
||||
readonly addFileContentAndSend = (
|
||||
fileContent: FileContent<string>,
|
||||
fileContent: FileContent<string>,
|
||||
): void => {
|
||||
this.handleFileContent(fileContent);
|
||||
this.chatModel.sendMessage("", undefined, fileContent);
|
||||
this.handleFileContent(fileContent);
|
||||
this.chatModel.sendMessage("", undefined, fileContent);
|
||||
};
|
||||
|
||||
// storage
|
||||
readonly storeFileContent = (fileContent: FileContent<string>): boolean => {
|
||||
const fileContentPath: string[] = this.getFileContentPath(
|
||||
fileContent.fileId,
|
||||
fileContent.fileContentId,
|
||||
);
|
||||
const fileContentPath: string[] = this.getFileContentPath(
|
||||
fileContent.fileId,
|
||||
fileContent.fileContentId,
|
||||
);
|
||||
|
||||
// check if fileContent already exists
|
||||
const existingFileContent: string | null =
|
||||
this.storageModel.read(fileContentPath);
|
||||
if (existingFileContent != 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(fileContent);
|
||||
this.storageModel.write(fileContentPath, stringifiedContent);
|
||||
return true;
|
||||
const stringifiedContent: string = stringify(fileContent);
|
||||
this.storageModel.write(fileContentPath, stringifiedContent);
|
||||
return true;
|
||||
};
|
||||
|
||||
readonly listFileIds = (): string[] => {
|
||||
return this.storageModel.list(this.basePath);
|
||||
return this.storageModel.list(this.basePath);
|
||||
};
|
||||
|
||||
readonly listFileContentIds = (fileId: string): string[] => {
|
||||
const filePath: string[] = this.getFilePath(fileId);
|
||||
return this.storageModel.list(filePath);
|
||||
const filePath: string[] = this.getFilePath(fileId);
|
||||
return this.storageModel.list(filePath);
|
||||
};
|
||||
|
||||
readonly selectLatestFileContentId = (
|
||||
fileContentIds: string[],
|
||||
fileContentIds: string[],
|
||||
): string | undefined => {
|
||||
return fileContentIds[fileContentIds.length - 1];
|
||||
return fileContentIds[fileContentIds.length - 1];
|
||||
};
|
||||
|
||||
readonly getFileContent = <T extends FileContent<string>>(
|
||||
fileId: string,
|
||||
fileContentName: string,
|
||||
reference: T,
|
||||
fileId: string,
|
||||
fileContentName: string,
|
||||
reference: T,
|
||||
): T | null => {
|
||||
const filePath: string[] = this.getFileContentPath(
|
||||
fileId,
|
||||
fileContentName,
|
||||
);
|
||||
const fileContentOrNull: T | null = this.storageModel.readStringifiable(
|
||||
filePath,
|
||||
reference,
|
||||
);
|
||||
return fileContentOrNull;
|
||||
const filePath: string[] = this.getFileContentPath(
|
||||
fileId,
|
||||
fileContentName,
|
||||
);
|
||||
const fileContentOrNull: T | null = this.storageModel.readStringifiable(
|
||||
filePath,
|
||||
reference,
|
||||
);
|
||||
return fileContentOrNull;
|
||||
};
|
||||
|
||||
readonly getLatestFileContent = <T extends FileContent<string>>(
|
||||
fileId: string,
|
||||
reference: T,
|
||||
fileId: string,
|
||||
reference: T,
|
||||
): T | null => {
|
||||
const fileContentsIds: string[] = this.listFileContentIds(fileId);
|
||||
const latestFileContentId: string | undefined =
|
||||
this.selectLatestFileContentId(fileContentsIds);
|
||||
if (latestFileContentId == undefined) return null;
|
||||
const fileContentsIds: string[] = this.listFileContentIds(fileId);
|
||||
const latestFileContentId: string | undefined =
|
||||
this.selectLatestFileContentId(fileContentsIds);
|
||||
if (latestFileContentId == undefined) return null;
|
||||
|
||||
const fileContent: T | null = this.getFileContent(
|
||||
fileId,
|
||||
latestFileContentId,
|
||||
reference,
|
||||
);
|
||||
return fileContent;
|
||||
const fileContent: T | null = this.getFileContent(
|
||||
fileId,
|
||||
latestFileContentId,
|
||||
reference,
|
||||
);
|
||||
return fileContent;
|
||||
};
|
||||
|
||||
// init
|
||||
constructor(
|
||||
storageModel: StorageModel,
|
||||
settingsModel: SettingsModel,
|
||||
chatModel: ChatModel,
|
||||
storageModel: StorageModel,
|
||||
settingsModel: SettingsModel,
|
||||
chatModel: ChatModel,
|
||||
) {
|
||||
this.chatModel = chatModel;
|
||||
this.settingsModel = settingsModel;
|
||||
this.storageModel = storageModel;
|
||||
this.chatModel = chatModel;
|
||||
this.settingsModel = settingsModel;
|
||||
this.storageModel = storageModel;
|
||||
|
||||
this.boardsAndTasksModel = new BoardsAndTasksModel(
|
||||
this.storageModel,
|
||||
this.settingsModel,
|
||||
chatModel,
|
||||
this,
|
||||
);
|
||||
this.boardsAndTasksModel = new BoardsAndTasksModel(
|
||||
this.storageModel,
|
||||
this.settingsModel,
|
||||
chatModel,
|
||||
this,
|
||||
);
|
||||
}
|
||||
|
||||
// utility
|
||||
static generateFileContentId = (creationDate: string): string => {
|
||||
return creationDate + v4();
|
||||
return creationDate + v4();
|
||||
};
|
||||
|
||||
static createFileContent = <T extends string>(
|
||||
fileId: string,
|
||||
type: T,
|
||||
fileId: string,
|
||||
type: T,
|
||||
): FileContent<T> => {
|
||||
const creationDate: string = createTimestamp();
|
||||
const fileContentId: string =
|
||||
FileModel.generateFileContentId(creationDate);
|
||||
const creationDate: string = createTimestamp();
|
||||
const fileContentId: string =
|
||||
FileModel.generateFileContentId(creationDate);
|
||||
|
||||
return {
|
||||
dataVersion: DATA_VERSION,
|
||||
return {
|
||||
dataVersion: DATA_VERSION,
|
||||
|
||||
fileId,
|
||||
fileContentId,
|
||||
creationDate,
|
||||
type,
|
||||
};
|
||||
fileId,
|
||||
fileContentId,
|
||||
creationDate,
|
||||
type,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// paths
|
||||
export enum FileModelSubPath {
|
||||
Data = "data",
|
||||
Model = "model",
|
||||
Chat = "chat",
|
||||
ModelView = "view",
|
||||
ModelTask = "tasks",
|
||||
ModelCalendar = "calendar",
|
||||
Model = "model",
|
||||
Chat = "chat",
|
||||
ModelView = "view",
|
||||
ModelTask = "tasks",
|
||||
ModelCalendar = "calendar",
|
||||
}
|
||||
|
||||
// types
|
||||
export interface FileContent<T extends string>
|
||||
extends ValidObject, StringEntryObject {
|
||||
readonly fileId: string;
|
||||
readonly fileContentId: string;
|
||||
readonly creationDate: string;
|
||||
readonly fileId: string;
|
||||
readonly fileContentId: string;
|
||||
readonly creationDate: string;
|
||||
|
||||
readonly type: T;
|
||||
}
|
||||
readonly type: T;
|
||||
}
|
||||
|
||||
// references
|
||||
export const FileContentReference: FileContent<string> = {
|
||||
|
||||
Reference in New Issue
Block a user