Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
404efd5
extract issues summary widget into edition partials
MattBudz Jun 29, 2026
c3c449e
merge develop to pick up crass 1.0.7 security update
MattBudz Jun 29, 2026
1fa82a2
extract shared tags accordion into a sub-partial
MattBudz Jun 29, 2026
f3ed086
move chart data to controller; set attributes on #issue-chart
MattBudz Jun 29, 2026
9635184
fix RuboCop ExtraSpacing violations in projects_controller
MattBudz Jun 29, 2026
2b8d3b8
use each over for..in for tag iteration
MattBudz Jul 15, 2026
52eac9f
extract tag grouping into a shared IssuesGrouping concern
MattBudz Jul 15, 2026
498db39
Merge remote-tracking branch 'origin/develop' into dashboard/extract-…
MattBudz Jul 15, 2026
fa855c9
rename IssuesGrouping to IssuesDimensionGrouping
MattBudz Jul 16, 2026
26abf01
add issues_summary route and controller
MattBudz Jul 16, 2026
e02447e
lazy-load the issues-summary widget via a turbo frame
MattBudz Jul 16, 2026
7f05c34
stop eagerly computing issue grouping in ProjectsController#show
MattBudz Jul 16, 2026
d7dde6d
add request spec for Projects::IssuesSummaryController
MattBudz Jul 16, 2026
67a9606
fix pre-existing RuboCop spacing offenses in routes.rb
MattBudz Jul 16, 2026
bc1ee96
initialize the issues chart on turbo:frame-load, not turbo:load
MattBudz Jul 17, 2026
df2b89b
add feature spec covering the lazy-loaded issues chart
MattBudz Jul 17, 2026
5f13e76
break out of the issues-summary frame when opening an issue
MattBudz Jul 17, 2026
d180a34
simplify build_all_tags_grouping with Hash.new(0)
MattBudz Jul 17, 2026
d4bab36
extract a colors array in initIssuesChart
MattBudz Jul 17, 2026
605e6ee
fix stray double space in colored_icon_for_model
MattBudz Jul 17, 2026
80ab8ed
drop manual alignment padding in initIssuesChart data variables
MattBudz Jul 17, 2026
4bec4b1
Merge branch 'develop' into dashboard/extract-issues-summary-edition-…
MattBudz Jul 21, 2026
3dbb787
match combobox options by attribute value instead of a raw selector
MattBudz Jul 21, 2026
adaa6c1
Merge remote-tracking branch 'origin/dashboard/extract-issues-summary…
MattBudz Jul 21, 2026
9f88530
Merge branch 'develop' into dashboard/extract-issues-summary-edition-…
MattBudz Aug 3, 2026
0fe97cd
move issues chart legend below chart, wrap horizontally
MattBudz Aug 3, 2026
51446af
Merge branch 'develop' into dashboard/extract-issues-summary-edition-…
MattBudz Aug 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 90 additions & 95 deletions app/assets/javascripts/hera/pages/projects/issues_chart.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,90 @@
document.addEventListener('turbo:load', function(){
var $dataElement = $('#issues-summary-data'),
$chartElement = $('#issue-chart');

if ($dataElement.length && $chartElement.find('svg').length == 0) {
var margin = {top: 20, bottom: 30},
width = 354;
height = 180 - margin.top - margin.bottom;

var x = d3.scaleBand().rangeRound([0, width]);

var y = d3.scaleLinear()
.range([height, 0]);

var xAxis = d3.axisBottom(x)
.tickSize(0);

var svg = d3.select('#issue-chart').append('svg')
.attr('width', width)
.attr('height', height + margin.top + margin.bottom)
.append('g')
.attr('transform', 'translate(0,' + margin.top + ')');

// --------------------------------------------------------- Data variables
var tags = $dataElement.data('tags');
var issuesByTag = $dataElement.data('issues-count');
var highest = 0;
var data = [];
var x_domain = [];

for (var key in tags){
issuesCount = issuesByTag[key];
highest = issuesCount > highest ? issuesCount : highest
data.push({letter: tags[key][0], frequency: issuesCount});
x_domain.push(tags[key][0]);
}
data.push({letter: 'N/A', frequency: issuesByTag['unassigned']})
x_domain.push('N/A');

var highest_y = Math.max(highest, issuesByTag['unassigned']);
// -------------------------------------------------------- /Data variables

x.domain(x_domain);

y.domain([0, highest_y]);

d3.selection.prototype.last = function() {
return d3.select(
this.nodes()[this.size() - 1]
);
};

x_axis = svg.append('g')
.attr('class', 'x axis')
.attr('transform', 'translate(0,' + height + ')')
.call(xAxis);
x_axis.selectAll("text").style("fill", "inherit");
x_axis.selectAll("path").style("stroke", "none");
x_axis.selectAll("text").last().classed("untagged", true);

var bars = svg.append('g');

bars.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('class', 'bar' )
.attr('x', function(d) { return x(d.letter); })
.attr('width', x.bandwidth())
.attr('y', function(d) { return y(d.frequency); })
.attr('height', function(d) { return height - y(d.frequency); });


bars.selectAll('text')
.data(data)
.enter().append('text')
.attr('x', function(d, i) { return x(d.letter) + x.bandwidth()/2; })
.attr('y', function(d) { return y(d.frequency);})
.attr('dy', -5)
.attr('text-anchor', 'middle')
.attr('class', 'counter' )
.text(function(d) {return d.frequency;});

var i = 0;
for( var key in tags ){
$($('.tick')[i]).attr('fill', tags[key][1]);
$($('.bar')[i]).attr('fill', tags[key][1]);
$($('.counter')[i]).attr('fill', tags[key][1]);
i++;
}

$($('.tick')[i]).addClass('untagged');
$($('.bar')[i]).addClass('untagged');
$($('.counter')[i]).addClass('untagged');
}
});
function initIssuesChart() {
const $chartElement = $('#issue-chart');

if (!$chartElement.length || $chartElement.find('svg').length > 0) { return; }

const margin = { top: 20, bottom: 30 };
const width = 354;
const height = 180 - margin.top - margin.bottom;

const x = d3.scaleBand().rangeRound([0, width]);
const y = d3.scaleLinear().range([height, 0]);

const xAxis = d3.axisBottom(x).tickSize(0);

const svg = d3.select('#issue-chart').append('svg')
.attr('width', width)
.attr('height', height + margin.top + margin.bottom)
.append('g')
.attr('transform', `translate(0,${margin.top})`);

// --------------------------------------------------------- Data variables
const tags = $chartElement.data('tags') || {};
const issuesByTag = $chartElement.data('issues-count') || {};
let highest = 0;
const data = [];
const x_domain = [];

Object.keys(tags).forEach(key => {
const count = issuesByTag[key] || 0;
highest = count > highest ? count : highest;
data.push({ letter: tags[key][0], frequency: count });
x_domain.push(tags[key][0]);
});

const unassignedCount = issuesByTag['unassigned'] || 0;
data.push({ letter: 'N/A', frequency: unassignedCount });
x_domain.push('N/A');

const highest_y = Math.max(highest, unassignedCount);
// -------------------------------------------------------- /Data variables

x.domain(x_domain);
y.domain([0, highest_y]);

d3.selection.prototype.last = function() {
return d3.select(this.nodes()[this.size() - 1]);
};

const x_axis = svg.append('g')
.attr('class', 'x axis')
.attr('transform', `translate(0,${height})`)
.call(xAxis);
x_axis.selectAll('text').style('fill', 'inherit');
x_axis.selectAll('path').style('stroke', 'none');
x_axis.selectAll('text').last().classed('untagged', true);

const bars = svg.append('g');

bars.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('class', 'bar')
.attr('x', d => x(d.letter))
.attr('width', x.bandwidth())
.attr('y', d => y(d.frequency))
.attr('height', d => height - y(d.frequency));

bars.selectAll('text')
.data(data)
.enter().append('text')
.attr('x', d => x(d.letter) + x.bandwidth() / 2)
.attr('y', d => y(d.frequency))
.attr('dy', -5)
.attr('text-anchor', 'middle')
.attr('class', 'counter')
.text(d => d.frequency);

const tagCount = Object.keys(tags).length;
Object.keys(tags).forEach((key, i) => {
$($('.tick')[i]).attr('fill', tags[key][1]);
$($('.bar')[i]).attr('fill', tags[key][1]);
$($('.counter')[i]).attr('fill', tags[key][1]);
});

$($('.tick')[tagCount]).addClass('untagged');
$($('.bar')[tagCount]).addClass('untagged');
$($('.counter')[tagCount]).addClass('untagged');
}

document.addEventListener('turbo:load', initIssuesChart);
26 changes: 16 additions & 10 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ class ProjectsController < AuthenticatedController

before_action :set_project

helper :hera
helper :hera
helper_method :current_project

def index
redirect_to project_path(current_project)
end

def show
@activities = Activity.latest
@authors = [current_user]
@boards = current_project.methodology_library.boards
@issues = current_project.issues.includes(:tags).sort
@activities = Activity.latest
@authors = [current_user]
@boards = current_project.methodology_library.boards
@issues = current_project.issues.includes(:tags).sort
@methodologies = current_project.methodology_library.notes.map { |n| Methodology.new(filename: n.id, content: n.text) }
@nodes = current_project.nodes.in_tree
@tags = current_project.tags
@nodes = current_project.nodes.in_tree
@tags = current_project.tags

@count_by_tag = { unassigned: 0 }
@count_by_tag = { unassigned: 0 }
@issues_by_tag = Hash.new { |h, k| h[k] = [] }

@tag_names = @tags.map do |tag|
Expand All @@ -30,15 +30,21 @@ def show
@issues.each do |issue|
if issue.tags.empty?
@issues_by_tag[:unassigned] << issue
@count_by_tag[:unassigned] += 1
@count_by_tag[:unassigned] += 1
else
issue.tags.each do |tag|
@issues_by_tag[tag.name] << issue
@count_by_tag[tag.name] += 1
@count_by_tag[tag.name] += 1
end
end
end

@chart_data = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks parity with pro since it isn't used there in the same controller. As a compromise, I'm fine with moving this definition in the CE view if we add a comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went a step further than the view-move compromise, extracted the tag-grouping logic (including @chart_data) into a shared IssuesGrouping concern, matching how Pro already needs to call it from more than one controller. ProjectsController#show now just calls build_all_tags_grouping. This should make the sync cleaner since Pro's version of the concern can now land as an addition to this file rather than introducing it from scratch.

dimension: 'tags',
tags: @tag_names.to_json,
issues_count: @count_by_tag.to_json
}

respond_to do |format|
format.html { render layout: 'hera/project' if !request.xhr? }
format.json { render json: @boards }
Expand Down
64 changes: 1 addition & 63 deletions app/views/projects/issues/_summary.html.erb
Original file line number Diff line number Diff line change
@@ -1,63 +1 @@
<section class="summary-panel">
<% if @issues.any? %>
<h4 class="header-underline">Issues so far</h4>
<div id="issue-chart"></div>

<div id="issues-accordion" role="tablist">
<% for tag in @tags do %>
<% if @issues_by_tag[tag.name].any? %>
<div class="card" style="border-color: <%= tag.color %>">
<a data-bs-toggle="collapse" href="#collape<%= tag.display_name %>" class="card-header" style="background: <%= tag.color %>" data-behavior="card-header">
<h5><%= tag.display_name %><span class="float-end"><i class="fa-solid fa-caret-up" data-behavior="caret-icon"></i></span></h5>
</a>

<div id="collape<%= tag.display_name %>" class="collapse show">
<div class="card-body p-0">
<ul class="list-group">
<% @issues_by_tag[tag.name].each do |issue| %>
<%= link_to [current_project, issue], class: 'list-group-item' do %>
<li><i class="fa-solid fa-bug me-2" style="color: <%= tag.color %>"></i><%= issue.title %></li>
<% end %>
<% end %>
</ul>
</div>
</div>
</div>
<% end %>
<% end %>

<%# unassigned %>
<% if @issues_by_tag[:unassigned].any? %>
<div class="card untagged">
<a data-bs-toggle="collapse" href="#collapeUnassigned" class="card-header" data-behavior="card-header">
<h5>Unassigned<span class="float-end"><i class="fa-solid fa-caret-up" data-behavior="caret-icon"></i></span></h5>
</a>

<div id="collapeUnassigned" class="collapse show">
<div class="card-body p-0">
<ul class="list-group">
<% @issues_by_tag[:unassigned].each do |issue| %>
<%= link_to [current_project, issue], class: 'list-group-item' do %>
<li><i class="fa-solid fa-bug me-2"></i><%= issue.title %></li>
<% end %>
<% end %>
</ul>
</div>
</div>
</div>
<% end %>
</div>

<% else %>
<%= render 'shared/empty_state',
actions_partial: 'projects/issues/empty_state_actions',
name: 'issue',
docs_link: 'https://dradis.com/support/guides/projects/issues.html',
text: 'Use issues to represent vulnerabilities or findings.'
%>
<% end %>
</section>

<% if @issues.any? %>
<div id='issues-summary-data' data-tags='<%= @tag_names.to_json %>' data-issues-count='<%= @count_by_tag.to_json %>'></div>
<% end %>
<%= render "projects/issues/summary/#{Dradis.edition}" %>
18 changes: 18 additions & 0 deletions app/views/projects/issues/summary/_ce.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<section class="summary-panel">
<% if @issues.any? %>
<h4 class="header-underline">Issues so far</h4>
<%= tag.div id: 'issue-chart', data: @chart_data %>

<div id="issues-accordion" role="tablist">
<%= render 'projects/issues/summary/tags_accordion' %>
</div>

<% else %>
<%= render 'shared/empty_state',
actions_partial: 'projects/issues/empty_state_actions',
name: 'issue',
docs_link: 'https://dradis.com/support/guides/projects/issues.html',
text: 'Use issues to represent vulnerabilities or findings.'
%>
<% end %>
</section>
39 changes: 39 additions & 0 deletions app/views/projects/issues/summary/_tags_accordion.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<% for tag in @tags do %>
Comment thread
MattBudz marked this conversation as resolved.
Outdated
<% if @issues_by_tag[tag.name].any? %>
<div class="card" style="border-color: <%= tag.color %>">
<a data-bs-toggle="collapse" href="#collapse<%= tag.display_name %>" class="card-header" style="background: <%= tag.color %>" data-behavior="card-header">
<h5><%= tag.display_name %><span class="float-end"><i class="fa-solid fa-caret-up" data-behavior="caret-icon"></i></span></h5>
</a>
<div id="collapse<%= tag.display_name %>" class="collapse show">
<div class="card-body p-0">
<ul class="list-group">
<% @issues_by_tag[tag.name].each do |issue| %>
<%= link_to [current_project, issue], class: 'list-group-item' do %>
<li><i class="fa-solid fa-bug me-2" style="color: <%= tag.color %>"></i><%= issue.title %></li>
<% end %>
<% end %>
</ul>
</div>
</div>
</div>
<% end %>
<% end %>

<% if @issues_by_tag[:unassigned].any? %>
<div class="card untagged">
<a data-bs-toggle="collapse" href="#collapseUnassigned" class="card-header" data-behavior="card-header">
<h5>Unassigned<span class="float-end"><i class="fa-solid fa-caret-up" data-behavior="caret-icon"></i></span></h5>
</a>
<div id="collapseUnassigned" class="collapse show">
<div class="card-body p-0">
<ul class="list-group">
<% @issues_by_tag[:unassigned].each do |issue| %>
<%= link_to [current_project, issue], class: 'list-group-item' do %>
<li><i class="fa-solid fa-bug me-2"></i><%= issue.title %></li>
<% end %>
<% end %>
</ul>
</div>
</div>
</div>
<% end %>
Loading