2024-07-24 00:38:37 +02:00
|
|
|
import * as React from "bloatless-react";
|
|
|
|
|
|
2024-07-24 17:28:49 +02:00
|
|
|
import BoardsAndTasksModel, { TaskFileContent } from "../../Model/Files/boardsAndTasksModel";
|
2024-07-24 15:57:02 +02:00
|
|
|
import { localeCompare, padZero } from "../../Model/Utility/utility";
|
2024-07-24 00:38:37 +02:00
|
|
|
|
|
|
|
|
import BoardViewModel from "./boardViewModel";
|
|
|
|
|
|
|
|
|
|
export default class TaskViewModel {
|
2024-07-24 17:28:49 +02:00
|
|
|
boardModel: BoardsAndTasksModel;
|
2024-07-24 00:38:37 +02:00
|
|
|
|
|
|
|
|
boardViewModel: BoardViewModel;
|
|
|
|
|
|
|
|
|
|
// data
|
2024-07-24 01:19:44 +02:00
|
|
|
task: TaskFileContent;
|
2024-07-24 00:38:37 +02:00
|
|
|
|
2024-07-24 14:34:28 +02:00
|
|
|
get sortingString(): string {
|
|
|
|
|
const splitDate: string[] = this.date.value.split("-");
|
|
|
|
|
const year = padZero(splitDate[0], 4);
|
|
|
|
|
const month = padZero(splitDate[1], 2);
|
|
|
|
|
const date = padZero(splitDate[2], 2);
|
|
|
|
|
|
|
|
|
|
const splitTime: string[] = this.time.value.split(":");
|
|
|
|
|
const hour = padZero(splitTime[0], 2);
|
|
|
|
|
const minute = padZero(splitTime[1], 2);
|
|
|
|
|
|
|
|
|
|
const priorityNumber = parseInt(this.priority.value);
|
|
|
|
|
const invertedPriority = 100 - priorityNumber;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
year + month + date + hour + minute + invertedPriority + this.name.value
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
2024-07-24 14:34:28 +02:00
|
|
|
index: React.State<number> = new React.State(0);
|
2024-07-24 00:38:37 +02:00
|
|
|
|
2024-07-24 14:34:28 +02:00
|
|
|
name: React.State<string> = new React.State("");
|
2024-07-24 00:38:37 +02:00
|
|
|
description: React.State<string> = new React.State("");
|
|
|
|
|
|
2024-07-24 03:36:21 +02:00
|
|
|
category: React.State<string> = new React.State("");
|
|
|
|
|
status: React.State<string> = new React.State("");
|
2024-07-24 00:38:37 +02:00
|
|
|
priority: React.State<string> = new React.State("");
|
2024-07-24 03:36:21 +02:00
|
|
|
|
2024-07-24 00:38:37 +02:00
|
|
|
date: React.State<string> = new React.State("");
|
|
|
|
|
time: React.State<string> = new React.State("");
|
|
|
|
|
|
2024-07-24 15:57:02 +02:00
|
|
|
selectedVersionId: React.State<string> = new React.State("");
|
|
|
|
|
versionIds: React.ListState<string> = new React.ListState();
|
|
|
|
|
|
2024-07-24 03:36:21 +02:00
|
|
|
// view
|
2024-07-24 13:34:33 +02:00
|
|
|
open = (): void => {
|
2024-07-24 13:31:28 +02:00
|
|
|
this.boardViewModel.selectTask(this);
|
2024-07-24 03:36:21 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-24 13:34:33 +02:00
|
|
|
close = (): void => {
|
2024-07-24 13:31:28 +02:00
|
|
|
this.boardViewModel.closeTask();
|
2024-07-24 03:36:21 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-24 13:34:33 +02:00
|
|
|
closeAndSave = (): void => {
|
|
|
|
|
this.close();
|
2024-07-24 03:36:21 +02:00
|
|
|
this.save();
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-24 14:34:28 +02:00
|
|
|
updateIndex = (): void => {
|
|
|
|
|
const index: number = this.boardViewModel.taskIndexManager.getIndex(this);
|
|
|
|
|
this.index.value = index;
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-24 14:10:09 +02:00
|
|
|
// settings
|
2024-07-24 00:38:37 +02:00
|
|
|
save = (): void => {
|
|
|
|
|
const newTaskFileContent: TaskFileContent =
|
2024-07-24 17:28:49 +02:00
|
|
|
BoardsAndTasksModel.createTaskFileContent(
|
2024-07-24 01:19:44 +02:00
|
|
|
this.task.fileId,
|
2024-07-24 00:38:37 +02:00
|
|
|
this.name.value,
|
2024-07-24 14:10:09 +02:00
|
|
|
this.task.boardId
|
2024-07-24 00:38:37 +02:00
|
|
|
);
|
|
|
|
|
|
2024-07-24 03:36:21 +02:00
|
|
|
newTaskFileContent.description = this.description.value;
|
2024-07-24 00:38:37 +02:00
|
|
|
newTaskFileContent.status = this.status.value;
|
|
|
|
|
newTaskFileContent.category = this.category.value;
|
|
|
|
|
newTaskFileContent.priority = this.priority.value;
|
|
|
|
|
newTaskFileContent.date = this.date.value;
|
|
|
|
|
newTaskFileContent.time = this.time.value;
|
|
|
|
|
|
2024-07-24 13:40:17 +02:00
|
|
|
this.boardModel.updateTaskAndSend(newTaskFileContent);
|
2024-07-24 13:45:24 +02:00
|
|
|
this.boardViewModel.showTaskInList(newTaskFileContent);
|
2024-07-24 14:34:28 +02:00
|
|
|
this.boardViewModel.updateTaskIndices();
|
2024-07-24 00:38:37 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-24 14:10:09 +02:00
|
|
|
deleteTask = (): void => {
|
|
|
|
|
this.close();
|
|
|
|
|
this.boardModel.deleteTask(this.task.boardId, this.task.fileId);
|
|
|
|
|
this.boardViewModel.removeTaskFromList(this.task.fileId);
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-24 00:38:37 +02:00
|
|
|
// load
|
2024-07-24 15:57:02 +02:00
|
|
|
loadVersionIds = (): void => {
|
|
|
|
|
const versionIds: string[] = this.boardModel.listTaskVersionIds(
|
|
|
|
|
this.task.fileId
|
|
|
|
|
);
|
|
|
|
|
const sortedVersionIds = versionIds.sort(localeCompare).reverse();
|
|
|
|
|
this.versionIds.clear();
|
|
|
|
|
this.versionIds.add(...sortedVersionIds);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
switchVersion = (versionId: string): void => {
|
|
|
|
|
const taskFileContent: TaskFileContent | null =
|
|
|
|
|
this.boardModel.getSpecificTaskFileContent(this.task.fileId, versionId);
|
|
|
|
|
if (taskFileContent == null) return;
|
|
|
|
|
|
|
|
|
|
this.task = taskFileContent;
|
|
|
|
|
this.loadTaskData();
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-24 00:38:37 +02:00
|
|
|
loadAllData = (): void => {
|
2024-07-24 15:57:02 +02:00
|
|
|
this.loadTaskData();
|
|
|
|
|
this.loadVersionIds();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
loadTaskData = (): void => {
|
2024-07-24 01:19:44 +02:00
|
|
|
this.name.value = this.task.name;
|
2024-07-24 03:36:21 +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.category.value = this.task.category ?? "";
|
|
|
|
|
this.status.value = this.task.status ?? "";
|
|
|
|
|
this.priority.value = this.task.priority ?? "";
|
2024-07-24 03:36:21 +02:00
|
|
|
|
2024-07-24 01:19:44 +02:00
|
|
|
this.date.value = this.task.date ?? "";
|
|
|
|
|
this.time.value = this.task.time ?? "";
|
2024-07-24 15:57:02 +02:00
|
|
|
|
|
|
|
|
this.selectedVersionId.value = this.task.fileContentId;
|
2024-07-24 00:38:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// init
|
|
|
|
|
constructor(
|
2024-07-24 17:28:49 +02:00
|
|
|
boardModel: BoardsAndTasksModel,
|
2024-07-24 00:38:37 +02:00
|
|
|
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
|
|
|
|
2024-07-24 15:57:02 +02:00
|
|
|
// load
|
2024-07-24 00:38:37 +02:00
|
|
|
this.loadAllData();
|
2024-07-24 15:57:02 +02:00
|
|
|
|
|
|
|
|
// subscriptions
|
|
|
|
|
this.selectedVersionId.subscribeSilent((selectedVersionId) => {
|
|
|
|
|
this.switchVersion(selectedVersionId);
|
|
|
|
|
});
|
2024-07-24 00:38:37 +02:00
|
|
|
}
|
|
|
|
|
}
|