Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Docker:
- Update default attachments & templates locations to storage/
- Include assets for all integrations regardless of enabled/disabled status
- Liquid: evaluate Liquid content before rendering all issues/evidence tables
- Nodes:
- Add more types and icons
- Rename addon upload/parent nodes and add icons
Expand Down
20 changes: 19 additions & 1 deletion app/assets/javascripts/hera/modules/liquid_async.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
document.addEventListener('turbo:load', function () {
// Helper for updating table sorting values
function updateLiquidSortValue(element, html) {
const liquidText = $('<div>').html(html).text().trim();
$(element).attr('data-sort', liquidText);
}

function liquidAsync() {
$('[data-behavior~=liquid-async]').each(function () {
const that = this,
data = { text: $(that).attr('data-content') },
$spinner = $(that).prev().find('[data-behavior~=liquid-spinner');

const requiresSortUpdate = $(that).is('[data-sort]')

fetch($(that).attr('data-path'), {
method: 'POST',
headers: {
Expand All @@ -16,8 +24,18 @@ document.addEventListener('turbo:load', function () {
.then((response) => response.text())
.then(function (html) {
$(that).html(html);

if (requiresSortUpdate) {
updateLiquidSortValue(that, html);
}

$(that).trigger('dradis:liquid-rendered');
$spinner.addClass('d-none');
});
});
};

document.addEventListener('turbo:load', liquidAsync);
$(document).on('dradis:fetch', function(event) {
liquidAsync();
});
12 changes: 11 additions & 1 deletion app/controllers/issues/evidence_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ class Issues::EvidenceController < AuthenticatedController
include ActivityTracking
include ContentFromTemplate
include DynamicFieldNamesCacher
include LiquidEnabledResource
include MultipleDestroy
include ProjectScoped

before_action :set_issues, only: [:create_multiple, :index, :new]
before_action :set_issues, only: [:create_multiple, :index, :new, :preview]
before_action :set_affected_nodes, only: :index
before_action :set_auto_save_key, only: :new
before_action :set_columns, only: :index
before_action :set_evidence, only: :preview

def index
render layout: false
Expand Down Expand Up @@ -78,6 +80,10 @@ def evidence_params
params.require(:evidence).permit(:author, :content, :issue_id, :node_id)
end

def liquid_resource_assigns
{ 'evidence' => EvidenceDrop.new(@evidence) }
end

def node_params_empty?
params[:evidence][:node_list].blank? &&
(params[:evidence][:node_ids].reject(&:empty?).empty?)
Expand Down Expand Up @@ -114,6 +120,10 @@ def set_auto_save_key
end
end

def set_evidence
@evidence = @issue.evidence.find_by(id: params[:id])
end

def set_issues
@issues = current_project.issues.order(:text)
@issue = @issues.find(params[:issue_id]) if params[:issue_id]
Expand Down
17 changes: 10 additions & 7 deletions app/views/issues/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<tr id="issue-<%= issue.id %>" data-tag-url="<%= project_issue_path(current_project, issue) %>">
<td class="select-checkbox" data-behavior="select-checkbox"></td>
<% @all_columns.each do |column| %>
<% data_attrs = { behavior: class_names(tag: column == 'Tags') } %>
<% sort, display =
case column
when 'Title'
Expand All @@ -50,16 +51,18 @@
when 'Updated'
[issue.updated_at.to_i, local_time_ago(issue.updated_at)]
else
[issue.fields.fetch(column, ''), markup(issue.fields.fetch(column, ''))]
field_content = issue.fields.fetch(column, '')
data_attrs[:behavior] = "#{data_attrs[:behavior]} liquid-async".strip
data_attrs[:path] = preview_project_issue_path(current_project, issue)
data_attrs[:content] = field_content

[field_content, field_content]
end
%>
<%= content_tag :td,
display,
class: class_names('text-break-spaces': column == 'Affected'),
data: {
behavior: class_names(tag: column == 'Tags'),
sort: sort
}
display,
class: class_names('text-break-spaces': column == 'Affected'),
data: data_attrs.merge({ sort: sort })
%>
<% end %>
<td class="column-actions">
Expand Down
13 changes: 11 additions & 2 deletions app/views/issues/evidence/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<tr id="evidence-<%= evidence.id %>">
<td class="select-checkbox" data-behavior="select-checkbox"></td>
<% @all_columns.each do |column| %>
<% data_attrs = {} %>
<%
sort, display =
case column
Expand All @@ -31,10 +32,18 @@
when 'Updated'
[evidence.updated_at.to_i, local_time_ago(evidence.updated_at)]
else
[evidence.fields.fetch(column, ''), markup(evidence.fields.fetch(column, ''))]
field_content = evidence.fields.fetch(column, '')
data_attrs[:behavior] = "#{data_attrs[:behavior]} liquid-async".strip
data_attrs[:path] = preview_project_issue_evidence_path(current_project, @issue, evidence)
data_attrs[:content] = field_content

[field_content, field_content]
end
%>
<td data-sort="<%= sort %>"><%= display %></td>
<%= content_tag :td,
display,
data: data_attrs.merge({ sort: sort })
%>
<% end %>
<td class="column-actions">
<%= link_to edit_project_node_evidence_path(current_project, node, evidence, return_to: :issue) do %>
Expand Down
13 changes: 11 additions & 2 deletions app/views/nodes/items_table/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<tr id="<%= class_name %>-<%= item.id %>">
<td class="select-checkbox" data-behavior="select-checkbox"></td>
<% columns.each do |column| %>
<% data_attrs = {} %>
<%
sort, display =
case column
Expand All @@ -47,10 +48,18 @@
when 'Updated'
[item.updated_at.to_i, local_time_ago(item.updated_at)]
else
[item.fields.fetch(column, ''), markup(item.fields.fetch(column, ''))]
field_content = item.fields.fetch(column, '')
data_attrs[:behavior] = "#{data_attrs[:behavior]} liquid-async".strip
data_attrs[:path] = preview_project_node_evidence_path(current_project, @node, item)
data_attrs[:content] = field_content

[field_content, field_content]
end
%>
<td data-sort="<%= sort %>"><%= display %></td>
<%= content_tag :td,
display,
data: data_attrs.merge({ sort: sort })
%>
<% end %>
<td class="column-actions">
<%= link_to [:edit, @node.project, @node, item] do %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
resources :merge, only: [:new, :create], controller: 'issues/merge'
end

resources :evidence, concerns: :multiple_destroy, controller: 'issues/evidence', only: [:index, :new]
resources :evidence, concerns: [:multiple_destroy, :previewable], controller: 'issues/evidence', only: [:index, :new]
resources :nodes, only: [:show], controller: 'issues/nodes'
resources :revisions, only: [:index, :show]
end
Expand Down