timeline

package
v0.0.0-...-95891f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package timeline provides the timeline addon for campaigns. This file embeds the plugin's SQL migrations and static files so they are available in the compiled binary regardless of the runtime working directory.

Package timeline provides interactive visual timelines for campaigns. Each campaign can have multiple timelines that reference a calendar and display calendar events in a zoomable, draggable D3.js visualization. Events are linked (not copied) from the calendar, preserving a single source of truth. Entity groups organize events into swim-lanes.

Registers "timeline" with the widget-binding framework. A timeline's bindable instance is a timeline record.

The entity-page `BlockTimeline` renders a campaign-level preview list (lazy /timelines/preview) when unbound, so there is no single default instance: DefaultInstance returns (_, false). A binding makes the block render one specific timeline instead.

Index

Constants

View Source
const (
	ZoomEra     = "era"
	ZoomCentury = "century"
	ZoomDecade  = "decade"
	ZoomYear    = "year"
	ZoomMonth   = "month"
	ZoomDay     = "day"
)

Zoom level constants for the timeline visualization.

View Source
const PluginSlug = "timeline"

PluginSlug is the timeline plugin's registry key; its static files are served at /static/plugins/timeline/.

View Source
const WidgetTypeTimeline = "timeline"

WidgetTypeTimeline is the persisted widget_type discriminator for timelines — an append-only namespace value; never rename.

Variables

View Source
var MigrationsFS embed.FS

MigrationsFS contains the embedded SQL migration files for the timeline plugin.

View Source
var StaticAssetsFS embed.FS

StaticAssetsFS holds the timeline's widget scripts, loaded on sight through the plugin's Widgets registration.

View Source
var ValidConnectionStyles = []string{"arrow", "dashed", "dotted", "solid"}

ValidConnectionStyles lists the allowed line styles for event connections.

ValidZoomLevels is the ordered set of zoom levels from widest to narrowest.

Functions

func IconColumns

func IconColumns() []database.IconColumn

IconColumns lists this plugin's stored icon columns and the default that replaces an unusable value, for the boot-time icon reconciler.

func IsValidConnectionStyle

func IsValidConnectionStyle(s string) bool

IsValidConnectionStyle returns true if the given style is recognized.

func IsValidZoom

func IsValidZoom(z string) bool

IsValidZoom returns true if the given string is a recognized zoom level.

func NewTimelineWidgetType

func NewTimelineWidgetType(svc TimelineService) widgetbindings.WidgetType

NewTimelineWidgetType builds the timeline WidgetType for registration into the widget-binding registry at app startup.

func PublicTextColumns

func PublicTextColumns() []database.PublicTextColumn

PublicTextColumns lists this plugin's stored rich text that is served as stored to everyone who can see its timeline or event, for the boot-time reconciler that removes GM-only parts.

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService, addonSvc addons.AddonService)

RegisterRoutes sets up all timeline-related routes. Timeline routes are scoped to a campaign and require membership. CRUD and event management require Owner/Scribe roles; viewing requires Player.

Types

type AITimelineReader

type AITimelineReader interface {
	ListTimelines(ctx context.Context, campaignID string, v permissions.Viewer) ([]Timeline, error)
	ListTimelineEvents(ctx context.Context, timelineID, campaignID string, v permissions.Viewer) ([]EventLink, error)
}

AITimelineReader is the part of TimelineService the lookup reads.

type AITimelines

type AITimelines struct {
	// contains filtered or unexported fields
}

AITimelines is the timeline plugin's part of the AI engine (aiplug): the `timelines` lookup, each timeline with its events. It reads through the service's viewer-aware list methods, so a Director-only timeline or event, and the link to a page the viewer may not open, stay out for exactly the viewers the Timeline screens hide them from: Safe privacy and a player's key read as a player.

func NewAITimelines

func NewAITimelines(svc AITimelineReader, off func(ctx context.Context, campaignID string) string) *AITimelines

NewAITimelines builds the lookup over the timeline service. off may be nil.

func (*AITimelines) Answer

func (t *AITimelines) Answer(ctx context.Context, campaignID string, a aiplug.Actor, _ aiplug.Record) (string, string, error)

Answer lists the timelines the Actor may see. Director-only rows exist in the answer only for the Director team, and are marked there.

func (*AITimelines) LookupInfo

func (*AITimelines) LookupInfo() aiplug.LookupInfo

LookupInfo describes `what: timelines` and its tool. It is not owner-only: the service hides what the viewer may not see, so a player's key gets the player's timelines.

type BindingCleaner

type BindingCleaner interface {
	OnInstanceDeleted(ctx context.Context, campaignID, widgetType, instanceID string) (int, error)
}

BindingCleaner sweeps a deleted instance's widget bindings. Implemented by widgetbindings.Service; injected via SetBindingCleaner. Optional — nil means no binding framework wired (Resolve's render-time guard skips and deletes orphaned bindings).

type CalendarEra

type CalendarEra struct {
	Name      string `json:"name"`
	StartYear int    `json:"start_year"`
	EndYear   *int   `json:"end_year,omitempty"`
	Color     string `json:"color"`
}

CalendarEra is a lightweight reference to a calendar era for D3 visualization.

type CalendarEraLister

type CalendarEraLister interface {
	ListEras(ctx context.Context, campaignID, calendarID string, role int) ([]CalendarEra, error)
}

CalendarEraLister fetches calendar eras for the D3 visualization background bands. Implemented as an adapter in app/routes.go to avoid importing the calendar package. Takes campaignID for the same cross-campaign scoping as CalendarEventLister.

type CalendarEventLinkLister

type CalendarEventLinkLister interface {
	// CalendarName returns calendarID's display name in campaignID, or ""
	// if it doesn't exist OR role may not see it (a dm_only calendar's real
	// name must not leak to a Player/anonymous timeline viewer through this
	// display-only field). Never used for authorization itself, so either
	// miss degrades to a blank name rather than an error — the same
	// role-only viewer shape EventsByIDs below already uses (no per-request
	// user id carried by this interface, so a per-user visibility_rules
	// allow/deny list on the calendar itself is not evaluated here; role is
	// enough to keep a dm_only calendar's name from a Player).
	CalendarName(ctx context.Context, campaignID, calendarID string, role int) string
	// EventsByIDs returns calendar_events rows for the given ids (all drawn
	// from calendarID — a timeline links events from exactly one calendar,
	// its own CalendarID), role-filtered (dm_only) exactly like the calendar
	// plugin's own event reads: an event the given role may not see is
	// simply ABSENT from the result — never present with its content
	// blanked — the same behavior the deleted `JOIN calendar_events ce ...
	// WHERE ce.visibility = 'everyone'` gave a Player (the row disappeared,
	// it didn't degrade).
	EventsByIDs(ctx context.Context, calendarID, campaignID string, eventIDs []string, role int) ([]CalendarEventRef, error)
}

CalendarEventLinkLister resolves calendar_events details for a timeline's OWN timeline_event_links rows, plus a timeline's calendar_id display name — the calendar-name read and the event-link read path, both of which cross the plugin boundary. Implemented by calendarEventLinkListerAdapter in app/routes.go, wired through SetCalendarEventLinkLister; separate from CalendarLister/CalendarEventLister/CalendarEraLister above. Optional: nil (never wired) means no calendar event can be resolved, so a timeline shows standalone events only — degraded, not broken ("dark means safe").

type CalendarEventLister

type CalendarEventLister interface {
	ListEventsForCalendar(ctx context.Context, campaignID, calendarID string, role int) ([]CalendarEventRef, error)
}

CalendarEventLister fetches calendar events for the event picker. Implemented as an adapter in app/routes.go to avoid importing the calendar package. Takes campaignID so a calendar from another campaign never resolves here.

type CalendarEventRef

type CalendarEventRef struct {
	ID          string  `json:"id"`
	Name        string  `json:"name"`
	Description *string `json:"description,omitempty"`
	Year        int     `json:"year"`
	Month       int     `json:"month"`
	Day         int     `json:"day"`
	EndYear     *int    `json:"end_year,omitempty"`
	EndMonth    *int    `json:"end_month,omitempty"`
	EndDay      *int    `json:"end_day,omitempty"`
	Category    *string `json:"category,omitempty"`
	Visibility  string  `json:"visibility"`
	EntityID    *string `json:"entity_id,omitempty"`
	EntityName  string  `json:"entity_name,omitempty"`
	EntityIcon  string  `json:"entity_icon,omitempty"`
}

CalendarEventRef is a lightweight reference to a calendar event, used both by the event picker (CalendarEventLister, above) and by CalendarEventLinkLister (below) to enrich a timeline's OWN timeline_event_links rows with the calendar event data they point at.

Description/EndYear/EndMonth/EndDay are additive fields the picker's own use never needed (a picker row shows just name + date), but an already- LINKED event's card does — they mirror calendar.Event's own fields.

type CalendarLister

type CalendarLister interface {
	ListCalendars(ctx context.Context, campaignID string) ([]CalendarRef, error)
}

CalendarLister fetches calendars for the calendar selector dropdown. Implemented as an adapter in app/routes.go to avoid importing the calendar package.

type CalendarRef

type CalendarRef struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

CalendarRef is a lightweight reference to a calendar used in selector dropdowns.

type CalendarScope

type CalendarScope interface {
	// CalendarInCampaign reports whether calendarID exists in campaignID. A
	// missing or foreign calendar is (false, nil); err is for failed reads.
	CalendarInCampaign(ctx context.Context, campaignID, calendarID string) (bool, error)
}

CalendarScope confirms a calendar belongs to a campaign before a timeline is bound to it, so a timeline only ever reads a calendar from its own campaign. Implemented as an adapter in app/routes.go.

type CreateConnectionInput

type CreateConnectionInput struct {
	SourceID   string
	TargetID   string
	SourceType string
	TargetType string
	Label      *string
	Color      *string
	Style      string
}

CreateConnectionInput is the validated input for creating an event connection.

type CreateEntityGroupInput

type CreateEntityGroupInput struct {
	Name  string
	Color string
}

CreateEntityGroupInput is the validated input for creating an entity group.

type CreateTimelineEventInput

type CreateTimelineEventInput struct {
	Name            string
	Description     *string
	DescriptionHTML *string
	EntityID        *string
	Year            int
	Month           int
	Day             int
	StartHour       *int
	StartMinute     *int
	EndYear         *int
	EndMonth        *int
	EndDay          *int
	EndHour         *int
	EndMinute       *int
	IsRecurring     bool
	RecurrenceType  *string
	Category        *string
	Visibility      string
	Label           *string
	Color           *string
	CreatedBy       string
}

CreateTimelineEventInput is the validated input for creating a standalone event.

type CreateTimelineInput

type CreateTimelineInput struct {
	CampaignID  string
	CalendarID  *string
	Name        string
	Description *string
	Color       string
	Icon        string
	Visibility  string
	ZoomDefault string
	CreatedBy   string
}

CreateTimelineInput is the validated input for creating a timeline.

type EntityGroup

type EntityGroup struct {
	ID         int    `json:"id"`
	TimelineID string `json:"timeline_id"`
	Name       string `json:"name"`
	Color      string `json:"color"`
	SortOrder  int    `json:"sort_order"`

	// Eager-loaded members (populated by some queries).
	Members []EntityGroupMember `json:"members,omitempty"`
}

EntityGroup is a named group of entities used for swim-lane organization on the timeline visualization.

type EntityGroupMember

type EntityGroupMember struct {
	ID       int    `json:"id"`
	GroupID  int    `json:"group_id"`
	EntityID string `json:"entity_id"`

	// Joined fields.
	EntityName string `json:"entity_name,omitempty"`
	EntityIcon string `json:"entity_icon,omitempty"`
}

EntityGroupMember links an entity to an entity group.

type EntityVisibilityGate

type EntityVisibilityGate interface {
	FilterViewableEntityIDs(ctx context.Context, campaignID string, entityIDs []string, role int, userID string) (map[string]bool, error)
}

EntityVisibilityGate resolves which of a set of entity IDs a viewer (role + userID) may see, applying the entities plugin's own canonical visibility policy (default is_private, custom per-subject grants, tag grants). Wraps entities.EntityService.FilterViewableEntityIDs — the same seam maps, media, npcs and sessions use — so a timeline event or entity-group member naming a dm_only/private entity never leaks that entity's name/icon to a viewer who could not otherwise see it.

type EventConnection

type EventConnection struct {
	ID         int       `json:"id"`
	TimelineID string    `json:"timeline_id"`
	SourceID   string    `json:"source_id"`
	TargetID   string    `json:"target_id"`
	SourceType string    `json:"source_type"`
	TargetType string    `json:"target_type"`
	Label      *string   `json:"label,omitempty"`
	Color      *string   `json:"color,omitempty"`
	Style      string    `json:"style"`
	CreatedAt  time.Time `json:"created_at"`
}

EventConnection represents a visual link between two events on the timeline visualization, rendered as an SVG line or arrow.

type EventLink struct {
	ID                 int       `json:"id"`
	TimelineID         string    `json:"timeline_id"`
	EventID            string    `json:"event_id"`
	Source             string    `json:"source"`
	DisplayOrder       int       `json:"display_order"`
	VisibilityOverride *string   `json:"visibility_override,omitempty"`
	VisibilityRules    *string   `json:"visibility_rules,omitempty"`
	Label              *string   `json:"label,omitempty"`
	ColorOverride      *string   `json:"color_override,omitempty"`
	CreatedAt          time.Time `json:"created_at"`

	// Calendar event fields (joined from calendar_events).
	EventName        string  `json:"event_name,omitempty"`
	EventDescription *string `json:"event_description,omitempty"`
	EventYear        int     `json:"event_year"`
	EventMonth       int     `json:"event_month"`
	EventDay         int     `json:"event_day"`
	EventEndYear     *int    `json:"event_end_year,omitempty"`
	EventEndMonth    *int    `json:"event_end_month,omitempty"`
	EventEndDay      *int    `json:"event_end_day,omitempty"`
	EventCategory    *string `json:"event_category,omitempty"`
	EventVisibility  string  `json:"event_visibility,omitempty"`
	EventEntityID    *string `json:"event_entity_id,omitempty"`
	EventEntityName  string  `json:"event_entity_name,omitempty"`
	EventEntityIcon  string  `json:"event_entity_icon,omitempty"`
}

EventLink is the join between a timeline and a calendar event, with per-link overrides for display properties and visibility. Also used as the unified event view when merging linked calendar events with standalone events. Source distinguishes the origin: "calendar" or "standalone".

func (*EventLink) EffectiveColor

func (el *EventLink) EffectiveColor() string

EffectiveColor returns the display color — the override if set, otherwise empty string (use default).

func (*EventLink) EffectiveLabel

func (el *EventLink) EffectiveLabel() string

EffectiveLabel returns the display label — the override if set, otherwise the original calendar event name.

func (*EventLink) EffectiveVisibility

func (el *EventLink) EffectiveVisibility() string

EffectiveVisibility returns the visibility override if set, otherwise falls back to the original calendar event's visibility.

func (*EventLink) ParseVisibilityRules

func (el *EventLink) ParseVisibilityRules() *VisibilityRules

ParseVisibilityRules parses the JSON visibility rules on an event link. Returns nil if no rules are set.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler processes HTTP requests for the timeline plugin.

func NewHandler

func NewHandler(svc TimelineService) *Handler

NewHandler creates a new timeline Handler.

func (*Handler) AddGroupMemberAPI

func (h *Handler) AddGroupMemberAPI(c *echo.Context) error

AddGroupMemberAPI adds an entity to an entity group. POST /campaigns/:id/timelines/:tid/groups/:gid/members

func (*Handler) CreateConnectionAPI

func (h *Handler) CreateConnectionAPI(c *echo.Context) error

CreateConnectionAPI creates a connection between two events on a timeline. POST /campaigns/:id/timelines/:tid/connections

func (*Handler) CreateEntityGroupAPI

func (h *Handler) CreateEntityGroupAPI(c *echo.Context) error

CreateEntityGroupAPI creates a new entity group for swim-lane organization. POST /campaigns/:id/timelines/:tid/groups

func (*Handler) CreateForm

func (h *Handler) CreateForm(c *echo.Context) error

CreateForm handles timeline creation from a form POST. POST /campaigns/:id/timelines

func (*Handler) CreateStandaloneEventAPI

func (h *Handler) CreateStandaloneEventAPI(c *echo.Context) error

CreateStandaloneEventAPI creates a new standalone event on a timeline. POST /campaigns/:id/timelines/:tid/standalone-events

func (*Handler) DeleteAPI

func (h *Handler) DeleteAPI(c *echo.Context) error

DeleteAPI deletes a timeline and all associated data. DELETE /campaigns/:id/timelines/:tid

func (*Handler) DeleteConnectionAPI

func (h *Handler) DeleteConnectionAPI(c *echo.Context) error

DeleteConnectionAPI removes a connection between two events. DELETE /campaigns/:id/timelines/:tid/connections/:cid

func (*Handler) DeleteEntityGroupAPI

func (h *Handler) DeleteEntityGroupAPI(c *echo.Context) error

DeleteEntityGroupAPI removes an entity group and all its members. DELETE /campaigns/:id/timelines/:tid/groups/:gid

func (*Handler) DeleteStandaloneEventAPI

func (h *Handler) DeleteStandaloneEventAPI(c *echo.Context) error

DeleteStandaloneEventAPI removes a standalone event from a timeline. DELETE /campaigns/:id/timelines/:tid/standalone-events/:eid

func (*Handler) EmbedTimeline

func (h *Handler) EmbedTimeline(c *echo.Context) error

EmbedTimeline returns a compact timeline visualization fragment for dashboard embedding. GET /campaigns/:id/timelines/embed

func (*Handler) Index

func (h *Handler) Index(c *echo.Context) error

Index lists all timelines for a campaign. GET /campaigns/:id/timelines

func (*Handler) LinkAllEventsAPI

func (h *Handler) LinkAllEventsAPI(c *echo.Context) error

LinkAllEventsAPI links all available calendar events to a timeline at once. POST /campaigns/:id/timelines/:tid/events/all

func (*Handler) LinkEventAPI

func (h *Handler) LinkEventAPI(c *echo.Context) error

LinkEventAPI links a calendar event to a timeline. POST /campaigns/:id/timelines/:tid/events

func (*Handler) ListAvailableEventsAPI

func (h *Handler) ListAvailableEventsAPI(c *echo.Context) error

ListAvailableEventsAPI returns calendar events not yet linked to a timeline. GET /campaigns/:id/timelines/:tid/available-events

func (*Handler) ListCalendarsAPI

func (h *Handler) ListCalendarsAPI(c *echo.Context) error

ListCalendarsAPI returns available calendars for the create timeline form. GET /campaigns/:id/timelines/calendars

func (*Handler) ListCampaignMembersAPI

func (h *Handler) ListCampaignMembersAPI(c *echo.Context) error

ListCampaignMembersAPI returns campaign members for the visibility user selector. GET /campaigns/:id/timelines/members

func (*Handler) ListConnectionsAPI

func (h *Handler) ListConnectionsAPI(c *echo.Context) error

ListConnectionsAPI returns the timeline's connections between events the viewer may see. GET /campaigns/:id/timelines/:tid/connections

func (*Handler) ListEntityGroupsAPI

func (h *Handler) ListEntityGroupsAPI(c *echo.Context) error

ListEntityGroupsAPI returns all entity groups for a timeline. GET /campaigns/:id/timelines/:tid/groups

func (*Handler) PreviewAPI

func (h *Handler) PreviewAPI(c *echo.Context) error

PreviewAPI returns an HTMX fragment for the dashboard timeline preview block. GET /campaigns/:id/timelines/preview

func (*Handler) RemoveGroupMemberAPI

func (h *Handler) RemoveGroupMemberAPI(c *echo.Context) error

RemoveGroupMemberAPI removes an entity from an entity group. DELETE /campaigns/:id/timelines/:tid/groups/:gid/members/:eid

func (*Handler) SetAuditService

func (h *Handler) SetAuditService(svc audit.AuditService)

SetAuditService wires the audit-log emitter for timeline mutations. Called after all plugins are constructed (matches entities pattern).

func (*Handler) SetMemberLister

func (h *Handler) SetMemberLister(ml campaigns.MemberLister)

SetMemberLister injects the campaign member lister for visibility settings.

func (*Handler) Show

func (h *Handler) Show(c *echo.Context) error

Show renders a single timeline with its events. GET /campaigns/:id/timelines/:tid

func (*Handler) TimelineDataAPI

func (h *Handler) TimelineDataAPI(c *echo.Context) error

TimelineDataAPI returns JSON data for the D3.js timeline visualization. GET /campaigns/:id/timelines/:tid/data

func (*Handler) UnlinkEventAPI

func (h *Handler) UnlinkEventAPI(c *echo.Context) error

UnlinkEventAPI removes a calendar event from a timeline. DELETE /campaigns/:id/timelines/:tid/events/:eid

func (*Handler) UpdateAPI

func (h *Handler) UpdateAPI(c *echo.Context) error

UpdateAPI updates timeline settings. PUT /campaigns/:id/timelines/:tid

func (*Handler) UpdateEntityGroupAPI

func (h *Handler) UpdateEntityGroupAPI(c *echo.Context) error

UpdateEntityGroupAPI modifies an existing entity group. PUT /campaigns/:id/timelines/:tid/groups/:gid

func (*Handler) UpdateEventVisibilityAPI

func (h *Handler) UpdateEventVisibilityAPI(c *echo.Context) error

UpdateEventVisibilityAPI updates per-event visibility on a timeline event link. PUT /campaigns/:id/timelines/:tid/events/:eid/visibility

func (*Handler) UpdateStandaloneEventAPI

func (h *Handler) UpdateStandaloneEventAPI(c *echo.Context) error

UpdateStandaloneEventAPI modifies a standalone event. PUT /campaigns/:id/timelines/:tid/standalone-events/:eid

func (*Handler) UpdateStandaloneEventVisibilityAPI

func (h *Handler) UpdateStandaloneEventVisibilityAPI(c *echo.Context) error

UpdateStandaloneEventVisibilityAPI updates visibility and per-user rules on a standalone event. PUT /campaigns/:id/timelines/:tid/standalone-events/:eid/visibility

func (*Handler) UpdateTimelineVisibilityAPI

func (h *Handler) UpdateTimelineVisibilityAPI(c *echo.Context) error

UpdateTimelineVisibilityAPI updates timeline visibility and per-user rules. PUT /campaigns/:id/timelines/:tid/visibility

type LinkEventInput

type LinkEventInput struct {
	Label         *string
	ColorOverride *string
}

LinkEventInput is the validated input for linking a calendar event to a timeline.

type MemberRef

type MemberRef struct {
	UserID   string `json:"user_id"`
	Username string `json:"username"`
	Role     string `json:"role"`
}

MemberRef is a lightweight reference to a campaign member for the visibility rules user selector.

type Timeline

type Timeline struct {
	ID              string    `json:"id"`
	CampaignID      string    `json:"campaign_id"`
	CalendarID      *string   `json:"calendar_id,omitempty"`
	Name            string    `json:"name"`
	Description     *string   `json:"description,omitempty"`
	DescriptionHTML *string   `json:"description_html,omitempty"`
	Color           string    `json:"color"`
	Icon            string    `json:"icon"`
	Visibility      string    `json:"visibility"`
	VisibilityRules *string   `json:"visibility_rules,omitempty"`
	SortOrder       int       `json:"sort_order"`
	ZoomDefault     string    `json:"zoom_default"`
	CreatedBy       *string   `json:"created_by,omitempty"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`

	// Joined fields (populated by some queries).
	CalendarName string `json:"calendar_name,omitempty"`
	EventCount   int    `json:"event_count,omitempty"`
}

Timeline is a named visual timeline within a campaign. It optionally references a calendar for date context and linked calendar events. When CalendarID is nil, the timeline only contains standalone events.

func (*Timeline) GetCampaignID

func (t *Timeline) GetCampaignID() string

GetCampaignID returns the campaign this timeline belongs to. Implements middleware.CampaignScoped for generic IDOR protection.

func (*Timeline) HasCalendar

func (t *Timeline) HasCalendar() bool

HasCalendar returns true if this timeline is linked to a calendar.

func (*Timeline) IsDMOnly

func (t *Timeline) IsDMOnly() bool

IsDMOnly returns true if this timeline is only visible to the DM.

func (*Timeline) ParseVisibilityRules

func (t *Timeline) ParseVisibilityRules() *VisibilityRules

ParseVisibilityRules parses the JSON visibility rules into a VisibilityRules struct. Returns nil if no rules are set.

type TimelineEvent

type TimelineEvent struct {
	ID              string    `json:"id"`
	TimelineID      string    `json:"timeline_id"`
	EntityID        *string   `json:"entity_id,omitempty"`
	Name            string    `json:"name"`
	Description     *string   `json:"description,omitempty"`
	DescriptionHTML *string   `json:"description_html,omitempty"`
	Year            int       `json:"year"`
	Month           int       `json:"month"`
	Day             int       `json:"day"`
	StartHour       *int      `json:"start_hour,omitempty"`
	StartMinute     *int      `json:"start_minute,omitempty"`
	EndYear         *int      `json:"end_year,omitempty"`
	EndMonth        *int      `json:"end_month,omitempty"`
	EndDay          *int      `json:"end_day,omitempty"`
	EndHour         *int      `json:"end_hour,omitempty"`
	EndMinute       *int      `json:"end_minute,omitempty"`
	IsRecurring     bool      `json:"is_recurring"`
	RecurrenceType  *string   `json:"recurrence_type,omitempty"`
	Category        *string   `json:"category,omitempty"`
	Visibility      string    `json:"visibility"`
	VisibilityRules *string   `json:"visibility_rules,omitempty"`
	DisplayOrder    int       `json:"display_order"`
	Label           *string   `json:"label,omitempty"`
	Color           *string   `json:"color,omitempty"`
	CreatedBy       *string   `json:"created_by,omitempty"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`

	// Joined fields (populated by queries that LEFT JOIN entities).
	EntityName string `json:"entity_name,omitempty"`
	EntityIcon string `json:"entity_icon,omitempty"`
}

TimelineEvent is a standalone event that belongs directly to a timeline without requiring a calendar. Provides full parity with calendar events (multi-day spans, times, recurrence) while being owned 1:N by a timeline.

func (e *TimelineEvent) ToEventLink() EventLink

ToEventLink converts a standalone TimelineEvent to an EventLink for unified rendering in the D3 visualization and event list.

type TimelineListData

type TimelineListData struct {
	CampaignID string
	Timelines  []Timeline
	IsOwner    bool
	IsScribe   bool
	CSRFToken  string
}

TimelineListData holds all data needed to render the timeline list page.

type TimelineRepository

type TimelineRepository interface {
	// Timeline CRUD.
	Create(ctx context.Context, t *Timeline) error
	GetByID(ctx context.Context, id string) (*Timeline, error)
	List(ctx context.Context, campaignID string, role int) ([]Timeline, error)
	ListByCalendar(ctx context.Context, calendarID string, role int) ([]Timeline, error)
	Update(ctx context.Context, t *Timeline) error
	Delete(ctx context.Context, id string) error

	// Search.
	Search(ctx context.Context, campaignID, query string, role int) ([]Timeline, error)

	// Event links.
	LinkEvent(ctx context.Context, link *EventLink) error
	UnlinkEvent(ctx context.Context, timelineID, eventID string) error
	ListEventLinks(ctx context.Context, timelineID string, role int) ([]EventLink, error)
	CountEvents(ctx context.Context, timelineID string) (int, error)

	// Event link visibility.
	UpdateEventLinkVisibility(ctx context.Context, timelineID, eventID string, visOverride, visRules patch.Field[string]) error

	// Standalone events.
	CreateEvent(ctx context.Context, e *TimelineEvent) error
	GetEvent(ctx context.Context, eventID string) (*TimelineEvent, error)
	UpdateEvent(ctx context.Context, e *TimelineEvent) error
	DeleteEvent(ctx context.Context, eventID string) error
	ListStandaloneEvents(ctx context.Context, timelineID string, role int) ([]TimelineEvent, error)
	CountStandaloneEvents(ctx context.Context, timelineID string) (int, error)

	// Entity groups.
	CreateEntityGroup(ctx context.Context, g *EntityGroup) error
	UpdateEntityGroup(ctx context.Context, g *EntityGroup) error
	DeleteEntityGroup(ctx context.Context, groupID int, timelineID string) error
	ListEntityGroups(ctx context.Context, timelineID string) ([]EntityGroup, error)
	AddGroupMember(ctx context.Context, groupID int, timelineID, entityID string) error
	RemoveGroupMember(ctx context.Context, groupID int, timelineID, entityID string) error

	// Event connections.
	CreateConnection(ctx context.Context, c *EventConnection) error
	DeleteConnection(ctx context.Context, connectionID int, timelineID string) error
	ListConnections(ctx context.Context, timelineID string) ([]EventConnection, error)
}

TimelineRepository defines persistence operations for timelines and related data.

func NewTimelineRepository

func NewTimelineRepository(db *sql.DB) TimelineRepository

NewTimelineRepository creates a new MariaDB-backed timeline repository.

type TimelineService

type TimelineService interface {
	// Timeline CRUD.
	CreateTimeline(ctx context.Context, campaignID string, input CreateTimelineInput) (*Timeline, error)
	GetTimeline(ctx context.Context, timelineID string) (*Timeline, error)
	// GetTimelineForViewer is GetTimeline's viewer-aware sibling: it returns
	// NotFound (never the timeline) unless the timeline both belongs to
	// campaignID (the cross-campaign IDOR guard) and is visible to v under
	// the same role + per-user rules ListTimelines applies
	// (timelineVisibleToViewer, ADR-058). Use this, not GetTimeline, on any
	// route a viewer weaker than Owner can reach.
	GetTimelineForViewer(ctx context.Context, timelineID, campaignID string, v permissions.Viewer) (*Timeline, error)
	// ListTimelines / ListTimelinesForCalendar / ListTimelineEvents take a
	// permissions.Viewer rather than (role, userID), so an anonymous visitor
	// (empty user id) cannot match the system-trusted bypass (ADR-049). A
	// caller that really is trusted says so with permissions.SystemViewer.
	ListTimelines(ctx context.Context, campaignID string, v permissions.Viewer) ([]Timeline, error)
	ListTimelinesForCalendar(ctx context.Context, calendarID string, v permissions.Viewer) ([]Timeline, error)
	UpdateTimeline(ctx context.Context, timelineID string, input UpdateTimelineInput) error
	DeleteTimeline(ctx context.Context, timelineID string) error

	// Event linking (calendar events).
	LinkEvent(ctx context.Context, timelineID, eventID string, input LinkEventInput) (*EventLink, error)
	LinkAllEvents(ctx context.Context, timelineID string, role int) (int, error)
	UnlinkEvent(ctx context.Context, timelineID, eventID string) error
	// ListTimelineEvents also takes campaignID, so a non-owner's result can
	// be narrowed by EntityVisibilityGate (a linked entity's visibility is a
	// separate check from the event's own).
	ListTimelineEvents(ctx context.Context, timelineID, campaignID string, v permissions.Viewer) ([]EventLink, error)
	ListAvailableEvents(ctx context.Context, timelineID string, role int) ([]CalendarEventRef, error)

	// Event link visibility.
	UpdateEventLinkVisibility(ctx context.Context, timelineID, eventID string, input UpdateEventVisibilityInput) error

	// Standalone events. UpdateStandaloneEvent and DeleteStandaloneEvent take
	// canAuthorDmOnly (Owner or a co-DM grant,
	// campaigns.CampaignContext.CanAuthorDmOnly) so a caller who cannot
	// author dm_only content gets the same NotFound a missing id would give
	// when the stored event is dm_only, regardless of which fields the
	// request touches.
	CreateStandaloneEvent(ctx context.Context, timelineID string, input CreateTimelineEventInput) (*TimelineEvent, error)
	GetStandaloneEvent(ctx context.Context, eventID string) (*TimelineEvent, error)
	UpdateStandaloneEvent(ctx context.Context, timelineID, eventID string, input UpdateTimelineEventInput, canAuthorDmOnly bool) error
	DeleteStandaloneEvent(ctx context.Context, timelineID, eventID string, canAuthorDmOnly bool) error

	// Entity groups.
	CreateEntityGroup(ctx context.Context, timelineID string, input CreateEntityGroupInput) (*EntityGroup, error)
	UpdateEntityGroup(ctx context.Context, timelineID string, groupID int, input UpdateEntityGroupInput) error
	DeleteEntityGroup(ctx context.Context, timelineID string, groupID int) error
	// ListEntityGroups takes campaignID and a Viewer so a non-owner's result
	// can be narrowed by EntityVisibilityGate, same as ListTimelineEvents:
	// a group member's entity link is a separate visibility check the caller
	// must supply.
	ListEntityGroups(ctx context.Context, timelineID, campaignID string, v permissions.Viewer) ([]EntityGroup, error)
	AddGroupMember(ctx context.Context, timelineID string, groupID int, entityID string) error
	RemoveGroupMember(ctx context.Context, timelineID string, groupID int, entityID string) error

	// Event connections.
	CreateConnection(ctx context.Context, timelineID string, input CreateConnectionInput) (*EventConnection, error)
	DeleteConnection(ctx context.Context, timelineID string, connectionID int) error
	// ListConnections returns the timeline's connections whose two ends are
	// both in among, the event list ListTimelineEvents gave the caller's
	// viewer. There is no unfiltered read: a connection names its ends and
	// carries a free-text label, so it is only shown alongside both events.
	ListConnections(ctx context.Context, timelineID string, among []EventLink) ([]EventConnection, error)

	// Search. Takes userID alongside role so the per-user visibility layer
	// can build the same permissions.Viewer ListTimelines builds — role
	// alone is not enough to keep a restricted timeline's name from leaking.
	SearchTimelines(ctx context.Context, campaignID, query string, role int, userID string) ([]map[string]string, error)

	// Calendar lookup.
	ListCalendars(ctx context.Context, campaignID string) ([]CalendarRef, error)
	ListCalendarEras(ctx context.Context, campaignID, calendarID string, role int) ([]CalendarEra, error)
}

TimelineService defines business logic for the timeline plugin.

func NewTimelineService

func NewTimelineService(repo TimelineRepository, calLists CalendarLister, calEvents CalendarEventLister, calEras CalendarEraLister) TimelineService

NewTimelineService creates a TimelineService backed by the given repository, calendar lister (for the selector dropdown), event lister (for the event picker), and era lister (for visualization background bands).

type TimelineViewData

type TimelineViewData struct {
	CampaignID   string
	Timeline     *Timeline
	Events       []EventLink
	EntityGroups []EntityGroup
	Connections  []EventConnection
	IsOwner      bool
	IsScribe     bool
	CSRFToken    string
	Members      []MemberRef
}

TimelineViewData holds all data needed to render a single timeline page.

type UpdateEntityGroupInput

type UpdateEntityGroupInput struct {
	Name  patch.Field[string] `json:"name"`
	Color patch.Field[string] `json:"color"`
}

UpdateEntityGroupInput is the validated input for updating an entity group. It is a PARTIAL update: an absent key keeps the stored value, and a group keeps its sort order, which this input does not carry at all. Both columns are NOT NULL, so an explicit null also preserves.

type UpdateEventVisibilityInput

type UpdateEventVisibilityInput struct {
	VisibilityOverride patch.Field[string] `json:"visibility_override"`
	VisibilityRules    patch.Field[string] `json:"visibility_rules"`
}

UpdateEventVisibilityInput is the validated input for updating event link visibility. Both columns are nullable and independent: a body naming only the override must not wipe the per-user rules, and an explicit null on either clears it (null override means "inherit the event's own").

type UpdateTimelineEventInput

type UpdateTimelineEventInput struct {
	Name            patch.Field[string]
	Description     patch.Field[string]
	DescriptionHTML patch.Field[string]
	EntityID        patch.Field[string]
	Year            patch.Field[int]
	Month           patch.Field[int]
	Day             patch.Field[int]
	StartHour       patch.Field[int]
	StartMinute     patch.Field[int]
	EndYear         patch.Field[int]
	EndMonth        patch.Field[int]
	EndDay          patch.Field[int]
	EndHour         patch.Field[int]
	EndMinute       patch.Field[int]
	IsRecurring     patch.Field[bool]
	RecurrenceType  patch.Field[string]
	Category        patch.Field[string]
	Visibility      patch.Field[string]
	VisibilityRules patch.Field[string]
	Label           patch.Field[string]
	Color           patch.Field[string]
}

UpdateTimelineEventInput is the validated input for updating a standalone event. It is a partial update: an absent field preserves the stored value, an explicit null clears it, a present value replaces it.

visibility_rules stays absent from this input on purpose: the dedicated PUT .../visibility endpoint owns it, so the edit modal cannot destroy it.

type UpdateTimelineInput

type UpdateTimelineInput struct {
	Name            string
	Description     patch.Field[string]
	DescriptionHTML patch.Field[string]
	Color           patch.Field[string]
	Icon            patch.Field[string]
	Visibility      patch.Field[string]
	VisibilityRules patch.Field[string]
	ZoomDefault     patch.Field[string]
}

UpdateTimelineInput is the validated input for updating timeline settings. Partial update (ADR-054): absent preserves, explicit null clears, present replaces.

VisibilityRules (and Visibility) stay owned by the dedicated PUT .../visibility endpoint (UpdateTimelineVisibilityAPI): canUserView() treats an absent VisibilityRules as visible to everyone, so this input must never let a settings save clear it implicitly.

Name is deliberately left a plain string: UpdateTimeline rejects a blank merged name with 400, so an absent name fails loudly instead of silently overwriting.

type VisibilityRules

type VisibilityRules struct {
	AllowedUsers []string `json:"allowed_users,omitempty"`
	DeniedUsers  []string `json:"denied_users,omitempty"`
}

VisibilityRules defines per-user visibility overrides for timelines and events. If AllowedUsers is set, only those users can see the item (whitelist). If DeniedUsers is set, those users cannot see the item (blacklist). AllowedUsers takes precedence: if set, DeniedUsers is ignored.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL