Skip to content

Commit a6deb15

Browse files
committed
Scaffold module browser
1 parent 3271f62 commit a6deb15

File tree

8 files changed

+104
-0
lines changed

8 files changed

+104
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class ModuleBrowserController < ApplicationController
4+
def index
5+
# FIXME: select clusters from Configuration.job_clusters
6+
@clusters = OodAppkit.clusters.select(&:job_allow?).reject { |c| c.metadata.hidden }
7+
@selected_clusters = params[:cluster]
8+
@modules = @clusters.flat_map do |cluster|
9+
HpcModule.all(cluster.id).each { |mod| mod.cluster = cluster.id }
10+
end
11+
@modules = @modules.group_by(&:name)
12+
end
13+
end

apps/dashboard/app/models/hpc_module.rb

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def all_versions(module_name)
3232
end
3333

3434
attr_reader :name, :version, :hidden
35+
attr_accessor :cluster
3536
alias hidden? hidden
3637

3738
def initialize(name, version: nil, hidden: false)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<ul class="nav nav-tabs mt-3" id="tabs-<%= name_id %>" role="tablist">
2+
<% clusters.each_with_index do |cluster, cidx| %>
3+
<% cluster_id = cluster.to_s.parameterize %>
4+
<li class="nav-item" role="presentation">
5+
<button class="nav-link <%= 'active' if cidx == 0 %>" id="tab-<%= name_id %>-<%= cluster_id %>" data-bs-toggle="tab" data-bs-target="#tab-pane-<%= name_id %>-<%= cluster_id %>" type="button" role="tab">
6+
<%= cluster.to_s.titleize %>
7+
</button>
8+
</li>
9+
<% end %>
10+
</ul>
11+
12+
<div class="tab-content p-3 border border-top-0">
13+
<% clusters.each_with_index do |cluster, cidx| %>
14+
<% cluster_id = cluster.to_s.parameterize %>
15+
<div class="tab-pane fade <%= 'show active' if cidx == 0 %>" id="tab-pane-<%= name_id %>-<%= cluster_id %>" role="tabpanel">
16+
<div class="d-flex flex-wrap gap-2">
17+
<% sorted_versions.select { |v| v.cluster == cluster }.each do |mod| %>
18+
<span class="badge bg-secondary p-2"><%= mod.version || "default" %></span>
19+
<% end %>
20+
</div>
21+
</div>
22+
<% end %>
23+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<%# TODO: Search, filter by cluster/architecture, sort %>
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<% sorted_versions = versions.sort_by(&:version).reverse %>
2+
<% latest_version = sorted_versions.first %>
3+
<% clusters = versions.map(&:cluster).uniq %>
4+
5+
<% if selected_clusters.blank? || clusters.include?(selected_clusters) %>
6+
<% name_id = name.to_s %>
7+
<tr>
8+
<td class="text-center">
9+
<button class="btn btn-sm border-0" type="button" data-bs-toggle="collapse" data-bs-target="#collapse-<%= name_id %>">
10+
>
11+
</button>
12+
</td>
13+
<td><%= name %></td>
14+
<td>
15+
<%= latest_version.version || "default" %>
16+
<% if sorted_versions.size > 1 %>
17+
<span class="text-muted small">(<%= sorted_versions.size - 1 %> others)</span>
18+
<% end %>
19+
</td>
20+
<%# TODO: Add desc after extending HpcModule %>
21+
<td><%= "No description available" %></td>
22+
<td><%= clusters.map { |c| c.to_s.titleize }.join(", ") %></td>
23+
</tr>
24+
25+
<tr class="collapse bg-light" id="collapse-<%= name_id %>">
26+
<td colspan="5">
27+
<div class="p-3">
28+
<strong>Available Modules:</strong>
29+
30+
<%= render 'cluster_tabs', name_id: name_id, clusters: clusters, sorted_versions: sorted_versions %>
31+
32+
<hr>
33+
34+
<%# TODO: Change module load command to use selected version %>
35+
<strong>Load module:</strong>
36+
<div><code>module load <%= latest_version.to_s %></code></div>
37+
38+
</div>
39+
</td>
40+
</tr>
41+
<% end %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div class="table-responsive">
2+
<table class="table">
3+
<thead class="table-light">
4+
<tr>
5+
<th></th>
6+
<th>Name</th>
7+
<th>Version(s)</th>
8+
<th>Description</th>
9+
<th>Clusters</th>
10+
</tr>
11+
</thead>
12+
<tbody id="moduleTable">
13+
<% modules.sort.each_with_index do |(name, versions), index| %>
14+
<%= render 'module_row', name: name, versions: versions, selected_clusters: selected_clusters %>
15+
<% end %>
16+
</tbody>
17+
</table>
18+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<h1 class="mb-4">Module Browser</h1>
2+
3+
<%= render 'filters' %>
4+
<%= render 'module_table', modules: @modules, selected_clusters: @selected_clusters %>

apps/dashboard/config/routes.rb

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@
128128
match '/404', :to => 'errors#not_found', :via => :all
129129
match '/500', :to => 'errors#internal_server_error', :via => :all
130130

131+
get 'module_browser' => 'module_browser#index', :as => 'module_browser'
132+
131133
# The priority is based upon order of creation: first created -> highest priority.
132134
# See how all your routes lay out with "rake routes".
133135

0 commit comments

Comments
 (0)