Files
CT/src/ViewModel/Pages/taskContainingPageViewModel.ts
T

68 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-07-26 06:20:16 +02:00
import * as React from "bloatless-react";
import BoardsAndTasksModel, {
2026-04-01 08:29:39 +00:00
TaskFileContent,
2024-07-26 06:20:16 +02:00
} from "../../Model/Files/boardsAndTasksModel";
import ChatViewModel from "../Chat/chatViewModel";
2024-07-26 06:20:16 +02:00
import CoreViewModel from "../Global/coreViewModel";
import { IndexManager } from "../../Model/Utility/utility";
import TaskViewModel from "./taskViewModel";
export default class TaskContainingPageViewModel {
2026-04-01 08:29:39 +00:00
boardsAndTasksModel: BoardsAndTasksModel;
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
// state
taskIndexManager: IndexManager<TaskViewModel> = new IndexManager(
(taskViewModel: TaskViewModel) => taskViewModel.sortingString,
);
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
selectedTaskViewModel: React.State<TaskViewModel | undefined> =
new React.State<any>(undefined);
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
taskViewModels: React.MapState<TaskViewModel> = new React.MapState();
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
// methods
createTaskFromBoardId = (boardId: string): void => {
const taskFileContent: TaskFileContent =
this.boardsAndTasksModel.createTask(boardId);
const taskViewModel: TaskViewModel = new TaskViewModel(
this.coreViewModel,
this.chatViewModel,
this.boardsAndTasksModel,
this,
taskFileContent,
);
this.selectTask(taskViewModel);
this.updateTaskIndices();
};
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
// view
showTask = (taskFileContent: TaskFileContent): void => {};
removeTaskFromView = (taskFileContent: TaskFileContent): void => {};
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
selectTask = (selectedTask: TaskViewModel): void => {
this.selectedTaskViewModel.value = selectedTask;
};
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
closeTask = () => {
this.selectedTaskViewModel.value = undefined;
};
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
updateTaskIndices = (): void => {
this.taskIndexManager.update([...this.taskViewModels.value.values()]);
for (const boardViewModel of this.taskViewModels.value.values()) {
boardViewModel.updateIndex();
}
};
2024-07-26 06:20:16 +02:00
2026-04-01 08:29:39 +00:00
// init
constructor(
public coreViewModel: CoreViewModel,
public chatViewModel: ChatViewModel,
boardsAndTasksModel: BoardsAndTasksModel,
) {
this.boardsAndTasksModel = boardsAndTasksModel;
}
2024-07-26 06:20:16 +02:00
}