From 90bf610b02e1201a19d1e5761e7278a702100db8 Mon Sep 17 00:00:00 2001 From: Black Ram <67595890+BlackRam-oss@users.noreply.github.com> Date: Thu, 16 May 2024 09:01:23 +0200 Subject: [PATCH] refactor: Update ActivityStoredAbstract and ActivityRoom constructors to use ActivityStoredAbstract instead of ActivityModel in onRun parameter --- src/classes/Activity.ts | 73 ++++++++++++++++++++++++++ src/classes/navigation/ActivityRoom.ts | 6 +++ 2 files changed, 79 insertions(+) diff --git a/src/classes/Activity.ts b/src/classes/Activity.ts index 57ba7e8..54cec76 100644 --- a/src/classes/Activity.ts +++ b/src/classes/Activity.ts @@ -76,6 +76,9 @@ export abstract class ActivityStoredAbstract { abstract get id(): string private defaultName?: string + /** + * The name + */ get name(): string { return this.getStorageProperty("name") || this.defaultName || "" } @@ -84,6 +87,9 @@ export abstract class ActivityStoredAbstract { } private defaultFromHour?: number + /** + * The hour when the activity starts. If the activity is not started yet, it will be hidden. + */ get fromHour(): number { return this.getStorageProperty("fromHour") || this.defaultFromHour || TimeManager.minDayHours } @@ -92,6 +98,9 @@ export abstract class ActivityStoredAbstract { } private defaultToHour?: number + /** + * The hour when the activity ends. If the activity is ended yet, it will be hidden. + */ get toHour(): number { return this.getStorageProperty("toHour") || this.defaultToHour || (TimeManager.maxDayHours + 1) } @@ -100,6 +109,9 @@ export abstract class ActivityStoredAbstract { } private defaultFromDay?: number + /** + * The day when the activity starts. If the activity is not started yet, it will be hidden. + */ get fromDay(): number | undefined { return this.getStorageProperty("fromDay") || this.defaultFromDay } @@ -108,6 +120,9 @@ export abstract class ActivityStoredAbstract { } private defaultToDay?: number + /** + * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden. + */ get toDay(): number | undefined { return this.getStorageProperty("toDay") || this.defaultToDay } @@ -116,6 +131,9 @@ export abstract class ActivityStoredAbstract { } private defaultDisabled: boolean | string + /** + * Whether is disabled. + */ get disabled(): boolean { let value = this.getStorageProperty("disabled") || this.defaultDisabled if (typeof value === "string") { @@ -128,6 +146,9 @@ export abstract class ActivityStoredAbstract { } private defaultHidden: boolean | string + /** + * Whether is hidden. If the activity is not started yet, it will be hidden. + */ get hidden(): boolean { if (this.fromDay && this.fromDay > TimeManager.currentDay) { return true @@ -149,15 +170,25 @@ export abstract class ActivityStoredAbstract { } private _icon?: GraphicItemType + /** + * The icon element. + */ get icon(): GraphicItemType | undefined { return this._icon } private _onRun: (activity: ActivityStoredAbstract) => void + /** + * The function that is called when the activity is runned. + */ get onRun(): () => void { return () => this._onRun(this) } + /** + * Whether the activity is a deadline. + * @returns Whether the activity is a deadline. + */ isExpired(): boolean { if (this.toDay && this.toDay <= TimeManager.currentDay) { return true @@ -165,6 +196,10 @@ export abstract class ActivityStoredAbstract { return false } + /** + * Export the activity properties. + * @returns The activity properties. + */ export(): ActivityProps { return { name: this.getStorageProperty("name") || this.defaultName, @@ -202,36 +237,57 @@ export default class ActivityModel { } private _id: string + /** + * The activity id, that is unique. + */ get id(): string { return this._id } private _name?: string + /** + * The name + */ get name(): string | undefined { return this._name } private _fromHour?: number + /** + * The hour when the activity starts. If the activity is not started yet, it will be hidden. + */ get fromHour(): number | undefined { return this._fromHour } private _toHour?: number + /** + * The hour when the activity ends. If the activity is ended yet, it will be hidden. + */ get toHour(): number | undefined { return this._toHour } private _fromDay?: number + /** + * The day when the activity starts. If the activity is not started yet, it will be hidden. + */ get fromDay(): number | undefined { return this._fromDay } private _toDay?: number + /** + * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden. + */ get toDay(): number | undefined { return this._toDay } private _disabled?: boolean | string + /** + * Whether is disabled. + */ get disabled(): boolean | undefined { if (typeof this._disabled === "string") { return getFlag(this._disabled) @@ -240,6 +296,9 @@ export default class ActivityModel { } private _hidden: boolean | string + /** + * Whether is hidden. If the activity is not started yet, it will be hidden. + */ get hidden(): boolean { if (this.fromDay && this.fromDay > TimeManager.currentDay) { return true @@ -254,15 +313,25 @@ export default class ActivityModel { } private _icon?: GraphicItemType + /** + * The icon element. + */ get icon(): GraphicItemType | undefined { return this._icon } private _onRun: OnRunActivityEvent + /** + * The function that is called when the activity is runned. + */ get onRun(): () => void { return () => this._onRun(this) } + /** + * Whether the activity is a deadline. + * @returns Whether the activity is a deadline. + */ isDeadline(): boolean { if (this.toDay && this.toDay <= TimeManager.currentDay) { return true @@ -270,6 +339,10 @@ export default class ActivityModel { return false } + /** + * Export the activity properties. + * @returns The activity properties. + */ export(): ActivityProps { return { name: this._name, diff --git a/src/classes/navigation/ActivityRoom.ts b/src/classes/navigation/ActivityRoom.ts index 77df317..189ccda 100644 --- a/src/classes/navigation/ActivityRoom.ts +++ b/src/classes/navigation/ActivityRoom.ts @@ -1,6 +1,9 @@ import { ActivityProps, ActivityStoredAbstract, OnRunActivityEvent } from "../Activity"; import RoomBaseModel from "./Room"; +/** + * The activity generated by the room. + */ export class ActivityRoom extends ActivityStoredAbstract { constructor(id: string, room: TRoom, onRun: OnRunActivityEvent, props: ActivityProps) { super(onRun, props) @@ -21,6 +24,9 @@ export class ActivityRoom extends A get id(): string { return this._id; } + /** + * The room where the activity is. + */ private _room: TRoom; get room(): TRoom { return this._room;