ubicloud/views/admin/index.erb
Jeremy Evans 5042633bb0 Support table-based model browsing and model searching on admin site using AutoForme
Table-based model browsing can be friendlier than the unordered list display
currently used on the admin site. However, you need to be careful to not
introduce N+1 queries when using table-based browsing.

AutoForme is a library that builds on top of Forme (already used on the
admin site) and provides the ability to browse and search the models in a
way that avoids N+1 queries.  It's quite flexible, requiring only a few
lines of configuration code per model to have it display and allow
searching of the columns desired.

AutoForme also supports CRUD actions for models, but those are currently
disabled, and it is only used for the tabular display and searching.
It also supports downloading of data in CSV format (both in browse and
search mode), which can be useful with external analysis tools.

One potential regression with the AutoForme based browsing and searching
is the use of offsets for pagination, instead of using a filter. If this
becomes problematic, it's possible to add filter-based pagination to
AutoForme.

While it is possible to implement table-based browsing without using
AutoForme, it would require reimplementing parts of AutoForme, and I
think using AutoForme will result in smaller and simpler code in the
long run.

Currently, this only implements the table-based browsing for Firewall
as a proof of concept. We can expand it to other models in the future.
2025-09-18 02:29:42 +09:00

61 lines
1.7 KiB
Text

<% @content_class = "" %>
<% unless @grouped_pages.empty? %>
<table class="page-table">
<caption>Active Pages</caption>
<thead>
<tr>
<th>VmHost</th>
<th>UBID</th>
<th>Created At</th>
<th>Summary</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<% @grouped_pages.sort_by { |k,| k || "z" }.each do |vmh_ubid, pages| %>
<% pages.each_with_index do |page, index| %>
<tr>
<% if index == 0 %>
<td rowspan="<%= pages.size %>">
<% if vmh_ubid %>
<a href="/model/VmHost/<%= vmh_ubid %>"><%= vmh_ubid %></a>
<% end%>
</td>
<% end %>
<td><a href="/model/Page/<%= page.ubid %>"><%= page.ubid %></a></td>
<td><%= page.created_at.strftime("%F %T") %></td>
<td><%= page.summary %></td>
<td><%== h(page.details).gsub(/\b[a-tv-z0-9]{26}\b/) do
if (klass = UBID.class_for_ubid(it))
"<a href=\"/model/#{klass}/#{it}\">#{it}</a>"
else
it
end
end %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<% end %>
<div class="container">
<h2>Browse by Model Class</h2>
<ul id="model-class-list">
<% autoforme_models = self.class.autoforme_models %>
<% @classes.each do |klass| %>
<li><a href="<%= autoforme_models[klass.to_s] ? "/autoforme/#{klass}/browse" : "/model/#{klass}" %>"><%= klass %></a></li>
<% end %>
</ul>
<h2 class="container">Manage</h2>
<ul>
<li><a href="/change-password">Change Password</a></li>
<li><a href="/multifactor-manage">Manage Multifactor Authentication</a></li>
</ul>
</div>