implement task sorting
This commit is contained in:
@@ -64,6 +64,10 @@ export function stringify(data: any): string {
|
||||
return JSON.stringify(data, null, 4);
|
||||
}
|
||||
|
||||
export function padZero(string: string | undefined, length: number): string {
|
||||
return (string ?? "").padStart(length, "0");
|
||||
}
|
||||
|
||||
export function parse(string: string): any {
|
||||
try {
|
||||
return JSON.parse(string);
|
||||
|
||||
@@ -9,6 +9,10 @@ export function TaskEntry(taskViewModel: TaskViewModel) {
|
||||
</button>
|
||||
);
|
||||
|
||||
taskViewModel.index.subscribe((newIndex) => {
|
||||
view.style.order = newIndex;
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import BoardModel, {
|
||||
} from "../../Model/Files/boardModel";
|
||||
|
||||
import { Color } from "../../colors";
|
||||
import { IndexManager } from "../../Model/Utility/utility";
|
||||
import StorageModel from "../../Model/Global/storageModel";
|
||||
import TaskPageViewModel from "./taskPageViewModel";
|
||||
import TaskViewModel from "./taskViewModel";
|
||||
@@ -19,6 +20,10 @@ export default class BoardViewModel {
|
||||
// data
|
||||
boardInfo: BoardInfoFileContent;
|
||||
|
||||
taskIndexManager: IndexManager<TaskViewModel> = new IndexManager(
|
||||
(taskViewModel: TaskViewModel) => taskViewModel.sortingString
|
||||
);
|
||||
|
||||
// state
|
||||
name: React.State<string> = new React.State("");
|
||||
color: React.State<Color> = new React.State<Color>(Color.Standard);
|
||||
@@ -66,7 +71,7 @@ export default class BoardViewModel {
|
||||
this.close();
|
||||
};
|
||||
|
||||
// tasks
|
||||
// methods
|
||||
createTask = (): void => {
|
||||
const taskFileContent: TaskFileContent = this.boardModel.createTask(
|
||||
this.boardInfo.fileId
|
||||
@@ -77,6 +82,12 @@ export default class BoardViewModel {
|
||||
taskFileContent
|
||||
);
|
||||
this.selectTask(taskViewModel);
|
||||
this.updateTaskIndices();
|
||||
};
|
||||
|
||||
removeTaskFromList = (taskId: string): void => {
|
||||
this.taskViewModels.remove(taskId);
|
||||
this.updateIndex();
|
||||
};
|
||||
|
||||
// storage
|
||||
@@ -104,10 +115,6 @@ export default class BoardViewModel {
|
||||
this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
|
||||
};
|
||||
|
||||
removeTaskFromList = (taskId: string): void => {
|
||||
this.taskViewModels.remove(taskId);
|
||||
}
|
||||
|
||||
select = (): void => {
|
||||
this.taskPageViewModel.selectBoard(this);
|
||||
};
|
||||
@@ -147,6 +154,13 @@ export default class BoardViewModel {
|
||||
this.index.value = index;
|
||||
};
|
||||
|
||||
updateTaskIndices = (): void => {
|
||||
this.taskIndexManager.update([...this.taskViewModels.value.values()]);
|
||||
for (const boardViewModel of this.taskViewModels.value.values()) {
|
||||
boardViewModel.updateIndex();
|
||||
}
|
||||
};
|
||||
|
||||
// load
|
||||
loadListRelevantData = (): void => {
|
||||
this.name.value = this.boardInfo.name;
|
||||
@@ -171,6 +185,8 @@ export default class BoardViewModel {
|
||||
);
|
||||
this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
|
||||
}
|
||||
|
||||
this.updateTaskIndices();
|
||||
};
|
||||
|
||||
loadData = (): void => {
|
||||
@@ -215,6 +231,7 @@ export default class BoardViewModel {
|
||||
(taskFileContent: TaskFileContent) => {
|
||||
if (taskFileContent.boardId != this.boardInfo.fileId) return;
|
||||
this.showTaskInList(taskFileContent);
|
||||
this.updateTaskIndices();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -56,18 +56,18 @@ export default class TaskPageViewModel {
|
||||
|
||||
this.showBoardInList(boardInfoFileContent);
|
||||
this.boardModel.updateBoardAndSend(boardInfoFileContent);
|
||||
this.updateIndices();
|
||||
this.updateBoardIndices();
|
||||
};
|
||||
|
||||
updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
|
||||
this.boardModel.updateBoardAndSend(boardInfoFileContent);
|
||||
this.updateIndices();
|
||||
this.updateBoardIndices();
|
||||
};
|
||||
|
||||
deleteBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
|
||||
this.boardModel.deleteBoard(boardInfoFileContent.fileId);
|
||||
this.boardViewModels.remove(boardInfoFileContent.fileId);
|
||||
this.updateIndices();
|
||||
this.updateBoardIndices();
|
||||
};
|
||||
|
||||
// view
|
||||
@@ -95,7 +95,7 @@ export default class TaskPageViewModel {
|
||||
this.storeLastUsedBoard();
|
||||
};
|
||||
|
||||
updateIndices = (): void => {
|
||||
updateBoardIndices = (): void => {
|
||||
this.boardIndexManager.update([...this.boardViewModels.value.values()]);
|
||||
for (const boardViewModel of this.boardViewModels.value.values()) {
|
||||
boardViewModel.updateIndex();
|
||||
@@ -134,7 +134,7 @@ export default class TaskPageViewModel {
|
||||
this.showBoardInList(boardInfo);
|
||||
}
|
||||
|
||||
this.updateIndices();
|
||||
this.updateBoardIndices();
|
||||
this.openLastUsedBoard();
|
||||
};
|
||||
|
||||
@@ -153,7 +153,7 @@ export default class TaskPageViewModel {
|
||||
boardModel.boardHandlerManager.addHandler(
|
||||
(boardInfoFileContent: BoardInfoFileContent) => {
|
||||
this.showBoardInList(boardInfoFileContent);
|
||||
this.updateIndices();
|
||||
this.updateBoardIndices();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import * as React from "bloatless-react";
|
||||
import BoardModel, { TaskFileContent } from "../../Model/Files/boardModel";
|
||||
|
||||
import BoardViewModel from "./boardViewModel";
|
||||
import { padZero } from "../../Model/Utility/utility";
|
||||
|
||||
export default class TaskViewModel {
|
||||
boardModel: BoardModel;
|
||||
@@ -12,14 +13,33 @@ export default class TaskViewModel {
|
||||
// data
|
||||
task: TaskFileContent;
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
// paths
|
||||
getFilePath = (): string[] => {
|
||||
return this.boardModel.getTaskFilePath(this.task.fileId);
|
||||
};
|
||||
|
||||
// state
|
||||
name: React.State<string> = new React.State("");
|
||||
index: React.State<number> = new React.State(0);
|
||||
|
||||
name: React.State<string> = new React.State("");
|
||||
description: React.State<string> = new React.State("");
|
||||
|
||||
category: React.State<string> = new React.State("");
|
||||
@@ -43,6 +63,11 @@ export default class TaskViewModel {
|
||||
this.save();
|
||||
};
|
||||
|
||||
updateIndex = (): void => {
|
||||
const index: number = this.boardViewModel.taskIndexManager.getIndex(this);
|
||||
this.index.value = index;
|
||||
};
|
||||
|
||||
// settings
|
||||
save = (): void => {
|
||||
const newTaskFileContent: TaskFileContent =
|
||||
@@ -61,6 +86,7 @@ export default class TaskViewModel {
|
||||
|
||||
this.boardModel.updateTaskAndSend(newTaskFileContent);
|
||||
this.boardViewModel.showTaskInList(newTaskFileContent);
|
||||
this.boardViewModel.updateTaskIndices();
|
||||
};
|
||||
|
||||
deleteTask = (): void => {
|
||||
|
||||
Reference in New Issue
Block a user