cardinal

Workspaces and dashboards

Ship workspaces, number cards, charts, chart sources, onboarding cards and widgets with an app.

A workspace is a page of tiles in the desk sidebar. An app ships it as a fixture, with the Number Cards and Dashboard Charts it shows. List each RecType in the manifest's fixtures, cards and charts before the workspace:

eden/app.exs
fixtures: ["Number Card", "Dashboard Chart", "Workspace", "Report"]

A workspace

The grid is 12 tiles wide. Each block has a type, and optionally x, y (its top left tile from 0) and w, h (its size).

eden/fixtures/workspace.yaml
- label: Eden
  module: Eden
  sequence_id: 70
  roles: [{role: System Manager}]
  content:
    - {type: number_card, x: 3, y: 0, w: 3, h: 1, number_card: AI Calls (This Week)}
    - {type: shortcut, x: 3, y: 1, w: 3, h: 1, link_to: Eve, link_type: Page}
    - {type: shortcut, x: 6, y: 1, w: 3, h: 1, link_to: Eden Settings}
    - {type: chart, x: 3, y: 2, w: 6, h: 3, chart: AI Calls (This Week)}
    - {type: card, x: 3, y: 6, w: 3, h: 2, label: Usage,
       links: [{link_to: AI Usage, link_type: Report}, {link_to: AI Call}]}

A user sees the workspace when they hold one of its roles and can open at least one of its blocks. A block without x and y goes in the first free space. A workspace holds 40 blocks at most.

Block typeSizes (w x h), default first
shortcut2x1, 1x1, 3x1
card2x2 to 4x4, 6x3, 6x4
number_card2x1, 3x1, 2x2, 4x2
quick_list4x2, 4x4, 6x4
chart4x2, 6x3, 12x4
todo, events, recent2x2, 4x2
note2x1, 2x2, 4x2. Takes text in Markdown
header, onboardingFull width, one tile high
widgetThe sizes the app declares

Number cards and charts

eden/fixtures/number_card.yaml
- {label: AI Calls (This Week), document_type: AI Call, filters_json: [[creation, timespan, this week]]}
eden/fixtures/dashboard_chart.yaml
- chart_name: AI Calls (This Week)
  chart_type: Count
  document_type: AI Call
  based_on: creation
  timespan: Last Week
  time_interval: Daily
  type: Bar
  module: Eden

A card or chart counts only the records the viewer may read.

Charts computed in code

For a chart a count cannot give, write a chart source.

Ship a Dashboard Chart Source record: {source_name: CRM Sales Trend, module: FCRM}.

Write <App>.ChartSources.<source name without spaces> with get/2:

crm/lib/chart_sources/dashboard.ex
defmodule Crm.ChartSources.CRMSalesTrend do
  @behaviour Cardinal.ChartSource
  @impl true
  def get(ctx, params), do: Crm.Services.DashboardService.chart(ctx, :sales_trend, params)
end

Ship a Dashboard Chart with chart_type: Custom and source: CRM Sales Trend.

params holds filters, timespan, time_interval, from_date, to_date and user (from the workspace's user filter). Return {:ok, %{labels: [...], datasets: [%{name, values}]}}. get/2 runs as the viewer.

Widgets

A widget is a Vue component the app draws in a tile. Declare it in the manifest:

crm/app.exs
widgets: [
  %{name: "number", label: "CRM Number", sizes: [{3, 2}, {2, 2}, {4, 2}],
    roles: ["Sales User", "Sales Manager", "System Manager"], module: Crm.Widgets.Number}
]

Register the component as <app>.<name> in the desk plugin, registerWidget('crm.number', NumberWidget), and place it:

- {type: widget, widget: crm.number, props: {name: total_leads}, x: 0, y: 0, w: 3, h: 2}

module may export check(props), which returns :ok or {:error, message} when a workspace with the block is saved. Optional roles and rectype limit who gets the block.

Onboarding

A Module Onboarding card lists first steps. Ship Module Onboarding and Onboarding Step records, then place the card:

crm/fixtures/onboarding_step.yaml
- {title: Add your first lead, onboarding: CRM Onboarding, sequence_id: 1, action: Create Entry,
   target: CRM Lead, action_label: Add a lead}
- {type: onboarding, onboarding: CRM Onboarding, x: 0, y: 24}

A Create Entry step is done once the user can read a record of its RecType.

Check content from code

Cardinal.Workspace.check(ctx, content) returns what a save of the content would refuse, without saving. Cardinal.Workspace.sizes/0 returns the size table above.

On this page