diff --git a/dist/index.js b/dist/index.js index 37e78682..801bdafd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1365,6 +1365,192 @@ } }; + // src/View/utility.ts + function allowDrop(event) { + event.preventDefault(); + } + function allowDrag(event) { + event.dataTransfer?.setData("text", ""); + } + + // src/ViewModel/Pages/taskViewModel.ts + var TaskViewModel = class { + // init + constructor(coreViewModel, boardsAndTasksModel, boardViewModel, calendarPageViewModel, taskFileContent) { + this.coreViewModel = coreViewModel; + this.boardsAndTasksModel = boardsAndTasksModel; + this.boardViewModel = boardViewModel; + this.calendarPageViewModel = calendarPageViewModel; + this.task = taskFileContent; + this.loadAllData(); + this.selectedVersionId.subscribeSilent((selectedVersionId) => { + this.switchVersion(selectedVersionId); + }); + } + boardsAndTasksModel; + boardViewModel; + calendarPageViewModel; + // 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); + const invertedPriority = 100 - priorityNumber; + return year + month + date + hour + minute + invertedPriority + this.name.value; + } + // paths + getFilePath = () => { + return this.boardsAndTasksModel.getTaskFilePath(this.task.fileId); + }; + // state + index = new State(0); + boardId = new State(""); + name = new State(""); + description = new State(""); + category = new State(""); + status = new State(""); + priority = new State(""); + date = new State(""); + time = new State(""); + selectedVersionId = new State(""); + versionIds = new ListState(); + // methods + dragStart = (event) => { + allowDrag(event); + this.coreViewModel.draggedObject.value = this; + }; + setCategoryAndStatus = (category, status) => { + if (category != void 0) this.category.value = category; + if (status != void 0) this.status.value = status; + this.save(); + }; + setBoardId = (boardId) => { + this.boardId.value = boardId; + this.save(); + }; + // view + open = () => { + this.boardViewModel?.selectTask(this); + }; + close = () => { + this.boardViewModel?.closeTask(); + }; + closeAndSave = () => { + this.close(); + this.save(); + }; + updateIndex = () => { + if (this.boardViewModel == null) return; + const index = this.boardViewModel.taskIndexManager.getIndex(this); + this.index.value = index; + }; + // settings + save = () => { + const newTaskFileContent = BoardsAndTasksModel.createTaskFileContent( + this.task.fileId, + this.name.value, + this.task.boardId + ); + newTaskFileContent.boardId = this.boardId.value; + newTaskFileContent.description = this.description.value; + 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; + this.boardsAndTasksModel.updateTaskAndSend(newTaskFileContent); + if (this.boardViewModel != null) { + this.boardViewModel.showTaskInList(newTaskFileContent); + this.boardViewModel.updateTaskIndices(); + } + if (this.calendarPageViewModel != null) { + } + }; + deleteTask = () => { + this.close(); + this.boardsAndTasksModel.deleteTask(this.task.boardId, this.task.fileId); + if (this.boardViewModel != null) { + this.boardViewModel.removeTaskFromList(this.task.fileId); + } + if (this.calendarPageViewModel != null) { + } + }; + // load + loadVersionIds = () => { + const versionIds = this.boardsAndTasksModel.listTaskVersionIds( + this.task.fileId + ); + const sortedVersionIds = versionIds.sort(localeCompare).reverse(); + this.versionIds.clear(); + this.versionIds.add(...sortedVersionIds); + }; + switchVersion = (versionId) => { + const taskFileContent = this.boardsAndTasksModel.getSpecificTaskFileContent( + this.task.fileId, + versionId + ); + if (taskFileContent == null) return; + this.task = taskFileContent; + this.loadTaskData(); + }; + loadAllData = () => { + this.loadTaskData(); + this.loadVersionIds(); + }; + loadTaskData = () => { + this.boardId.value = this.task.boardId; + this.name.value = this.task.name; + this.description.value = this.task.description ?? ""; + this.category.value = this.task.category ?? ""; + this.status.value = this.task.status ?? ""; + this.priority.value = this.task.priority ?? ""; + this.date.value = this.task.date ?? ""; + this.time.value = this.task.time ?? ""; + this.selectedVersionId.value = this.task.fileContentId; + }; + }; + + // src/ViewModel/Pages/calendarPageViewModel.ts + var CalendarPageViewModel = class { + // init + constructor(coreViewModel, storageModel2, calendarModel, boardAndTasksModel) { + this.coreViewModel = coreViewModel; + this.storageModel = storageModel2; + this.calendarModel = calendarModel; + this.boardAndTasksModel = boardAndTasksModel; + } + storageModel; + calendarModel; + boardAndTasksModel; + // paths + getBasePath = () => { + return [...this.calendarModel.getViewPath()]; + }; + // state + taskViewModels = new MapState(); + // view + showTask = (taskFileContent) => { + const taskViewModel = new TaskViewModel( + this.coreViewModel, + this.boardAndTasksModel, + null, + this, + taskFileContent + ); + this.taskViewModels.set(taskFileContent.fileId, taskViewModel); + }; + // storage + // load + loadData = () => { + }; + }; + // src/ViewModel/Chat/chatMessageViewModel.ts var ChatMessageViewModel = class { // init @@ -1562,146 +1748,6 @@ }; }; - // src/View/utility.ts - function allowDrop(event) { - event.preventDefault(); - } - function allowDrag(event) { - event.dataTransfer?.setData("text", ""); - } - - // src/ViewModel/Pages/taskViewModel.ts - var TaskViewModel = class { - // init - constructor(coreViewModel, boardModel, boardViewModel, taskFileContent) { - this.coreViewModel = coreViewModel; - this.boardsAndTasksModel = boardModel; - this.boardViewModel = boardViewModel; - this.task = taskFileContent; - this.loadAllData(); - this.selectedVersionId.subscribeSilent((selectedVersionId) => { - this.switchVersion(selectedVersionId); - }); - } - boardsAndTasksModel; - 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); - const invertedPriority = 100 - priorityNumber; - return year + month + date + hour + minute + invertedPriority + this.name.value; - } - // paths - getFilePath = () => { - return this.boardsAndTasksModel.getTaskFilePath(this.task.fileId); - }; - // state - index = new State(0); - boardId = new State(""); - name = new State(""); - description = new State(""); - category = new State(""); - status = new State(""); - priority = new State(""); - date = new State(""); - time = new State(""); - selectedVersionId = new State(""); - versionIds = new ListState(); - // methods - dragStart = (event) => { - allowDrag(event); - this.coreViewModel.draggedObject.value = this; - }; - setCategoryAndStatus = (category, status) => { - if (category != void 0) this.category.value = category; - if (status != void 0) this.status.value = status; - this.save(); - }; - setBoardId = (boardId) => { - this.boardId.value = boardId; - this.save(); - }; - // view - open = () => { - this.boardViewModel.selectTask(this); - }; - close = () => { - this.boardViewModel.closeTask(); - }; - closeAndSave = () => { - this.close(); - this.save(); - }; - updateIndex = () => { - const index = this.boardViewModel.taskIndexManager.getIndex(this); - this.index.value = index; - }; - // settings - save = () => { - const newTaskFileContent = BoardsAndTasksModel.createTaskFileContent( - this.task.fileId, - this.name.value, - this.task.boardId - ); - newTaskFileContent.boardId = this.boardId.value; - newTaskFileContent.description = this.description.value; - 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; - this.boardsAndTasksModel.updateTaskAndSend(newTaskFileContent); - this.boardViewModel.showTaskInList(newTaskFileContent); - this.boardViewModel.updateTaskIndices(); - }; - deleteTask = () => { - this.close(); - this.boardsAndTasksModel.deleteTask(this.task.boardId, this.task.fileId); - this.boardViewModel.removeTaskFromList(this.task.fileId); - }; - // load - loadVersionIds = () => { - const versionIds = this.boardsAndTasksModel.listTaskVersionIds( - this.task.fileId - ); - const sortedVersionIds = versionIds.sort(localeCompare).reverse(); - this.versionIds.clear(); - this.versionIds.add(...sortedVersionIds); - }; - switchVersion = (versionId) => { - const taskFileContent = this.boardsAndTasksModel.getSpecificTaskFileContent( - this.task.fileId, - versionId - ); - if (taskFileContent == null) return; - this.task = taskFileContent; - this.loadTaskData(); - }; - loadAllData = () => { - this.loadTaskData(); - this.loadVersionIds(); - }; - loadTaskData = () => { - this.boardId.value = this.task.boardId; - this.name.value = this.task.name; - this.description.value = this.task.description ?? ""; - this.category.value = this.task.category ?? ""; - this.status.value = this.task.status ?? ""; - this.priority.value = this.task.priority ?? ""; - this.date.value = this.task.date ?? ""; - this.time.value = this.task.time ?? ""; - this.selectedVersionId.value = this.task.fileContentId; - }; - }; - // src/ViewModel/Pages/boardViewModel.ts var BoardViewModel = class { // init @@ -1782,6 +1828,7 @@ this.coreViewModel, this.boardsAndTasksModel, this, + null, taskFileContent ); this.selectTask(taskViewModel); @@ -1827,6 +1874,7 @@ this.coreViewModel, this.boardsAndTasksModel, this, + null, taskFileContent ); this.taskViewModels.set(taskFileContent.fileId, taskViewModel); @@ -1896,6 +1944,7 @@ this.coreViewModel, this.boardsAndTasksModel, this, + null, taskFileContent ); this.taskViewModels.set(taskFileContent.fileId, taskViewModel); @@ -1914,7 +1963,7 @@ constructor(coreViewModel, storageModel2, boardModel, chatViewModel) { this.coreViewModel = coreViewModel; this.storageModel = storageModel2; - this.boardModel = boardModel; + this.boardsAndTasksModel = boardModel; this.chatViewModel = chatViewModel; boardModel.boardHandlerManager.addHandler( (boardInfoFileContent) => { @@ -1924,7 +1973,7 @@ ); } storageModel; - boardModel; + boardsAndTasksModel; chatViewModel; // data boardIndexManager = new IndexManager( @@ -1932,7 +1981,7 @@ ); // paths getBasePath = () => { - return [...this.boardModel.getViewPath()]; + return [...this.boardsAndTasksModel.getViewPath()]; }; getBoardViewPath = (boardId) => { return [...this.getBasePath(), boardId]; @@ -1952,18 +2001,18 @@ // methods createBoard = () => { if (this.cannotCreateBoard.value == true) return; - const boardInfoFileContent = this.boardModel.createBoard(this.newBoardNameInput.value); + const boardInfoFileContent = this.boardsAndTasksModel.createBoard(this.newBoardNameInput.value); this.newBoardNameInput.value = ""; this.showBoardInList(boardInfoFileContent); - this.boardModel.updateBoardAndSend(boardInfoFileContent); + this.boardsAndTasksModel.updateBoardAndSend(boardInfoFileContent); this.updateBoardIndices(); }; updateBoard = (boardInfoFileContent) => { - this.boardModel.updateBoardAndSend(boardInfoFileContent); + this.boardsAndTasksModel.updateBoardAndSend(boardInfoFileContent); this.updateBoardIndices(); }; deleteBoard = (boardInfoFileContent) => { - this.boardModel.deleteBoard(boardInfoFileContent.fileId); + this.boardsAndTasksModel.deleteBoard(boardInfoFileContent.fileId); this.boardViewModels.remove(boardInfoFileContent.fileId); this.updateBoardIndices(); }; @@ -1972,7 +2021,7 @@ const boardViewModel = new BoardViewModel( this.coreViewModel, this.storageModel, - this.boardModel, + this.boardsAndTasksModel, this, boardInfo ); @@ -2011,9 +2060,9 @@ // load loadData = () => { this.boardViewModels.clear(); - const boardIds = this.boardModel.listBoardIds(); + const boardIds = this.boardsAndTasksModel.listBoardIds(); for (const boardId of boardIds) { - const boardInfo = this.boardModel.getBoardInfo(boardId); + const boardInfo = this.boardsAndTasksModel.getBoardInfo(boardId); if (boardInfo == null) continue; this.showBoardInList(boardInfo); } @@ -2031,6 +2080,12 @@ this.chatModel = chatModel; this.settingsViewModel = settingsViewModel2; this.chatListViewModel = chatListViewModel2; + this.calendarViewModel = new CalendarPageViewModel( + coreViewModel, + this.storageModel, + this.chatModel.fileModel.calendarModel, + this.chatModel.fileModel.boardsAndTasksModel + ); this.taskPageViewModel = new TaskPageViewModel( this.coreViewModel, this.storageModel, @@ -2057,6 +2112,7 @@ storageModel; settingsViewModel; chatListViewModel; + calendarViewModel; taskPageViewModel; messagePageViewModel; settingsPageViewModel; @@ -2182,6 +2238,12 @@ }; }; + // src/View/ChatPages/calendarPage.tsx + function CalendarPage(calendarPageViewModel) { + calendarPageViewModel.loadData(); + return /* @__PURE__ */ createElement("div", { id: "calendar-page" }); + } + // src/View/Components/ribbonButton.tsx function RibbonButton(label, icon, isSelected, select) { return /* @__PURE__ */ createElement( @@ -3319,6 +3381,9 @@ case "tasks" /* Tasks */: { return TaskPage(chatViewModel.taskPageViewModel); } + case "calendar" /* Calendar */: { + return CalendarPage(chatViewModel.calendarViewModel); + } default: { return MessagePage(chatViewModel.messagePageViewModel); } diff --git a/src/View/ChatPages/calendarPage.tsx b/src/View/ChatPages/calendarPage.tsx new file mode 100644 index 00000000..4071f663 --- /dev/null +++ b/src/View/ChatPages/calendarPage.tsx @@ -0,0 +1,9 @@ +import * as React from "bloatless-react"; + +import CalendarPageViewModel from "../../ViewModel/Pages/calendarPageViewModel"; + +export function CalendarPage(calendarPageViewModel: CalendarPageViewModel) { + calendarPageViewModel.loadData(); + + return
; +} diff --git a/src/View/chatPage.tsx b/src/View/chatPage.tsx index 985ea43a..e84b62ec 100644 --- a/src/View/chatPage.tsx +++ b/src/View/chatPage.tsx @@ -4,6 +4,7 @@ import * as React from "bloatless-react"; import ChatViewModel, { ChatPageType } from "../ViewModel/Chat/chatViewModel"; +import { CalendarPage } from "./ChatPages/calendarPage"; import { ChatViewToggleButton } from "./Components/chatViewToggleButton"; import { MessagePage } from "./ChatPages/messagePage"; import { SettingsPage } from "./ChatPages/settingsPage"; @@ -23,6 +24,9 @@ export function ChatPage(chatViewModel: ChatViewModel) { case ChatPageType.Tasks: { return TaskPage(chatViewModel.taskPageViewModel); } + case ChatPageType.Calendar: { + return CalendarPage(chatViewModel.calendarViewModel) + } default: { return MessagePage(chatViewModel.messagePageViewModel); } diff --git a/src/ViewModel/Chat/chatViewModel.ts b/src/ViewModel/Chat/chatViewModel.ts index b3677970..33c59d9e 100644 --- a/src/ViewModel/Chat/chatViewModel.ts +++ b/src/ViewModel/Chat/chatViewModel.ts @@ -1,8 +1,12 @@ import * as React from "bloatless-react"; import ChatModel, { ChatMessage } from "../../Model/Chat/chatModel"; -import StorageModel, { StorageModelSubPath, filePaths } from "../../Model/Global/storageModel"; +import StorageModel, { + StorageModelSubPath, + filePaths, +} from "../../Model/Global/storageModel"; +import CalendarPageViewModel from "../Pages/calendarPageViewModel"; import ChatListViewModel from "./chatListViewModel"; import { Color } from "../../colors"; import CoreViewModel from "../Global/coreViewModel"; @@ -17,6 +21,7 @@ export default class ChatViewModel { settingsViewModel: SettingsViewModel; chatListViewModel: ChatListViewModel; + calendarViewModel: CalendarPageViewModel; taskPageViewModel: TaskPageViewModel; messagePageViewModel: MessagePageViewModel; settingsPageViewModel: SettingsPageViewModel; @@ -91,6 +96,12 @@ export default class ChatViewModel { this.chatListViewModel = chatListViewModel; // page viewModels + this.calendarViewModel = new CalendarPageViewModel( + coreViewModel, + this.storageModel, + this.chatModel.fileModel.calendarModel, + this.chatModel.fileModel.boardsAndTasksModel + ); this.taskPageViewModel = new TaskPageViewModel( this.coreViewModel, this.storageModel, diff --git a/src/ViewModel/Pages/boardViewModel.ts b/src/ViewModel/Pages/boardViewModel.ts index 577337e6..57a3cfec 100644 --- a/src/ViewModel/Pages/boardViewModel.ts +++ b/src/ViewModel/Pages/boardViewModel.ts @@ -82,6 +82,7 @@ export default class BoardViewModel { this.coreViewModel, this.boardsAndTasksModel, this, + null, taskFileContent ); this.selectTask(taskViewModel); @@ -136,6 +137,7 @@ export default class BoardViewModel { this.coreViewModel, this.boardsAndTasksModel, this, + null, taskFileContent ); this.taskViewModels.set(taskFileContent.fileId, taskViewModel); @@ -222,6 +224,7 @@ export default class BoardViewModel { this.coreViewModel, this.boardsAndTasksModel, this, + null, taskFileContent ); this.taskViewModels.set(taskFileContent.fileId, taskViewModel); diff --git a/src/ViewModel/Pages/calendarPageViewModel.ts b/src/ViewModel/Pages/calendarPageViewModel.ts new file mode 100644 index 00000000..aacc434e --- /dev/null +++ b/src/ViewModel/Pages/calendarPageViewModel.ts @@ -0,0 +1,57 @@ +import * as React from "bloatless-react"; + +import BoardsAndTasksModel, { + TaskFileContent, +} from "../../Model/Files/boardsAndTasksModel"; + +import CalendarModel from "../../Model/Files/calendarModel"; +import CoreViewModel from "../Global/coreViewModel"; +import StorageModel from "../../Model/Global/storageModel"; +import TaskViewModel from "./taskViewModel"; + +export default class CalendarPageViewModel { + storageModel: StorageModel; + calendarModel: CalendarModel; + boardAndTasksModel: BoardsAndTasksModel; + + // paths + getBasePath = (): string[] => { + return [...this.calendarModel.getViewPath()]; + }; + + // state + taskViewModels: React.MapState