GanttEx.Live.Columns (GanttEx v0.1.0)

Copy Markdown View Source

Builds the grid columns from the :column slots of GanttEx.Live.Gantt.

Built-in fields get a translated label, a width, an alignment and an inline editor by default:

FieldLabelEditor
:textTask name:text
:start_dateStart time:date
:end_dateEnd time:date
:durationDuration:number
:progressProgress:progress
:typeType:type
:wbsWBSnone
:add(add button)none

Any other field is read from the task :meta and is not editable unless an editor is given. The tree is shown in the column marked with tree, or in the :text column.

iex> labels = GanttEx.I18n.labels("en")
iex> columns = GanttEx.Live.Columns.build([], labels)
iex> Enum.map(columns, &{&1.field, &1.label, &1.tree})
[{:text, "Task name", true}, {:start_date, "Start time", false}, {:duration, "Duration", false}, {:add, "", false}]
iex> [owner] = GanttEx.Live.Columns.build([%{field: :owner_name}], labels, widths: %{"owner_name" => 150})
iex> {owner.label, owner.width, owner.editor, owner.tree}
{"Owner name", 150, nil, true}

Summary

Types

t()

A normalized column.

Functions

Normalizes column slots (or the default columns when none are given).

Finds a column by its field sent as a string by the client.

Returns the sum of the column widths.

Types

t()

@type t() :: %{
  :field => atom() | String.t(),
  :label => String.t(),
  :width => pos_integer(),
  :align => String.t(),
  :tree => boolean(),
  :editor => atom() | nil,
  :sortable => boolean(),
  :inner_block => term(),
  optional(atom()) => term()
}

A normalized column.

Functions

build(slots, labels, opts \\ [])

@spec build([map()], map(), keyword()) :: [t()]

Normalizes column slots (or the default columns when none are given).

Options

  • :widths - widths set by the user, keyed by the field as a string.
  • :readonly - drops the :add column.

find(columns, field)

@spec find([t()], String.t()) :: t() | nil

Finds a column by its field sent as a string by the client.

total_width(columns)

@spec total_width([t()]) :: non_neg_integer()

Returns the sum of the column widths.