graph
const TASK_SELECT_COLUMNS
const TASK_SELECT_COLUMNS: &str = "\
id, project_id, title, priority, status, description, \
assigned_to, metadata, resolved_at, created_at, updated_at";The task columns, in the order task::Model::try_from reads a row, for the raw task query.
struct GraphParams
pub struct GraphParamsQuery parameters shared by graph pages.
| Field | Type | Description |
|---|---|---|
all |
Option<String> | 1, true, yes or all includes completed and cancelled iterations and resolved tasks. |
direction |
Option<String> | The Mermaid flow direction: TD, BT, LR or RL; anything else gives TB. |
single |
Option<String> | 1, true, yes or all keeps the relationship page to one diagram, without per-iteration sections. |
Implements Deserialize<'de>.
struct RelationshipGraphTemplate
struct RelationshipGraphTemplateThe project relationship graph page: one diagram of the shown iterations, their tasks and related tasks, and phase sections per iteration when there are several.
| Field | Type | Description |
|---|---|---|
direction |
String | The Mermaid flow direction, such as TB or LR, kept in the page’s links. |
graph |
MermaidGraph | The diagram of the whole project. |
include_all |
bool | Whether finished iterations and resolved tasks are shown, kept in the page’s links. |
sections |
Vec<PhaseGraphSection> | The per-iteration phase diagrams; empty in single-diagram mode or with one iteration or none. |
single_diagram |
bool | Whether the page shows only the project diagram, kept in the page’s links. |
Implements Template, Display, FastWritable.
struct PhaseGraphTemplate
struct PhaseGraphTemplateThe phase graph page: one diagram per phase of each iteration.
| Field | Type | Description |
|---|---|---|
direction |
String | The Mermaid flow direction, such as TB or LR, kept in the page’s links. |
include_all |
bool | Whether finished iterations and resolved tasks are shown, kept in the page’s links. |
sections |
Vec<PhaseGraphSection> | One section per iteration, with its phase diagrams. |
Implements Template, Display, FastWritable.
struct GraphData
struct GraphDataThe iterations, tasks and edges that the graph pages draw, loaded once per request.
| Field | Type | Description |
|---|---|---|
iteration_tasks |
Vec<IterationTaskEdge> | Phase memberships of the loaded tasks in the loaded iterations. |
iterations |
Vec<IterationNode> | The iterations shown, oldest first. |
relationships |
Vec<RelationshipEdge> | Relationships that touch a loaded task, with any task end among the loaded tasks. |
tasks |
BTreeMap<String, TaskNode> | The tasks shown, by full id. |
struct IterationNode
struct IterationNodeAn iteration as a graph node.
| Field | Type | Description |
|---|---|---|
id |
String | The full iteration id. |
status |
String | The iteration status as text, such as active. |
title |
String | The iteration title, wrapped into the node’s label. |
struct IterationTaskEdge
struct IterationTaskEdgeA task’s membership in one phase of an iteration, drawn as an edge from the iteration.
| Field | Type | Description |
|---|---|---|
iteration_id |
String | The full iteration id. |
phase |
u32 | The phase number within the iteration. |
task_id |
String | The full task id. |
struct MermaidGraph
struct MermaidGraphOne diagram, as Mermaid flowchart source with its caption.
| Field | Type | Description |
|---|---|---|
mermaid |
String | The Mermaid flowchart source. |
task_count |
usize | How many task nodes the diagram holds. |
title |
String | The caption, such as project relationships or phase 2. |
struct PhaseGraphSection
struct PhaseGraphSectionOne iteration’s section on a graph page, with a diagram per phase.
| Field | Type | Description |
|---|---|---|
iteration_id |
String | The full iteration id, for its link. |
iteration_short_id |
String | The first eight characters of the iteration id, for display. |
iteration_status |
String | The iteration status as text. |
iteration_title |
String | The iteration title, shown as the section heading. |
phases |
Vec<PhaseGraph> | The iteration’s phases in ascending order. |
struct PhaseGraph
struct PhaseGraphThe diagram of one phase of an iteration.
| Field | Type | Description |
|---|---|---|
graph |
MermaidGraph | The phase’s tasks and the tasks related to them, plus any task with a relationship whose source is not a task. |
number |
u32 | The phase number; the sections are in ascending phase order. |
struct RelationshipEdge
struct RelationshipEdgeA stored relationship between two entities, as a graph edge.
| Field | Type | Description |
|---|---|---|
rel_type |
RelationshipType | The kind of relationship, such as blocks or child-of. |
source_id |
String | The full id of the source entity. |
source_type |
EntityType | The entity type of the source; only a task source is checked against the selected tasks. |
target_id |
String | The full id of the target entity. |
target_type |
EntityType | The entity type of the target; only a task target is checked against the selected tasks. |
struct TaskNode
struct TaskNodeA task as a graph node.
| Field | Type | Description |
|---|---|---|
id |
String | The full task id. |
priority |
Option<u8> | The task priority, shown as P<n>, if set. |
status |
String | The task status as text, such as in-progress; it picks the node’s colour class. |
title |
String | The task title, wrapped into the node’s label. |
fn graph_relationships
pub async fn graph_relationships(
State(state): State<AppState>,
Query(params): Query<GraphParams>,
) -> Result<Html<String>, web::Error>Project relationship graph page.
Handles GET /graphs and GET /graphs/relationships. With more than one iteration, and without single, it
adds a phase section per iteration under the project diagram.
| Parameter | Type | Description |
|---|---|---|
State(state) |
State<AppState> | the shared app state, for the store and the project id |
Query(params) |
Query<GraphParams> | the query string: all, direction and single |
| returns | Result<Html<String>, web::Error> | The rendered page, or a web::Error when the store or the template fails. |
fn graph_phases
pub async fn graph_phases(
State(state): State<AppState>,
Query(params): Query<GraphParams>,
) -> Result<Html<String>, web::Error>Per-iteration phase relationship graph page.
Handles GET /graphs/phases; the single parameter is ignored.
| Parameter | Type | Description |
|---|---|---|
State(state) |
State<AppState> | the shared app state, for the store and the project id |
Query(params) |
Query<GraphParams> | the query string: all and direction |
| returns | Result<Html<String>, web::Error> | The rendered page, or a web::Error when the store or the template fails. |
fn parse_direction
fn parse_direction(direction: Option<&str>) -> StringAccept a Mermaid flow direction from the query string.
| Parameter | Type | Description |
|---|---|---|
direction |
Option<&str> | the direction query value, if given |
| returns | String | TD, BT, LR or RL as given, or TB for anything else. |
fn parse_include_all
fn parse_include_all(value: Option<&str>) -> boolRead the all query value, which includes finished iterations and resolved tasks.
| Parameter | Type | Description |
|---|---|---|
value |
Option<&str> | the all query value, if given |
| returns | bool | Whether the value is one that parse_bool accepts as true. |
fn parse_bool
fn parse_bool(value: Option<&str>) -> boolRead a query flag.
| Parameter | Type | Description |
|---|---|---|
value |
Option<&str> | the query value, if given |
| returns | bool | true for 1, true, yes or all, and false for anything else or nothing. |
fn load_graph_data
async fn load_graph_data(state: &AppState, include_all: bool) -> Result<GraphData, web::Error>Load the iterations, their tasks and the tasks’ relationships for a graph page.
Without include_all it skips completed and cancelled iterations and done and cancelled tasks. Tasks reached
only through a relationship are added, and edges to tasks that were filtered out are dropped.
| Parameter | Type | Description |
|---|---|---|
state |
&AppState | the shared app state, for the store and the project id |
include_all |
bool | whether to include finished iterations and resolved tasks |
| returns | Result<GraphData, web::Error> | The graph data, or a web::Error when the store fails. |
fn fetch_iteration_task_edges
async fn fetch_iteration_task_edges(
conn: &Connection,
iteration_ids: &[Id],
) -> Result<Vec<IterationTaskEdge>, Error>Read the phase memberships of the given iterations.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
iteration_ids |
&[Id] | the iterations to read |
| returns | Result<Vec<IterationTaskEdge>, Error> | One edge per task in each iteration, ordered by iteration, phase and the time it was added; empty for no ids. |
fn fetch_task_relationship_edges
async fn fetch_task_relationship_edges(
conn: &Connection,
task_ids: &HashSet<String>,
) -> Result<Vec<RelationshipEdge>, Error>Read every relationship whose source or target is one of the given tasks.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
task_ids |
&HashSet<String> | the full ids of the tasks |
| returns | Result<Vec<RelationshipEdge>, Error> | The relationships, ordered by type and creation time; empty for no ids. |
fn fetch_task_nodes
async fn fetch_task_nodes(
conn: &Connection,
project_id: &Id,
task_ids: &HashSet<String>,
include_all: bool,
) -> Result<BTreeMap<String, TaskNode>, Error>Read the given tasks of the project as graph nodes.
| Parameter | Type | Description |
|---|---|---|
conn |
&Connection | the database connection |
project_id |
&Id | the project the tasks must belong to |
task_ids |
&HashSet<String> | the full ids of the tasks |
include_all |
bool | whether to keep done and cancelled tasks |
| returns | Result<BTreeMap<String, TaskNode>, Error> | The tasks found, by full id; empty for no ids. |
fn placeholders
fn placeholders(count: usize, start: usize) -> StringWrite numbered SQL placeholders for an IN (...) list.
| Parameter | Type | Description |
|---|---|---|
count |
usize | how many placeholders to write |
start |
usize | the number of the first one |
| returns | String | The placeholders joined by commas, such as ?2, ?3, ?4. |
fn build_phase_sections
fn build_phase_sections(data: &GraphData, direction: &str) -> Vec<PhaseGraphSection>Build one section per iteration, with a diagram for each of its phases.
| Parameter | Type | Description |
|---|---|---|
data |
&GraphData | the loaded graph data |
direction |
&str | the Mermaid flow direction |
| returns | Vec<PhaseGraphSection> | The sections, in the order of data.iterations; an iteration with no tasks has no phases. |
fn build_mermaid
fn build_mermaid(
iterations: &[IterationNode],
tasks: &BTreeMap<String, TaskNode>,
iteration_tasks: &[IterationTaskEdge],
relationships: &[RelationshipEdge],
direction: &str,
stack_iterations: bool,
) -> StringWrite Mermaid flowchart source for iterations, tasks and their edges.
Each node links to its page. Task-to-task relationships are drawn in their parent or blocker direction, and an
edge with an end outside tasks is skipped.
| Parameter | Type | Description |
|---|---|---|
iterations |
&[IterationNode] | the iteration nodes, in display order |
tasks |
&BTreeMap<String, TaskNode> | the task nodes, by full id |
iteration_tasks |
&[IterationTaskEdge] | the phase memberships, drawn as iteration-to-task edges |
relationships |
&[RelationshipEdge] | the relationships; only task-to-task ones are drawn |
direction |
&str | the Mermaid flow direction |
stack_iterations |
bool | whether to join consecutive iterations with a dotted next iteration edge |
| returns | String | The flowchart source, one statement per line. |
fn relationship_display
fn relationship_display(rel: &RelationshipEdge) -> (&str, &str, &'static str)Orient a relationship for drawing, so inverse types read the same way.
| Parameter | Type | Description |
|---|---|---|
rel |
&RelationshipEdge | the relationship |
| returns | (&str, &str, &'static str) | The source id, the target id and the edge label: parent of, blocks or relates to. |
fn node_id
fn node_id(kind: &str, entity_id: &str) -> StringMake a Mermaid node identifier from an entity id.
| Parameter | Type | Description |
|---|---|---|
kind |
&str | the prefix, I for an iteration or T for a task |
entity_id |
&str | the full entity id |
| returns | String | The prefix, an underscore and the first twelve characters of the id. |
fn label
fn label(parts: impl IntoIterator<Item = String>) -> StringJoin the non-empty parts of a node label.
| Parameter | Type | Description |
|---|---|---|
parts |
impl IntoIterator<Item = String> | the parts, such as the short id, title, status and priority |
| returns | String | The escaped parts joined by |. |
fn escape_label
fn escape_label(text: &str) -> StringEscape text for a quoted Mermaid label.
| Parameter | Type | Description |
|---|---|---|
text |
&str | the label text |
| returns | String | The text with backslashes and double quotes escaped and newlines turned into spaces. |
fn wrapped_title
fn wrapped_title(title: &str) -> StringWrap a long title for a node, four words to a line.
| Parameter | Type | Description |
|---|---|---|
title |
&str | the entity title |
| returns | String | The title as given when it has four words or fewer, or else its words in lines of four joined by <br/>. |
fn mermaid_class_for_status
fn mermaid_class_for_status(status: &str) -> &'static strPick the Mermaid class that colours a node by its status.
| Parameter | Type | Description |
|---|---|---|
status |
&str | the status as text |
| returns | &'static str | active, open, progress, done (for done or completed) or cancelled; open for anything else. |