Module: Protege::ToolkitsHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/protege/toolkits_helper.rb

Overview

View helpers for the toolkit dashboard. The member-tool checklist is built from the uniform extension manifest; the allow/deny gate is edited as ToolkitRule child rows (see the toolkit-rules partials). The overview helpers keep computed display values (tool names, proactive/count labels) out of the templates.

Instance Method Summary collapse

Instance Method Details

#all_toolkitsActiveRecord::Relation<Protege::Toolkit>

Every Toolkit for the global sidebar listing, ordered by name.

Returns:



12
13
14
# File 'app/helpers/protege/toolkits_helper.rb', line 12

def all_toolkits
  Toolkit.order(:name)
end

#attachable_toolkits(agent) ⇒ ActiveRecord::Relation<Protege::Toolkit>

The toolkits not yet attached to an agent — the options for its attach form.

Parameters:

Returns:

  • (ActiveRecord::Relation<Protege::Toolkit>)

    the attachable toolkits, by name



52
53
54
# File 'app/helpers/protege/toolkits_helper.rb', line 52

def attachable_toolkits(agent)
  Toolkit.where.not(id: agent.toolkit_ids).order(:name)
end

#gate_rule_kind_color(rule) ⇒ Symbol

The badge colour for a gate rule — green for allow, red for deny.

Parameters:

Returns:

  • (Symbol)

    :green or :red



44
45
46
# File 'app/helpers/protege/toolkits_helper.rb', line 44

def gate_rule_kind_color(rule)
  rule.allow? ? :green : :red
end

#toolkit_overview(toolkit) ⇒ Hash{String=>String}

The labelled summary rows shown in a toolkit's overview card.

Parameters:

Returns:

  • (Hash{String=>String})

    the info-card rows



28
29
30
# File 'app/helpers/protege/toolkits_helper.rb', line 28

def toolkit_overview(toolkit)
  { 'Tools' => toolkit_member_tool_names(toolkit) }
end

#toolkit_tool_count_label(toolkit) ⇒ String

A short "N tools" label for a toolkit listing.

Parameters:

Returns:

  • (String)

    the pluralized tool count



36
37
38
# File 'app/helpers/protege/toolkits_helper.rb', line 36

def toolkit_tool_count_label(toolkit)
  pluralize(toolkit.member_tool_ids.size, 'tool')
end

#toolkit_tool_optionsArray<Protege::Manifest::Entry>

The tool manifest entries offered as the member-tool checklist — the toolkit equivalent of AgentsHelper#agent_tool_options, built from the uniform extension manifest.

Returns:



20
21
22
# File 'app/helpers/protege/toolkits_helper.rb', line 20

def toolkit_tool_options
  Manifest.registered(:tool)
end