ubicloud/views/vm/index.erb
Burak Yucesoy 1dbaef3f72 Merge web and api serializers for vms
Polymorphic authorization checks and options based serializers made serializers
strong enough to format slightly different outputs based on the needs of web
and api endpoints. This commit merges the two vm serializers into one.

There were few notable differences in the two serializers though:
- Web serializer had  storage_encryption field, which was only used to put a
text in the Vm view. Since all user created vms have storage encryption, I
removed this field.
- Web serializer used private_ip4 and private_ip6 fields as opposed to what we
use in the api serializer; private_ipv4 and private_ipv6. I changed the field
names to follow the format in the api serializer.
2024-05-28 21:42:31 +03:00

79 lines
3.4 KiB
Text

<% @page_title = "Virtual Machines" %>
<div class="auto-refresh hidden" data-interval="10"></div>
<% if @vms.count > 0 %>
<div class="space-y-1">
<%== render(
"components/breadcrumb",
locals: {
back: @project_data[:path],
parts: [%w[Projects /project], [@project_data[:name], @project_data[:path]], ["Virtual Machines", "#"]]
}
) %>
<%== render(
"components/page_header",
locals: {
title: "Virtual Machines",
right_items: has_project_permission("Vm:create") ? [
render("components/button", locals: { text: "Create Virtual Machine", link: "vm/create" })
] : []
}
) %>
</div>
<div class="grid gap-6">
<div class="overflow-hidden rounded-lg shadow ring-1 ring-black ring-opacity-5 bg-white divide-y divide-gray-200">
<table class="min-w-full divide-y divide-gray-300">
<thead class="bg-gray-50">
<tr>
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">Name</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Location</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Size</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">Storage Size</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">State</th>
<th scope="col" class="px-3 py-3.5 text-left text-sm font-semibold text-gray-900">IP Address</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
<% @vms.each do |vm| %>
<tr>
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium sm:pl-6" scope="row">
<a href="<%= @project_data[:path] %><%= vm[:path] %>" class="text-orange-600 hover:text-orange-700">
<%= vm[:name] %>
</a>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500"><%= vm[:location] %></td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500"><%= vm[:size] %></td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500"><%= vm[:storage_size_gib] %>
GB</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
<%== render("components/vm_state_label", locals: { state: vm[:state] }) %>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
<% if vm[:ip4] %>
<%== render("components/copieble_content", locals: { content: vm[:ip4], message: "Copied IPv4" }) %>
<% else %>
<%== render("components/copieble_content", locals: { content: vm[:ip6], message: "Copied IPv6" }) %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<% else %>
<%== render(
"components/empty_state",
locals: {
icon: "hero-server-stack",
title: "No virtual machines",
description: "You don't have permission to create virtual machines."
}.merge(has_project_permission("Vm:create") ? {
description: "Get started by creating a new virtual machine.",
button_link: "#{@project_data[:path]}/vm/create",
button_title: "New Virtual Machine"
} : {})
) %>
<% end %>