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

82 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-07-24 00:38:37 +02:00
import * as React from "bloatless-react";
import BoardModel, {
TaskFileContent,
} from "../../Model/Files/boardModel";
import BoardViewModel from "./boardViewModel";
export default class TaskViewModel {
boardModel: BoardModel;
boardViewModel: BoardViewModel;
// data
2024-07-24 01:19:44 +02:00
task: TaskFileContent;
2024-07-24 00:38:37 +02:00
// paths
getFilePath = (): string[] => {
2024-07-24 01:19:44 +02:00
return this.boardModel.getTaskFilePath(this.task.fileId);
2024-07-24 00:38:37 +02:00
};
// state
name: React.State<string> = new React.State("");
category: React.State<string> = new React.State("");
status: React.State<string> = new React.State("");
description: React.State<string> = new React.State("");
priority: React.State<string> = new React.State("");
date: React.State<string> = new React.State("");
time: React.State<string> = new React.State("");
// storage
save = (): void => {
const newTaskFileContent: TaskFileContent =
BoardModel.createTaskFileContent(
2024-07-24 01:19:44 +02:00
this.task.fileId,
2024-07-24 00:38:37 +02:00
this.name.value,
this.boardViewModel.boardInfo.fileId
);
newTaskFileContent.status = this.status.value;
newTaskFileContent.category = this.category.value;
newTaskFileContent.description = this.description.value;
newTaskFileContent.priority = this.priority.value;
newTaskFileContent.date = this.date.value;
newTaskFileContent.time = this.time.value;
this.boardModel.updateTask(newTaskFileContent);
2024-07-24 01:19:44 +02:00
this.boardViewModel.trackTask(this);
2024-07-24 00:38:37 +02:00
};
// load
loadAllData = (): void => {
2024-07-24 01:19:44 +02:00
this.name.value = this.task.name;
2024-07-24 00:38:37 +02:00
2024-07-24 01:19:44 +02:00
this.category.value = this.task.category ?? "";
this.status.value = this.task.status ?? "";
2024-07-24 00:38:37 +02:00
2024-07-24 01:19:44 +02:00
this.description.value = this.task.description ?? "";
2024-07-24 00:38:37 +02:00
2024-07-24 01:19:44 +02:00
this.priority.value = this.task.priority ?? "";
this.date.value = this.task.date ?? "";
this.time.value = this.task.time ?? "";
2024-07-24 00:38:37 +02:00
};
// init
constructor(
boardModel: BoardModel,
boardViewModel: BoardViewModel,
2024-07-24 01:19:44 +02:00
taskFileContent: TaskFileContent
2024-07-24 00:38:37 +02:00
) {
this.boardModel = boardModel;
this.boardViewModel = boardViewModel;
2024-07-24 01:19:44 +02:00
this.task = taskFileContent;
2024-07-24 00:38:37 +02:00
this.loadAllData();
}
}