integrate taskViewModel

This commit is contained in:
marlon-erler
2024-07-24 01:19:44 +02:00
parent 5a34a54273
commit bd880dfa06
8 changed files with 195 additions and 71 deletions
+9 -3
View File
@@ -128,13 +128,13 @@ export default class BoardModel {
};
//tasks
createTask = (boardId: string, name: string): void => {
createTask = (boardId: string): TaskFileContent => {
const taskFileContent: TaskFileContent = BoardModel.createTaskFileContent(
v4(),
name,
"",
boardId
);
this.updateTask(taskFileContent);
return taskFileContent;
};
updateTask = (taskFileContent: TaskFileContent): void => {
@@ -162,6 +162,12 @@ export default class BoardModel {
return fileIds;
};
getTaskFileContent = (taskId: string): TaskFileContent | null => {
const taskFileContentOrNull: TaskFileContent | null =
this.fileModel.getLatestFileContent(taskId, TaskFileContentReference);
return taskFileContentOrNull;
};
deleteTask = (boardId: string, taskId: string): void => {
const taskFilePath: string[] = this.getTaskFilePath(taskId);
const taskReferencePath: string[] = this.getTaskReferencePath(
+5 -4
View File
@@ -3,13 +3,14 @@ import * as React from "bloatless-react";
import ChatListModel from "../../Model/Chat/chatListModel";
import ChatModel from "../../Model/Chat/chatModel";
import ChatViewModel from "./chatViewModel";
import FileModel from "../../Model/Files/fileModel";
import { IndexManager } from "../../Model/Utility/utility";
import SettingsViewModel from "../Global/settingsViewModel";
import StorageModel from "../../Model/Global/storageModel";
export default class ChatListViewModel {
chatListModel: ChatListModel;
storageModel: StorageModel;
chatListModel: ChatListModel;
settingsViewModel: SettingsViewModel;
// data
@@ -55,8 +56,8 @@ export default class ChatListViewModel {
createChatViewModel = (chatModel: ChatModel): ChatViewModel => {
return new ChatViewModel(
chatModel,
this.storageModel,
chatModel,
this.settingsViewModel,
this
);
@@ -90,12 +91,12 @@ export default class ChatListViewModel {
// init
constructor(
chatListModel: ChatListModel,
storageModel: StorageModel,
chatListModel: ChatListModel,
settingsViewModel: SettingsViewModel
) {
this.chatListModel = chatListModel;
this.storageModel = storageModel;
this.chatListModel = chatListModel;
this.settingsViewModel = settingsViewModel;
this.loadChats();
+3 -3
View File
@@ -77,21 +77,21 @@ export default class ChatViewModel {
// init
constructor(
chatModel: ChatModel,
storageModel: StorageModel,
chatModel: ChatModel,
settingsViewModel: SettingsViewModel,
chatListViewModel: ChatListViewModel
) {
// models
this.chatModel = chatModel;
this.storageModel = storageModel;
this.chatModel = chatModel;
this.settingsViewModel = settingsViewModel;
this.chatListViewModel = chatListViewModel;
// page viewModels
this.taskPageViewModel = new TaskPageViewModel(
this.chatModel.fileModel.taskModel,
this.storageModel,
this.chatModel.fileModel.taskModel,
this
);
this.messagePageViewModel = new MessagePageViewModel(this);
+40 -3
View File
@@ -2,12 +2,15 @@ import * as React from "bloatless-react";
import BoardModel, {
BoardInfoFileContent,
BoardInfoFileContentReference,
TaskFileContent,
TaskFileContentReference,
} from "../../Model/Files/boardModel";
import { Color } from "../../colors";
import FileModel from "../../Model/Files/fileModel";
import StorageModel from "../../Model/Global/storageModel";
import TaskPageViewModel from "./taskPageViewModel";
import TaskViewModel from "./taskViewModel";
export default class BoardViewModel {
storageModel: StorageModel;
@@ -33,6 +36,8 @@ export default class BoardViewModel {
index: React.State<number> = new React.State(0);
taskViewModels: React.MapState<TaskViewModel> = new React.MapState();
// paths
getBasePath = (): string[] => {
return [...this.taskPageViewModel.getBoardViewPath(this.boardInfo.fileId)];
@@ -82,7 +87,7 @@ export default class BoardViewModel {
this.index.value = index;
};
// methods
// settings
saveSettings = (): void => {
const newBoardInfoFileContent: BoardInfoFileContent =
BoardModel.createBoardInfoFileContent(
@@ -102,7 +107,18 @@ export default class BoardViewModel {
this.close();
};
// store
// tasks
createTask = (): TaskViewModel => {
const taskFileContent: TaskFileContent = this.boardModel.createTask(this.boardInfo.fileId);
const taskViewModel: TaskViewModel = new TaskViewModel(this.boardModel, this, taskFileContent);
return taskViewModel;
}
trackTask = (taskViewModel: TaskViewModel): void => {
this.taskViewModels.set(taskViewModel.task.fileId, taskViewModel);
}
// storage
storeLastUsedView = (): void => {
const path: string[] = this.getLastUsedBoardPath();
const lastUsedView: string = this.selectedPage.value;
@@ -123,8 +139,29 @@ export default class BoardViewModel {
this.color.value = this.boardInfo.color;
};
loadTasks = (): void => {
this.taskViewModels.clear();
const taskIds: string[] = this.boardModel.listTaskIds(
this.boardInfo.fileId
);
for (const taskId of taskIds) {
const taskFileContent: TaskFileContent | null =
this.boardModel.getTaskFileContent(taskId);
if (taskFileContent == null) continue;
const taskViewModel: TaskViewModel = new TaskViewModel(
this.boardModel,
this,
taskFileContent
);
this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
}
};
loadData = (): void => {
this.restoreLastUsedView();
this.loadTasks();
};
// init
+3 -3
View File
@@ -4,10 +4,10 @@ import BoardModel, {
BoardInfoFileContent,
BoardInfoFileContentReference,
} from "../../Model/Files/boardModel";
import FileModel, { FileContent } from "../../Model/Files/fileModel";
import BoardViewModel from "./boardViewModel";
import ChatViewModel from "../Chat/chatViewModel";
import { FileContent } from "../../Model/Files/fileModel";
import { IndexManager } from "../../Model/Utility/utility";
import StorageModel from "../../Model/Global/storageModel";
import { checkMatchesObjectStructure } from "../../Model/Utility/typeSafety";
@@ -154,12 +154,12 @@ export default class TaskPageViewModel {
// init
constructor(
boardModel: BoardModel,
storageModel: StorageModel,
boardModel: BoardModel,
chatViewModel: ChatViewModel
) {
this.boardModel = boardModel;
this.storageModel = storageModel;
this.boardModel = boardModel;
this.chatViewModel = chatViewModel;
+13 -21
View File
@@ -6,20 +6,18 @@ import BoardModel, {
} 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;
task: TaskFileContent;
// paths
getFilePath = (): string[] => {
return this.boardModel.getTaskFilePath(this.fileId);
return this.boardModel.getTaskFilePath(this.task.fileId);
};
// state
@@ -38,7 +36,7 @@ export default class TaskViewModel {
save = (): void => {
const newTaskFileContent: TaskFileContent =
BoardModel.createTaskFileContent(
this.fileId,
this.task.fileId,
this.name.value,
this.boardViewModel.boardInfo.fileId
);
@@ -51,39 +49,33 @@ export default class TaskViewModel {
newTaskFileContent.time = this.time.value;
this.boardModel.updateTask(newTaskFileContent);
this.boardViewModel.trackTask(this);
};
// load
loadAllData = (): void => {
const path: string[] = this.getFilePath();
const taskFileContent: TaskFileContent | null =
this.storageModel.readStringifiable(path, TaskFileContentReference);
if (taskFileContent == null) return;
this.name.value = this.task.name;
this.name.value = taskFileContent.name;
this.category.value = this.task.category ?? "";
this.status.value = this.task.status ?? "";
this.category.value = taskFileContent.category ?? "";
this.status.value = taskFileContent.status ?? "";
this.description.value = this.task.description ?? "";
this.description.value = taskFileContent.description ?? "";
this.priority.value = taskFileContent.priority ?? "";
this.date.value = taskFileContent.date ?? "";
this.time.value = taskFileContent.time ?? "";
this.priority.value = this.task.priority ?? "";
this.date.value = this.task.date ?? "";
this.time.value = this.task.time ?? "";
};
// init
constructor(
boardModel: BoardModel,
storageModel: StorageModel,
boardViewModel: BoardViewModel,
fileId: string
taskFileContent: TaskFileContent
) {
this.boardModel = boardModel;
this.storageModel = storageModel;
this.boardViewModel = boardViewModel;
this.fileId = fileId;
this.task = taskFileContent;
this.loadAllData();
}
+1 -1
View File
@@ -32,8 +32,8 @@ const storageViewModel = new StorageViewModel(storageModel);
const settingsViewModel = new SettingsViewModel(settingsModel);
const connectionViewModel = new ConnectionViewModel(connectionModel);
const chatListViewModel = new ChatListViewModel(
chatListModel,
storageModel,
chatListModel,
settingsViewModel
);