diff --git a/src/Model/Files/boadModel.ts b/src/Model/Files/boardModel.ts similarity index 99% rename from src/Model/Files/boadModel.ts rename to src/Model/Files/boardModel.ts index 9613128e..acb626ba 100644 --- a/src/Model/Files/boadModel.ts +++ b/src/Model/Files/boardModel.ts @@ -243,7 +243,7 @@ export interface TaskFileContent extends FileContent<"task"> { description?: string; - priority?: number; + priority?: string; date?: string; time?: string; } diff --git a/src/Model/Files/fileModel.ts b/src/Model/Files/fileModel.ts index 981f7001..213dd16c 100644 --- a/src/Model/Files/fileModel.ts +++ b/src/Model/Files/fileModel.ts @@ -9,7 +9,7 @@ import { } from "../Utility/utility"; import StorageModel, { filePaths } from "../Global/storageModel"; -import BoardModel from "./boadModel"; +import BoardModel from "./boardModel"; import ChatModel from "../Chat/chatModel"; import { v4 } from "uuid"; diff --git a/src/ViewModel/Pages/boardViewModel.ts b/src/ViewModel/Pages/boardViewModel.ts index b3ed37a9..d97f4149 100644 --- a/src/ViewModel/Pages/boardViewModel.ts +++ b/src/ViewModel/Pages/boardViewModel.ts @@ -1,6 +1,9 @@ import * as React from "bloatless-react"; -import BoardModel, { BoardInfoFileContent } from "../../Model/Files/boadModel"; +import BoardModel, { + BoardInfoFileContent, + BoardInfoFileContentReference, +} from "../../Model/Files/boardModel"; import { Color } from "../../colors"; import StorageModel from "../../Model/Global/storageModel"; @@ -8,11 +11,14 @@ import TaskPageViewModel from "./taskPageViewModel"; export default class BoardViewModel { storageModel: StorageModel; + boardModel: BoardModel; + taskPageViewModel: TaskPageViewModel; - // state + // data boardInfo: BoardInfoFileContent; + // state name: React.State = new React.State(""); color: React.State = new React.State(Color.Standard); @@ -123,11 +129,13 @@ export default class BoardViewModel { // init constructor( + storageModel: StorageModel, + boardModel: BoardModel, taskPageViewModel: TaskPageViewModel, - boardInfo: BoardInfoFileContent, - storageModel: StorageModel + boardInfo: BoardInfoFileContent ) { this.storageModel = storageModel; + this.boardModel = boardModel; this.taskPageViewModel = taskPageViewModel; this.boardInfo = boardInfo; diff --git a/src/ViewModel/Pages/taskPageViewModel.ts b/src/ViewModel/Pages/taskPageViewModel.ts index cf3eeedd..a14be5cc 100644 --- a/src/ViewModel/Pages/taskPageViewModel.ts +++ b/src/ViewModel/Pages/taskPageViewModel.ts @@ -3,7 +3,7 @@ import * as React from "bloatless-react"; import BoardModel, { BoardInfoFileContent, BoardInfoFileContentReference, -} from "../../Model/Files/boadModel"; +} from "../../Model/Files/boardModel"; import BoardViewModel from "./boardViewModel"; import ChatViewModel from "../Chat/chatViewModel"; @@ -14,7 +14,7 @@ import { checkMatchesObjectStructure } from "../../Model/Utility/typeSafety"; export default class TaskPageViewModel { storageModel: StorageModel; - taskModel: BoardModel; + boardModel: BoardModel; chatViewModel: ChatViewModel; @@ -25,7 +25,7 @@ export default class TaskPageViewModel { // paths getBasePath = (): string[] => { - return [...this.taskModel.getViewPath()]; + return [...this.boardModel.getViewPath()]; }; getBoardViewPath = (boardId): string[] => { @@ -66,7 +66,7 @@ export default class TaskPageViewModel { if (this.cannotCreateBoard.value == true) return; const boardInfoFileContent: BoardInfoFileContent = - this.taskModel.createBoard(this.newBoardNameInput.value); + this.boardModel.createBoard(this.newBoardNameInput.value); this.newBoardNameInput.value = ""; this.showBoardInList(boardInfoFileContent); @@ -74,12 +74,12 @@ export default class TaskPageViewModel { }; updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => { - this.taskModel.updateBoard(boardInfoFileContent); + this.boardModel.updateBoard(boardInfoFileContent); this.updateIndices(); }; deleteBoard = (boardInfoFileContent: BoardInfoFileContent): void => { - this.taskModel.deleteBoard(boardInfoFileContent.fileId); + this.boardModel.deleteBoard(boardInfoFileContent.fileId); this.boardViewModels.remove(boardInfoFileContent.fileId); this.updateIndices(); }; @@ -87,9 +87,10 @@ export default class TaskPageViewModel { // view showBoardInList = (boardInfo: BoardInfoFileContent): void => { const boardViewModel: BoardViewModel = new BoardViewModel( + this.storageModel, + this.boardModel, this, - boardInfo, - this.storageModel + boardInfo ); this.boardViewModels.set(boardInfo.fileId, boardViewModel); }; @@ -138,10 +139,10 @@ export default class TaskPageViewModel { loadData = (): void => { this.boardViewModels.clear(); - const boardIds: string[] = this.taskModel.listBoardIds(); + const boardIds: string[] = this.boardModel.listBoardIds(); for (const boardId of boardIds) { const boardInfo: BoardInfoFileContent | null = - this.taskModel.getBoardInfo(boardId); + this.boardModel.getBoardInfo(boardId); if (boardInfo == null) continue; this.showBoardInList(boardInfo); @@ -153,17 +154,17 @@ export default class TaskPageViewModel { // init constructor( - taskModel: BoardModel, + boardModel: BoardModel, storageModel: StorageModel, chatViewModel: ChatViewModel ) { - this.taskModel = taskModel; + this.boardModel = boardModel; this.storageModel = storageModel; this.chatViewModel = chatViewModel; // handlers - taskModel.boardHandlerManager.addHandler( + boardModel.boardHandlerManager.addHandler( (boardInfoFileContent: BoardInfoFileContent) => { this.showBoardInList(boardInfoFileContent); this.updateIndices(); diff --git a/src/ViewModel/Pages/taskViewModel.ts b/src/ViewModel/Pages/taskViewModel.ts new file mode 100644 index 00000000..5734c3f7 --- /dev/null +++ b/src/ViewModel/Pages/taskViewModel.ts @@ -0,0 +1,90 @@ +import * as React from "bloatless-react"; + +import BoardModel, { + TaskFileContent, + TaskFileContentReference, +} from "../../Model/Files/boardModel"; + +import BoardViewModel from "./boardViewModel"; +import StorageModel from "../../Model/Global/storageModel"; + +export default class TaskViewModel { + boardModel: BoardModel; + storageModel: StorageModel; + + boardViewModel: BoardViewModel; + + // data + fileId: string; + + // paths + getFilePath = (): string[] => { + return this.boardModel.getTaskFilePath(this.fileId); + }; + + // state + name: React.State = new React.State(""); + + category: React.State = new React.State(""); + status: React.State = new React.State(""); + + description: React.State = new React.State(""); + + priority: React.State = new React.State(""); + date: React.State = new React.State(""); + time: React.State = new React.State(""); + + // storage + save = (): void => { + const newTaskFileContent: TaskFileContent = + BoardModel.createTaskFileContent( + this.fileId, + this.name.value, + this.boardViewModel.boardInfo.fileId + ); + + newTaskFileContent.status = this.status.value; + newTaskFileContent.category = this.category.value; + newTaskFileContent.description = this.description.value; + newTaskFileContent.priority = this.priority.value; + newTaskFileContent.date = this.date.value; + newTaskFileContent.time = this.time.value; + + this.boardModel.updateTask(newTaskFileContent); + }; + + // load + loadAllData = (): void => { + const path: string[] = this.getFilePath(); + const taskFileContent: TaskFileContent | null = + this.storageModel.readStringifiable(path, TaskFileContentReference); + if (taskFileContent == null) return; + + this.name.value = taskFileContent.name; + + this.category.value = taskFileContent.category ?? ""; + this.status.value = taskFileContent.status ?? ""; + + this.description.value = taskFileContent.description ?? ""; + + this.priority.value = taskFileContent.priority ?? ""; + this.date.value = taskFileContent.date ?? ""; + this.time.value = taskFileContent.time ?? ""; + }; + + // init + constructor( + boardModel: BoardModel, + storageModel: StorageModel, + boardViewModel: BoardViewModel, + fileId: string + ) { + this.boardModel = boardModel; + this.storageModel = storageModel; + this.boardViewModel = boardViewModel; + + this.fileId = fileId; + + this.loadAllData(); + } +} diff --git a/src/taskViewModel.ts b/src/taskViewModel.ts deleted file mode 100644 index 3781887a..00000000 --- a/src/taskViewModel.ts +++ /dev/null @@ -1,27 +0,0 @@ -import * as React from "bloatless-react"; - -import BoardViewModel from "./ViewModel/Pages/boardViewModel"; - -export default class TaskViewModel { - boardViewModel: BoardViewModel; - - // state - name: React.State = new React.State(""); - - category: React.State = new React.State(""); - status: React.State = new React.State(""); - - description: React.State = new React.State(""); - - priority: React.State = new React.State(""); - date: React.State = new React.State(""); - time: React.State = new React.State(""); - - // storage - save = (): void => {} - - // init - constructor(boardViewModel: BoardViewModel) { - this.boardViewModel = boardViewModel; - } -} \ No newline at end of file