add month grid
This commit is contained in:
@@ -9,7 +9,10 @@ import {
|
||||
parseValidObject,
|
||||
stringify,
|
||||
} from "../Utility/utility";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "../Global/storageModel";
|
||||
import StorageModel, {
|
||||
StorageModelSubPath,
|
||||
filePaths,
|
||||
} from "../Global/storageModel";
|
||||
import { decryptString, encryptString } from "../Utility/crypto";
|
||||
|
||||
import ChatListModel from "./chatListModel";
|
||||
@@ -39,19 +42,31 @@ export default class ChatModel {
|
||||
|
||||
// paths
|
||||
getBasePath = (): string[] => {
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.chatBase(this.id));
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPath.Chat,
|
||||
filePaths.chat.chatBase(this.id)
|
||||
);
|
||||
};
|
||||
|
||||
getInfoPath = (): string[] => {
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.info(this.id));
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPath.Chat,
|
||||
filePaths.chat.info(this.id)
|
||||
);
|
||||
};
|
||||
|
||||
getColorPath = (): string[] => {
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.color(this.id));
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPath.Chat,
|
||||
filePaths.chat.color(this.id)
|
||||
);
|
||||
};
|
||||
|
||||
getMessageDirPath = (): string[] => {
|
||||
return StorageModel.getPath(StorageModelSubPath.Chat, filePaths.chat.messages(this.id));
|
||||
return StorageModel.getPath(
|
||||
StorageModelSubPath.Chat,
|
||||
filePaths.chat.messages(this.id)
|
||||
);
|
||||
};
|
||||
|
||||
getMessagePath = (id: string): string[] => {
|
||||
@@ -236,7 +251,7 @@ export default class ChatModel {
|
||||
this.loadColor();
|
||||
this.subscribe();
|
||||
|
||||
this.fileModel = new FileModel(this, this.storageModel);
|
||||
this.fileModel = new FileModel(this.storageModel, this.settingsModel, this);
|
||||
}
|
||||
|
||||
// utility
|
||||
|
||||
@@ -6,17 +6,22 @@ import {
|
||||
} from "../Utility/typeSafety";
|
||||
import FileModel, { FileContent, FileModelSubPath } from "./fileModel";
|
||||
|
||||
import CalendarModel from "./calendarModel";
|
||||
import ChatModel from "../Chat/chatModel";
|
||||
import { Color } from "../../colors";
|
||||
import { HandlerManager } from "../Utility/utility";
|
||||
import SettingsModel from "../Global/settingsModel";
|
||||
import StorageModel from "../Global/storageModel";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export default class BoardsAndTasksModel {
|
||||
storageModel: StorageModel;
|
||||
settingsModel: SettingsModel;
|
||||
chatModel: ChatModel;
|
||||
fileModel: FileModel;
|
||||
|
||||
calendarModel: CalendarModel;
|
||||
|
||||
// data
|
||||
boardHandlerManager: HandlerManager<BoardInfoFileContent> =
|
||||
new HandlerManager();
|
||||
@@ -153,8 +158,6 @@ export default class BoardsAndTasksModel {
|
||||
};
|
||||
|
||||
storeTask = (taskFileContent: TaskFileContent): void => {
|
||||
console.log(taskFileContent);
|
||||
|
||||
// store info
|
||||
this.fileModel.storeFileContent(taskFileContent);
|
||||
|
||||
@@ -164,6 +167,9 @@ export default class BoardsAndTasksModel {
|
||||
taskFileContent.fileId
|
||||
);
|
||||
this.storageModel.write(taskReferencePath, "");
|
||||
|
||||
// add to calendar
|
||||
this.calendarModel.storeTaskReference(taskFileContent);
|
||||
};
|
||||
|
||||
listTaskIds = (boardId: string): string[] => {
|
||||
@@ -214,12 +220,20 @@ export default class BoardsAndTasksModel {
|
||||
// init
|
||||
constructor(
|
||||
storageModel: StorageModel,
|
||||
settingsModel: SettingsModel,
|
||||
chatModel: ChatModel,
|
||||
fileModel: FileModel
|
||||
) {
|
||||
this.storageModel = storageModel;
|
||||
this.settingsModel = settingsModel;
|
||||
this.chatModel = chatModel;
|
||||
this.fileModel = fileModel;
|
||||
this.storageModel = storageModel;
|
||||
|
||||
this.calendarModel = new CalendarModel(
|
||||
this.storageModel,
|
||||
this.settingsModel,
|
||||
this.fileModel
|
||||
);
|
||||
}
|
||||
|
||||
// utility
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
// this file extends the BoardsAndTasksModel regarding calendar features.
|
||||
// it is responsible for managing calendar-realted reference files for tasks.
|
||||
|
||||
import BoardsAndTasksModel, {
|
||||
TaskFileContent,
|
||||
TaskFileContentReference,
|
||||
} from "./boardsAndTasksModel";
|
||||
import FileModel, { FileContent, FileModelSubPath } from "./fileModel";
|
||||
import FileModel, { FileModelSubPath } from "./fileModel";
|
||||
|
||||
import SettingsModel from "../Global/settingsModel";
|
||||
import StorageModel from "../Global/storageModel";
|
||||
import { checkMatchesObjectStructure } from "../Utility/typeSafety";
|
||||
import { TaskFileContent } from "./boardsAndTasksModel";
|
||||
|
||||
export default class CalendarModel {
|
||||
storageModel: StorageModel;
|
||||
fileModel: FileModel;
|
||||
settingsModel: SettingsModel;
|
||||
|
||||
// paths
|
||||
getBasePath = (): string[] => {
|
||||
@@ -31,18 +28,10 @@ export default class CalendarModel {
|
||||
return [...this.getMonthContainerPath(), monthString];
|
||||
};
|
||||
|
||||
// handlers
|
||||
handleFileContent = (fileContent: FileContent<string>): void => {
|
||||
if (
|
||||
checkMatchesObjectStructure(fileContent, TaskFileContentReference) ==
|
||||
false
|
||||
)
|
||||
return;
|
||||
};
|
||||
|
||||
// main
|
||||
storeTaskReference = (taskFileContent: TaskFileContent): void => {
|
||||
if (taskFileContent.date == undefined) return;
|
||||
|
||||
const monthString: string = CalendarModel.isoToMonthString(
|
||||
taskFileContent.date
|
||||
);
|
||||
@@ -58,21 +47,73 @@ export default class CalendarModel {
|
||||
return this.storageModel.list(monthPath);
|
||||
};
|
||||
|
||||
generateMonthGrid = <T>(
|
||||
year: number,
|
||||
month: number,
|
||||
defaultValueCreator: () => T
|
||||
): MonthGrid<T> => {
|
||||
// get first day of month
|
||||
const date: Date = new Date();
|
||||
date.setFullYear(year);
|
||||
date.setMonth(month - 1);
|
||||
date.setDate(1);
|
||||
|
||||
// get offset
|
||||
const offset: number =
|
||||
date.getDay() - parseInt(this.settingsModel.firstDayOfWeek);
|
||||
|
||||
// get total day count
|
||||
date.setMonth(month);
|
||||
date.setDate(-1);
|
||||
const daysInMonth: number = date.getDate() + 1;
|
||||
|
||||
const grid: MonthGrid<T> = {
|
||||
offset,
|
||||
days: {},
|
||||
};
|
||||
|
||||
for (let i = 0; i < daysInMonth; i++) {
|
||||
grid.days[i + 1] = defaultValueCreator();
|
||||
}
|
||||
|
||||
return grid;
|
||||
};
|
||||
|
||||
// init
|
||||
constructor(
|
||||
storageModel: StorageModel,
|
||||
fileModel: FileModel, ) {
|
||||
settingsModel: SettingsModel,
|
||||
fileModel: FileModel
|
||||
) {
|
||||
this.storageModel = storageModel;
|
||||
this.settingsModel = settingsModel;
|
||||
this.fileModel = fileModel;
|
||||
}
|
||||
|
||||
// utility
|
||||
static isoToMonthString = (dateISOString: string): string => {
|
||||
const [year, month, _] = dateISOString.split("-");
|
||||
return `${year}-${month}`;
|
||||
return CalendarModel.getMonthString(year, month);
|
||||
};
|
||||
|
||||
static isoToDateString = (dateISOString: string): string | undefined => {
|
||||
const [year, month, date, _] = dateISOString.split("-");
|
||||
return date;
|
||||
};
|
||||
|
||||
static getMonthString = (year: string = "", month: string = ""): string => {
|
||||
const paddedYear: string = year.padStart(4, "0");
|
||||
const paddedMonth: string = month.padStart(2, "0");
|
||||
return `${paddedYear}-${paddedMonth}`;
|
||||
};
|
||||
}
|
||||
|
||||
export enum CalendarModelSubPaths {
|
||||
Months = "months",
|
||||
}
|
||||
|
||||
// types
|
||||
export interface MonthGrid<T> {
|
||||
offset: number;
|
||||
days: { [date: string]: T };
|
||||
}
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
// this file is responsible for managing files within chats.
|
||||
|
||||
import { DATA_VERSION, ValidObject } from "../Utility/typeSafety";
|
||||
import StorageModel, {
|
||||
StorageModelSubPath,
|
||||
filePaths,
|
||||
} from "../Global/storageModel";
|
||||
import {
|
||||
HandlerManager,
|
||||
StringEntryObject,
|
||||
createTimestamp,
|
||||
parseValidObject,
|
||||
stringify,
|
||||
} from "../Utility/utility";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "../Global/storageModel";
|
||||
|
||||
import BoardsAndTasksModel from "./boardsAndTasksModel";
|
||||
import CalendarModel from "./calendarModel";
|
||||
import ChatModel from "../Chat/chatModel";
|
||||
import SettingsModel from "../Global/settingsModel";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export default class FileModel {
|
||||
chatModel: ChatModel;
|
||||
storageModel: StorageModel;
|
||||
settingsModel: SettingsModel;
|
||||
|
||||
chatModel: ChatModel;
|
||||
boardsAndTasksModel: BoardsAndTasksModel;
|
||||
calendarModel: CalendarModel;
|
||||
|
||||
// paths
|
||||
getBasePath = (): string[] => {
|
||||
@@ -34,9 +36,7 @@ export default class FileModel {
|
||||
return [...this.getBasePath(), FileModelSubPath.Data];
|
||||
};
|
||||
|
||||
getModelContainerPath = (
|
||||
modelName: FileModelSubPath
|
||||
): string[] => {
|
||||
getModelContainerPath = (modelName: FileModelSubPath): string[] => {
|
||||
return [...this.getBasePath(), FileModelSubPath.Model, modelName];
|
||||
};
|
||||
|
||||
@@ -65,7 +65,6 @@ export default class FileModel {
|
||||
if (didStore == false) return;
|
||||
|
||||
this.boardsAndTasksModel.handleFileContent(fileContent);
|
||||
this.calendarModel.handleFileContent(fileContent);
|
||||
};
|
||||
|
||||
// methods
|
||||
@@ -135,14 +134,23 @@ export default class FileModel {
|
||||
);
|
||||
return fileContent;
|
||||
};
|
||||
|
||||
|
||||
// init
|
||||
constructor(chatModel: ChatModel, storageModel: StorageModel) {
|
||||
constructor(
|
||||
storageModel: StorageModel,
|
||||
settingsModel: SettingsModel,
|
||||
chatModel: ChatModel
|
||||
) {
|
||||
this.chatModel = chatModel;
|
||||
this.settingsModel = settingsModel;
|
||||
this.storageModel = storageModel;
|
||||
|
||||
this.boardsAndTasksModel = new BoardsAndTasksModel(this.storageModel, chatModel, this);
|
||||
this.calendarModel = new CalendarModel(this.storageModel, this);
|
||||
this.boardsAndTasksModel = new BoardsAndTasksModel(
|
||||
this.storageModel,
|
||||
this.settingsModel,
|
||||
chatModel,
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
// utility
|
||||
@@ -175,10 +183,12 @@ export enum FileModelSubPath {
|
||||
ModelView = "view",
|
||||
ModelTask = "tasks",
|
||||
ModelCalendar = "calendar",
|
||||
};
|
||||
}
|
||||
|
||||
// types
|
||||
export interface FileContent<T extends string> extends ValidObject, StringEntryObject {
|
||||
export interface FileContent<T extends string>
|
||||
extends ValidObject,
|
||||
StringEntryObject {
|
||||
fileId: string;
|
||||
fileContentId: string;
|
||||
creationDate: string;
|
||||
|
||||
Reference in New Issue
Block a user