PhoenixLiveCalendar.Resource (PhoenixLiveCalendar v0.1.0)

Copy Markdown View Source

Represents a schedulable resource such as a room, person, or piece of equipment.

Resources are displayed as columns (in day/week resource views) or rows (in timeline views). Events link to resources via resource_id or resource_ids.

Examples

# Simple room
%PhoenixLiveCalendar.Resource{id: "room-a", title: "Conference Room A"}

# Person with type
%PhoenixLiveCalendar.Resource{
  id: "dr-smith",
  title: "Dr. Smith",
  type: :person,
  color: "bg-accent"
}

# Hierarchical: building > room
%PhoenixLiveCalendar.Resource{id: "floor-1", title: "First Floor"}
%PhoenixLiveCalendar.Resource{id: "room-101", title: "Room 101", parent_id: "floor-1"}

Summary

Functions

Returns the children of this resource from a flat list of resources.

Returns whether this resource is a root (has no parent).

Returns only root-level resources from a list, sorted by order.

Builds a tree structure from a flat list of resources.

Types

t()

@type t() :: %PhoenixLiveCalendar.Resource{
  color: String.t() | nil,
  extra: map(),
  id: term(),
  order: integer() | nil,
  parent_id: term() | nil,
  title: String.t(),
  type: atom() | nil
}

Functions

children(resource, resources)

@spec children(t(), [t()]) :: [t()]

Returns the children of this resource from a flat list of resources.

root?(resource)

@spec root?(t()) :: boolean()

Returns whether this resource is a root (has no parent).

roots(resources)

@spec roots([t()]) :: [t()]

Returns only root-level resources from a list, sorted by order.

to_tree(resources)

@spec to_tree([t()]) :: [{t(), list()}]

Builds a tree structure from a flat list of resources.

Returns a list of {resource, children} tuples where children is recursively structured the same way.