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
4 changes: 2 additions & 2 deletions app/controllers/maintenance_tasks/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class ApplicationController < MaintenanceTasks.parent_controller.constantize
policy.style_src_elem(
BULMA_CDN,
# <style> tag in app/views/layouts/maintenance_tasks/application.html.erb
"'sha256-Uhc2rCuqplhR7sM05OaAY3Fv+TFerqLtTOPdVycAIQ4='",
"'sha256-jxixiCsEmOniWo0ywDFgxS+LQe+frJrsg1dfPPTJhAA='",
)
capybara_lockstep_scripts = [
"'sha256-1AoN3ZtJC5OvqkMgrYvhZjp4kI8QjJjO7TAyKYiDw+U='",
"'sha256-QVSzZi6ZsX/cu4h+hIs1iVivG1BxUmJggiEsGDIXBG0='", # with debug on
] if defined?(Capybara::Lockstep)
policy.script_src_elem(
# <script> tag in app/views/layouts/maintenance_tasks/application.html.erb
"'sha256-NiHKryHWudRC2IteTqmY9v1VkaDUA/5jhgXkMTkgo2w='",
"'sha256-n0UyWNeUyfUfrkvN/G1LqwSiN8WTlXTbA2BCEPmtKrQ='",
# <script> tag for capybara-lockstep
*capybara_lockstep_scripts,
)
Expand Down
12 changes: 11 additions & 1 deletion app/controllers/maintenance_tasks/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ class TasksController < ApplicationController
# Renders the maintenance_tasks/tasks page, displaying
# available tasks to users, grouped by category.
def index
@available_tasks = TaskDataIndex.available_tasks.group_by(&:category)
all_tasks = TaskDataIndex.available_tasks
@namespaces = helpers.extract_namespaces(all_tasks)
@selected_namespace = params[:namespace]

filtered_tasks = if @selected_namespace.present?
all_tasks.select { |task| task.name.start_with?("#{@selected_namespace}::") }
else
all_tasks
end

@available_tasks = filtered_tasks.group_by(&:category)
end

# Renders the page responsible for providing Task actions to users.
Expand Down
50 changes: 50 additions & 0 deletions app/helpers/maintenance_tasks/tasks_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,55 @@ def attribute_required?(task, parameter_name)
validator.kind == :presence
end
end

# Extracts unique namespaces from a collection of tasks.
#
# @param tasks [Array] collection of task objects with a name method.
# @return [Array<String>] sorted unique namespaces.
def extract_namespaces(tasks)
tasks
.filter_map { |task| task.name.deconstantize.presence }
.uniq
.sort
end

# Builds a nested tree structure from a flat list of namespaces.
#
# @param namespaces [Array<String>] flat list of namespaces.
# @return [Hash] nested tree structure.
def build_namespace_tree(namespaces)
namespaces.each_with_object({}) do |namespace, tree|
parts = namespace.split("::")
parts.each_with_index.inject(tree) do |current, (part, index)|
full_path = parts[0..index].join("::")
current[part] ||= { name: part, full_path: full_path, children: {} }
current[part][:children]
end
end
end

# Renders a namespace tree node with nested children using details/summary.
#
# @param node [Hash] the node to render { name:, full_path:, children: }.
# @param selected_namespace [String, nil] the currently selected namespace.
# @return [ActiveSupport::SafeBuffer] HTML for the node.
def render_namespace_node(node, selected_namespace)
is_active = selected_namespace == node[:full_path]
is_expanded = is_active || selected_namespace&.start_with?("#{node[:full_path]}::")
link = link_to(node[:name], tasks_path(namespace: node[:full_path]), class: class_names("is-active" => is_active))

content_tag(:li) do
if node[:children].present?
content_tag(:details, open: is_expanded || nil) do
content_tag(:summary) { link } +
content_tag(:ul) do
safe_join(node[:children].values.sort_by { |n| n[:name] }.map { |child| render_namespace_node(child, selected_namespace) })
end
end
else
link
end
end
end
end
end
15 changes: 15 additions & 0 deletions app/views/layouts/maintenance_tasks/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@
<div class="navbar-brand">
<%= link_to 'Maintenance Tasks', root_path, class: 'navbar-item is-size-4 has-text-weight-semibold has-text-danger' %>
</div>
<% if action_name == "index" %>
<div class="navbar-end">
<div class="navbar-item">
<div class="task-search" data-tasks-path="<%= tasks_path %>">
<%= text_field_tag :task_search, nil,
id: "task-search-input",
class: "input",
placeholder: "Search tasks...",
autocomplete: "off",
aria: { label: "Search tasks", autocomplete: "list", controls: "task-search-results" } %>
<div class="task-search-results" id="task-search-results" role="listbox"></div>
</div>
</div>
</div>
<% end %>
</nav>
Loading