unclesp1d3r/CipherSwarm

View on GitHub
app/views/campaigns/show.html.erb

Summary

Maintainability
Test Coverage
<%= render Railsboot::HeaderComponent.new do |header| %>
  <% header.with_heading do %>
    <%= title @campaign.name %>
  <% end %>
  <%= header.with_actions do %>
    <% if can? :create, @campaign => Attack %>
      <%= render Railsboot::Button::LinkComponent.new(href: new_campaign_attack_path(@campaign, attack_mode: :dictionary), size: "sm", title: "Add Dictionary Attack") do %>
        <%= inline_svg_tag "dictionary_attack_icon.svg",
                           size: "20px",
                           preserve_aspect_ratio: true,
                           title: "Add Dictionary Attack" %>
      <% end %>
      <%= render Railsboot::Button::LinkComponent.new(href: new_campaign_attack_path(@campaign, attack_mode: :mask), size: "sm", title: "Add Mask Attack") do %>
        <%= inline_svg_tag "mask_attack_icon.svg",
                           size: "20px",
                           preserve_aspect_ratio: true,
                           title: "Add Mask Attack" %>
      <% end %>
      <%= render Railsboot::Button::LinkComponent.new(href: new_campaign_attack_path(@campaign, attack_mode: :hybrid_dictionary), size: "sm", title: "Add Hybrid Attack") do %>
        <%= inline_svg_tag "hybrid_attack_icon.svg",
                           size: "20px",
                           preserve_aspect_ratio: true,
                           title: "Add Hybrid Dictionary Attack" %>
      <% end %>
      <%= render Railsboot::Button::LinkComponent.new(href: new_campaign_attack_path(@campaign, attack_mode: :hybrid_mask), size: "sm", title: "Add Hybrid Attack") do %>
        <%= inline_svg_tag "hybrid_attack_icon.svg",
                           size: "20px",
                           preserve_aspect_ratio: true,
                           title: "Add Hybrid Mask Attack" %>
      <% end %>
      <% if can? :edit, @campaign %>
        <%= render Railsboot::Button::LinkComponent.new(variant: "warning", href: edit_campaign_path(@campaign), size: "sm", title: "Edit") do %>
          <%= icon("pencil") %>
        <% end %>
      <% end %>
    <% end %>
  <% end %>
  <% header.with_breadcrumb.with_items([
       { text: "Dashboard", href: root_path },
       { text: "Activity", href: campaigns_path },
       { text: @campaign.name, href: @campaign, active: true }
                                       ]) %>
<% end %>
<%= turbo_stream_from @campaign %>
<small class="text-muted">Created <%= time_ago_in_words(@campaign.created_at) %> ago</small>
<h4><%= @campaign.priority.humanize %></h4>
<p><%= @campaign.description %></p>
<% if @campaign.attacks.empty? %>
  <%= render Railsboot::BlankSlateComponent.new do |blankslate| %>
    <% blankslate.with_icon do %>
      <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" fill="currentColor" class="bi bi-sticky" viewBox="0 0 16 16">
        <path d="M2.5 1A1.5 1.5 0 0 0 1 2.5v11A1.5 1.5 0 0 0 2.5 15h6.086a1.5 1.5 0 0 0 1.06-.44l4.915-4.914A1.5 1.5 0 0 0 15 8.586V2.5A1.5 1.5 0 0 0 13.5 1zM2 2.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 .5.5V8H9.5A1.5 1.5 0 0 0 8 9.5V14H2.5a.5.5 0 0 1-.5-.5zm7 11.293V9.5a.5.5 0 0 1 .5-.5h4.293z"/>
      </svg>
    <% end %>
    <% blankslate.with_heading(tag: "h3").with_content("The campaign is empty") %>
    <% blankslate.with_description.with_content("A campaign is a collection of attacks. You can add attacks to this campaign.") %>
    <% blankslate.with_primary_action do %>
      Click one of the attack buttons above to add an attack to this campaign.
    <% end %>
  <% end %>
<% else %>
  <%= render Railsboot::StepperComponent.new do |stepper| %>
    <%= render partial: "attack_stepper_line", collection: @campaign.attacks, as: :attack, locals: { campaign: @campaign, stepper: } %>
  <% end %>
<% end %>