Skip to content

Commit

Permalink
Show number of pattern matches in pattern list
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 22, 2024
1 parent 88b0a73 commit 1c53b34
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/Cavil/Model/Patterns.pm
Expand Up @@ -159,7 +159,17 @@ sub checksum ($self, $pattern) {
}

sub for_license ($self, $license) {
return $self->pg->db->select('license_patterns', '*', {license => $license}, 'created')->hashes->to_array;
my $db = $self->pg->db;
my $patterns = $db->select('license_patterns', '*', {license => $license}, 'created')->hashes->to_array;
for my $pattern (@$patterns) {
my $count = $db->query(
'SELECT COUNT(*) AS matches, COUNT(DISTINCT(package)) AS packages
FROM pattern_matches WHERE pattern = ?', $pattern->{id}
)->hash;
$pattern->{matches} = $count->{matches};
$pattern->{packages} = $count->{packages};
}
return $patterns;
}

sub paginate_known_licenses ($self, $options) {
Expand Down
6 changes: 6 additions & 0 deletions templates/license/show.html.ep
Expand Up @@ -62,6 +62,12 @@
%= $match->{export_restricted} ? 'Export Restricted' : ''
</span>
% }
% my $matches = $match->{matches};
% my $packages = $match->{packages};
<span class="float-end">
<%= $matches %> <%= $matches == 1 ? 'match' : 'matches' %> in
<%= $packages %> <%= $packages == 1 ? 'package' : 'packages' %>
</span>
</div>
</div>
</div>
Expand Down

0 comments on commit 1c53b34

Please sign in to comment.