2024-07-22 19:54:39 +02:00
|
|
|
import * as React from "bloatless-react";
|
|
|
|
|
|
2024-07-23 00:25:28 +02:00
|
|
|
import TaskModel, {
|
|
|
|
|
BoardInfoFileContent,
|
|
|
|
|
BoardInfoFileContentReference,
|
|
|
|
|
} from "../../Model/Files/taskModel";
|
2024-07-22 20:02:13 +02:00
|
|
|
|
2024-07-23 00:57:40 +02:00
|
|
|
import BoardViewModel from "./boardViewModel";
|
2024-07-23 02:50:22 +02:00
|
|
|
import ChatViewModel from "../Chat/chatViewModel";
|
2024-07-23 00:25:28 +02:00
|
|
|
import { FileContent } from "../../Model/Files/fileModel";
|
2024-07-22 20:02:13 +02:00
|
|
|
import StorageModel from "../../Model/Global/storageModel";
|
2024-07-23 00:25:28 +02:00
|
|
|
import { checkMatchesObjectStructure } from "../../Model/Utility/typeSafety";
|
2024-07-22 20:02:13 +02:00
|
|
|
|
2024-07-22 21:07:44 +02:00
|
|
|
export default class TaskPageViewModel {
|
2024-07-23 02:50:22 +02:00
|
|
|
storageModel: StorageModel;
|
2024-07-22 20:02:13 +02:00
|
|
|
taskModel: TaskModel;
|
|
|
|
|
|
2024-07-23 02:50:22 +02:00
|
|
|
chatViewModel: ChatViewModel;
|
|
|
|
|
|
2024-07-22 20:02:13 +02:00
|
|
|
// state
|
|
|
|
|
newBoardNameInput: React.State<string> = new React.State("");
|
|
|
|
|
|
2024-07-23 01:40:30 +02:00
|
|
|
boardViewModels: React.MapState<BoardViewModel> = new React.MapState();
|
2024-07-22 20:02:13 +02:00
|
|
|
|
2024-07-23 13:51:27 +02:00
|
|
|
selectedBoardId: React.State<string | undefined> = new React.State<
|
|
|
|
|
string | undefined
|
2024-07-23 02:40:11 +02:00
|
|
|
>(undefined);
|
|
|
|
|
|
2024-07-22 20:02:13 +02:00
|
|
|
// guards
|
|
|
|
|
cannotCreateBoard: React.State<boolean> = React.createProxyState(
|
|
|
|
|
[this.newBoardNameInput],
|
|
|
|
|
() => this.newBoardNameInput.value == ""
|
|
|
|
|
);
|
|
|
|
|
|
2024-07-23 00:25:28 +02:00
|
|
|
// handlers
|
|
|
|
|
handleFileContent = (fileContent: FileContent<string>): void => {
|
|
|
|
|
if (
|
|
|
|
|
checkMatchesObjectStructure(fileContent, BoardInfoFileContentReference) ==
|
|
|
|
|
false
|
|
|
|
|
)
|
|
|
|
|
return;
|
2024-07-23 02:40:11 +02:00
|
|
|
this.showBoardInList(fileContent as BoardInfoFileContent);
|
2024-07-23 00:25:28 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-22 20:02:13 +02:00
|
|
|
// methods
|
|
|
|
|
createBoard = (): void => {
|
|
|
|
|
if (this.cannotCreateBoard.value == true) return;
|
|
|
|
|
|
2024-07-23 00:32:29 +02:00
|
|
|
const boardInfoFileContent: BoardInfoFileContent =
|
|
|
|
|
this.taskModel.createBoard(this.newBoardNameInput.value);
|
2024-07-22 20:02:13 +02:00
|
|
|
this.newBoardNameInput.value = "";
|
2024-07-23 00:05:48 +02:00
|
|
|
|
2024-07-23 02:40:11 +02:00
|
|
|
this.showBoardInList(boardInfoFileContent);
|
2024-07-23 00:05:48 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-23 13:19:08 +02:00
|
|
|
updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
|
|
|
|
|
this.taskModel.updateBoard(boardInfoFileContent);
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 00:25:28 +02:00
|
|
|
// view
|
2024-07-23 02:40:11 +02:00
|
|
|
showBoardInList = (boardInfo: BoardInfoFileContent): void => {
|
2024-07-23 00:57:40 +02:00
|
|
|
const boardViewModel: BoardViewModel = new BoardViewModel(this, boardInfo);
|
2024-07-23 01:40:30 +02:00
|
|
|
this.boardViewModels.set(boardInfo.fileId, boardViewModel);
|
2024-07-23 00:25:28 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-23 02:40:11 +02:00
|
|
|
selectBoard = (boardViewModel: BoardViewModel): void => {
|
2024-07-23 13:51:27 +02:00
|
|
|
this.selectedBoardId.value = boardViewModel.boardInfo.fileId;
|
2024-07-23 02:50:22 +02:00
|
|
|
this.chatViewModel.displayedColor.value = boardViewModel.color.value;
|
2024-07-23 02:40:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
closeBoard = (): void => {
|
2024-07-23 13:51:27 +02:00
|
|
|
this.selectedBoardId.value = undefined;
|
2024-07-23 02:50:22 +02:00
|
|
|
this.chatViewModel.resetColor();
|
2024-07-23 02:40:11 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-23 00:05:48 +02:00
|
|
|
// load
|
|
|
|
|
loadData = (): void => {
|
2024-07-23 00:57:40 +02:00
|
|
|
this.boardViewModels.clear();
|
2024-07-23 00:05:48 +02:00
|
|
|
|
|
|
|
|
const boardIds: string[] = this.taskModel.listBoardIds();
|
|
|
|
|
for (const boardId of boardIds) {
|
|
|
|
|
const boardInfo: BoardInfoFileContent | null =
|
|
|
|
|
this.taskModel.getBoardInfo(boardId);
|
2024-07-23 00:25:28 +02:00
|
|
|
if (boardInfo == null) continue;
|
|
|
|
|
|
2024-07-23 02:40:11 +02:00
|
|
|
this.showBoardInList(boardInfo);
|
2024-07-23 00:05:48 +02:00
|
|
|
}
|
2024-07-22 20:02:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// init
|
2024-07-23 02:50:22 +02:00
|
|
|
constructor(
|
|
|
|
|
taskModel: TaskModel,
|
|
|
|
|
storageModel: StorageModel,
|
|
|
|
|
chatViewModel: ChatViewModel
|
|
|
|
|
) {
|
2024-07-22 20:02:13 +02:00
|
|
|
this.taskModel = taskModel;
|
2024-07-23 02:50:22 +02:00
|
|
|
this.storageModel = storageModel;
|
|
|
|
|
|
|
|
|
|
this.chatViewModel = chatViewModel;
|
2024-07-23 01:40:30 +02:00
|
|
|
|
|
|
|
|
// handlers
|
2024-07-23 01:58:34 +02:00
|
|
|
taskModel.boardHandlerManager.addHandler(
|
|
|
|
|
(boardInfoFileContent: BoardInfoFileContent) => {
|
2024-07-23 02:40:11 +02:00
|
|
|
this.showBoardInList(boardInfoFileContent);
|
2024-07-23 01:58:34 +02:00
|
|
|
}
|
|
|
|
|
);
|
2024-07-22 20:02:13 +02:00
|
|
|
}
|
|
|
|
|
}
|