defmodule LabelmakerWeb.LabelsHTML do use LabelmakerWeb, :html embed_templates "labels_html/*" def format_size(bytes) when bytes < 1024, do: "#{bytes} B" def format_size(bytes) when bytes < 1024 * 1024, do: "#{Float.round(bytes / 1024, 1)} KB" def format_size(bytes), do: "#{Float.round(bytes / (1024 * 1024), 1)} MB" def format_datetime({{year, month, day}, {hour, minute, second}}) do "#{year}-#{pad(month)}-#{pad(day)} #{pad(hour)}:#{pad(minute)}:#{pad(second)}" end defp pad(num) when num < 10, do: "0#{num}" defp pad(num), do: "#{num}" def pagination_range(current_page, total_pages) do cond do total_pages <= 7 -> # Show all pages if there are 7 or fewer 1..total_pages current_page <= 4 -> # Near the beginning: show first 5, then last [1, 2, 3, 4, 5, :ellipsis, total_pages] current_page >= total_pages - 3 -> # Near the end: show first, then last 5 [1, :ellipsis, total_pages - 4, total_pages - 3, total_pages - 2, total_pages - 1, total_pages] true -> # In the middle: show first, current +/- 1, and last [1, :ellipsis, current_page - 1, current_page, current_page + 1, :ellipsis, total_pages] end end end