towerops/lib/towerops_web/live/site_live/form.html.heex
Graham McIntire a2d96f8e6e
Implement hierarchical agent assignment for SNMP polling
Add three-level agent assignment hierarchy (Equipment > Site > Organization)
allowing flexible agent deployment strategies. Agents now receive only equipment
assigned to them through direct assignment or inheritance from site/organization
defaults.

Key changes:
- Add agent_token_id to Sites table with migration
- Implement get_effective_agent_token/1 for hierarchical resolution
- Add list_agent_polling_targets/1 to return polling targets per agent
- Update API config endpoint to use hierarchical polling targets
- Add agent assignment UI to equipment, site, and organization forms
- Show agent source (direct/site/org/none) in equipment form
- Add equipment count column to agent list
- Update terminology from "poll from server" to "cloud polling"

Tests:
- Add 8 comprehensive tests for list_agent_polling_targets/1
- Add end-to-end test for hierarchical config endpoint
- All 775 tests passing
2026-01-14 08:38:50 -06:00

80 lines
2.8 KiB
Text

<Layouts.authenticated
flash={@flash}
current_scope={@current_scope}
current_organization={@organization}
>
<div class="mb-4">
<.link
navigate={
if @live_action == :edit,
do: ~p"/orgs/#{@organization.slug}/sites/#{@site.id}",
else: ~p"/orgs/#{@organization.slug}/sites"
}
class="inline-flex items-center gap-1 text-sm text-zinc-600 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-100"
>
<.icon name="hero-arrow-left" class="h-4 w-4" />
{if @live_action == :edit, do: "Back to Site", else: "Back to Sites"}
</.link>
</div>
<.header>
{@page_title}
<:subtitle>
{if @live_action == :new,
do: "Add a new site to your organization",
else: "Update site details"}
</:subtitle>
</.header>
<div class="max-w-2xl">
<.form for={@form} id="site-form" phx-change="validate" phx-submit="save">
<.input field={@form[:name]} type="text" label="Site Name" required />
<.input
field={@form[:parent_site_id]}
type="select"
label="Parent Site (optional)"
prompt="No parent site"
options={Enum.map(@available_parent_sites, &{&1.name, &1.id})}
/>
<.input field={@form[:location]} type="text" label="Location" />
<%= if @available_agents != [] do %>
<.input
field={@form[:agent_token_id]}
type="select"
label="Default Agent for Site"
prompt="Inherit from organization"
options={Enum.map(@available_agents, &{&1.name, &1.id})}
/>
<p class="mt-1 text-sm text-zinc-600 dark:text-zinc-400">
Set a default agent for all equipment at this site. Equipment can override this setting individually.
</p>
<% end %>
<.input field={@form[:description]} type="textarea" label="Description" />
<div class="flex gap-3 mt-6">
<.button phx-disable-with="Saving..." variant="primary">Save Site</.button>
<.button navigate={~p"/orgs/#{@organization.slug}/sites"}>Cancel</.button>
</div>
</.form>
<%= if @live_action == :edit do %>
<div class="mt-12 pt-8 border-t border-zinc-200 dark:border-zinc-800">
<h3 class="text-lg font-semibold text-red-600 dark:text-red-500 mb-4">Danger Zone</h3>
<p class="text-sm text-zinc-600 dark:text-zinc-400 mb-4">
Once you delete a site, there is no going back. This will also delete all equipment at this site.
</p>
<.button
phx-click="delete"
data-confirm="Are you sure you want to delete this site? This will also delete all equipment at this site."
variant="danger"
>
<.icon name="hero-trash" class="h-4 w-4" /> Delete Site
</.button>
</div>
<% end %>
</div>
</Layouts.authenticated>