prepare CalendarPageViewModel, allow TaskViewModel to be used by BoardViewModel or CalendarPageViewModel
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import * as React from "bloatless-react";
|
||||
|
||||
import ChatModel, { ChatMessage } from "../../Model/Chat/chatModel";
|
||||
import StorageModel, { StorageModelSubPath, filePaths } from "../../Model/Global/storageModel";
|
||||
import StorageModel, {
|
||||
StorageModelSubPath,
|
||||
filePaths,
|
||||
} from "../../Model/Global/storageModel";
|
||||
|
||||
import CalendarPageViewModel from "../Pages/calendarPageViewModel";
|
||||
import ChatListViewModel from "./chatListViewModel";
|
||||
import { Color } from "../../colors";
|
||||
import CoreViewModel from "../Global/coreViewModel";
|
||||
@@ -17,6 +21,7 @@ export default class ChatViewModel {
|
||||
settingsViewModel: SettingsViewModel;
|
||||
chatListViewModel: ChatListViewModel;
|
||||
|
||||
calendarViewModel: CalendarPageViewModel;
|
||||
taskPageViewModel: TaskPageViewModel;
|
||||
messagePageViewModel: MessagePageViewModel;
|
||||
settingsPageViewModel: SettingsPageViewModel;
|
||||
@@ -91,6 +96,12 @@ export default class ChatViewModel {
|
||||
this.chatListViewModel = chatListViewModel;
|
||||
|
||||
// page viewModels
|
||||
this.calendarViewModel = new CalendarPageViewModel(
|
||||
coreViewModel,
|
||||
this.storageModel,
|
||||
this.chatModel.fileModel.calendarModel,
|
||||
this.chatModel.fileModel.boardsAndTasksModel
|
||||
);
|
||||
this.taskPageViewModel = new TaskPageViewModel(
|
||||
this.coreViewModel,
|
||||
this.storageModel,
|
||||
|
||||
@@ -82,6 +82,7 @@ export default class BoardViewModel {
|
||||
this.coreViewModel,
|
||||
this.boardsAndTasksModel,
|
||||
this,
|
||||
null,
|
||||
taskFileContent
|
||||
);
|
||||
this.selectTask(taskViewModel);
|
||||
@@ -136,6 +137,7 @@ export default class BoardViewModel {
|
||||
this.coreViewModel,
|
||||
this.boardsAndTasksModel,
|
||||
this,
|
||||
null,
|
||||
taskFileContent
|
||||
);
|
||||
this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
|
||||
@@ -222,6 +224,7 @@ export default class BoardViewModel {
|
||||
this.coreViewModel,
|
||||
this.boardsAndTasksModel,
|
||||
this,
|
||||
null,
|
||||
taskFileContent
|
||||
);
|
||||
this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import * as React from "bloatless-react";
|
||||
|
||||
import BoardsAndTasksModel, {
|
||||
TaskFileContent,
|
||||
} from "../../Model/Files/boardsAndTasksModel";
|
||||
|
||||
import CalendarModel from "../../Model/Files/calendarModel";
|
||||
import CoreViewModel from "../Global/coreViewModel";
|
||||
import StorageModel from "../../Model/Global/storageModel";
|
||||
import TaskViewModel from "./taskViewModel";
|
||||
|
||||
export default class CalendarPageViewModel {
|
||||
storageModel: StorageModel;
|
||||
calendarModel: CalendarModel;
|
||||
boardAndTasksModel: BoardsAndTasksModel;
|
||||
|
||||
// paths
|
||||
getBasePath = (): string[] => {
|
||||
return [...this.calendarModel.getViewPath()];
|
||||
};
|
||||
|
||||
// state
|
||||
taskViewModels: React.MapState<TaskViewModel> = new React.MapState();
|
||||
|
||||
// view
|
||||
showTask = (taskFileContent: TaskFileContent): void => {
|
||||
const taskViewModel: TaskViewModel = new TaskViewModel(
|
||||
this.coreViewModel,
|
||||
this.boardAndTasksModel,
|
||||
null,
|
||||
this,
|
||||
taskFileContent
|
||||
);
|
||||
this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
|
||||
};
|
||||
|
||||
// storage
|
||||
|
||||
// load
|
||||
loadData = (): void => {}
|
||||
|
||||
// init
|
||||
constructor(
|
||||
public coreViewModel: CoreViewModel,
|
||||
storageModel: StorageModel,
|
||||
calendarModel: CalendarModel,
|
||||
boardAndTasksModel: BoardsAndTasksModel,
|
||||
) {
|
||||
this.storageModel = storageModel;
|
||||
this.calendarModel = calendarModel;
|
||||
this.boardAndTasksModel = boardAndTasksModel;
|
||||
}
|
||||
}
|
||||
|
||||
export enum TaskPageViewModelSubPath {
|
||||
LastUsedBoard = "last-used-board",
|
||||
}
|
||||
@@ -9,11 +9,10 @@ import ChatViewModel from "../Chat/chatViewModel";
|
||||
import CoreViewModel from "../Global/coreViewModel";
|
||||
import { IndexManager } from "../../Model/Utility/utility";
|
||||
import StorageModel from "../../Model/Global/storageModel";
|
||||
import TaskViewModel from "./taskViewModel";
|
||||
|
||||
export default class TaskPageViewModel {
|
||||
storageModel: StorageModel;
|
||||
boardModel: BoardsAndTasksModel;
|
||||
boardsAndTasksModel: BoardsAndTasksModel;
|
||||
|
||||
chatViewModel: ChatViewModel;
|
||||
|
||||
@@ -24,7 +23,7 @@ export default class TaskPageViewModel {
|
||||
|
||||
// paths
|
||||
getBasePath = (): string[] => {
|
||||
return [...this.boardModel.getViewPath()];
|
||||
return [...this.boardsAndTasksModel.getViewPath()];
|
||||
};
|
||||
|
||||
getBoardViewPath = (boardId): string[] => {
|
||||
@@ -55,21 +54,21 @@ export default class TaskPageViewModel {
|
||||
if (this.cannotCreateBoard.value == true) return;
|
||||
|
||||
const boardInfoFileContent: BoardInfoFileContent =
|
||||
this.boardModel.createBoard(this.newBoardNameInput.value);
|
||||
this.boardsAndTasksModel.createBoard(this.newBoardNameInput.value);
|
||||
this.newBoardNameInput.value = "";
|
||||
|
||||
this.showBoardInList(boardInfoFileContent);
|
||||
this.boardModel.updateBoardAndSend(boardInfoFileContent);
|
||||
this.boardsAndTasksModel.updateBoardAndSend(boardInfoFileContent);
|
||||
this.updateBoardIndices();
|
||||
};
|
||||
|
||||
updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
|
||||
this.boardModel.updateBoardAndSend(boardInfoFileContent);
|
||||
this.boardsAndTasksModel.updateBoardAndSend(boardInfoFileContent);
|
||||
this.updateBoardIndices();
|
||||
};
|
||||
|
||||
deleteBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
|
||||
this.boardModel.deleteBoard(boardInfoFileContent.fileId);
|
||||
this.boardsAndTasksModel.deleteBoard(boardInfoFileContent.fileId);
|
||||
this.boardViewModels.remove(boardInfoFileContent.fileId);
|
||||
this.updateBoardIndices();
|
||||
};
|
||||
@@ -79,7 +78,7 @@ export default class TaskPageViewModel {
|
||||
const boardViewModel: BoardViewModel = new BoardViewModel(
|
||||
this.coreViewModel,
|
||||
this.storageModel,
|
||||
this.boardModel,
|
||||
this.boardsAndTasksModel,
|
||||
this,
|
||||
boardInfo
|
||||
);
|
||||
@@ -130,10 +129,10 @@ export default class TaskPageViewModel {
|
||||
loadData = (): void => {
|
||||
this.boardViewModels.clear();
|
||||
|
||||
const boardIds: string[] = this.boardModel.listBoardIds();
|
||||
const boardIds: string[] = this.boardsAndTasksModel.listBoardIds();
|
||||
for (const boardId of boardIds) {
|
||||
const boardInfo: BoardInfoFileContent | null =
|
||||
this.boardModel.getBoardInfo(boardId);
|
||||
this.boardsAndTasksModel.getBoardInfo(boardId);
|
||||
if (boardInfo == null) continue;
|
||||
|
||||
this.showBoardInList(boardInfo);
|
||||
@@ -151,7 +150,7 @@ export default class TaskPageViewModel {
|
||||
chatViewModel: ChatViewModel
|
||||
) {
|
||||
this.storageModel = storageModel;
|
||||
this.boardModel = boardModel;
|
||||
this.boardsAndTasksModel = boardModel;
|
||||
|
||||
this.chatViewModel = chatViewModel;
|
||||
|
||||
|
||||
@@ -6,13 +6,15 @@ import BoardsAndTasksModel, {
|
||||
import { localeCompare, padZero } from "../../Model/Utility/utility";
|
||||
|
||||
import BoardViewModel from "./boardViewModel";
|
||||
import CalendarPageViewModel from "./calendarPageViewModel";
|
||||
import CoreViewModel from "../Global/coreViewModel";
|
||||
import { allowDrag } from "../../View/utility";
|
||||
|
||||
export default class TaskViewModel {
|
||||
boardsAndTasksModel: BoardsAndTasksModel;
|
||||
|
||||
boardViewModel: BoardViewModel;
|
||||
boardViewModel: BoardViewModel | null;
|
||||
calendarPageViewModel: CalendarPageViewModel | null;
|
||||
|
||||
// data
|
||||
task: TaskFileContent;
|
||||
@@ -77,11 +79,11 @@ export default class TaskViewModel {
|
||||
|
||||
// view
|
||||
open = (): void => {
|
||||
this.boardViewModel.selectTask(this);
|
||||
this.boardViewModel?.selectTask(this);
|
||||
};
|
||||
|
||||
close = (): void => {
|
||||
this.boardViewModel.closeTask();
|
||||
this.boardViewModel?.closeTask();
|
||||
};
|
||||
|
||||
closeAndSave = (): void => {
|
||||
@@ -90,6 +92,7 @@ export default class TaskViewModel {
|
||||
};
|
||||
|
||||
updateIndex = (): void => {
|
||||
if (this.boardViewModel == null) return;
|
||||
const index: number = this.boardViewModel.taskIndexManager.getIndex(this);
|
||||
this.index.value = index;
|
||||
};
|
||||
@@ -112,14 +115,24 @@ export default class TaskViewModel {
|
||||
newTaskFileContent.time = this.time.value;
|
||||
|
||||
this.boardsAndTasksModel.updateTaskAndSend(newTaskFileContent);
|
||||
this.boardViewModel.showTaskInList(newTaskFileContent);
|
||||
this.boardViewModel.updateTaskIndices();
|
||||
|
||||
if (this.boardViewModel != null) {
|
||||
this.boardViewModel.showTaskInList(newTaskFileContent);
|
||||
this.boardViewModel.updateTaskIndices();
|
||||
}
|
||||
if (this.calendarPageViewModel != null) {
|
||||
}
|
||||
};
|
||||
|
||||
deleteTask = (): void => {
|
||||
this.close();
|
||||
this.boardsAndTasksModel.deleteTask(this.task.boardId, this.task.fileId);
|
||||
this.boardViewModel.removeTaskFromList(this.task.fileId);
|
||||
|
||||
if (this.boardViewModel != null) {
|
||||
this.boardViewModel.removeTaskFromList(this.task.fileId);
|
||||
}
|
||||
if (this.calendarPageViewModel != null) {
|
||||
}
|
||||
};
|
||||
|
||||
// load
|
||||
@@ -168,12 +181,14 @@ export default class TaskViewModel {
|
||||
// init
|
||||
constructor(
|
||||
public coreViewModel: CoreViewModel,
|
||||
boardModel: BoardsAndTasksModel,
|
||||
boardViewModel: BoardViewModel,
|
||||
boardsAndTasksModel: BoardsAndTasksModel,
|
||||
boardViewModel: BoardViewModel | null,
|
||||
calendarPageViewModel: CalendarPageViewModel | null,
|
||||
taskFileContent: TaskFileContent
|
||||
) {
|
||||
this.boardsAndTasksModel = boardModel;
|
||||
this.boardsAndTasksModel = boardsAndTasksModel;
|
||||
this.boardViewModel = boardViewModel;
|
||||
this.calendarPageViewModel = calendarPageViewModel;
|
||||
|
||||
this.task = taskFileContent;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user