lib/App/teai/Dash/Rounds.pm

filter: Statementstmt 17.8% 26 / 146 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 38 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 28.1% 9 / 32 Podpod 100% 2 / 2 totaltotal 12.4% 37 / 297 CC 54 SCAR 43.4
CC
54
Cov
11%
__ANON__
272.0
_sent
90.0
__ANON__
72.0
CRAP 76.6
« lib/App/teai/Exec.pm ↑ Summary lib/App/teai/Hook.pm »
1 package App::teai::Dash::Rounds;
2 1 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use App::teai::Err;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use App::teai::Bus ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use App::teai::Dash ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use App::teai::Dash::Threads ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use App::teai::Presence ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use App::teai::Round ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use App::teai::Wire ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.08';
12  
13 1 ▶BEGIN { *esc = \&App::teai::Dash::esc }
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 0 ▶sub nav ($class) { ([ 'Rounds', '/rounds' ], [ 'New round', '/round/new' ]) }
Subroutine nav: not called CC=1 SCAR=6.9
Pod documented
16  
17 0 ▶sub routes ($class) {
Subroutine routes: not called CC=1 SCAR=6.9
Pod documented
18 return (
19 0 [ GET => qr{\A/rounds\z}, \&_list ],
20 [ GET => qr{\A/round/new\z}, \&_new ],
21 [ POST => qr{\A/round/new\z}, \&_start ],
22 [ GET => qr{\A/round/([^/]+)/([^/]+)\z}, \&_round ],
23 [ POST => qr{\A/round/([^/]+)/([^/]+)/collect\z}, \&_collect ],
24 [ POST => qr{\A/round/([^/]+)/([^/]+)/resend\z}, \&_resend ],
25 );
26 }
27  
28 0 ▶sub _cells (@html) { join '', map { "<td>$_</td>" } @html }
Subroutine _cells: not called CC=1 SCAR=6.9
29 0 ▶sub _href ($project, $thread) { esc("/round/$project/$thread") }
Subroutine _href: not called CC=1 SCAR=6.9
30 0 ▶sub _link ($project, $thread) { '<p><a href="' . _href($project, $thread) . '">' . esc("round $thread") . "</a></p>\n" }
Subroutine _link: not called CC=1 SCAR=6.9
31  
32 0 ▶sub _list ($c) {
Subroutine _list: not called CC=3 SCAR=24.8
33 0 my $project = $c->param('project');
34 0 ▶ $project = undef if defined $project && !length $project;
Branch: 1 branch
BranchTrueFalseTotal
if defined $project and not length $project 0 0 0
Condition0%0/3
defined $project and not length $project
!ll&&!rl&&r
000
MC/DC0%0/2
defined $project and not length $project
defined $project not length $project
Truth table0%0/3
A and not(B)
A= defined $projectB= not length $project
ABresult
0X0
100
111
35 0 ▶ App::teai::Round::list($c->bus, $project, $c->cb(sub ($list, $e = undef) {
Subroutine __ANON__: not called CC=8 SCAR=42.8
36 0 ▶ return $c->fail($e) if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 0 0 0
37 my $rows = join '', map {
38 0 my ($p, $t, $lead) = @$_{qw(project thread lead)};
39 '<tr id="round-' . esc("$p.$t") . '">' . _cells(
40 esc($p), '<a href="' . _href($p, $t) . '">' . esc($t) . '</a>',
41 esc($lead) . ($lead eq $c->operator ? ' (this dashboard)' : ''),
42 0 ▶ esc(join ', ', sort keys %{ $_->{members} }), esc($_->{created}),
Branch: 1 branch
BranchTrueFalseTotal
$lead eq $c->operator ? : 0 0 0
43 ) . "</tr>\n";
44 } reverse @$list;
45 0 my %projects = map { ($_->{project} => 1) } @$list;
46 my @links = defined $project ? ([ 'every project', '/rounds' ])
47 0 ▶ : map { [ "project $_", "/rounds?project=$_" ] } sort keys %projects;
Branch: 1 branch
BranchTrueFalseTotal
defined $project ? : 0 0 0
48 my $html = '<p class="counts">' . esc(scalar(@$list) . (@$list == 1 ? ' round' : ' rounds')) . '</p>'
49 0 ▶ . '<p>' . join(' ', map { '<a href="' . esc($_->[1]) . '">' . esc($_->[0]) . '</a>' } @links, [ 'new round', '/round/new' ]) . "</p>\n"
Branch: 2 branches
BranchTrueFalseTotal
@$list == 1 ? : 0 0 0
$rows ? : 0 0 0
50 . ($rows ? qq{<div class="scroll"><table><thead><tr><th>project</th><th>thread</th><th>lead</th><th>members</th>}
51 . qq{<th>created</th></tr></thead>\n<tbody>\n$rows</tbody></table></div>\n} : '');
52 0 ▶ $c->page(200, defined $project ? "Rounds of $project" : 'Rounds', $html);
Branch: 1 branch
BranchTrueFalseTotal
defined $project ? : 0 0 0
53 0 }));
54 }
55  
56 0 ▶sub _new ($c) {
Subroutine _new: not called CC=1 SCAR=6.9
57 0 ▶ App::teai::Presence::list($c->bus, $c->cb(sub ($peers, $e = undef) {
Subroutine __ANON__: not called CC=16 SCAR=56.1
58 0 ▶ my $note = !defined $e ? undef : App::teai::Bus::no_bucket($e) ? 'the hub has no teai_peers bucket: run teai init'
Branch: 2 branches
BranchTrueFalseTotal
!defined($e) ? : 0 0 0
App::teai::Bus::no_bucket($e) ? : 0 0 0
59 : 'cannot read presence (' . App::teai::Bus::_text($e) . ')';
60 0 my %agent;
61 0 ▶ for my $id (keys %{ $peers // {} }) {
Condition0%0/2
$peers // {}
l!l
00
MC/DC0%0/1
$peers // {}
$peers
Truth table0%0/2
A
A= $peers
Aresult
11
00
62 0 my $p = $peers->{$id};
63 0 ▶ next if $id eq $c->operator || !$p->{live} || !@{ $p->{live} };
Branch: 1 branch
BranchTrueFalseTotal
if $id eq $c->operator or not $p->{"live"} or not @{$p->{"live"};} 0 0 0
Condition0%0/6
$id eq $c->operator or not $p->{"live"} or not @{$p->{"live"};}
l!l&&r!l&&!r
000
$id eq $c->operator or not $p->{"live"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$id eq $c->operator or not $p->{"live"} or not @{$p->{"live"};}
$id eq $c->operator not $p->{"live"} not @{$p->{"live"};}
Truth table0%0/4
A or not(B) or not(C)
A= $id eq $c->operatorB= not $p->{"live"}C= not @{$p->{"live"};}
ABCresult
1XX1
01X1
0011
0000
64 0 $agent{$id} = $p->{agent};
65 }
66 0 my (%count, %n);
67 0 $count{$_}++ for values %agent;
68 my $boxes = join '', map {
69 0 my ($id, $p) = ($_, $peers->{$_});
70 0 my $agent = $agent{$id};
71 0 ▶ my $name = $count{$agent} > 1 ? $agent . ++$n{$agent} : $agent;
Branch: 1 branch
BranchTrueFalseTotal
$count{$agent} > 1 ? : 0 0 0
72 '<label><input type="checkbox" name="pick" value="' . esc("$name=$id") . '">'
73 . esc("$name = $id (" . join(', ', 'project ' . ($p->{project} // '-'), 'role ' . ($p->{role} // '-'),
74 0 ▶ 'live ' . join(',', @{ $p->{live} })) . ')') . "</label>\n";
Condition0%0/4
$p->{"project"} // "-"
l!l
00
$p->{"role"} // "-"
l!l
00
MC/DC0%0/1
$p->{"project"} // "-"
$p->{"project"}
MC/DC0%0/1
$p->{"role"} // "-"
$p->{"role"}
Truth table0%0/2
A
A= $p->{"project"}
Aresult
11
00
Truth table0%0/2
A
A= $p->{"role"}
Aresult
11
00
75 0 ▶ } sort { $agent{$a} cmp $agent{$b} || $a cmp $b } keys %agent;
Condition0%0/3
$agent{$a} cmp $agent{$b} || $a cmp $b
l!l&&r!l&&!r
000
MC/DC0%0/2
$agent{$a} cmp $agent{$b} || $a cmp $b
$agent{$a} cmp $agent{$b} $a cmp $b
Truth table0%0/3
A || B
A= $agent{$a} cmp $agent{$b}B= $a cmp $b
ABresult
1X1
011
000
76 0 ▶ my $inner = '<p>' . esc('The round is started in project ' . $c->project . ' by ' . $c->operator
Branch: 1 branch
BranchTrueFalseTotal
defined $note ? : 0 0 0
Condition0%0/2
$boxes or "<p>no live session</p>"
l!l
00
MC/DC0%0/1
$boxes or "<p>no live session</p>"
$boxes
Truth table0%0/2
A
A= $boxes
Aresult
11
00
77 . ', its lead; the replies come to its inbox.') . "</p>\n"
78 . '<label>Thread <input type="text" name="thread"></label>'
79 . '<label>Brief <textarea name="brief"></textarea></label>'
80 . '<fieldset><legend>Live sessions</legend>'
81 . (defined $note ? '<p class="note">' . esc($note) . '</p>' : $boxes || '<p>no live session</p>') . '</fieldset>'
82 . '<label>Members, one NAME=SESSION a line <textarea name="members"></textarea></label>';
83 0 $c->page(200, 'New round', $c->form('/round/new', {}, $inner, 'start the round'));
84 0 }));
85 }
86  
87 0 ▶sub _sent ($c, $title, $project, $thread, $res, $e) {
Subroutine _sent: not called CC=9 SCAR=45.0
88 0 ▶ my $r = $res // (ref $e && eval { $e->isa('App::teai::Err') } ? $e->{result} : undef);
Branch: 1 branch
BranchTrueFalseTotal
ref $e && eval { do { $e->isa('App::teai::Err') } } ? : 0 0 0
Condition0%0/6
$res // (ref $e && eval { do { $e->isa("App::teai::Err") } } ? $e->{"result"} : undef)
l!l&&r!l&&!r
000
ref $e and eval { do { $e->isa("App::teai::Err") } }
!ll&&!rl&&r
000
MC/DC0%0/3
$res // (ref $e && eval { do { $e->isa("App::teai::Err") } } ? $e->{"result"} : undef)
$res ref $e eval { do { $e->isa("App::teai::Err") } }
Truth table0%0/4
A // B and C
A= $resB= ref $eC= eval { do { $e->isa("App::teai::Err") } }
ABCresult
1XX1
0111
00X0
0100
89 0 ▶ return $c->fail($e) if defined $e && !$r;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e and not $r 0 0 0
Condition0%0/3
defined $e and not $r
!ll&&!rl&&r
000
MC/DC0%0/2
defined $e and not $r
defined $e not $r
Truth table0%0/3
A and not(B)
A= defined $eB= not $r
ABresult
0X0
100
111
90 0 my $html = '';
91 0 $html .= '<ul>' . join('', map { '<li>' . esc("$_->{name} $_->{session} $_->{seq}") . '</li>' } @{ $r->{sent} }) . "</ul>\n"
92 0 ▶ if @{ $r->{sent} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$r->{"sent"};} 0 0 0
93 0 $html .= join '', map { '<p class="note">' . esc($_) . "</p>\n" } @{ $r->{warnings} };
94 0 $html .= join '', map { '<p class="error">' . esc("brief not sent to $_->{name}: $_->{error}") . "</p>\n" } @{ $r->{failed} };
95 0 $html .= _link($project, $thread);
96 0 ▶ return $c->fail_result($e, $html) if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 0 0 0
97 0 ▶ return $c->result(200, $title, $html) if @{ $r->{sent} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$r->{"sent"};} 0 0 0
98 0 $c->result(502, 'Not sent', $html);
99 }
100  
101 0 ▶sub _members ($c) {
Subroutine _members: not called CC=6 SCAR=37.4
102 0 my @members;
103 0 ▶ for my $item (map { s/\A\s+|\s+\z//gr } $c->params('pick'), split /\r\n?|\n/, $c->param('members') // '') {
Condition0%0/2
$c->param("members") // ""
l!l
00
MC/DC0%0/1
$c->param("members") // ""
$c->param("members")
Truth table0%0/2
A
A= $c->param("members")
Aresult
11
00
104 0 ▶ next unless length $item;
Branch: 1 branch
BranchTrueFalseTotal
unless length $item 0 0 0
105 0 my ($name, $session) = $item =~ /\A([^=]*)=(.*)\z/s;
106 0 ▶ App::teai::Err::fail(2, "invalid member '$item': give NAME=SESSION")
Branch: 1 branch
BranchTrueFalseTotal
unless App::teai::Wire::valid_id($name) and App::teai::Wire::valid_id($session) 0 0 0
Condition0%0/3
App::teai::Wire::valid_id($name) and App::teai::Wire::valid_id($session)
!ll&&!rl&&r
000
MC/DC0%0/2
App::teai::Wire::valid_id($name) and App::teai::Wire::valid_id($session)
App::teai::Wire::valid_id($name) App::teai::Wire::valid_id($session)
Truth table0%0/3
A and B
A= App::teai::Wire::valid_id($name)B= App::teai::Wire::valid_id($session)
ABresult
0X0
100
111
107 unless App::teai::Wire::valid_id($name) && App::teai::Wire::valid_id($session);
108 0 push @members, [ $name, $session ];
109 }
110 0 return \@members;
111 }
112  
113 0 ▶sub _start ($c) {
Subroutine _start: not called CC=4 SCAR=30.0
114 0 ▶ my $members = eval { _members($c) } or return $c->fail($@);
Branch: 1 branch
BranchTrueFalseTotal
my $members = eval { do { _members($c) } } or return $c->fail($@) 0 0 0
115 0 ▶ my ($project, $thread) = ($c->project, $c->param('thread') // '');
Condition0%0/2
$c->param("thread") // ""
l!l
00
MC/DC0%0/1
$c->param("thread") // ""
$c->param("thread")
Truth table0%0/2
A
A= $c->param("thread")
Aresult
11
00
116 0 App::teai::Round::start($c->bus,
117 project => $project, thread => $thread, lead => $c->operator, members => $members, role => 'operator',
118 body => ($c->param('brief') // '') =~ s/\r\n?/\n/gr,
119 0 ▶ $c->cb(sub ($res, $e = undef) { _sent($c, 'Round started', $project, $thread, $res, $e) }));
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$c->param("brief") // ""
l!l
00
MC/DC0%0/1
$c->param("brief") // ""
$c->param("brief")
Truth table0%0/2
A
A= $c->param("brief")
Aresult
11
00
120 }
121  
122 0 ▶sub _resend ($c, $project, $thread) {
Subroutine _resend: not called CC=1 SCAR=6.9
123 0 App::teai::Round::resend($c->bus,
124 project => $project, thread => $thread, lead => $c->operator, names => [ $c->params('name') ], role => 'operator',
125 0 ▶ $c->cb(sub ($res, $e = undef) { _sent($c, 'Brief sent again', $project, $thread, $res, $e) }));
Subroutine __ANON__: not called CC=2 SCAR=17.9
126 }
127  
128 0 ▶sub _replies ($got, $thread) {
Subroutine _replies: not called CC=2 SCAR=17.9
129 0 my $members = $got->{record}{members};
130 0 my %of = map { my $n = $_; map { ($_ => $n) } @{ $members->{$n}{seqs} } } keys %$members;
131 0 return @{ $got->{replies} }
132 0 ▶ ? join '', map { App::teai::Dash::Threads::article($_, label => $of{ $_->{re} }, page => "/thread/$thread") } @{ $got->{replies} }
Branch: 1 branch
BranchTrueFalseTotal
@{$got->{'replies'};} ? : 0 0 0
133 : "<p>no reply yet</p>\n";
134 }
135  
136 0 ▶sub _round ($c, $project, $thread) {
Subroutine _round: not called CC=1 SCAR=6.9
137 0 ▶ $c->hold(sub ($done) { App::teai::Round::status($c->bus, $project, $thread, $done) }, sub ($st, $e = undef) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=3 SCAR=24.8
138 0 ▶ defined $e ? $c->fail($e) : _render($c, $st);
Branch: 1 branch
BranchTrueFalseTotal
defined $e ? : 0 0 0
139 0 });
140 }
141  
142 0 ▶sub _render ($c, $st) {
Subroutine _render: not called CC=5 SCAR=34.0
143 0 my $rec = $st->{record};
144 0 my ($p, $t, $lead) = @$rec{qw(project thread lead)};
145 0 my $mine = $lead eq $c->operator;
146 0 my $base = "/round/$p/$t";
147 0 my %inline = map { ($_->{seq} => 1) } @{ $st->{replies} };
148 my $rows = join '', map {
149 0 my $m = $_;
150 0 my $reply = $m->{reply};
151 '<tr id="member-' . esc($m->{name}) . '">' . _cells(
152 esc($m->{name}), esc($m->{session}), esc($m->{state}),
153 0 ▶ join(', ', map { '<a href="' . esc("/thread/$t#m$_") . '">' . esc($_) . '</a>' } @{ $m->{briefs} }),
Branch: 3 branches
BranchTrueFalseTotal
defined $reply ? : 0 0 0
$inline{$reply} ? : 0 0 0
$mine ? : 0 0 0
154 defined $reply ? '<a href="' . esc(($inline{$reply} ? '' : "/thread/$t") . "#m$reply") . '">' . esc($reply) . '</a>' : '-',
155 0 $mine ? $c->form("$base/resend", { name => $m->{name} }, '', 're-send the brief') : '',
156 ) . "</tr>\n";
157 0 } @{ $st->{members} };
158 0 ▶ my $html = '<p class="head">' . esc("project $p, lead $lead, created $rec->{created}, brief $rec->{brief}{bytes} bytes")
Branch: 1 branch
BranchTrueFalseTotal
$mine ? : 0 0 0
159 . ' <a href="' . esc("/thread/$t") . '">' . esc("thread $t") . "</a></p>\n"
160 . ($mine ? $c->form("$base/collect", {}, '<p>Mark the replies below read in the inbox of this dashboard.</p>', 'collect')
161 : '<p class="note">' . esc("led by $lead: shown only") . "</p>\n")
162 . qq{<div class="scroll"><table><thead><tr><th>member</th><th>session</th><th>state</th><th>briefs</th><th>reply</th>}
163 . qq{<th></th></tr></thead>\n<tbody>\n$rows</tbody></table></div>\n<h2>Replies</h2>\n} . _replies($st, $t);
164 0 $c->page(200, "Round $t", $html, watch => "thread:$t");
165 }
166  
167 0 ▶sub _collect ($c, $project, $thread) {
Subroutine _collect: not called CC=1 SCAR=6.9
168 0 ▶ $c->hold(sub ($done) { App::teai::Round::collect($c->bus, $project, $thread, ack => $c->operator, $done) }, sub ($r, $e = undef) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=5 SCAR=34.0
169 0 ▶ return $c->fail_after($e) if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 0 0 0
170 0 my $n = @{ $r->{replies} };
171 0 ▶ my $html = '<p>' . esc("$n " . ($n == 1 ? 'reply' : 'replies') . ' collected and marked read') . "</p>\n";
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 0 0 0
172 0 ▶ $html .= '<p class="note">' . esc('no reply yet from ' . join(', ', @{ $r->{missing} })) . "</p>\n" if @{ $r->{missing} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$r->{"missing"};} 0 0 0
173 0 $c->result(200, "Round $thread", $html . _replies($r, $thread) . _link($project, $thread));
174 0 });
175 }
176  
177 1 1;
178 __END__
« lib/App/teai/Exec.pm ↑ Summary lib/App/teai/Hook.pm »