2024-07-23 00:57:40 +02:00
|
|
|
import * as React from "bloatless-react";
|
|
|
|
|
|
2024-07-24 00:38:37 +02:00
|
|
|
import BoardModel, {
|
|
|
|
|
BoardInfoFileContent,
|
|
|
|
|
BoardInfoFileContentReference,
|
|
|
|
|
} from "../../Model/Files/boardModel";
|
2024-07-23 13:19:08 +02:00
|
|
|
|
2024-07-23 00:57:40 +02:00
|
|
|
import { Color } from "../../colors";
|
2024-07-23 21:33:22 +02:00
|
|
|
import StorageModel from "../../Model/Global/storageModel";
|
2024-07-23 00:57:40 +02:00
|
|
|
import TaskPageViewModel from "./taskPageViewModel";
|
|
|
|
|
|
|
|
|
|
export default class BoardViewModel {
|
2024-07-23 21:33:22 +02:00
|
|
|
storageModel: StorageModel;
|
2024-07-24 00:38:37 +02:00
|
|
|
boardModel: BoardModel;
|
|
|
|
|
|
2024-07-23 00:57:40 +02:00
|
|
|
taskPageViewModel: TaskPageViewModel;
|
|
|
|
|
|
2024-07-24 00:38:37 +02:00
|
|
|
// data
|
2024-07-23 00:57:40 +02:00
|
|
|
boardInfo: BoardInfoFileContent;
|
|
|
|
|
|
2024-07-24 00:38:37 +02:00
|
|
|
// state
|
2024-07-23 00:57:40 +02:00
|
|
|
name: React.State<string> = new React.State("");
|
|
|
|
|
color: React.State<Color> = new React.State<Color>(Color.Standard);
|
|
|
|
|
|
2024-07-23 02:40:11 +02:00
|
|
|
isSelected: React.State<boolean>;
|
2024-07-23 13:09:46 +02:00
|
|
|
isPresentingSettingsModal: React.State<boolean> = new React.State(false);
|
2024-07-23 15:25:16 +02:00
|
|
|
isPresentingFilterModal: React.State<boolean> = new React.State(false);
|
|
|
|
|
isPresentingNewTaskModal: React.State<boolean> = new React.State(false);
|
2024-07-23 02:40:11 +02:00
|
|
|
|
2024-07-23 15:41:03 +02:00
|
|
|
selectedPage: React.State<BoardPageType> = new React.State<BoardPageType>(
|
|
|
|
|
BoardPageType.List
|
|
|
|
|
);
|
|
|
|
|
|
2024-07-23 14:27:38 +02:00
|
|
|
index: React.State<number> = new React.State(0);
|
|
|
|
|
|
2024-07-23 21:33:22 +02:00
|
|
|
// paths
|
|
|
|
|
getBasePath = (): string[] => {
|
|
|
|
|
return [...this.taskPageViewModel.getBoardViewPath(this.boardInfo.fileId)];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getLastUsedBoardPath = (): string[] => {
|
|
|
|
|
return [...this.getBasePath(), BoardViewModelSubPaths.LastUsedView];
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 02:40:11 +02:00
|
|
|
// view
|
|
|
|
|
select = (): void => {
|
|
|
|
|
this.taskPageViewModel.selectBoard(this);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
close = (): void => {
|
|
|
|
|
this.taskPageViewModel.closeBoard();
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 13:09:46 +02:00
|
|
|
showSettings = (): void => {
|
|
|
|
|
this.isPresentingSettingsModal.value = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hideSettings = (): void => {
|
2024-07-23 13:19:08 +02:00
|
|
|
this.saveSettings();
|
2024-07-23 13:09:46 +02:00
|
|
|
this.isPresentingSettingsModal.value = false;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 15:25:16 +02:00
|
|
|
showFilterModal = (): void => {
|
|
|
|
|
this.isPresentingFilterModal.value = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hideFilterModal = (): void => {
|
|
|
|
|
this.isPresentingFilterModal.value = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
showNewTaskModal = (): void => {
|
|
|
|
|
this.isPresentingNewTaskModal.value = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
hideNewTaskModal = (): void => {
|
|
|
|
|
this.isPresentingNewTaskModal.value = false;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 14:27:38 +02:00
|
|
|
updateIndex = (): void => {
|
|
|
|
|
const index: number =
|
|
|
|
|
this.taskPageViewModel.boardIndexManager.getIndex(this);
|
|
|
|
|
this.index.value = index;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 13:19:08 +02:00
|
|
|
// methods
|
|
|
|
|
saveSettings = (): void => {
|
|
|
|
|
const newBoardInfoFileContent: BoardInfoFileContent =
|
2024-07-24 00:12:45 +02:00
|
|
|
BoardModel.createBoardInfoFileContent(
|
2024-07-23 13:19:08 +02:00
|
|
|
this.boardInfo.fileId,
|
|
|
|
|
this.name.value,
|
|
|
|
|
this.color.value
|
|
|
|
|
);
|
|
|
|
|
this.taskPageViewModel.updateBoard(newBoardInfoFileContent);
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 13:53:50 +02:00
|
|
|
applyColor = (): void => {
|
|
|
|
|
this.taskPageViewModel.chatViewModel.setDisplayedColor(this.color.value);
|
2024-07-23 13:48:17 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-23 14:31:50 +02:00
|
|
|
deleteBoard = (): void => {
|
|
|
|
|
this.taskPageViewModel.deleteBoard(this.boardInfo);
|
|
|
|
|
this.close();
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 21:33:22 +02:00
|
|
|
// store
|
|
|
|
|
storeLastUsedView = (): void => {
|
|
|
|
|
const path: string[] = this.getLastUsedBoardPath();
|
|
|
|
|
const lastUsedView: string = this.selectedPage.value;
|
|
|
|
|
this.storageModel.write(path, lastUsedView);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
restoreLastUsedView = (): void => {
|
|
|
|
|
const path: string[] = this.getLastUsedBoardPath();
|
|
|
|
|
const lastUsedView: string | null = this.storageModel.read(path);
|
|
|
|
|
if (lastUsedView == null) return;
|
|
|
|
|
|
|
|
|
|
this.selectedPage.value = lastUsedView as BoardPageType;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-23 00:57:40 +02:00
|
|
|
// load
|
|
|
|
|
loadListRelevantData = (): void => {
|
|
|
|
|
this.name.value = this.boardInfo.name;
|
|
|
|
|
this.color.value = this.boardInfo.color;
|
2024-07-23 02:40:11 +02:00
|
|
|
};
|
2024-07-23 00:57:40 +02:00
|
|
|
|
2024-07-23 21:33:22 +02:00
|
|
|
loadData = (): void => {
|
|
|
|
|
this.restoreLastUsedView();
|
|
|
|
|
};
|
2024-07-23 00:57:40 +02:00
|
|
|
|
|
|
|
|
// init
|
2024-07-23 02:40:11 +02:00
|
|
|
constructor(
|
2024-07-24 00:38:37 +02:00
|
|
|
storageModel: StorageModel,
|
|
|
|
|
boardModel: BoardModel,
|
2024-07-23 02:40:11 +02:00
|
|
|
taskPageViewModel: TaskPageViewModel,
|
2024-07-24 00:38:37 +02:00
|
|
|
boardInfo: BoardInfoFileContent
|
2024-07-23 02:40:11 +02:00
|
|
|
) {
|
2024-07-23 21:33:22 +02:00
|
|
|
this.storageModel = storageModel;
|
2024-07-24 00:38:37 +02:00
|
|
|
this.boardModel = boardModel;
|
2024-07-23 00:57:40 +02:00
|
|
|
this.taskPageViewModel = taskPageViewModel;
|
|
|
|
|
this.boardInfo = boardInfo;
|
|
|
|
|
|
|
|
|
|
this.loadListRelevantData();
|
2024-07-23 02:40:11 +02:00
|
|
|
|
|
|
|
|
this.isSelected = React.createProxyState(
|
2024-07-23 13:51:27 +02:00
|
|
|
[this.taskPageViewModel.selectedBoardId],
|
|
|
|
|
() =>
|
|
|
|
|
this.taskPageViewModel.selectedBoardId.value == this.boardInfo.fileId
|
2024-07-23 02:40:11 +02:00
|
|
|
);
|
2024-07-23 13:48:17 +02:00
|
|
|
|
2024-07-23 13:53:50 +02:00
|
|
|
this.color.subscribe(() => {
|
|
|
|
|
if (this.isSelected.value == false) return;
|
|
|
|
|
this.applyColor();
|
2024-07-23 13:48:17 +02:00
|
|
|
});
|
2024-07-23 21:33:22 +02:00
|
|
|
this.selectedPage.subscribeSilent(() => {
|
|
|
|
|
this.storeLastUsedView();
|
|
|
|
|
});
|
2024-07-23 00:57:40 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-23 15:41:03 +02:00
|
|
|
|
2024-07-23 21:33:22 +02:00
|
|
|
export enum BoardViewModelSubPaths {
|
|
|
|
|
LastUsedView = "last-used-view",
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 15:41:03 +02:00
|
|
|
// types
|
|
|
|
|
export enum BoardPageType {
|
|
|
|
|
List = "list",
|
|
|
|
|
Kanban = "kanban",
|
|
|
|
|
StatusGrid = "status-grid",
|
|
|
|
|
}
|