implement task sorting

This commit is contained in:
marlon-erler
2024-07-24 14:34:28 +02:00
parent 71d840e024
commit 34692d1232
6 changed files with 112 additions and 22 deletions
+49 -10
View File
@@ -356,6 +356,9 @@
function stringify(data) { function stringify(data) {
return JSON.stringify(data, null, 4); return JSON.stringify(data, null, 4);
} }
function padZero(string, length) {
return (string ?? "").padStart(length, "0");
}
function parse(string) { function parse(string) {
try { try {
return JSON.parse(string); return JSON.parse(string);
@@ -1440,11 +1443,25 @@
boardViewModel; boardViewModel;
// data // data
task; task;
get sortingString() {
const splitDate = this.date.value.split("-");
const year = padZero(splitDate[0], 4);
const month = padZero(splitDate[1], 2);
const date = padZero(splitDate[2], 2);
const splitTime = this.time.value.split(":");
const hour = padZero(splitTime[0], 2);
const minute = padZero(splitTime[1], 2);
const priorityNumber = parseInt(this.priority.value);
console.log(priorityNumber, this.priority.value);
const invertedPriority = 100 - priorityNumber;
return year + month + date + hour + minute + invertedPriority + this.name.value;
}
// paths // paths
getFilePath = () => { getFilePath = () => {
return this.boardModel.getTaskFilePath(this.task.fileId); return this.boardModel.getTaskFilePath(this.task.fileId);
}; };
// state // state
index = new State(0);
name = new State(""); name = new State("");
description = new State(""); description = new State("");
category = new State(""); category = new State("");
@@ -1463,6 +1480,11 @@
this.close(); this.close();
this.save(); this.save();
}; };
updateIndex = () => {
console.log(this.sortingString);
const index = this.boardViewModel.taskIndexManager.getIndex(this);
this.index.value = index;
};
// settings // settings
save = () => { save = () => {
const newTaskFileContent = BoardModel.createTaskFileContent( const newTaskFileContent = BoardModel.createTaskFileContent(
@@ -1478,6 +1500,7 @@
newTaskFileContent.time = this.time.value; newTaskFileContent.time = this.time.value;
this.boardModel.updateTaskAndSend(newTaskFileContent); this.boardModel.updateTaskAndSend(newTaskFileContent);
this.boardViewModel.showTaskInList(newTaskFileContent); this.boardViewModel.showTaskInList(newTaskFileContent);
this.boardViewModel.updateTaskIndices();
}; };
deleteTask = () => { deleteTask = () => {
this.close(); this.close();
@@ -1510,6 +1533,9 @@
taskPageViewModel; taskPageViewModel;
// data // data
boardInfo; boardInfo;
taskIndexManager = new IndexManager(
(taskViewModel) => taskViewModel.sortingString
);
// state // state
name = new State(""); name = new State("");
color = new State("standard" /* Standard */); color = new State("standard" /* Standard */);
@@ -1545,7 +1571,7 @@
this.taskPageViewModel.deleteBoard(this.boardInfo); this.taskPageViewModel.deleteBoard(this.boardInfo);
this.close(); this.close();
}; };
// tasks // methods
createTask = () => { createTask = () => {
const taskFileContent = this.boardModel.createTask( const taskFileContent = this.boardModel.createTask(
this.boardInfo.fileId this.boardInfo.fileId
@@ -1556,6 +1582,11 @@
taskFileContent taskFileContent
); );
this.selectTask(taskViewModel); this.selectTask(taskViewModel);
this.updateTaskIndices();
};
removeTaskFromList = (taskId) => {
this.taskViewModels.remove(taskId);
this.updateIndex();
}; };
// storage // storage
storeLastUsedView = () => { storeLastUsedView = () => {
@@ -1578,9 +1609,6 @@
); );
this.taskViewModels.set(taskFileContent.fileId, taskViewModel); this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
}; };
removeTaskFromList = (taskId) => {
this.taskViewModels.remove(taskId);
};
select = () => { select = () => {
this.taskPageViewModel.selectBoard(this); this.taskPageViewModel.selectBoard(this);
}; };
@@ -1610,6 +1638,12 @@
const index = this.taskPageViewModel.boardIndexManager.getIndex(this); const index = this.taskPageViewModel.boardIndexManager.getIndex(this);
this.index.value = index; this.index.value = index;
}; };
updateTaskIndices = () => {
this.taskIndexManager.update([...this.taskViewModels.value.values()]);
for (const boardViewModel of this.taskViewModels.value.values()) {
boardViewModel.updateIndex();
}
};
// load // load
loadListRelevantData = () => { loadListRelevantData = () => {
this.name.value = this.boardInfo.name; this.name.value = this.boardInfo.name;
@@ -1630,6 +1664,7 @@
); );
this.taskViewModels.set(taskFileContent.fileId, taskViewModel); this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
} }
this.updateTaskIndices();
}; };
loadData = () => { loadData = () => {
this.restoreLastUsedView(); this.restoreLastUsedView();
@@ -1657,6 +1692,7 @@
(taskFileContent) => { (taskFileContent) => {
if (taskFileContent.boardId != this.boardInfo.fileId) return; if (taskFileContent.boardId != this.boardInfo.fileId) return;
this.showTaskInList(taskFileContent); this.showTaskInList(taskFileContent);
this.updateTaskIndices();
} }
); );
} }
@@ -1697,16 +1733,16 @@
this.newBoardNameInput.value = ""; this.newBoardNameInput.value = "";
this.showBoardInList(boardInfoFileContent); this.showBoardInList(boardInfoFileContent);
this.boardModel.updateBoardAndSend(boardInfoFileContent); this.boardModel.updateBoardAndSend(boardInfoFileContent);
this.updateIndices(); this.updateBoardIndices();
}; };
updateBoard = (boardInfoFileContent) => { updateBoard = (boardInfoFileContent) => {
this.boardModel.updateBoardAndSend(boardInfoFileContent); this.boardModel.updateBoardAndSend(boardInfoFileContent);
this.updateIndices(); this.updateBoardIndices();
}; };
deleteBoard = (boardInfoFileContent) => { deleteBoard = (boardInfoFileContent) => {
this.boardModel.deleteBoard(boardInfoFileContent.fileId); this.boardModel.deleteBoard(boardInfoFileContent.fileId);
this.boardViewModels.remove(boardInfoFileContent.fileId); this.boardViewModels.remove(boardInfoFileContent.fileId);
this.updateIndices(); this.updateBoardIndices();
}; };
// view // view
showBoardInList = (boardInfo) => { showBoardInList = (boardInfo) => {
@@ -1728,7 +1764,7 @@
this.chatViewModel.resetColor(); this.chatViewModel.resetColor();
this.storeLastUsedBoard(); this.storeLastUsedBoard();
}; };
updateIndices = () => { updateBoardIndices = () => {
this.boardIndexManager.update([...this.boardViewModels.value.values()]); this.boardIndexManager.update([...this.boardViewModels.value.values()]);
for (const boardViewModel of this.boardViewModels.value.values()) { for (const boardViewModel of this.boardViewModels.value.values()) {
boardViewModel.updateIndex(); boardViewModel.updateIndex();
@@ -1757,7 +1793,7 @@
if (boardInfo == null) continue; if (boardInfo == null) continue;
this.showBoardInList(boardInfo); this.showBoardInList(boardInfo);
} }
this.updateIndices(); this.updateBoardIndices();
this.openLastUsedBoard(); this.openLastUsedBoard();
}; };
// init // init
@@ -1768,7 +1804,7 @@
boardModel.boardHandlerManager.addHandler( boardModel.boardHandlerManager.addHandler(
(boardInfoFileContent) => { (boardInfoFileContent) => {
this.showBoardInList(boardInfoFileContent); this.showBoardInList(boardInfoFileContent);
this.updateIndices(); this.updateBoardIndices();
} }
); );
} }
@@ -2378,6 +2414,9 @@
// src/View/Components/taskEntry.tsx // src/View/Components/taskEntry.tsx
function TaskEntry(taskViewModel) { function TaskEntry(taskViewModel) {
const view = /* @__PURE__ */ createElement("button", { class: "tile", "on:click": taskViewModel.open }, /* @__PURE__ */ createElement("b", { "subscribe:innerText": taskViewModel.name })); const view = /* @__PURE__ */ createElement("button", { class: "tile", "on:click": taskViewModel.open }, /* @__PURE__ */ createElement("b", { "subscribe:innerText": taskViewModel.name }));
taskViewModel.index.subscribe((newIndex) => {
view.style.order = newIndex;
});
return view; return view;
} }
var TaskViewModelToEntry = (taskViewModel) => { var TaskViewModelToEntry = (taskViewModel) => {
+4
View File
@@ -64,6 +64,10 @@ export function stringify(data: any): string {
return JSON.stringify(data, null, 4); 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 { export function parse(string: string): any {
try { try {
return JSON.parse(string); return JSON.parse(string);
+4
View File
@@ -9,6 +9,10 @@ export function TaskEntry(taskViewModel: TaskViewModel) {
</button> </button>
); );
taskViewModel.index.subscribe((newIndex) => {
view.style.order = newIndex;
});
return view; return view;
} }
+22 -5
View File
@@ -6,6 +6,7 @@ import BoardModel, {
} from "../../Model/Files/boardModel"; } from "../../Model/Files/boardModel";
import { Color } from "../../colors"; import { Color } from "../../colors";
import { IndexManager } from "../../Model/Utility/utility";
import StorageModel from "../../Model/Global/storageModel"; import StorageModel from "../../Model/Global/storageModel";
import TaskPageViewModel from "./taskPageViewModel"; import TaskPageViewModel from "./taskPageViewModel";
import TaskViewModel from "./taskViewModel"; import TaskViewModel from "./taskViewModel";
@@ -19,6 +20,10 @@ export default class BoardViewModel {
// data // data
boardInfo: BoardInfoFileContent; boardInfo: BoardInfoFileContent;
taskIndexManager: IndexManager<TaskViewModel> = new IndexManager(
(taskViewModel: TaskViewModel) => taskViewModel.sortingString
);
// state // state
name: React.State<string> = new React.State(""); name: React.State<string> = new React.State("");
color: React.State<Color> = new React.State<Color>(Color.Standard); color: React.State<Color> = new React.State<Color>(Color.Standard);
@@ -66,7 +71,7 @@ export default class BoardViewModel {
this.close(); this.close();
}; };
// tasks // methods
createTask = (): void => { createTask = (): void => {
const taskFileContent: TaskFileContent = this.boardModel.createTask( const taskFileContent: TaskFileContent = this.boardModel.createTask(
this.boardInfo.fileId this.boardInfo.fileId
@@ -77,6 +82,12 @@ export default class BoardViewModel {
taskFileContent taskFileContent
); );
this.selectTask(taskViewModel); this.selectTask(taskViewModel);
this.updateTaskIndices();
};
removeTaskFromList = (taskId: string): void => {
this.taskViewModels.remove(taskId);
this.updateIndex();
}; };
// storage // storage
@@ -104,10 +115,6 @@ export default class BoardViewModel {
this.taskViewModels.set(taskFileContent.fileId, taskViewModel); this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
}; };
removeTaskFromList = (taskId: string): void => {
this.taskViewModels.remove(taskId);
}
select = (): void => { select = (): void => {
this.taskPageViewModel.selectBoard(this); this.taskPageViewModel.selectBoard(this);
}; };
@@ -147,6 +154,13 @@ export default class BoardViewModel {
this.index.value = index; this.index.value = index;
}; };
updateTaskIndices = (): void => {
this.taskIndexManager.update([...this.taskViewModels.value.values()]);
for (const boardViewModel of this.taskViewModels.value.values()) {
boardViewModel.updateIndex();
}
};
// load // load
loadListRelevantData = (): void => { loadListRelevantData = (): void => {
this.name.value = this.boardInfo.name; this.name.value = this.boardInfo.name;
@@ -171,6 +185,8 @@ export default class BoardViewModel {
); );
this.taskViewModels.set(taskFileContent.fileId, taskViewModel); this.taskViewModels.set(taskFileContent.fileId, taskViewModel);
} }
this.updateTaskIndices();
}; };
loadData = (): void => { loadData = (): void => {
@@ -215,6 +231,7 @@ export default class BoardViewModel {
(taskFileContent: TaskFileContent) => { (taskFileContent: TaskFileContent) => {
if (taskFileContent.boardId != this.boardInfo.fileId) return; if (taskFileContent.boardId != this.boardInfo.fileId) return;
this.showTaskInList(taskFileContent); this.showTaskInList(taskFileContent);
this.updateTaskIndices();
} }
); );
} }
+6 -6
View File
@@ -56,18 +56,18 @@ export default class TaskPageViewModel {
this.showBoardInList(boardInfoFileContent); this.showBoardInList(boardInfoFileContent);
this.boardModel.updateBoardAndSend(boardInfoFileContent); this.boardModel.updateBoardAndSend(boardInfoFileContent);
this.updateIndices(); this.updateBoardIndices();
}; };
updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => { updateBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
this.boardModel.updateBoardAndSend(boardInfoFileContent); this.boardModel.updateBoardAndSend(boardInfoFileContent);
this.updateIndices(); this.updateBoardIndices();
}; };
deleteBoard = (boardInfoFileContent: BoardInfoFileContent): void => { deleteBoard = (boardInfoFileContent: BoardInfoFileContent): void => {
this.boardModel.deleteBoard(boardInfoFileContent.fileId); this.boardModel.deleteBoard(boardInfoFileContent.fileId);
this.boardViewModels.remove(boardInfoFileContent.fileId); this.boardViewModels.remove(boardInfoFileContent.fileId);
this.updateIndices(); this.updateBoardIndices();
}; };
// view // view
@@ -95,7 +95,7 @@ export default class TaskPageViewModel {
this.storeLastUsedBoard(); this.storeLastUsedBoard();
}; };
updateIndices = (): void => { updateBoardIndices = (): void => {
this.boardIndexManager.update([...this.boardViewModels.value.values()]); this.boardIndexManager.update([...this.boardViewModels.value.values()]);
for (const boardViewModel of this.boardViewModels.value.values()) { for (const boardViewModel of this.boardViewModels.value.values()) {
boardViewModel.updateIndex(); boardViewModel.updateIndex();
@@ -134,7 +134,7 @@ export default class TaskPageViewModel {
this.showBoardInList(boardInfo); this.showBoardInList(boardInfo);
} }
this.updateIndices(); this.updateBoardIndices();
this.openLastUsedBoard(); this.openLastUsedBoard();
}; };
@@ -153,7 +153,7 @@ export default class TaskPageViewModel {
boardModel.boardHandlerManager.addHandler( boardModel.boardHandlerManager.addHandler(
(boardInfoFileContent: BoardInfoFileContent) => { (boardInfoFileContent: BoardInfoFileContent) => {
this.showBoardInList(boardInfoFileContent); this.showBoardInList(boardInfoFileContent);
this.updateIndices(); this.updateBoardIndices();
} }
); );
} }
+27 -1
View File
@@ -3,6 +3,7 @@ import * as React from "bloatless-react";
import BoardModel, { TaskFileContent } from "../../Model/Files/boardModel"; import BoardModel, { TaskFileContent } from "../../Model/Files/boardModel";
import BoardViewModel from "./boardViewModel"; import BoardViewModel from "./boardViewModel";
import { padZero } from "../../Model/Utility/utility";
export default class TaskViewModel { export default class TaskViewModel {
boardModel: BoardModel; boardModel: BoardModel;
@@ -12,14 +13,33 @@ export default class TaskViewModel {
// data // data
task: TaskFileContent; 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 // paths
getFilePath = (): string[] => { getFilePath = (): string[] => {
return this.boardModel.getTaskFilePath(this.task.fileId); return this.boardModel.getTaskFilePath(this.task.fileId);
}; };
// state // 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(""); description: React.State<string> = new React.State("");
category: React.State<string> = new React.State(""); category: React.State<string> = new React.State("");
@@ -43,6 +63,11 @@ export default class TaskViewModel {
this.save(); this.save();
}; };
updateIndex = (): void => {
const index: number = this.boardViewModel.taskIndexManager.getIndex(this);
this.index.value = index;
};
// settings // settings
save = (): void => { save = (): void => {
const newTaskFileContent: TaskFileContent = const newTaskFileContent: TaskFileContent =
@@ -61,6 +86,7 @@ export default class TaskViewModel {
this.boardModel.updateTaskAndSend(newTaskFileContent); this.boardModel.updateTaskAndSend(newTaskFileContent);
this.boardViewModel.showTaskInList(newTaskFileContent); this.boardViewModel.showTaskInList(newTaskFileContent);
this.boardViewModel.updateTaskIndices();
}; };
deleteTask = (): void => { deleteTask = (): void => {