defmodule ToweropsWeb.DeviceLive.Components.BackupsTab do @moduledoc """ LiveComponent for the device MikroTik backups tab. Displays MikroTik configuration backups with download, compare, and backup-now functionality. """ use ToweropsWeb, :live_component alias ToweropsWeb.DeviceLive.Helpers.DataLoaders alias ToweropsWeb.DeviceLive.Helpers.Formatters @impl true def update(assigns, socket) do {:ok, socket |> assign(assigns) |> load_backups_data()} end defp load_backups_data(socket) do device = socket.assigns.device mikrotik_backups = DataLoaders.load_mikrotik_backups(device) socket |> assign(:mikrotik_backups, mikrotik_backups) |> assign(:selected_backup_ids, MapSet.new()) end @impl true def render(assigns) do ~H"""
| <.icon name="hero-check-circle" class="h-4 w-4 mx-auto" /> | Date | Original Size | Compressed Size | Ratio | Source | Actions |
|---|---|---|---|---|---|---|
| = 2 } title={ if MapSet.member?(@selected_backup_ids, backup.id), do: "Selected for comparison", else: if(MapSet.size(@selected_backup_ids) >= 2, do: "Maximum 2 backups can be selected", else: "Select to compare" ) } class="h-4 w-4 rounded border-gray-300 text-blue-600 focus:ring-blue-600 disabled:opacity-50 disabled:cursor-not-allowed dark:border-gray-600 dark:bg-gray-700" /> | {ToweropsWeb.TimeHelpers.format_iso8601(backup.backed_up_at, @timezone)} | {format_bytes(backup.config_size_bytes)} | {format_bytes(backup.compressed_size_bytes)} | {compression_ratio}% | {String.replace(backup.trigger_source, "_", " ") |> String.capitalize()} |
<%= if ToweropsWeb.Permissions.owner?(@current_scope) do %>
<.button
phx-click="delete_backup"
phx-value-id={backup.id}
data-confirm={
t(
"Are you sure you want to delete this backup? This action cannot be undone."
)
}
variant="danger"
>
<.icon name="hero-trash" class="h-4 w-4" /> Delete
<% end %>
|
Automatic backups run daily at {ToweropsWeb.TimeHelpers.format_utc_hour( 7, @timezone )}.
<% else %>{t("Assign an agent to enable automatic backups.")}
<% end %>{t("Enable MikroTik API in device settings to enable configuration backups.")}