prepare taskViewModel

This commit is contained in:
marlon-erler
2024-07-24 00:38:37 +02:00
parent 29c69dc15e
commit 5a34a54273
6 changed files with 118 additions and 46 deletions
+12 -4
View File
@@ -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<string> = new React.State("");
color: React.State<Color> = new React.State<Color>(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;
+14 -13
View File
@@ -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();
+90
View File
@@ -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<string> = new React.State("");
category: React.State<string> = new React.State("");
status: React.State<string> = new React.State("");
description: React.State<string> = new React.State("");
priority: React.State<string> = new React.State("");
date: React.State<string> = new React.State("");
time: React.State<string> = 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();
}
}