src/app/features/todos/model/todo.ts

Description

Base Entity Type for the Todo Feature.

All fields are defined in config (in the database) and customized there, this class only serves as an interface for required fields upon which core functionalities are built.

Extends

Entity

Relationships

Used by

No results matching.

Depends on

Index

Properties
Methods
Accessors

Properties

assignedTo
Type : string[]
Default value : []
Decorators :
@DatabaseField({label: undefined, dataType: 'entity', isArray: true, additional: 'User', showInDetailsView: true, defaultValue: undefined, anonymize: 'retain'})
Optional completed
Type : TodoCompletion
Decorators :
@DatabaseField({label: undefined, viewComponent: 'DisplayTodoCompletion', editComponent: 'EditTodoCompletion', anonymize: 'retain'})
deadline
Type : Date
Decorators :
@DatabaseField({dataType: 'date-only', label: undefined, showInDetailsView: true, anonymize: 'retain'})
description
Type : string
Default value : ""
Decorators :
@DatabaseField({label: undefined, editComponent: 'EditLongText', showInDetailsView: true})
Static hasPII
Type : unknown
Default value : true
Inherited from Entity
Static icon
Type : IconName
Default value : "tasks"
Inherited from Entity
Static label
Type : unknown
Default value : $localize`:label for entity:Task`
Inherited from Entity
Static labelPlural
Type : unknown
Default value : $localize`:label (plural) for entity:Tasks`
relatedEntities
Type : string[]
Default value : []
Decorators :
@DatabaseField({dataType: 'entity', isArray: true, label: undefined, additional: undefined, entityReferenceRole: 'composite', showInDetailsView: true, anonymize: 'retain'})

other records (e.g. a recurring activity, group membership, ...) to which this task is related in some way.

This property saves ids including their entity type prefix.

repetitionInterval
Type : TimeInterval
Decorators :
@DatabaseField({label: undefined, additional: undefined, showInDetailsView: true, anonymize: 'retain'})
startDate
Type : Date
Decorators :
@DatabaseField({dataType: 'date-only', label: undefined, description: undefined, showInDetailsView: true, anonymize: 'retain'})
subject
Type : string
Default value : ""
Decorators :
@DatabaseField({label: undefined, showInDetailsView: true})
Static toStringAttributes
Type : []
Default value : ["subject"]
Inherited from Entity
Static Optional _isCustomizedType
todo: This property is no longer used and will be removed in future versions.
Type : boolean
Inherited from Entity

True if this type's schema has been customized dynamically from the config.

_rev
Type : string
Decorators :
@DatabaseField({anonymize: 'retain', isInternalField: true})
Inherited from Entity

internal database doc revision, used to detect conflicts by PouchDB/CouchDB

anonymized
Type : boolean
Decorators :
@DatabaseField({anonymize: 'retain', isInternalField: true})
Inherited from Entity

Whether this entity has been anonymized and therefore cannot be re-activated.

Static color
Type : string | ColorMapping[]
Inherited from Entity

color used for to highlight this entity type across the app.

Can be either:

  • A simple string (hex color code) for a single color
  • An array of ColorMapping objects for conditional colors based on entity properties
created
Type : UpdateMetadata
Decorators :
@DatabaseField({anonymize: 'retain', isInternalField: true})
Inherited from Entity
Static DATABASE
Type : string
Default value : "app"
Inherited from Entity

The database where these entities are stored.

Static Optional enableUserAccounts
Type : boolean
Inherited from Entity

Whether to enable user account creation for this entity type. When true, the UI will allow management of user accounts associated with this entity.

Static ENTITY_TYPE
Type : string
Default value : "Entity"
Inherited from Entity

The entity's type. In classes extending Entity this is usually overridden by the class annotation @DatabaseEntity('NewEntity'). The type needs to be used as routing path in lower case. The routing path can be defined in the configuration file.

inactive
Type : boolean
Decorators :
@DatabaseField({anonymize: 'retain', isInternalField: true})
Inherited from Entity
Static Optional isInternalEntity
Type : boolean
Inherited from Entity

if this entity type is an internal entity, i.e. only defined in the code base to store internal system data and not visible to the user for customization.

Static schema
Type : EntitySchema
Inherited from Entity

EntitySchema defining property transformations from/to the database. This is auto-generated from the property annotations @DatabaseField().

see /additional-documentation/how-to-guides/create-a-new-entity-type.html

Static Optional toBlockDetailsAttributes
Type : EntityBlockConfig
Inherited from Entity

Defining which attributes will be displayed in a tooltip on hover when the record is displayed as an entity-block.

updated
Type : UpdateMetadata
Decorators :
@DatabaseField({anonymize: 'retain', isInternalField: true})
Inherited from Entity

Methods

Static create
create(properties: Partial<Todo>)
Parameters :
Name Type Optional
properties Partial<Todo> No
Returns : Todo
getWarningLevel
getWarningLevel()
Inherited from Entity
Returns : WarningLevel
assertValid
assertValid()
Inherited from Entity

Checks if the entity is valid and if the check fails, throws an error explaining the failed check.

Returns : void
Public copy
copy(newId: string | boolean)
Inherited from Entity

Deep copy of the entity. The resulting entity will be of the same type as this (taking into account subclassing). All schema field values that are objects or arrays are deep-cloned to avoid shared mutable state between original and copy.

Parameters :
Name Type Optional Default value Description
newId string | boolean No false

if true, a new entityId will be generated; if a string, that value is used as new entityId

Returns : unknown
Static createPrefixedId
createPrefixedId(type: string, id: string)
Inherited from Entity

Create a prefixed id by adding the type prefix if it isn't already part of the given id.

Parameters :
Name Type Optional Description
type string No

The type prefix to be added.

id string No

The id to be extended with a prefix.

Returns : string
Static extractEntityIdFromId
extractEntityIdFromId(id: string)
Inherited from Entity

Extract entityId without prefix.

Parameters :
Name Type Optional Description
id string No

An entity's id including prefix.

Returns : string
Static extractTypeFromId
extractTypeFromId(id: string)
Inherited from Entity

Extract the ENTITY_TYPE from an id.

Parameters :
Name Type Optional Description
id string No

An entity's id including prefix.

Returns : string
Public getColor
getColor()
Inherited from Entity

Used by some generic UI components to set the color for the entity instance. Override this method as needed.

Returns : string
Static getColorWithConditions
getColorWithConditions(entity: Entity)
Inherited from Entity

Static method to evaluate conditional colors for an entity based on ColorMapping configuration.

Parameters :
Name Type Optional
entity Entity No
Returns : string
getConstructor
getConstructor()
Inherited from Entity

Get the class (Entity or the actual subclass of the instance) to call static methods on the correct class considering inheritance

Public getId
getId(withoutPrefix: unknown)
Inherited from Entity

Returns the id of this entity.

Note that an id is final and can't be changed after the object has been instantiated, hence there is no setId() method.

Parameters :
Name Type Optional Default value
withoutPrefix unknown No false
Returns : string

the unique id of this entity

getSchema
getSchema()
Inherited from Entity

Get the entity schema of this class

Returns : EntitySchema
Public getType
getType()
Inherited from Entity

Returns the type which is used to categorize this entity in the database.

Important: Do not overwrite this method! Types are handled internally.

Returns : string

the entity's type (which is the class name).

Accessors

isActive
getisActive()
isCompleted
getisCompleted()
isOverdue
getisOverdue()
import { DatabaseEntity } from "../../../core/entity/database-entity.decorator";
import { Entity } from "../../../core/entity/model/entity";
import { DatabaseField } from "../../../core/entity/database-field.decorator";
import { TimeInterval } from "../recurring-interval/time-interval";
import { TodoCompletion } from "./todo-completion";
import { WarningLevel } from "../../../child-dev-project/warning-level";
import { PLACEHOLDERS } from "../../../core/entity/schema/entity-schema-field";
import { IconName } from "@fortawesome/fontawesome-svg-core";

/**
 * Base Entity Type for the Todo Feature.
 *
 * All fields are defined in config (in the database) and customized there,
 * this class only serves as an interface for required fields upon which core functionalities are built.
 */
@DatabaseEntity("Todo")
export class Todo extends Entity {
  static override label = $localize`:label for entity:Task`;
  static override labelPlural = $localize`:label (plural) for entity:Tasks`;
  static override icon: IconName = "tasks";
  static override toStringAttributes = ["subject"];
  static override hasPII = true;

  static create(properties: Partial<Todo>): Todo {
    const instance = new Todo();
    Object.assign(instance, properties);
    return instance;
  }

  @DatabaseField({ label: $localize`:Label:Subject`, showInDetailsView: true })
  subject: string = "";

  @DatabaseField({
    dataType: "date-only",
    label: $localize`:Label:Deadline`,
    showInDetailsView: true,
    anonymize: "retain",
  })
  deadline: Date;

  @DatabaseField({
    dataType: "date-only",
    label: $localize`:Label:Start date`,
    description: $localize`:Description:When you are planning to start work so that you keep enough time before the actual hard deadline.`,
    showInDetailsView: true,
    anonymize: "retain",
  })
  startDate: Date;

  @DatabaseField({
    label: $localize`:Label:Description`,
    editComponent: "EditLongText",
    showInDetailsView: true,
  })
  description: string = "";

  @DatabaseField({
    label: $localize`:Label:Assigned to`,
    dataType: "entity",
    isArray: true,
    additional: "User",
    showInDetailsView: true,
    defaultValue: {
      mode: "dynamic",
      config: { value: PLACEHOLDERS.CURRENT_USER },
    },
    anonymize: "retain",
  })
  assignedTo: string[] = [];

  /**
   * other records (e.g. a recurring activity, group membership, ...) to which this task is related in some way.
   *
   * This property saves ids including their entity type prefix.
   */
  @DatabaseField({
    dataType: "entity",
    isArray: true,
    label: $localize`:label for the related Entities:Related Records`,
    additional: ["Child", "School", "RecurringActivity"],
    entityReferenceRole: "composite",
    showInDetailsView: true,
    anonymize: "retain",
  })
  relatedEntities: string[] = [];

  @DatabaseField({
    label: $localize`:label for Todo entity property:repeats`,
    additional: [
      {
        label: $localize`:repetition interval option:every week`,
        interval: { amount: 1, unit: "week" },
      },
      {
        label: $localize`:repetition interval option:every month`,
        interval: { amount: 1, unit: "month" },
      },
    ] as { label: string; interval: TimeInterval }[],
    showInDetailsView: true,
    anonymize: "retain",
  })
  repetitionInterval: TimeInterval;

  @DatabaseField({
    label: $localize`:label for Todo entity property:completed`,
    viewComponent: "DisplayTodoCompletion",
    editComponent: "EditTodoCompletion",
    anonymize: "retain",
  })
  completed?: TodoCompletion;

  override get isActive(): boolean {
    if (this.inactive) {
      // manual archiving of records takes precedence
      return false;
    }

    return !this.completed;
  }

  get isCompleted(): boolean {
    // used for filter
    return !!this.completed;
  }

  get isOverdue(): boolean {
    // used for filter
    return !!(
      !this.completed &&
      this.deadline &&
      this.deadline.getTime() < new Date().getTime()
    );
  }

  override getWarningLevel(): WarningLevel {
    if (this.isOverdue) {
      return WarningLevel.URGENT;
    }
    if (this.completed) {
      return WarningLevel.OK;
    }
    return WarningLevel.NONE;
  }
}

results matching ""

    No results matching ""