diff --git a/dist/index.js b/dist/index.js index bf43d725..c892d6be 100644 --- a/dist/index.js +++ b/dist/index.js @@ -356,6 +356,9 @@ function stringify(data) { return JSON.stringify(data, null, 4); } + function padZero(string, length) { + return (string ?? "").padStart(length, "0"); + } function parse(string) { try { return JSON.parse(string); @@ -1440,11 +1443,25 @@ boardViewModel; // data 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 getFilePath = () => { return this.boardModel.getTaskFilePath(this.task.fileId); }; // state + index = new State(0); name = new State(""); description = new State(""); category = new State(""); @@ -1463,6 +1480,11 @@ this.close(); this.save(); }; + updateIndex = () => { + console.log(this.sortingString); + const index = this.boardViewModel.taskIndexManager.getIndex(this); + this.index.value = index; + }; // settings save = () => { const newTaskFileContent = BoardModel.createTaskFileContent( @@ -1478,6 +1500,7 @@ newTaskFileContent.time = this.time.value; this.boardModel.updateTaskAndSend(newTaskFileContent); this.boardViewModel.showTaskInList(newTaskFileContent); + this.boardViewModel.updateTaskIndices(); }; deleteTask = () => { this.close(); @@ -1510,6 +1533,9 @@ taskPageViewModel; // data boardInfo; + taskIndexManager = new IndexManager( + (taskViewModel) => taskViewModel.sortingString + ); // state name = new State(""); color = new State("standard" /* Standard */); @@ -1545,7 +1571,7 @@ this.taskPageViewModel.deleteBoard(this.boardInfo); this.close(); }; - // tasks + // methods createTask = () => { const taskFileContent = this.boardModel.createTask( this.boardInfo.fileId @@ -1556,6 +1582,11 @@ taskFileContent ); this.selectTask(taskViewModel); + this.updateTaskIndices(); + }; + removeTaskFromList = (taskId) => { + this.taskViewModels.remove(taskId); + this.updateIndex(); }; // storage storeLastUsedView = () => { @@ -1578,9 +1609,6 @@ ); this.taskViewModels.set(taskFileContent.fileId, taskViewModel); }; - removeTaskFromList = (taskId) => { - this.taskViewModels.remove(taskId); - }; select = () => { this.taskPageViewModel.selectBoard(this); }; @@ -1610,6 +1638,12 @@ const index = this.taskPageViewModel.boardIndexManager.getIndex(this); this.index.value = index; }; + updateTaskIndices = () => { + this.taskIndexManager.update([...this.taskViewModels.value.values()]); + for (const boardViewModel of this.taskViewModels.value.values()) { + boardViewModel.updateIndex(); + } + }; // load loadListRelevantData = () => { this.name.value = this.boardInfo.name; @@ -1630,6 +1664,7 @@ ); this.taskViewModels.set(taskFileContent.fileId, taskViewModel); } + this.updateTaskIndices(); }; loadData = () => { this.restoreLastUsedView(); @@ -1657,6 +1692,7 @@ (taskFileContent) => { if (taskFileContent.boardId != this.boardInfo.fileId) return; this.showTaskInList(taskFileContent); + this.updateTaskIndices(); } ); } @@ -1697,16 +1733,16 @@ this.newBoardNameInput.value = ""; this.showBoardInList(boardInfoFileContent); this.boardModel.updateBoardAndSend(boardInfoFileContent); - this.updateIndices(); + this.updateBoardIndices(); }; updateBoard = (boardInfoFileContent) => { this.boardModel.updateBoardAndSend(boardInfoFileContent); - this.updateIndices(); + this.updateBoardIndices(); }; deleteBoard = (boardInfoFileContent) => { this.boardModel.deleteBoard(boardInfoFileContent.fileId); this.boardViewModels.remove(boardInfoFileContent.fileId); - this.updateIndices(); + this.updateBoardIndices(); }; // view showBoardInList = (boardInfo) => { @@ -1728,7 +1764,7 @@ this.chatViewModel.resetColor(); this.storeLastUsedBoard(); }; - updateIndices = () => { + updateBoardIndices = () => { this.boardIndexManager.update([...this.boardViewModels.value.values()]); for (const boardViewModel of this.boardViewModels.value.values()) { boardViewModel.updateIndex(); @@ -1757,7 +1793,7 @@ if (boardInfo == null) continue; this.showBoardInList(boardInfo); } - this.updateIndices(); + this.updateBoardIndices(); this.openLastUsedBoard(); }; // init @@ -1768,7 +1804,7 @@ boardModel.boardHandlerManager.addHandler( (boardInfoFileContent) => { this.showBoardInList(boardInfoFileContent); - this.updateIndices(); + this.updateBoardIndices(); } ); } @@ -2378,6 +2414,9 @@ // src/View/Components/taskEntry.tsx function TaskEntry(taskViewModel) { 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; } var TaskViewModelToEntry = (taskViewModel) => { diff --git a/src/Model/Utility/utility.ts b/src/Model/Utility/utility.ts index 5bc72d88..51880737 100644 --- a/src/Model/Utility/utility.ts +++ b/src/Model/Utility/utility.ts @@ -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); diff --git a/src/View/Components/taskEntry.tsx b/src/View/Components/taskEntry.tsx index 5f737ac9..f5e0caae 100644 --- a/src/View/Components/taskEntry.tsx +++ b/src/View/Components/taskEntry.tsx @@ -9,6 +9,10 @@ export function TaskEntry(taskViewModel: TaskViewModel) { ); + taskViewModel.index.subscribe((newIndex) => { + view.style.order = newIndex; + }); + return view; } diff --git a/src/ViewModel/Pages/boardViewModel.ts b/src/ViewModel/Pages/boardViewModel.ts index de91e6c9..bbdc983b 100644 --- a/src/ViewModel/Pages/boardViewModel.ts +++ b/src/ViewModel/Pages/boardViewModel.ts @@ -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 = new IndexManager( + (taskViewModel: TaskViewModel) => taskViewModel.sortingString + ); + // state name: React.State = new React.State(""); color: React.State = new React.State(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(); } ); } diff --git a/src/ViewModel/Pages/taskPageViewModel.ts b/src/ViewModel/Pages/taskPageViewModel.ts index 88498490..dcc39429 100644 --- a/src/ViewModel/Pages/taskPageViewModel.ts +++ b/src/ViewModel/Pages/taskPageViewModel.ts @@ -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(); } ); } diff --git a/src/ViewModel/Pages/taskViewModel.ts b/src/ViewModel/Pages/taskViewModel.ts index f784f55a..bfb6995a 100644 --- a/src/ViewModel/Pages/taskViewModel.ts +++ b/src/ViewModel/Pages/taskViewModel.ts @@ -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 = new React.State(""); + index: React.State = new React.State(0); + name: React.State = new React.State(""); description: React.State = new React.State(""); category: React.State = 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 => {