add chron to coreVM
This commit is contained in:
Vendored
+40
-4
@@ -660,8 +660,8 @@
|
|||||||
const monthPath = this.getMonthPath(monthString);
|
const monthPath = this.getMonthPath(monthString);
|
||||||
return this.storageModel.list(monthPath);
|
return this.storageModel.list(monthPath);
|
||||||
};
|
};
|
||||||
this.generateMonthGrid = (year, month, defaultValueCreator) => {
|
this.generateMonthGrid = (coreViewModel2, year, month, defaultValueCreator) => {
|
||||||
const date = /* @__PURE__ */ new Date();
|
const date = coreViewModel2.unwrappedTodayDate;
|
||||||
const isCurrentMonth = year == date.getFullYear() && month == date.getMonth() + 1;
|
const isCurrentMonth = year == date.getFullYear() && month == date.getMonth() + 1;
|
||||||
date.setDate(1);
|
date.setDate(1);
|
||||||
date.setMonth(month - 1);
|
date.setMonth(month - 1);
|
||||||
@@ -2290,6 +2290,17 @@
|
|||||||
if (isHandled == true) break;
|
if (isHandled == true) break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// CHRON
|
||||||
|
this.chronHandlerManager = new HandlerManager();
|
||||||
|
this.todayDate = new State(/* @__PURE__ */ new Date());
|
||||||
|
this.startChron = () => {
|
||||||
|
setInterval(this.chronHandlerManager.trigger, 2e3);
|
||||||
|
};
|
||||||
|
this.handleChron = () => {
|
||||||
|
const newDate = /* @__PURE__ */ new Date();
|
||||||
|
if (this.unwrappedTodayDate.toDateString() == newDate.toDateString()) return;
|
||||||
|
this.todayDate.value = /* @__PURE__ */ new Date();
|
||||||
|
};
|
||||||
// DRAG & DROP
|
// DRAG & DROP
|
||||||
this.draggedObject = new State(void 0);
|
this.draggedObject = new State(void 0);
|
||||||
// SUGGESTIONS
|
// SUGGESTIONS
|
||||||
@@ -2302,6 +2313,11 @@
|
|||||||
window.onpopstate = () => {
|
window.onpopstate = () => {
|
||||||
this.closeContext(this.context.contextId, true);
|
this.closeContext(this.context.contextId, true);
|
||||||
};
|
};
|
||||||
|
this.startChron();
|
||||||
|
this.chronHandlerManager.setHandler(
|
||||||
|
"core-view-model",
|
||||||
|
this.handleChron
|
||||||
|
);
|
||||||
}
|
}
|
||||||
get contexts() {
|
get contexts() {
|
||||||
return [...this.contextStack.values()];
|
return [...this.contextStack.values()];
|
||||||
@@ -2314,6 +2330,9 @@
|
|||||||
this.contextStack.set(context.contextId, context);
|
this.contextStack.set(context.contextId, context);
|
||||||
history.pushState({ id: context.contextId }, "");
|
history.pushState({ id: context.contextId }, "");
|
||||||
}
|
}
|
||||||
|
get unwrappedTodayDate() {
|
||||||
|
return new Date(this.todayDate.value);
|
||||||
|
}
|
||||||
// util
|
// util
|
||||||
static checkIsKeystroke(e) {
|
static checkIsKeystroke(e) {
|
||||||
return (e.metaKey || e.altKey) && e.ctrlKey;
|
return (e.metaKey || e.altKey) && e.ctrlKey;
|
||||||
@@ -2692,6 +2711,7 @@
|
|||||||
return [...this.calendarModel.getViewPath()];
|
return [...this.calendarModel.getViewPath()];
|
||||||
};
|
};
|
||||||
// state
|
// state
|
||||||
|
this.currentTodayDate = void 0;
|
||||||
this.selectedYear = new State(0);
|
this.selectedYear = new State(0);
|
||||||
this.selectedMonth = new State(0);
|
this.selectedMonth = new State(0);
|
||||||
this.selectedDate = new State(0);
|
this.selectedDate = new State(0);
|
||||||
@@ -2763,7 +2783,7 @@
|
|||||||
this.taskViewModels.remove(taskFileContent.fileId);
|
this.taskViewModels.remove(taskFileContent.fileId);
|
||||||
};
|
};
|
||||||
this.showToday = () => {
|
this.showToday = () => {
|
||||||
const today = /* @__PURE__ */ new Date();
|
const today = this.coreViewModel.todayDate.value;
|
||||||
this.selectedYear.value = today.getFullYear();
|
this.selectedYear.value = today.getFullYear();
|
||||||
this.selectedMonth.value = today.getMonth() + 1;
|
this.selectedMonth.value = today.getMonth() + 1;
|
||||||
this.selectedDate.value = today.getDate();
|
this.selectedDate.value = today.getDate();
|
||||||
@@ -2792,9 +2812,16 @@
|
|||||||
if (draggedObject instanceof TaskViewModel == false) return;
|
if (draggedObject instanceof TaskViewModel == false) return;
|
||||||
draggedObject.setDate(ISOString);
|
draggedObject.setDate(ISOString);
|
||||||
};
|
};
|
||||||
|
this.updateMonthGrid = () => {
|
||||||
|
if (this.currentTodayDate == this.coreViewModel.todayDate.value.toISOString())
|
||||||
|
return;
|
||||||
|
this.loadMonthTasks();
|
||||||
|
this.currentTodayDate = this.coreViewModel.todayDate.value.toISOString();
|
||||||
|
};
|
||||||
// load
|
// load
|
||||||
this.loadMonthTasks = () => {
|
this.loadMonthTasks = () => {
|
||||||
this.monthGrid.value = this.calendarModel.generateMonthGrid(
|
this.monthGrid.value = this.calendarModel.generateMonthGrid(
|
||||||
|
this.coreViewModel,
|
||||||
this.selectedYear.value,
|
this.selectedYear.value,
|
||||||
this.selectedMonth.value,
|
this.selectedMonth.value,
|
||||||
() => new MapState()
|
() => new MapState()
|
||||||
@@ -2823,6 +2850,10 @@
|
|||||||
this.showTask(taskFileContent);
|
this.showTask(taskFileContent);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
this.coreViewModel.chronHandlerManager.setHandler(
|
||||||
|
`calendar-${this.chatViewModel.chatModel.id}`,
|
||||||
|
this.updateMonthGrid
|
||||||
|
);
|
||||||
this.showToday();
|
this.showToday();
|
||||||
this.registerKeyStroke("-" /* Reset */, this.showToday);
|
this.registerKeyStroke("-" /* Reset */, this.showToday);
|
||||||
this.registerKeyStroke("k", this.showPreviousMonth);
|
this.registerKeyStroke("k", this.showPreviousMonth);
|
||||||
@@ -4000,7 +4031,12 @@
|
|||||||
[selectedDate],
|
[selectedDate],
|
||||||
() => selectedDate.value == parseInt(date)
|
() => selectedDate.value == parseInt(date)
|
||||||
);
|
);
|
||||||
const isToday = monthGrid.isCurrentMonth == true && parseInt(date) == (/* @__PURE__ */ new Date()).getDate();
|
const isToday = createProxyState(
|
||||||
|
[coreViewModel2.todayDate],
|
||||||
|
() => {
|
||||||
|
return monthGrid.isCurrentMonth == true && date == coreViewModel2.unwrappedTodayDate.getDate().toString();
|
||||||
|
}
|
||||||
|
);
|
||||||
const eventCount = createProxyState(
|
const eventCount = createProxyState(
|
||||||
[mapState],
|
[mapState],
|
||||||
() => mapState.value.size
|
() => mapState.value.size
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import FileModel, { FileModelSubPath } from "./fileModel";
|
|||||||
import SettingsModel from "../Global/settingsModel";
|
import SettingsModel from "../Global/settingsModel";
|
||||||
import StorageModel from "../Global/storageModel";
|
import StorageModel from "../Global/storageModel";
|
||||||
import { TaskFileContent } from "./boardsAndTasksModel";
|
import { TaskFileContent } from "./boardsAndTasksModel";
|
||||||
|
import CoreViewModel from "../../ViewModel/Global/coreViewModel";
|
||||||
|
|
||||||
export default class CalendarModel {
|
export default class CalendarModel {
|
||||||
readonly storageModel: StorageModel;
|
readonly storageModel: StorageModel;
|
||||||
@@ -57,12 +58,13 @@ export default class CalendarModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
generateMonthGrid = <T>(
|
generateMonthGrid = <T>(
|
||||||
|
coreViewModel: CoreViewModel,
|
||||||
year: number,
|
year: number,
|
||||||
month: number,
|
month: number,
|
||||||
defaultValueCreator: () => T,
|
defaultValueCreator: () => T,
|
||||||
): MonthGrid<T> => {
|
): MonthGrid<T> => {
|
||||||
// get today
|
// get today
|
||||||
const date: Date = new Date();
|
const date = coreViewModel.unwrappedTodayDate;
|
||||||
const isCurrentMonth: boolean =
|
const isCurrentMonth: boolean =
|
||||||
year == date.getFullYear() && month == date.getMonth() + 1;
|
year == date.getFullYear() && month == date.getMonth() + 1;
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,16 @@ export function MonthGrid<T>(
|
|||||||
() => selectedDate.value == parseInt(date),
|
() => selectedDate.value == parseInt(date),
|
||||||
);
|
);
|
||||||
|
|
||||||
const isToday: boolean =
|
const isToday = React.createProxyState(
|
||||||
|
[coreViewModel.todayDate],
|
||||||
|
() => {
|
||||||
|
return (
|
||||||
monthGrid.isCurrentMonth == true &&
|
monthGrid.isCurrentMonth == true &&
|
||||||
parseInt(date) == new Date().getDate();
|
date ==
|
||||||
|
coreViewModel.unwrappedTodayDate.getDate().toString()
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const eventCount: React.State<number> =
|
const eventCount: React.State<number> =
|
||||||
React.createProxyState(
|
React.createProxyState(
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import ConnectionModel from "../../Model/Global/connectionModel";
|
|||||||
import ChatListModel from "../../Model/Chat/chatListModel";
|
import ChatListModel from "../../Model/Chat/chatListModel";
|
||||||
import FileTransferModel from "../../Model/Global/fileTransferModel";
|
import FileTransferModel from "../../Model/Global/fileTransferModel";
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
|
import { HandlerManager } from "../../Model/Utility/utility";
|
||||||
|
|
||||||
export default class CoreViewModel {
|
export default class CoreViewModel {
|
||||||
readonly BUILD = "Build 26.04.15.B";
|
readonly BUILD = "Build 26.04.16.A";
|
||||||
|
|
||||||
translations: Translations;
|
translations: Translations;
|
||||||
|
|
||||||
@@ -58,6 +59,23 @@ export default class CoreViewModel {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// CHRON
|
||||||
|
chronHandlerManager = new HandlerManager<void>();
|
||||||
|
todayDate = new React.State<Date>(new Date());
|
||||||
|
get unwrappedTodayDate() {
|
||||||
|
return new Date(this.todayDate.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
startChron = (): void => {
|
||||||
|
setInterval(this.chronHandlerManager.trigger, 2000);
|
||||||
|
};
|
||||||
|
|
||||||
|
handleChron = (): void => {
|
||||||
|
const newDate = new Date();
|
||||||
|
if (this.unwrappedTodayDate.toDateString() == newDate.toDateString()) return;
|
||||||
|
this.todayDate.value = new Date();
|
||||||
|
};
|
||||||
|
|
||||||
// DRAG & DROP
|
// DRAG & DROP
|
||||||
draggedObject: React.State<any> = new React.State<any>(undefined);
|
draggedObject: React.State<any> = new React.State<any>(undefined);
|
||||||
|
|
||||||
@@ -85,6 +103,12 @@ export default class CoreViewModel {
|
|||||||
window.onpopstate = () => {
|
window.onpopstate = () => {
|
||||||
this.closeContext(this.context.contextId, true);
|
this.closeContext(this.context.contextId, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.startChron();
|
||||||
|
this.chronHandlerManager.setHandler(
|
||||||
|
"core-view-model",
|
||||||
|
this.handleChron,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// util
|
// util
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// state
|
// state
|
||||||
|
currentTodayDate: string | undefined = undefined;
|
||||||
selectedYear: React.State<number> = new React.State(0);
|
selectedYear: React.State<number> = new React.State(0);
|
||||||
selectedMonth: React.State<number> = new React.State(0);
|
selectedMonth: React.State<number> = new React.State(0);
|
||||||
selectedDate: React.State<number> = new React.State(0);
|
selectedDate: React.State<number> = new React.State(0);
|
||||||
@@ -121,7 +122,7 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
showToday = (): void => {
|
showToday = (): void => {
|
||||||
const today: Date = new Date();
|
const today: Date = this.coreViewModel.todayDate.value;
|
||||||
this.selectedYear.value = today.getFullYear();
|
this.selectedYear.value = today.getFullYear();
|
||||||
this.selectedMonth.value = today.getMonth() + 1;
|
this.selectedMonth.value = today.getMonth() + 1;
|
||||||
this.selectedDate.value = today.getDate();
|
this.selectedDate.value = today.getDate();
|
||||||
@@ -158,9 +159,21 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
|||||||
draggedObject.setDate(ISOString);
|
draggedObject.setDate(ISOString);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateMonthGrid = (): void => {
|
||||||
|
if (
|
||||||
|
this.currentTodayDate ==
|
||||||
|
this.coreViewModel.todayDate.value.toISOString()
|
||||||
|
)
|
||||||
|
return;
|
||||||
|
this.loadMonthTasks();
|
||||||
|
this.currentTodayDate =
|
||||||
|
this.coreViewModel.todayDate.value.toISOString();
|
||||||
|
};
|
||||||
|
|
||||||
// load
|
// load
|
||||||
loadMonthTasks = (): void => {
|
loadMonthTasks = (): void => {
|
||||||
this.monthGrid.value = this.calendarModel.generateMonthGrid(
|
this.monthGrid.value = this.calendarModel.generateMonthGrid(
|
||||||
|
this.coreViewModel,
|
||||||
this.selectedYear.value,
|
this.selectedYear.value,
|
||||||
this.selectedMonth.value,
|
this.selectedMonth.value,
|
||||||
() => new React.MapState(),
|
() => new React.MapState(),
|
||||||
@@ -206,6 +219,10 @@ export default class CalendarPageViewModel extends TaskContainingPageViewModel {
|
|||||||
this.showTask(taskFileContent);
|
this.showTask(taskFileContent);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
this.coreViewModel.chronHandlerManager.setHandler(
|
||||||
|
`calendar-${this.chatViewModel.chatModel.id}`,
|
||||||
|
this.updateMonthGrid,
|
||||||
|
);
|
||||||
|
|
||||||
// initiate
|
// initiate
|
||||||
this.showToday();
|
this.showToday();
|
||||||
|
|||||||
Reference in New Issue
Block a user