| 1 | package Mojolicious::Plugin::Fondation::Workflow::UI::Bootstrap; | ||||||||||||||||||||||||||||||
| 2 | 1 | $Mojolicious::Plugin::Fondation::Workflow::UI::Bootstrap::VERSION = '0.02'; | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Bootstrap 5 UI components for Fondation::Workflow | ||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||
| 5 | # Provides template helpers for rendering workflow state badges, | ||||||||||||||||||||||||||||||
| 6 | # action buttons, history timelines, progress bars, and Mermaid.js graphs. | ||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Mojo::Base 'Mojolicious::Plugin', -signatures; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub fondation_meta { | ||||||||||||||||||||||||||||
|
Subroutine
fondation_meta: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 11 | return { | ||||||||||||||||||||||||||||||
| 12 | 0 | dependencies => [ | |||||||||||||||||||||||||||||
| 13 | 'Fondation::Layout::Bootstrap', | ||||||||||||||||||||||||||||||
| 14 | 'Fondation::Workflow', | ||||||||||||||||||||||||||||||
| 15 | ], | ||||||||||||||||||||||||||||||
| 16 | }; | ||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub register ($self, $app, $conf) { | ||||||||||||||||||||||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | # ── workflow_state($wf) — state badge ────────────────────────────── | ||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $app->helper(workflow_state => sub ($c, $wf, %attrs) { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return '' unless $wf && ref $wf; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$wf and ref $wf
MC/DC0%0/2
$wf and ref $wf
$wf
ref $wf
Truth table0%0/3
A and B
A= $wfB= ref $wf
| |||||||||||||||||||||||||||||||
| 25 | 0 | my $state = $wf->state; | |||||||||||||||||||||||||||||
| 26 | 0 | my $label = $wf->state_label; | |||||||||||||||||||||||||||||
| 27 | 0 | my $color = $wf->state_color; | |||||||||||||||||||||||||||||
| 28 | 0 | my $icon = $wf->state_icon; | |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $icon_html = $icon ? qq{<i class="bi bi-$icon me-1"></i>} : ''; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $class = join ' ', 'badge', "bg-$color", ($attrs{class} // ''); | ||||||||||||||||||||||||||||
|
Condition0%0/2
$attrs{"class"} // ""
MC/DC0%0/1
$attrs{"class"} // ""
$attrs{"class"}
Truth table0%0/2
A
A= $attrs{"class"}
| |||||||||||||||||||||||||||||||
| 32 | 0 | return qq{<span class="$class">$icon_html$label</span>}; | |||||||||||||||||||||||||||||
| 33 | 0 | }); | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | # ── workflow_actions($wf) — action buttons ──────────────────────── | ||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $app->helper(workflow_actions => sub ($c, $wf, %attrs) { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return '' unless $wf && ref $wf; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$wf and ref $wf
MC/DC0%0/2
$wf and ref $wf
$wf
ref $wf
Truth table0%0/3
A and B
A= $wfB= ref $wf
| |||||||||||||||||||||||||||||||
| 39 | 0 | my $actions = $wf->actions; | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return '' unless $actions && @$actions; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$actions and @$actions
MC/DC0%0/2
$actions and @$actions
$actions
@$actions
Truth table0%0/3
A and B
A= $actionsB= @$actions
| |||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | 0 | my $html = ''; | |||||||||||||||||||||||||||||
| 43 | 0 | for my $a (@$actions) { | |||||||||||||||||||||||||||||
| 44 | 0 | my $color = "btn-$a->{color}"; | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $icon = $a->{icon} ? qq{<i class="bi bi-$a->{icon} me-1"></i>} : ''; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $confirm = $a->{confirm} ? qq{ data-confirm="$a->{confirm}"} : ''; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 47 | 0 | $html .= qq{<button class="btn btn-sm $color workflow-action"$confirm data-action="$a->{name}">$icon$a->{label}</button>\n}; | |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $class = join ' ', 'btn-group', ($attrs{class} // ''); | ||||||||||||||||||||||||||||
|
Condition0%0/2
$attrs{"class"} // ""
MC/DC0%0/1
$attrs{"class"} // ""
$attrs{"class"}
Truth table0%0/2
A
A= $attrs{"class"}
| |||||||||||||||||||||||||||||||
| 50 | 0 | return qq{<div class="$class" role="group">$html</div>}; | |||||||||||||||||||||||||||||
| 51 | 0 | }); | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | # ── workflow_progress($wf) — state graph/tree ──────────────────── | ||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | $app->helper(workflow_progress => sub ($c, $wf, %attrs) { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return '' unless $wf; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 57 | 0 | my $current = $wf->state; | |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||
| 59 | 0 | my $config = $wf->_workflow_config; | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $states = $config->{state} // []; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"state"} // []
MC/DC0%0/1
$config->{"state"} // []
$config->{"state"}
Truth table0%0/2
A
A= $config->{"state"}
| |||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return '' unless @$states; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||
| 63 | # Build adjacency map: state_name => [next_state_names...] | ||||||||||||||||||||||||||||||
| 64 | # and metadata map: state_name => { label, color, icon } | ||||||||||||||||||||||||||||||
| 65 | 0 | my (%next, %meta); | |||||||||||||||||||||||||||||
| 66 | 0 | for my $s (@$states) { | |||||||||||||||||||||||||||||
| 67 | 0 | my $name = $s->{name}; | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my $fd = $s->{fondation} // {}; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$s->{"fondation"} // {}
MC/DC0%0/1
$s->{"fondation"} // {}
$s->{"fondation"}
Truth table0%0/2
A
A= $s->{"fondation"}
| |||||||||||||||||||||||||||||||
| 69 | $meta{$name} = { | ||||||||||||||||||||||||||||||
| 70 | label => $c->l($fd->{label} // $name), | ||||||||||||||||||||||||||||||
| 71 | color => $fd->{color} // 'secondary', | ||||||||||||||||||||||||||||||
| 72 | icon => $fd->{icon}, | ||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | }; | ||||||||||||||||||||||||||||
|
Condition0%0/5
$fd->{"label"} // $name
$fd->{"color"} // "secondary"
MC/DC0%0/2
$fd->{"label"} // $name
$fd->{"label"}
$name
MC/DC0%0/1
$fd->{"color"} // "secondary"
$fd->{"color"}
Truth table0%0/3
A // B
A= $fd->{"label"}B= $name
Truth table0%0/2
A
A= $fd->{"color"}
| |||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $actions = $s->{action} // []; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$s->{"action"} // []
MC/DC0%0/1
$s->{"action"} // []
$s->{"action"}
Truth table0%0/2
A
A= $s->{"action"}
| |||||||||||||||||||||||||||||||
| 75 | 0 | $next{$name} = [ map { $_->{resulting_state} } @$actions ]; | |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | # Reconstruct the effective path from history (eliminate backtracks). | ||||||||||||||||||||||||||||||
| 79 | # When the user goes block→unblock (back to in_progress) and then | ||||||||||||||||||||||||||||||
| 80 | # resolve→resolved, "blocked" is a dead-end branch — it should not | ||||||||||||||||||||||||||||||
| 81 | # appear as visited on the current path. | ||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my @history = @{ $wf->history // [] }; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$wf->history // []
MC/DC0%0/1
$wf->history // []
$wf->history
Truth table0%0/2
A
A= $wf->history
| |||||||||||||||||||||||||||||||
| 83 | 0 | my @path; # ordered chain of states on the current path | |||||||||||||||||||||||||||||
| 84 | my %path_set; # fast lookup | ||||||||||||||||||||||||||||||
| 85 | 0 | for my $h (@history) { | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | my $s = $h->{state} // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$h->{"state"} // ""
MC/DC0%0/1
$h->{"state"} // ""
$h->{"state"}
Truth table0%0/2
A
A= $h->{"state"}
| |||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | next unless $s; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 88 | # Backtracking: if we reach a state already in the path, | ||||||||||||||||||||||||||||||
| 89 | # truncate everything after it. | ||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ($path_set{$s}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | while (@path && $path[-1] ne $s) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@path and $path[-1] ne $s
MC/DC0%0/2
@path and $path[-1] ne $s
@path
$path[-1] ne $s
Truth table0%0/3
A and B
A= @pathB= $path[-1] ne $s
| |||||||||||||||||||||||||||||||
| 92 | 0 | delete $path_set{pop @path}; | |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||
| 94 | 0 | next; | |||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||
| 96 | 0 | push @path, $s; | |||||||||||||||||||||||||||||
| 97 | 0 | $path_set{$s} = 1; | |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||
| 99 | # Always mark current state as on-path | ||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $path_set{$current} = 1 unless $path_set{$current}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 101 | 0 | my %visited = %path_set; | |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||
| 103 | # Recursive tree builder (tracks path to avoid cycles) | ||||||||||||||||||||||||||||||
| 104 | 0 | my $render; | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $render = sub ($state_name, $prefix = '', $is_last = 0, $depth = 0, $seen = {}) { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=20 SCAR=60.4
| |||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | return '' unless exists $meta{$state_name}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 107 | return qq{<div class="wf-node"><span class="wf-prefix text-muted small">$prefix</span>} | ||||||||||||||||||||||||||||||
| 108 | . qq{<span class="badge bg-light text-muted border">↩ $meta{$state_name}{label} (cycle)</span></div>\n} | ||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if $seen->{$state_name}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | 0 | my $m = $meta{$state_name}; | |||||||||||||||||||||||||||||
| 112 | 0 | my $label = $m->{label}; | |||||||||||||||||||||||||||||
| 113 | 0 | my $color = $m->{color}; | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | my $icon = $m->{icon} ? qq{<i class="bi bi-$m->{icon} me-1"></i>} : ''; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | 0 | my $is_current = $state_name eq $current; | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my $is_visited = $visited{$state_name} && !$is_current; | ||||||||||||||||||||||||||||
|
Condition0%0/3
$visited{$state_name} && !$is_current
MC/DC0%0/2
$visited{$state_name} && !$is_current
$visited{$state_name}
!$is_current
Truth table0%0/3
A && not(B)
A= $visited{$state_name}B= !$is_current
| |||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | my $badge_class = $is_current ? "bg-$color" | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 120 | : $is_visited ? 'bg-success' | ||||||||||||||||||||||||||||||
| 121 | : 'bg-light text-muted border'; | ||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my $marker = $is_current ? '●' | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 123 | : $is_visited ? '✓' | ||||||||||||||||||||||||||||||
| 124 | : '○'; | ||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my $connector = $depth > 0 ? ($is_last ? ' └─ ' : ' ├─ ') : ''; | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 127 | 0 | my $html = qq{<div class="wf-node">}; | |||||||||||||||||||||||||||||
| 128 | 0 | $html .= qq{<span class="wf-prefix text-muted small">$prefix$connector</span>}; | |||||||||||||||||||||||||||||
| 129 | 0 | $html .= qq{<span class="badge $badge_class">$icon$marker $label</span>}; | |||||||||||||||||||||||||||||
| 130 | 0 | $html .= qq{</div>\n}; | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | my @children = @{ $next{$state_name} // [] }; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$next{$state_name} // []
MC/DC0%0/1
$next{$state_name} // []
$next{$state_name}
Truth table0%0/2
A
A= $next{$state_name}
| |||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | return $html unless @children; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $child_prefix = $depth > 0 | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 136 | ? ($is_last ? ' ' : ' │ ') | ||||||||||||||||||||||||||||||
| 137 | : ''; | ||||||||||||||||||||||||||||||
| 138 | 0 | my $full_prefix = $prefix . $child_prefix; | |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||
| 140 | 0 | my %child_seen = (%$seen, $state_name => 1); | |||||||||||||||||||||||||||||
| 141 | 0 | for my $i (0 .. $#children) { | |||||||||||||||||||||||||||||
| 142 | 0 | my $child = $children[$i]; | |||||||||||||||||||||||||||||
| 143 | 0 | my $child_last = $i == $#children; | |||||||||||||||||||||||||||||
| 144 | 0 | $html .= $render->($child, $full_prefix, $child_last, $depth + 1, \%child_seen); | |||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||
| 146 | 0 | return $html; | |||||||||||||||||||||||||||||
| 147 | 0 | }; | |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $initial = $config->{initial_state} // $states->[0]{name}; | ||||||||||||||||||||||||||||
|
Condition0%0/3
$config->{"initial_state"} // $states->[0]{"name"}
MC/DC0%0/2
$config->{"initial_state"} // $states->[0]{"name"}
$config->{"initial_state"}
$states->[0]{"name"}
Truth table0%0/3
A // B
A= $config->{"initial_state"}B= $states->[0]{"name"}
| |||||||||||||||||||||||||||||||
| 150 | 0 | return qq{<div class="workflow-progress font-monospace small">\n} | |||||||||||||||||||||||||||||
| 151 | . $render->($initial) | ||||||||||||||||||||||||||||||
| 152 | . qq{</div>}; | ||||||||||||||||||||||||||||||
| 153 | 0 | }); | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | # ── workflow_history($wf) — history timeline ────────────────────── | ||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | $app->helper(workflow_history => sub ($c, $wf, %attrs) { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=13 SCAR=52.0
| |||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | return '' unless $wf && ref $wf; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$wf and ref $wf
MC/DC0%0/2
$wf and ref $wf
$wf
ref $wf
Truth table0%0/3
A and B
A= $wfB= ref $wf
| |||||||||||||||||||||||||||||||
| 159 | 0 | my $entries = $wf->history; | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | return '' unless $entries && @$entries; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$entries and @$entries
MC/DC0%0/2
$entries and @$entries
$entries
@$entries
Truth table0%0/3
A and B
A= $entriesB= @$entries
| |||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | 0 | my $html = qq{<div class="workflow-history">}; | |||||||||||||||||||||||||||||
| 163 | 0 | for my $e (@$entries) { | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | my $action = $e->{action} // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$e->{"action"} // ""
MC/DC0%0/1
$e->{"action"} // ""
$e->{"action"}
Truth table0%0/2
A
A= $e->{"action"}
| |||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | my $state = $e->{state} // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$e->{"state"} // ""
MC/DC0%0/1
$e->{"state"} // ""
$e->{"state"}
Truth table0%0/2
A
A= $e->{"state"}
| |||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | my $user = $e->{user} // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$e->{"user"} // ""
MC/DC0%0/1
$e->{"user"} // ""
$e->{"user"}
Truth table0%0/2
A
A= $e->{"user"}
| |||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | my $date = $e->{date} // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$e->{"date"} // ""
MC/DC0%0/1
$e->{"date"} // ""
$e->{"date"}
Truth table0%0/2
A
A= $e->{"date"}
| |||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | my $desc = $e->{description} // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$e->{"description"} // ""
MC/DC0%0/1
$e->{"description"} // ""
$e->{"description"}
Truth table0%0/2
A
A= $e->{"description"}
| |||||||||||||||||||||||||||||||
| 169 | 0 | $html .= qq{<div class="d-flex align-items-start mb-2">}; | |||||||||||||||||||||||||||||
| 170 | 0 | $html .= qq{<div class="me-2 text-primary">●</div>}; | |||||||||||||||||||||||||||||
| 171 | 0 | $html .= qq{<div>}; | |||||||||||||||||||||||||||||
| 172 | 0 | $html .= qq{<strong>$action</strong>}; | |||||||||||||||||||||||||||||
| 173 | 0 | ▶ | $html .= qq{ <span class="text-muted small">$date</span>} if $date; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | $html .= qq{<br><small class="text-muted">$desc</small>} if $desc; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 175 | 0 | $html .= qq{</div></div>}; | |||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||
| 177 | 0 | $html .= '</div>'; | |||||||||||||||||||||||||||||
| 178 | 0 | return $html; | |||||||||||||||||||||||||||||
| 179 | 0 | }); | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | # ── workflow_graph($wf) — Mermaid.js state diagram ──────────────── | ||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $app->helper(workflow_graph => sub ($c, $wf, %attrs) { | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=30 SCAR=68.4
| |||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | return '' unless $wf && ref $wf; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$wf and ref $wf
MC/DC0%0/2
$wf and ref $wf
$wf
ref $wf
Truth table0%0/3
A and B
A= $wfB= ref $wf
| |||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||
| 186 | 0 | my $config = $wf->_workflow_config; | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my $states = $config->{state} // []; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{"state"} // []
MC/DC0%0/1
$config->{"state"} // []
$config->{"state"}
Truth table0%0/2
A
A= $config->{"state"}
| |||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | return '' unless @$states; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||
| 190 | 0 | my $current = $wf->state; | |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||
| 192 | # Build adjacency + metadata | ||||||||||||||||||||||||||||||
| 193 | 0 | my (%next, %meta); | |||||||||||||||||||||||||||||
| 194 | 0 | for my $s (@$states) { | |||||||||||||||||||||||||||||
| 195 | 0 | my $name = $s->{name}; | |||||||||||||||||||||||||||||
| 196 | 0 | ▶ | my $fd = $s->{fondation} // {}; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$s->{"fondation"} // {}
MC/DC0%0/1
$s->{"fondation"} // {}
$s->{"fondation"}
Truth table0%0/2
A
A= $s->{"fondation"}
| |||||||||||||||||||||||||||||||
| 197 | $meta{$name} = { | ||||||||||||||||||||||||||||||
| 198 | name => $name, | ||||||||||||||||||||||||||||||
| 199 | label => $c->l($fd->{label} // $name), | ||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | color => $fd->{color} // 'secondary', | ||||||||||||||||||||||||||||
|
Condition0%0/5
$fd->{"label"} // $name
$fd->{"color"} // "secondary"
MC/DC0%0/2
$fd->{"label"} // $name
$fd->{"label"}
$name
MC/DC0%0/1
$fd->{"color"} // "secondary"
$fd->{"color"}
Truth table0%0/3
A // B
A= $fd->{"label"}B= $name
Truth table0%0/2
A
A= $fd->{"color"}
| |||||||||||||||||||||||||||||||
| 201 | }; | ||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | my $actions = $s->{action} // []; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$s->{"action"} // []
MC/DC0%0/1
$s->{"action"} // []
$s->{"action"}
Truth table0%0/2
A
A= $s->{"action"}
| |||||||||||||||||||||||||||||||
| 203 | 0 | $next{$name} = $actions; | |||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||
| 206 | # Determine path set (same backtracking logic as progress) | ||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | my @history = @{ $wf->history // [] }; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$wf->history // []
MC/DC0%0/1
$wf->history // []
$wf->history
Truth table0%0/2
A
A= $wf->history
| |||||||||||||||||||||||||||||||
| 208 | 0 | my (@path, %path_set); | |||||||||||||||||||||||||||||
| 209 | 0 | for my $h (@history) { | |||||||||||||||||||||||||||||
| 210 | 0 | ▶ | my $s = $h->{state} // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$h->{"state"} // ""
MC/DC0%0/1
$h->{"state"} // ""
$h->{"state"}
Truth table0%0/2
A
A= $h->{"state"}
| |||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | next unless $s; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if ($path_set{$s}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | while (@path && $path[-1] ne $s) { delete $path_set{pop @path} } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@path and $path[-1] ne $s
MC/DC0%0/2
@path and $path[-1] ne $s
@path
$path[-1] ne $s
Truth table0%0/3
A and B
A= @pathB= $path[-1] ne $s
| |||||||||||||||||||||||||||||||
| 214 | 0 | next; | |||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||
| 216 | 0 | push @path, $s; $path_set{$s} = 1; | |||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | $path_set{$current} = 1 unless $path_set{$current}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||
| 220 | # Short safe IDs for Mermaid | ||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | my $sid = sub ($name) { 'S_' . ($name =~ s/[^a-zA-Z0-9]/_/gr) }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 222 | 0 | my @visited_nodes; | |||||||||||||||||||||||||||||
| 223 | my @future_nodes; | ||||||||||||||||||||||||||||||
| 224 | 0 | my $current_node = ''; | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||
| 226 | # Classify nodes | ||||||||||||||||||||||||||||||
| 227 | 0 | for my $s_name (sort keys %meta) { | |||||||||||||||||||||||||||||
| 228 | 0 | my $id = $sid->($s_name); | |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ($s_name eq $current) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 230 | 0 | $current_node = $id; | |||||||||||||||||||||||||||||
| 231 | } elsif ($path_set{$s_name}) { | ||||||||||||||||||||||||||||||
| 232 | 0 | push @visited_nodes, $id; | |||||||||||||||||||||||||||||
| 233 | } else { | ||||||||||||||||||||||||||||||
| 234 | 0 | push @future_nodes, $id; | |||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||
| 238 | # Generate edges with action labels | ||||||||||||||||||||||||||||||
| 239 | 0 | my @lines; | |||||||||||||||||||||||||||||
| 240 | 0 | my @sorted = sort { $a->{name} cmp $b->{name} } values %meta; | |||||||||||||||||||||||||||||
| 241 | 0 | for my $s (@sorted) { | |||||||||||||||||||||||||||||
| 242 | 0 | my $s_name = $s->{name}; | |||||||||||||||||||||||||||||
| 243 | 0 | my $from_id = $sid->($s_name); | |||||||||||||||||||||||||||||
| 244 | 0 | ▶ | for my $action (@{ $next{$s_name} // [] }) { | ||||||||||||||||||||||||||||
|
Condition0%0/2
$next{$s_name} // []
MC/DC0%0/1
$next{$s_name} // []
$next{$s_name}
Truth table0%0/2
A
A= $next{$s_name}
| |||||||||||||||||||||||||||||||
| 245 | 0 | my $to_name = $action->{resulting_state}; | |||||||||||||||||||||||||||||
| 246 | 0 | my $to_id = $sid->($to_name); | |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | my $label = $action->{name} // ''; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$action->{"name"} // ""
MC/DC0%0/1
$action->{"name"} // ""
$action->{"name"}
Truth table0%0/2
A
A= $action->{"name"}
| |||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | my $fd = $action->{fondation} // {}; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$action->{"fondation"} // {}
MC/DC0%0/1
$action->{"fondation"} // {}
$action->{"fondation"}
Truth table0%0/2
A
A= $action->{"fondation"}
| |||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | $label = $fd->{label} if $fd->{label}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 250 | 0 | my $from_label = $meta{$s_name}{label}; | |||||||||||||||||||||||||||||
| 251 | 0 | my $to_label = $meta{$to_name}{label}; | |||||||||||||||||||||||||||||
| 252 | 0 | push @lines, qq{ ${from_id}["$from_label"] -->|"$label"| ${to_id}["$to_label"]}; | |||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||
| 256 | 0 | my $mermaid = "flowchart TD\n" | |||||||||||||||||||||||||||||
| 257 | . join("\n", @lines) . "\n" | ||||||||||||||||||||||||||||||
| 258 | . "\n" | ||||||||||||||||||||||||||||||
| 259 | . " classDef visited fill:#198754,color:#fff,stroke:#198754\n" | ||||||||||||||||||||||||||||||
| 260 | . " classDef current fill:#0d6efd,color:#fff,stroke:#0d6efd,stroke-width:3px\n" | ||||||||||||||||||||||||||||||
| 261 | . " classDef future fill:#e9ecef,color:#6c757d,stroke:#dee2e6\n"; | ||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | $mermaid .= " class $current_node current\n" if $current_node; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | $mermaid .= " class " . join(',', @visited_nodes) . " visited\n" if @visited_nodes; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | $mermaid .= " class " . join(',', @future_nodes) . " future\n" if @future_nodes; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||
| 267 | 0 | return $mermaid; | |||||||||||||||||||||||||||||
| 268 | 0 | }); | |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||
| 270 | 0 | return $self; | |||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||
| 273 | 1 | 1; | |||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||
| 275 | __END__ | ||||||||||||||||||||||||||||||